hello I have 2 variables, "left" and "max" left = Players that are within max = Maximum players that can enter as I can do that when "left" is equal to "max" run an action such as a minigame is initiated or command I have already tried: Code (Text): if (left == max) { // action } but it does not work, I have to put on Main class or another class? thanks Main class 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 left = String.valueOf(0); 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("&", "§")); if (String.valueOf(0) == max) { Bukkit.broadcastMessage("TEST"); } if } 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(); }
Code (Text): if (String.valueOf(0) == max) { Bukkit.broadcastMessage("TEST"); } Holy crap? Why initialize "left" as a String "0"? Just do: Code (Text): int left = 0; And max is a integer, why do you want to test it as a String??? Just do: Code (Text): if(0 == max) { ... } And please learn Java better To compare strings you have to use: Code (Text): "somestring".equals("someotherstring")
You can't compare two strings with ==, you have to use String#equals(). However, if you only want to store numbers, you can use int instead of string.