hello, how could I do this?

Discussion in 'Spigot Plugin Development' started by RuloGamer, May 17, 2015.

  1. I am creating a plugin that has the option "AutoRun"
    in OnEnable if "AutoRun" is true a command that opens a tournament running, I have the following variables: "left" and "max"

    as I can do so when "left" is equal to "max" run an action (start a tournament)?

    Code (Text):
        @Override
        public void onEnable() {
            instance = this;
             File configFile = new File(getDataFolder(), "config.yml");
            if (!configFile.exists()) {
            saveDefaultConfig();
            }
            getServer().getPluginManager().registerEvents(new TListener(), this);
            getCommand("tpvp").setExecutor(new TCommand());
            if (getConfig().get("save.mysaveditems") != null) {
                for(String key : getConfig().getConfigurationSection("save.mysaveditems.").getKeys(false)) {
                    ItemStack[] value = ((List<ItemStack>) getConfig().get("save.mysaveditems." + key)).toArray(new ItemStack[0]);
                    mySavedItems.put(key, value);
                }
            }
         
            if (instance.getConfig().getBoolean("settings.AutoRun.enable") == true) {
                Bukkit.getLogger().info("[TournamentPvP] AutoRun is Enable");
                int players = instance.getConfig().getInt("settings.AutoRun.players");
                instance.place = players;
                BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
                scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                    @Override
                    public void run() {
                        int max = instance.getConfig().getInt("settings.AutoRun.players");
                        if (!instance.start && !instance.open) {
                            String kit = instance.getConfig().getString("settings.AutoRun.kit");
                            if (instance.getConfig().contains("location1") || instance.getConfig().contains("location2")) {
                                if (instance.getConfig().contains("kits." + kit)) {
                                    instance.open = true;
                                    instance.kit = kit;
                                    instance.place = max;
                                    String announce = instance.getConfig().getString("messages.announce").replace("<playerleft>", String.valueOf(left)).replace("<playermax>", String.valueOf(max)).replace("<kit>", kit).replaceAll("&", "§");
                                    Bukkit.getServer().broadcastMessage(instance.getConfig().getString("setting.PrefixMessages") + announce.replaceAll("&", "§"));
                                } else {
                                    Bukkit.getServer().broadcastMessage(instance.getConfig().getString("messages.NonExistentKit").replace("<kit>", kit).replaceAll("&", "§"));
                                }
                            } else {
                                Bukkit.getServer().broadcastMessage(instance.getConfig().getString("messages.NonExistentSpawn").replaceAll("&", "§"));
                            }
                        }
                    }
                }, getConfig().getInt("settings.AutoRun.time")*20L, getConfig().getInt("settings.AutoRun.time")*20L);
            } else {
                Bukkit.getLogger().info("[TournamentPvP] AutoRun is Disable");
            }
         
            getConfig().set("save", null);
            saveConfig();
        }
    thanks
     
  2. Are you saying you don't know how to compare numbers?
     
  3. konsolas

    Supporter

    if(left == max)

    :/
     
  4. if (left == max);

    but I could say where to put it, because I try onEnable within the code and not detected D:
     
  5. Oh :p, well you can put a left int within your scheduler(but not inside the method!), set it to 0 and increase it on each call, when the time left is equal to max you can do stuff(and also cancel the scheduler)
     
  6. I'm sorry, I did not quite understand D: I could explain it better? :)

    I speak Spanish and not much English :C
     
  7. Inside your Runnable, put "int left = 0;" (make sure to not put it in run()), and inside the run() call left++;(or ++left; or left += 1; :p), then check if left == max, and then do stuff