Hello everyone. I want to add func when player uses certain item and after column of blocks appears with height equal 6, but RIGHT_CLICK_BLOCK called twice and set 7-height pillar and also removed 2 items instead of 1. I don't register event twice and I tried check main hand Code presents below Code: @EventHandler public void onItemUse(PlayerInteractEvent e) { if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) { if(EquipmentSlot.HAND.equals(e.getHand()) && flag_basic.targetItem.isSimilar(e.getItem())) { Location basicOrigin = e.getClickedBlock().getLocation(); e.getItem().setAmount(e.getItem().getAmount() - 1); for (int iB = 0; iB < 6; iB++) { basicOrigin.add(0, 1, 0); Bukkit.getServer().getWorld(e.getPlayer().getWorld().getName()).getBlockAt(basicOrigin).setType(Material.OAK_LOG); } } } }
Try this code, it worked for me. Tested in 1.7.10 version. Use "==" instead of .equals() to compare Enums. Code: @EventHandler public void onItemUse(PlayerInteractEvent e) { if(e.getItem().getType() == Material.STICK && e.getAction() == Action.RIGHT_CLICK_BLOCK) { Block b = e.getClickedBlock(); e.getItem().setAmount(e.getItem().getAmount() - 1); for(int iB = 1; iB <= 6; iB++) { b.getRelative(BlockFace.UP, iB).setType(Material.LOG); } } }
If it runs twice you might be registering the pluginmanager registerevents function twice. Check in your onEnable() that that isn't true.