Right Click on item not working.

Discussion in 'Plugin Development' started by JoltTheBolt, Dec 23, 2020.

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

    JoltTheBolt

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("incinerator")) {
                   ItemStack Incinerator = new ItemStack(Material.DIAMOND_SWORD);
                ItemMeta Incineratormeta = Incinerator.getItemMeta();
                Incineratormeta.setDisplayName(ChatColor.GOLD.toString() + ChatColor.BOLD.toString() + "Incinerator");
                ArrayList<String> lore = new ArrayList<String>();
                lore.add(ChatColor.DARK_AQUA.toString() + ChatColor.BOLD.toString() + "Item Ability: " + ChatColor.AQUA.toString() + "Incineration");
                lore.add(ChatColor.WHITE.toString() + "Burns everything " + ChatColor.DARK_GREEN.toString() + "5 blocks ");
                lore.add(ChatColor.WHITE.toString() + "ahead of you");
                Incineratormeta.setLore(lore);
                   Incinerator.setItemMeta(Incineratormeta);
                sender.sendMessage(ChatColor.GOLD + "You have been bestowed the power of Incinerator!");
                Player player = (Player) sender;
                Inventory inventory = player.getInventory();
                inventory.addItem(Incinerator);
                return true;
            }
            return false;
        }
     
        @EventHandler
        public void onInteract(PlayerInteractEvent e) {
        Action action = e.getAction();
    
        if (action == Action.RIGHT_CLICK_AIR) {
    
        Player p = e.getPlayer();
        ItemStack item = p.getInventory().getItemInHand();
        if(item != null && item.getType() == Material.DIAMOND_SWORD) {
            if(item.hasItemMeta() &&
               item.getItemMeta().hasDisplayName() &&
               item.getItemMeta().getDisplayName().equals(ChatColor.GOLD.toString() + ChatColor.BOLD.toString() + "Incinerator")) {
        p.sendMessage(ChatColor.GOLD + "Ability Used!");
        Location start = p.getEyeLocation();
        Vector increase = start.getDirection();
        for (int counter = 0; counter < 100; counter++) {
        start = start.add(increase);
        p.playEffect(p.getLocation(), Effect.MOBSPAWNER_FLAMES, null);
    
    }
        }
        }
    }
        }
    }
    Everything is all good and working until EventHandler.
    I want the incinerator to spawn particles when I right click.
    Nothing happens when I right click. I tried to test it by writing the message but the message didn't got send either.
    Therefore, I think there is a problem in my EventHandler, can you please tell me where? Thank you!
     
    Last edited: Dec 23, 2020
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    JoltTheBolt

    I did this at the start:
    Code:
    public final class JoltItems extends JavaPlugin implements Listener{
    What else do I need to do?
     
  4. Offline

    timtower Administrator Administrator Moderator

    @JoltTheBolt
    getServer().getPluginManager().registerEvents(this, this);
     
  5. Offline

    JoltTheBolt

    @timtower THANK YOU So Much! You're the BEST EVER MR.TIM! :D
     
Thread Status:
Not open for further replies.

Share This Page