Messages Being Sent Twice

Discussion in 'Spigot Plugin Help' started by MaxNatural, May 28, 2016.

  1. I right click the NPC and it sends the message twice.
    I just need it to send once.

    Thank you!

    Code (Text):
        private Random random = new Random();
       
        @EventHandler
        public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent e) {
            Entity entity = e.getRightClicked();
            if (entity instanceof Zombie) {
                String output = null;
               
                Player player = e.getPlayer();
               
                switch (this.random.nextInt(10)) {
                case 0:
                        player.sendMessage(Hub.rita + "Test1");
                case 1:
                        player.sendMessage(Hub.rita + "Test2");
                }
            } else {
                e.setCancelled(true);
            }
        }
       
     
  2. Are you registering the event twice?
     
  3. I have the event registered and command registered

    Code (Text):
            Bukkit.getServer().getPluginManager().registerEvents(new NPC(this), this);

    this.getCommand("npc").setExecutor(new NPC(this));
     
  4. You need a break; to end each condition in your switch statement. That might help.
     
  5. It worked for the first two and I added more... Now it sends two messages again.

    Code (Text):
        @EventHandler
        public void onPlayerInteractEntityEvent(PlayerInteractEntityEvent e) {
            Entity entity = e.getRightClicked();
            if (entity instanceof Zombie) {
                String output = null;
               
                Player player = e.getPlayer();
               
                switch (this.random.nextInt(9)) {
               
                case 0:
                        player.sendMessage(Hub.npc + "Message1");
                break;
               
                case 1:
                        player.sendMessage(Hub.npc + "Message2");
                break;
               
                case 2:
                    player.sendMessage(Hub.npc + "Message3");
                break;
               
                case 3:
                    player.sendMessage(Hub.npc + "Message4");
                break;
               
               
                case 4:
                    player.sendMessage(Hub.npc + "Message5!");
                break;
               
               
                case 5:
                    player.sendMessage(Hub.npc + "Message6");
               
                break;
               
               
                case 6:
                    player.sendMessage(Hub.npc + "Message7");
                break;
               
               
                case 7:
                    player.sendMessage(Hub.npc + "Message8");
                break;
               
               
                case 8:
                    player.sendMessage(Hub.npc + "Message9");
                break;
               
               
                }
            } else {
                e.setCancelled(true);
            }
        }