Cant get this plugin to work.

Discussion in 'Plugin Development' started by xXRobbie21Xx, May 6, 2014.

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

    xXRobbie21Xx

    Hey, im trying to make a plugin that will change the item in your hand when you click it, but i cant seem to get it to function properly.
    Here is my code


    Code:
    @EventHandler
        public void onPlayerInteractEvent(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            ItemStack mWC = new ItemStack(Material.RECORD_10, 1);
            ItemMeta creeper = mWC.getItemMeta();
            creeper.setDisplayName("MobWand Creeper");
            ItemStack mWV = new ItemStack(Material.RECORD_11, 1);
            ItemMeta villager = mWC.getItemMeta();
            villager.setDisplayName("MobWand Villager");
            ItemStack mWZP = new ItemStack(Material.RECORD_7, 1);
            ItemMeta pigman = mWC.getItemMeta();
            pigman.setDisplayName("MobWand Pigman");
            ItemStack mWZ = new ItemStack(Material.RECORD_3, 1);
            ItemMeta zombie = mWC.getItemMeta();
            zombie.setDisplayName("MobWand Zombie");
     
            if (p.getItemInHand().getItemMeta().getDisplayName()
                    .startsWith("MobWand"))
                ;
            if (event.getAction() == Action.RIGHT_CLICK_AIR
                    || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if (p.getItemInHand().getItemMeta().getDisplayName()
                        .endsWith("Creeper")) {
                    PlayerInventory pi = p.getInventory();
                    pi.setItemInHand(mWV);
                } else if (p.getItemInHand().getItemMeta().getDisplayName()
                        .endsWith("Villager")) {
                    PlayerInventory pi = p.getInventory();
                    pi.setItemInHand(mWZP);
                } else if (p.getItemInHand().getItemMeta().getDisplayName()
                        .endsWith("PigMan")) {
                    PlayerInventory pi = p.getInventory();
                    pi.setItemInHand(mWZ);
                } else if (p.getItemInHand().getItemMeta().getDisplayName()
                        .endsWith("Zombie")) {
                    PlayerInventory pi = p.getInventory();
                    pi.setItemInHand(mWC);
                }
     
            }
     
            }
    This code is suppose to change the item in the players hand when the player right clicks the item in the inventory.
    Instead, the item is simply switching to the correct item but it has no meta data and it wont allow any more switching.
    In other words, they right click the item they need to -- it turns into the correct item(with no meta data) -- when the player attempts to click it again nothing happens

    P.s if there is anything that i can do to make this easier on you just let me know.

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

    TGRHavoc

    xXRobbie21Xx
    You could use the
    Code:java
    1. [syntax=java][/syntax]
    tags to make it easier to read..
     
  3. Offline

    Zethariel

    xXRobbie21Xx use debug messages to see if your code gets fired at all.
     
  4. Offline

    Rocoty

    Well, you could start by telling us what it does opposed to what it should do. We can't help you unless you tell us what's wrong. You only told us that something is wrong. Tell the details. tl;dr You tell us what, we tell you why.

    And please put the code in syntax tags.
     
  5. Offline

    RawCode

    1) valid code paste with trace messages
    2) valid stacktrace

    then we may talk.

    ps. not expect anyone to ever try reading your post at it's current stage.
     
  6. Offline

    xXRobbie21Xx

    TGRHavoc Rocoty yeah sorry guys that was stupid of me, i wasn't thinking strait, I tried to clarify it up a bit.
     
Thread Status:
Not open for further replies.

Share This Page