Solved sendMessage shows twice in chat

Discussion in 'Bukkit Help' started by PikaThieme, Jan 16, 2017.

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

    PikaThieme

    So I was making a plugin with a sendmessage in it. Everything works fine except 1 thing. The sendMessage displayes twice when it should just go once. I tought that it'd be a bug from spigot or something.
    Hope you guys can help me :)

    Code:
    Code:
    package main.pikathieme.eeneentwee.events;
    
    import org.bukkit.ChatColor;
    import org.bukkit.GameMode;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.event.player.PlayerInteractAtEntityEvent;
    import org.bukkit.event.inventory.*;
    
    public class Openinv implements Listener {
        @EventHandler
        public void PopoInvTake(PlayerInteractAtEntityEvent e) {
            if (e.getRightClicked() instanceof Player) {
              
                Player p = e.getPlayer();
              
                if  (p.hasPermission("minetopia.invsee")) {
                    Player r = (Player)e.getRightClicked();
                    if (!r.hasPermission("minetopia.invdeny") || r.getGameMode() != GameMode.CREATIVE) {
                    p.openInventory(r.getInventory());
                    r.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + ChatColor.WHITE + "" + ChatColor.BOLD + "112" + ChatColor.BLUE + "" + org.bukkit.ChatColor.BOLD + "] " + ChatColor.RED + p.getName() + ChatColor.WHITE + " kijkt in je inventory!");
                    p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + ChatColor.WHITE + "" + ChatColor.BOLD + "112" + ChatColor.BLUE + "" + ChatColor.BOLD + "] " + ChatColor.WHITE + "Je kijkt nu in de inventory van " + ChatColor.RED + r.getName() + ChatColor.WHITE + "!");
                    }
                    else{
                        p.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "[" + ChatColor.WHITE + "" + ChatColor.BOLD + "112" + ChatColor.BLUE + "" + org.bukkit.ChatColor.BOLD + "] " + ChatColor.RED + "Je hebt geen permissie om in de inventory van " + ChatColor.WHITE + r.getName() + ChatColor.RED + " te kijken!");
                    }
                }
                
            }
        }
        @EventHandler
        public void ClickEvent(InventoryClickEvent e) {
            if (e.getClickedInventory().getType() == (InventoryType.PLAYER) && !e.getClickedInventory().equals(e.getWhoClicked().getInventory())) {
                if (!e.getWhoClicked().hasPermission("minetopia.invtake")) {
                    e.setCancelled(true);
                }
            }
        }
        
    }
     
    Last edited by a moderator: Jan 16, 2017
  2. Offline

    Zombie_Striker

    @PikaThieme
    It's not really a "Bug". PlayerInteractWithEntityEvent is triggered twice because it runs for both hands. If you only want it to trigger once, make sure the it is only running for the right hand.
     
  3. Offline

    PikaThieme

    removed
     
    Last edited: Jan 20, 2017
  4. Offline

    Zombie_Striker

    @PikaThieme
    edit

    If(e.getHand == EquipmentSlot.HAND){
    //do stuff
    }
     
  5. Offline

    PikaThieme

    Removed
     
    Last edited: Jan 20, 2017
  6. Offline

    timtower Moderator Moderator

    @PikaThieme Remove the semicolon after the if statement
    if(e.getHand() == EquipmentSlot.HAND); {
     
  7. Offline

    PikaThieme

    @timtower I already figured it out but still thanks ;)
     
  8. Offline

    timtower Moderator Moderator

    @PikaThieme Then please mark the thread as solved if it is.
     
  9. Offline

    PikaThieme

    @timtower I only need to test it but I will do that when I'm home :p
     
Thread Status:
Not open for further replies.

Share This Page