Interact issues

Discussion in 'Plugin Development' started by BoulYT, Dec 31, 2018.

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

    BoulYT

    I would like to ask if the player has the compass in his hand and if so the inventory should open
    Does not work. Please help
    translated by Google

    Code:
    package de.boulyt.lobby.listeners;import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.inventory.InventoryType;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.Inventory;
    
    public class NavigatorListener implements Listener {
    
        @EventHandler
        public void ballFiring(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Action a = event.getAction();
            if ((a == Action.PHYSICAL) || (event.getItem() == null) || (event.getItem().getType() == Material.COMPASS)) {
                Inventory inventory = Bukkit.createInventory(null, InventoryType.BREWING, "§aNavigator");
                player.openInventory(inventory);
            }
    
        }
    
    }
    
     
    Last edited by a moderator: Dec 31, 2018
  2. Offline

    timtower Administrator Administrator Moderator

    @BoulYT Did you register the event?
     
  3. You should add this line to prevent your event to be called twice, maybe that should help

    if (event.getHand().equals(EquipmentSlot.HAND))
    {

    }

    Try to add System.out.println("") something to see if your event is called too
     
  4. Offline

    Escad

    The action is only physical if you're interacting with pressure plates, tripwire hooks, etc. Instead, check if it's Action.RIGHT_CLICK_BLOCK or Action.RIGHT_CLICK_AIR
     
Thread Status:
Not open for further replies.

Share This Page