Solved Scoreboard toggling

Discussion in 'Plugin Development' started by Ezrab_, Aug 9, 2018.

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


    I would like to toggle a scoreboard in bukkit by using a command '/sb toggle'. However I can't seem to make it work because the compiler keeps looping through the code. So if I remove a key from the ArrayList, the compiler will continue it's executing which isn't what I want.

    2. // Creating the ArrayList to store the data.
    4. ArrayList<UUID> toggle = new ArrayList<>();
    6. // Checking if it contains the player's UUID.
    8. if (toggle.contains(p.getUniqueId())) {
    10. // Removing the UUID from the ArrayList to turn the scoreboard off.
    11. toggle.remove(p.getUniqueId());
    12. p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
    13. p.sendMessage(Main.msg + ChatColor.RED + "Scoreboard turned off.");
    14. } else {
    15. // Adding the UUID again to the ArrayList so that we it can turn on.
    16. toggle.add(p.getUniqueId());
    17. SideScoreboard.getInstance().setScoreboardPlayer(p);
    18. p.sendMessage(ChatColor.GREEN + "Scoreboard turned on.");
    19. }

    So the problem is that it keeps telling me that the Scoreboard is turned on. When it really should just toggle between off and on each time I execute the command.

    EDIT : Had to make the ArrayList global, silly from me.
    Last edited: Aug 9, 2018
Thread Status:
Not open for further replies.

Share This Page