Issue with Item Event detection

Discussion in 'Plugin Development' started by Is3kai, Mar 1, 2024.

  1. Offline

    Is3kai

    I've been working for the last few days on a basic item detection aspect of a plugin I am developing for an SMP. However, the class meant to be used as the even handler is not picking up the usages of said items. Below, I will post both the Item initializer and the event handler code files. If anyone wouldn't mind taking a look through them to tell me what I'm doing wrong, that would help me out immensely.


    Event Handler Code:
    Code:
    package org.smpmakers.dimensionsmp.Handlers;
    
    import net.kyori.adventure.text.Component;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.persistence.PersistentDataType;
    import org.smpmakers.dimensionsmp.DimensionSMP;
    import org.smpmakers.dimensionsmp.Keys;
    
    import static org.bukkit.Bukkit.getServer;
    
    public class EventScript implements Listener {
    
    public EventScript(DimensionSMP plugin){
    getServer().getPluginManager().registerEvents(this, plugin);
    }
    public void onPlayerInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    
    if (event.getAction().isRightClick()) {
    ItemStack item = event.getItem();
    if (item != null && item.hasItemMeta() && item.getItemMeta().getPersistentDataContainer().has(Keys.WARP_NUM, PersistentDataType.INTEGER)) {
    int warpNum = item.getItemMeta().getPersistentDataContainer().get(Keys.WARP_NUM, PersistentDataType.INTEGER);
    activateWarp(player, warpNum);
    }
    }
    }
    
    private void activateWarp(Player player, int warpNum) {
    switch (warpNum) {
    case 1:
    player.sendMessage(Component.text("Activating Flamma Warp"));
    // Add your Flamma Warp activation logic herebreak;
    case 2:
    player.sendMessage(Component.text("Activating Aqua Warp"));
    // Add your Aqua Warp activation logic herebreak;
    case 3:
    player.sendMessage(Component.text("Activating Terra Warp"));
    // Add your Terra Warp activation logic herebreak;
    case 4:
    player.sendMessage(Component.text("Activating Ventus Warp"));
    // Add your Ventus Warp activation logic herebreak;
    case 5:
    player.sendMessage(Component.text("Activating Lux Warp"));
    // Add your Lux Warp activation logic herebreak;
    case 6:
    player.sendMessage(Component.text("Activating Tenebrus Warp"));
    // Add your Tenebrus Warp activation logic herebreak;
    case 7:
    player.sendMessage(Component.text("Activating Locus Warp"));
    // Add your Locus Warp activation logic herebreak;
    case 8:
    player.sendMessage(Component.text("Activating Tempus Warp"));
    // Add your Tempus Warp activation logic herebreak;
    default:
    break;
    }
    }
    }
    
    ItemManager code:
    Code:
    
    package org.smpmakers.dimensionsmp.Items;
    
    import net.kyori.adventure.text.Component;
    import net.kyori.adventure.text.format.Style;
    import net.kyori.adventure.text.format.TextDecoration;
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.persistence.PersistentDataType;
    import org.smpmakers.dimensionsmp.Keys;
    
    public class ItemManager {
    
    public static ItemStack warp1;
    public static ItemStack warp2;
    public static ItemStack warp3;
    public static ItemStack warp4;
    public static ItemStack warp5;
    public static ItemStack warp6;
    public static ItemStack warp7;
    public static ItemStack warp8;
    
    public ItemStack totem1;
    public ItemStack totem2;
    public ItemStack totem3;
    public ItemStack totem4;
    public ItemStack totem5;
    public ItemStack totem6;
    public ItemStack totem7;
    public ItemStack totem8;
    
    public static void init(){
    createWarp(1, "Flamma Warp");
    createWarp(2, "Aqua Warp");
    createWarp(3, "Terra Warp");
    createWarp(4, "Ventus Warp");
    createWarp(5, "Lux Warp");
    createWarp(6, "Tenebrus Warp");
    createWarp(7, "Locus Warp");
    createWarp(8, "Tempus Warp");
    }
    
    private static void createWarp(int warpNum, String name){
    ItemStack item = new ItemStack(Material.CARROT_ON_A_STICK);
    ItemMeta meta = item.getItemMeta();
    
    // Set display namemeta.displayName(Component.text(name).style(Style.style().decoration(TextDecoration.ITALIC, false).decoration(TextDecoration.BOLD, true)));
    
    // Store warp number in PersistentDataContainer using the key from Keys classmeta.getPersistentDataContainer().set(Keys.WARP_NUM, PersistentDataType.INTEGER, warpNum);
    
    item.setItemMeta(meta);
    
    switch (warpNum) {
    case 1: warp1 = item; break;
    case 2: warp2 = item; break;
    case 3: warp3 = item; break;
    case 4: warp4 = item; break;
    case 5: warp5 = item; break;
    case 6: warp6 = item; break;
    case 7: warp7 = item; break;
    case 8: warp8 = item; break;
    default: break;
    }
    }
    
    }
     
    Last edited by a moderator: Mar 2, 2024
  2. Online

    timtower Administrator Administrator Moderator

    You are missing the @Eventhandler
     
  3. Offline

    Is3kai

    I feel dumb now lol.
     

Share This Page