Solved Monster Eggs - get monster in PlayerInteractEvent

Discussion in 'Plugin Development' started by iliasdewachter, May 11, 2013.

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

    iliasdewachter

    Hi all,

    Here's what I got:
    Code:
    @EventHandler
    public void onInteract(PlayerInteractEvent event) {
    Player player = event.getPlayer();
    if (event.getAction() == Action.RIGHT_CLICK_BLOCK)
    {
      if (player.getItemInHand() != null)
      {
        if (player.getItemInHand().getTypeId() == 383) // Monster egg
        {
          final ItemStack is = player.getItemInHand();
          if (is.hasItemMeta()==false) return;
          ItemMeta im = is.getItemMeta();
          im.setDisplayName(player.getName() + "'s minion");
          is.setItemMeta(im);
        }
      }
    }
    }
    My question: How can get the entity that will come out of the monster egg? (and change its name)
     
  2. Offline

    ZeusAllMighty11

    You can't..

    But you can use EntitySpawnEvent
     
  3. Offline

    iliasdewachter

    doesn't exist :(

    Edit: What about ItemSpawnEvent?

    How can I get the player from that event?
     
  4. Offline

    ZeusAllMighty11

  5. Offline

    iliasdewachter

    Ok, thanks, but how can I get the player?
     
  6. Offline

    afistofirony

    You could get the itemMeta of the spawn egg (which corresponds to the entity it spawns, i.e. 383:120 spawns a villager) and adjust the display name of the spawn egg accordingly, which should set the spawned mob's name as well.
     
  7. Offline

    iliasdewachter

    I've already tried that, doesn't work...

    I got it, in my interact event:
    Code:
                        int data = player.getItemInHand().getData().getData();
                        if (data==51) // skeleton
                        {
                            @SuppressWarnings("deprecation")
                            Skeleton skeleton = (Skeleton) player.getWorld().spawnCreature(player.getLocation(), EntityType.SKELETON);
                            skeleton.setCustomName(player.getName() + "'s minion");
                            event.setCancelled(true);
                        }
                       
                        if (data==54) // zombie
                        {
                            @SuppressWarnings("deprecation")
                            Zombie zombie = (Zombie) player.getWorld().spawnCreature(player.getLocation(), EntityType.ZOMBIE);
                            zombie.setCustomName(player.getName() + "'s minion");
                            event.setCancelled(true);
                        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page