How to get time and do an action when the player kills a specific mob?

Discussion in 'Plugin Development' started by jonathanyan, Aug 14, 2011.

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

    jonathanyan

    I'm making this plugin for hunts for mobs (e.g. there may be a server-wide hunt for spiders, etc) and I don't know how to get time from the server and how to initiate an action when the player kills a specific mob.
    Help is greatly appreciated!
    Thanks!
     
  2. Offline

    feildmaster

    System.currentTimeMillis(); for system time... (You have to iterate what time it actually is though...)

    Event.Type.ENTITY_DEATH might help you.
     
  3. Offline

    DrBowe

    @feildmaster
    Why not use getTime()?

    As for the entity, you'd want to use onEntityDeath, and then check the cause to see if a player killed it. You could then act from there
     
  4. Offline

    feildmaster

    @DrBoweNur : I forget some of the basic commands sometimes... :D
     
  5. Offline

    jonathanyan

    Thanks.

    As for "you'd want to use onEntityDeath, and then check the cause to see if a player killed it. You could then act from there", could someone explain how?
    Thanks again
     
  6. Offline

    feildmaster

    Register : Event.Entity_Death

    Code:
        public void onEntityDeath(EntityDeathEvent event) {
            DamageCause cause = event.getEntity().getLastDamageCause().getCause();
            if(cause == DamageCause.ENTITY_ATTACK || cause == DamageCause.PROJECTILE) {
                
            }
        }
    something like that...
     
  7. Offline

    RPFeltz

    Code:
        CreatureType huntType = CreatureType.SPIDER;
    
        public void onEntityDeath(EntityDeathEvent event) {
            Entity entity = event.getEntity();
            CreatureType creatureType = CreatureType.fromName(entity.getClass().getSimpleName().replaceFirst("Craft", ""));
            if (creatureType == huntType) {
                EntityDamageEvent lastDamageCause = entity.getLastDamageCause();
                if(lastDamageCause instanceof EntityDamageByEntityEvent) {
                    EntityDamageByEntityEvent entityDamageByEntityEvent = (EntityDamageByEntityEvent) lastDamageCause;
                    Entity damager = entityDamageByEntityEvent.getDamager();
                    if (damager instanceof Player) {
                        Player player = (Player) damager;
                        // Stuff
                    }
                }
            }
        }
     
Thread Status:
Not open for further replies.

Share This Page