Solved Linking classes help.

Discussion in 'Plugin Development' started by Mitchelll, Feb 14, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Mitchelll

    So, I have a plugin called "Super Saiyan Transformations." and in that plugin has it's own timer. Now, the old timer for some reason wont work in multiple classes, so I decided to look around and try to make a dynamic cooldown class for my plugin. So far it's worked, but now I have to call the methods from the cooldown class in other multiple classes that need to use this. Now, I've tried fixing it, but to no avail. I'll post these classes that need to use this cooldown method.

    SSJ_Command class
    Code:
    public class SSJ_Command extends JavaPlugin {
     
        HashMap<String, Integer> map = new HashMap<String, Integer>();
     
        public void onEnable() {
            PluginManager pm = Bukkit.getServer().getPluginManager();
            getCommand("ssg").setExecutor(new SSG_Command(this));
            getCommand("kaioken").setExecutor(new KAIOKEN_Command(this));
            pm.registerEvents(new Listeners(this), this);
            pm.registerEvents(new Cooldown(this), this);
            getLogger().info("Super Saiyan has been ENABLED");
        }
    
        public void onDisable() {
            getLogger().info("Super Saiyan has been DISBLED");
        }
     
    (cmd.getName().equalsIgnoreCase("Potential") && player.hasPermission("ssj.builder")) {
                    if (args.length == 0) {
                        player.sendMessage(ChatColor.RED + "Correct Ussage: /potential unleashed");
                    } else if (args[0].equalsIgnoreCase("unleashed") && player.hasPermission("ssj.potential")) {
                        if (map.containsKey(player.getName())) {
                            player.sendMessage(ChatColor.RED
                                    + "You are still on cooldown for another "
                                    + getTimeLeft(player, map) + " seconds!");
                        } else {
    // some code here
                        setCooldownLength(player, 30, map);
                        startCooldown(player, map);
                        }
                    }
                }
    SSG_Command class
    Code:
    public class SSG_Command implements CommandExecutor {
    
        HashMap<String, Integer> map = new HashMap<String, Integer>();
    
        public SSG_Command(SSJ_Command ssj_Command) {
            // TODO Auto-generated constructor stub
        }
    
                if (cmd.getName().equalsIgnoreCase("ssg") && player.hasPermission("ssj.ssg")) {
                    if (args.length == 0) {
                        player.sendMessage(ChatColor.RED + "Correct Ussage: /ssg [ID]");
                        player.sendMessage(ChatColor.RED + "Correct Ussage: /ssj list");
                    } else if (args[0].equalsIgnoreCase("1") && player.hasPermission("ssj.ssg1")) {
                        if (map.containsKey(player.getName())) {
                            player.sendMessage(ChatColor.RED + "You are still on cooldown for another "
                                    + getTimeLeft(player, map) + " seconds!");
                        } else {
    //some code here
                            setCooldownLength(player, 30, map);
                            startCooldown(player, map);
                        }
    KAIOKEN_Command Class
    Code:
                public class KAIOKEN_Command implements CommandExecutor, Plugin{
     
        HashMap<String, Integer> map = new HashMap<String, Integer>();
     
        public KAIOKEN_Command(SSJ_Command ssj_Command) {
            // TODO Auto-generated constructor stub
        }             
    
    if (cmd.getName().equalsIgnoreCase("kaioken")) {
                    if (args.length == 0) {
                        player.sendMessage(ChatColor.RED + "Correct Ussage: /kaioken x[ID]");
                        player.sendMessage(ChatColor.RED + "Correct Ussage: /ssj list");
    } else if (args[0].equalsIgnoreCase("x1") && player.hasPermission("ssj.x1")) {
                        if (map.containsKey(player.getName())) {
                            player.sendMessage(ChatColor.RED + "You are still on cooldown for another "
                                    + getTimeLeft(player, map) + " seconds!");
                        } else {
            //some code here
                            setCooldownLength(player, 30, map);
                            startCooldown(player, map);
                        }
    Cooldown class
    Code:
    public class Cooldown implements Listener{
        
    
    
    
        int task;
        public SSJ_Command p;
    
        public Cooldown(SSJ_Command i) {
            p = i;
        }
    
        public void setCooldownLength(Player player, int time, HashMap<String, Integer> hashmap) {
            hashmap.put(player.getName(), time);
        }
        public int getTimeLeft(Player player, HashMap<String, Integer> hashmap) {
            int time = hashmap.get(player.getName());
            return time;
        }
        @SuppressWarnings("deprecation")
        public void startCooldown(final Player player, final HashMap<String, Integer> hashmap) {
            task = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(p, new BukkitRunnable() {
                public void run() {
                    int time = hashmap.get(player.getName());
                    if(time != 0) {
                        hashmap.put(player.getName(), time - 1);
                    } else {
                        hashmap.remove(player.getName());
                        Bukkit.getServer().getScheduler().cancelTask(task);
                    }
                }
            }, 0L, 20L);
        }
    }
    So, my question here is; how do I call the methods from the cooldown class to all of these command classes without causing any more errors in the code?
     
Thread Status:
Not open for further replies.

Share This Page