Event not working?

Discussion in 'Programming' started by MrCelsius88, Jul 11, 2021.

  1. Hi! I am very new to making minecraft plugins, however I have a little bit of experience with java coding. I am trying to have it so that when I right click on an armor stand (with an empty hand) it will take me to a different world, but it seems like the event is not even being executed, does someone know what I am doing wrong?

    Code (Java):
     @EventHandler
        public void rightClickArmorStand(PlayerInteractAtEntityEvent e) {
            //get player
            Player player = e.getPlayer();
                if(e.getRightClicked().getType() == EntityType.ARMOR_STAND){
                    //Loops through every entity
                    for(LivingEntity entity : player.getWorld().getLivingEntities()){
                        //check what duel the entity is named
                        if(entity.getCustomName() == "Classic Duels") {
                            player.sendMessage("Going to classic duels");
                            queForClassic = 1;
                            Queue();
                            break;
                        }
                        else if(entity.getCustomName() == "Sumo Duels") {
                            player.sendMessage("Going to sumo duels");
                            queForSumo = 1;
                            Queue();
                            break;
                        }
                    }
                }
            }    
    EDIT: Yes the onEnable and onDisable events are working
     
  2. You're comparing strings using == instead of #equals.
    Why do you need to loop over all entities to send a player to a world?
     

  3. Hello,
    please make sure your event is working.

    put below this
    Code (Java):
     if(e.getRightClicked().getType() == EntityType.ARMOR_STAND){
    a simple debug message like System.out.println("clicked");

    Then tell me if it appears in the console when you click on the stand.
     
  4. you should use something like this @EventHandler (priority = EventPriority.NORMAL)
     
  5. Code (Java):
    public class Main {

       public void onEnable() {
            Bukkit.getPluginManager.registerEvents(new classwithlistener(), this);
        }

    }
    you need to register the events in your onenable aka your Main class that extends JavaPlugin
     
  6. Strahan

    Benefactor

    Normal is the default, so explicitly setting it is pointless.