Solved How to Get Egg Thrower's Name.???

Discussion in 'Plugin Development' started by waco001, Oct 7, 2012.

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

    waco001

    Hi I have the following code:
    Code:
       
    @EventHandler(priority = EventPriority.HIGHEST)
        public void EggThrow(ProjectileHitEvent e){
            if (e.getEntity() instanceof Egg){
                Location loc = e.getEntity().getLocation();
                World world = loc.getWorld();
                world.createExplosion(loc, 5);   
                Bukkit.broadcastMessage(ChatColor.RED + "" + player + " Threw an egg!");
     
     
            }
    Its probably very simple but I just need to get the username of whoever threw the egg... Thanks
     
  2. Offline

    HouseMD

    String player = e.getPlayer().getName();
     
  3. Offline

    waco001

    wait its not working.... 'The method getPlayer() is undefined for the type ProjectileHitEvent' comes up
     
  4. Offline

    Courier

    Code:java
    1. LivingEntity ent = e.getEntity().getShooter();
    2. String name = ent == null ? "Dispenser" : ent instanceof Player ? ((Player)ent).getName() : ent.getType().getName();
    That gets the player's name if it was a player, and the entity-type's name if it was not a player. Eggs can only be thrown by players unless a plugin makes entites throw eggs.
     
  5. Offline

    waco001

    Thanks soo Much! You dont know how much it helped me thx
     
  6. Offline

    KeybordPiano459

    Add the [SOLVED] tag to the title please
     
Thread Status:
Not open for further replies.

Share This Page