Giving the player an item when the player right clicks a certain witch.

Discussion in 'Plugin Development' started by superchris05326, Apr 18, 2014.

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

    superchris05326

    I want players to right click a witch named "Elder Wizard" and then they would get an item. This is what I have and Im not sure why it doesnt work:
    @EventHandler
    public void onClickWitch(PlayerInteractEntityEvent event){
    Player p = event.getPlayer();
    Entity entity = event.getRightClicked();
    if(entity instanceof Witch){
    Witch w = (Witch) entity;
    if(w.getCustomName() == "Elder Wizard"){
    p.getInventory().addItem(getlvl1Wand());
    }
    }
    return;
    }

    Here is the getlvl1Wand method:
    public ItemStack getlvl1Wand(){
    ItemStack lvl1Wand = new ItemStack(Material.STICK, 1);
    ItemMeta wandMeta = lvl1Wand.getItemMeta();
    wandMeta.setDisplayName(ChatColor.LIGHT_PURPLE + "Sky Wand" );
    lvl1Wand.setItemMeta(wandMeta);
    return lvl1Wand;
    }
     
  2. Offline

    TheMcScavenger

    Does the witch have a custom name?
     
  3. Offline

    superchris05326

  4. Offline

    rohan576

    superchris05326
    Code:java
    1. if (event.getRightClicked() instanceof Witch) {
    2. if (event.getRightClicked().getCustomName().contains("Elder Wizard")) {
    3. event.getPlayer().getInventory.addItem(getlvl1Wand());
    4. }
    5. }
     
  5. Offline

    superchris05326

Thread Status:
Not open for further replies.

Share This Page