Toggle nightvision

Discussion in 'Plugin Development' started by Random_Tomato, Jun 3, 2017.

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

    Random_Tomato

    Hey Everyone, I am working on another part of my plugin, and I have a major issue, basically when the /nightvision command is toggled if their are multiple people on at once the command glitches out. Is there a way to make it so each player is separate and it isn't all joined as one.

    Code:
    public class Vision implements CommandExecutor {
        public boolean isReaching = false;
        
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
                    Player player = (Player) sender;
                    if(cmd.getName().equalsIgnoreCase("nightvision")){
                    if(!isReaching){
                    isReaching = true;
                    player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 1000000, 0));
                    player.sendMessage(ChatColor.GOLD + "Night Vision:" + ChatColor.GREEN + "" + ChatColor.BOLD + " Enabled!");
                    }
                    else if(isReaching){
                    isReaching = false;
                    player.removePotionEffect(PotionEffectType.NIGHT_VISION);
                    player.sendMessage(ChatColor.GOLD + "Night Vision:" + ChatColor.RED + "" + ChatColor.BOLD + " Disabled!");
                     }
                    else {
                    return false;
                 }
             }
           return false;         
        }
    }
    Thank you for your time looking at this thread
    - Random
     
  2. Offline

    Horsey

    What do you mean 'glitches out'? please be more specific.
     
  3. Offline

    YoloSanta

    This code looks very similar, if you stole this online please just stop what your doing, also don't add a player join delay on this plugin make a separate plugin for that.
     
  4. Offline

    Horsey

    The problem with your code is that you have only one Boolean for the entire server. Use a hashmap with UUIDs as the key and booleans as the value. Then when you need to get whether a player has night vision enabled, just get the Boolean using their UUID
     
  5. Offline

    timtower Administrator Administrator Moderator

    @Horsey Or a list with uuids and contains.
     
Thread Status:
Not open for further replies.

Share This Page