Check for ItemMeta on Event

Discussion in 'Plugin Development' started by tylerthecreeper1, Feb 19, 2014.

Thread Status:
Not open for further replies.
  1. Hello. I am new to java and have some issues with coding. I am adding new features to a simple plugin I made (Still waiting for it to be approved).

    The plugin is called Thor, and gives a player a stone axe when they use a command, and the axe smites lightning, and left click is a knockback. I need to add to my event for lightning, to check the players inventory for the axe with the name "Hammer". Currently, any stone axe works for lightning, except the knockback, since the item meta adds the enchant.

    I can't figure out how to add to the event to check for the axe with the item meta "Hammer"

    Here's my code..
    1. @EventHandler(priority=EventPriority.HIGH)
    2. public void onPlayerUse(PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if(event.getAction().equals(Action.RIGHT_CLICK_AIR)){
    5. if (player.getItemInHand().getType() == Material.STONE_AXE) {
    6. // Creates a bolt of lightning at a given location. In this case, that location is where the player is looking.
    7. // Can only create lightning up to 200 blocks away.
    8. if(event.getPlayer().hasPermission("thor.smite")){
    9. Block block = player.getTargetBlock(null, 200);
    10. Location location = block.getLocation();
    11. World world = player.getWorld();
    12. world.strikeLightning(location);
    13. }
    14. }
    15. }
    16. }
    17. }

    This is also set for Action.RIGHT_CLICK_AIR, in another class. I'm pretty sure the same item meta code would be in both.
  2. Offline


    Wouldn't it be like:
  3. KaiPol I just tried that right before you replied, and I got errors and the lightning didn't work.

    KaiPol Do I need an else statement before the event of lightning?

    I fixed this and got it working, but now my permissions are messed up, I can smite lightning regardless of permission. (thor.smite is the perm for lightning, thor.hammer to spawn axe)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 6, 2016
  4. Offline


  5. Offline


    How did you fix it?
Thread Status:
Not open for further replies.

Share This Page