Solved PlayerInteract Event

Discussion in 'Plugin Development' started by greeves12, Oct 6, 2017.

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

    greeves12

    Basically what I'm trying to do is have an item that you can click that will make all the players disappear and then it will replace that item with a new item that will enable players again. My issue is, when I click on the redstone, it disables players and replaces it with glowstone, however, when I click on the glowstone, it stays glowstone but prints out the message "Players have reappeared" and then "Players have vanished". How could I fix that?

    Code:
     if(action == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.GLOWSTONE_DUST){
                    for(Player ps : Bukkit.getOnlinePlayers()){
                        p.showPlayer(ps);
                        p.sendMessage(Main.prefix + "§bPlayers have reappeared");
                    }
                    ItemStack hidePlayer1 = new ItemStack(Material.REDSTONE);
                    ItemMeta hidePlayerMeta1 = hidePlayer1.getItemMeta();
                    hidePlayerMeta1.setDisplayName("§e§lHide Players");
                    hidePlayer1.setItemMeta(hidePlayerMeta1);
                    p.getInventory().setItemInHand(hidePlayer1);
    
                    e.setCancelled(true);
                }
                if(action == Action.RIGHT_CLICK_AIR && p.getItemInHand().getType() == Material.REDSTONE){
                    for(Player ps : Bukkit.getOnlinePlayers()){
                        p.hidePlayer(ps);
                        p.sendMessage(Main.prefix + "§aPlayers have vanished");
                    }
                    ItemStack enablePlayer = new ItemStack(Material.GLOWSTONE_DUST);
                    ItemMeta enableMeta = enablePlayer.getItemMeta();
                    enableMeta.setDisplayName("§2Enable Players");
                    enablePlayer.setItemMeta(enableMeta);
                    p.getInventory().setItemInHand(enablePlayer);
    
                    e.setCancelled(true);
                }



    EDIT: To whom it might concern. I solved it myself by adding an else if statement instead of a regular if
     
    Last edited: Oct 6, 2017
Thread Status:
Not open for further replies.

Share This Page