Solved Interaction Events

Discussion in 'Plugin Development' started by JuliusTOw3R, May 27, 2015.

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

    JuliusTOw3R

    Hello. I've troubles with my interaction events. I've simply no idea what is wrong with them, but I'll let you guys have a look at my code to see if you can find anything there is wrong.

    Code:
    public static ItemStack kunai() {
    
            ItemStack kunai = new ItemStack(Material.BLAZE_ROD);
            ItemMeta kunaiMeta = kunai.getItemMeta();
    
            kunaiMeta.setDisplayName("§eKunai");
            kunai.setItemMeta(kunaiMeta);
    
            return kunai;
    
        }
    
        @EventHandler
        public void onKunaiThrow(PlayerInteractEvent e) {
    
            Player p = e.getPlayer();
    
            if (e.getAction() == Action.RIGHT_CLICK_AIR
                    || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    
                if (p.getItemInHand() == kunai()) {
    
                    e.getPlayer().launchProjectile(Arrow.class);
    
                }
            }
        }
    
        @EventHandler
        public void onKunaiDamage(EntityDamageByEntityEvent e) {
    
            if (e.getDamager() instanceof Arrow) {
    
                Arrow a = (Arrow) e.getDamager();
    
                if (a.getShooter() instanceof Player) {
    
                    Player p = (Player) a.getShooter();
    
                    if (p.getItemInHand() == kunai()) {
    
                        e.setDamage(5.0);
    
                    }
                }
            }
        }
    That's the code for the item. As you can see I use a public static ItemStack for the item. I've been sitting and thinking over this for over an hour, but I can't figure it out.

    Thanks for your help,

    - Julius
     
  2. Offline

    Zombie_Striker

    @JuliusTOw3R
    Unless the item in his hand is the exactly the same instance, which it never will, your check to see if they're the same will return false. Try using same checks (Displayname == Kunia#Displayname(), Lore == kunia#Lore(), Type = Kunia#Type() ect.)
     
  3. Offline

    JuliusTOw3R

    Alright thanks, I will try it out. Thanks for your help @FisheyLP! :3
     
    Last edited: May 28, 2015
Thread Status:
Not open for further replies.

Share This Page