I have an autobroadcast feature in my plugin however im seeing a problem that players want to sometimes turn that feature off but i cant figure our how to actually toggle it on and off with a command. this is what i thought would work: Code: (onEnable section) this.interval = getConfig().getInt("Interval"); List<String> tempArray = getConfig().getStringList("Broadcasts"); List<String> bList = new ArrayList(); for (String s : tempArray) { bList.add(ChatColor.translateAlternateColorCodes('&', s)); this.stopChat = false; } this.broadcasts = bList; Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() { public void run() { Main.this.broadcast(); } }, 0L, this.interval * 20); } private void broadcast() { if (this.stopBC = false) { this.line += 1; if (this.line > this.broadcasts.size() - 1) { this.line = 0; } Bukkit.broadcastMessage((String)this.broadcasts.get(this.line)); return; } if (this.stopBC = true) { return; } onCommand section } if ((command.getName().toLowerCase().equalsIgnoreCase("stopbc")) && ( (sender.hasPermission("chatadmin.broadcasts.stop")) || (sender.isOp()))) { if (this.stopBC) { sender.sendMessage("You have started the Broadcasts."); this.stopBC = false; return true; } sender.sendMessage(ChatColor.RED + "You have stopped the Broadcasts."); this.stopBC = true; return true; }
First, your onCommand section doesn't use an else statement. You're turning stopBC to false and then back on again! Add an else statement and that should be it.
so? Code: private void broadcast() { if (this.stopBC = false) { this.line += 1; if (this.line > this.broadcasts.size() - 1) { this.line = 0; } Bukkit.broadcastMessage((String)this.broadcasts.get(this.line)); return; } else if (this.stopBC = true) { return; } When i do that i get an error on the second return; and it doesnt tell me why.
I just saw it, you have "this.stopBC = false" when it should be "this.stopBC == false". I have made this mistake multiple times and can be overlooked easily.