右键单击一个项目

On right click of an Item

我正在尝试重制 Hypixel Skyblock,我正在尝试制作一把可以传送你前进的剑。我不需要这方面的帮助,但我需要这方面的帮助:我放了一些测试代码,只是为了看看它是否有效,但它没有

@EventHandler(priority=EventPriority.HIGH)
    public void onPlayerUse(PlayerInteractEvent event){
        Player p = event.getPlayer();
        World world = p.getWorld();
        Location pLocation = p.getLocation();
        Location tLocation = new Location(world, pLocation.getX(), pLocation.getY() + 2, pLocation.getZ());
     
        if(p.getItemInHand() == ItemUtils.Aspect_Of_The_End()){
            p.teleport(tLocation);
        }
    }

但是当我右击时,它不会向上传送 2 个方块,我不知道为什么。

这是项目本身的代码:

public static ItemStack Aspect_Of_The_End()
{
        ItemStack Aspect_Of_The_End = new ItemStack(Material.DIAMOND_SWORD);
        ItemMeta itemMeta_aote = Aspect_Of_The_End.getItemMeta();
        itemMeta_aote.setDisplayName(ChatColor.BLUE + "Aspect Of The End");
        itemMeta_aote.addItemFlags(ItemFlag.HIDE_ENCHANTS);
        itemMeta_aote.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
        List<String> l = new ArrayList<String>();
        l.add(Utils.chat("&7") + "Damage: " + Utils.chat("&c") + "+100");
        l.add(Utils.chat("&7") + "Strength: " + Utils.chat("&c") + "+100");
        l.add(" ");
        l.add(Utils.chat("&6") + "Item Ability: Instant Transmission " + Utils.chat("&e") + "RIGHT CLICK");
        l.add(Utils.chat("&7") + "Teleport " + Utils.chat("&a") + "8 blocks " + Utils.chat("&7") + "ahead of");
        l.add(Utils.chat("&7") + "you and gain " + Utils.chat("&a") + "+50 " + Utils.chat("&f") + "✦ Speed");
        l.add(Utils.chat("&7") + "for " + Utils.chat("&a") + "3 seconds.");
        l.add(Utils.chat("&8") + "Mana Cost: " + Utils.chat("&3") + "50");
        l.add(" ");
        l.add(Utils.chat("&9") + "RARE SWORD");
        itemMeta_aote.setLore(l);
        Aspect_Of_The_End.setItemMeta(itemMeta_aote);
        ShapedRecipe recipe_aote = new ShapedRecipe(Aspect_Of_The_End);
        recipe_aote.shape(" e "," e "," d ");
        recipe_aote.setIngredient('e', Material.EYE_OF_ENDER);
        recipe_aote.setIngredient('d', Material.DIAMOND);
        Bukkit.addRecipe(recipe_aote);
        return Aspect_Of_The_End;
}

编辑:忘记说了,但是在控制台、eclipse 和右键单击剑时都没有错误。

您想使用 .equals() 而不是 == 来检查它是否是结束的方面。