1.17.1 My item listeners are not working.

Discussion in 'Spigot Plugin Development' started by xDParsi64, Oct 15, 2021.

  1. This is supposed to make the player go flying when they jump, however it doesn't, it also is meant to stop fall damage but doesn't...



    Code (Text):


    package custom.main.events;

    import custom.main.items.ItemManager;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.player.PlayerMoveEvent;

    public class GodBootsEvent implements Listener {


          // Player gets sent flying when they jump
        @EventHandler
        public void onJump(PlayerMoveEvent event) {
            Player player = (Player) event.getPlayer();
            if (player.getInventory().getBoots() != null)
                if (player.getInventory().getBoots().getItemMeta().equals(ItemManager.godboots))
                    if (player.getInventory().getBoots().getItemMeta().hasLore())
                        if (event.getFrom().getY() < event.getTo().getY() &&
                                player.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.AIR) {
                            player.setVelocity(player.getLocation().getDirection().multiply(2).setY(2));
                        }
        }
        // Player doesn't take fall damage if they do.
        @EventHandler
        public void onFall(EntityDamageEvent event) {
            if (event.getEntity() instanceof Player) {
                Player player = (Player) event.getEntity();
                if (event.getCause() == EntityDamageEvent.DamageCause.FALL) {
                    if (player.getInventory().getBoots() != null)
                        if (player.getInventory().getBoots().getItemMeta().equals(ItemManager.godboots))
                            if (player.getInventory().getBoots().getItemMeta().hasLore()) {
                                event.setCancelled(true);
                            }
                }
            }
        }
    I would really appreciate if anyone could fine the problem here, thank you
     
  2. Listener registered?
     
  3. Since you're using 1.17, you can use the PersistentDataContainer of the item to store the item's data - you should use this instead of using the item meta to check whether the item is the item you want.