Cuboid plugin : mobDamage and PVP flags problem

Discussion in 'Plugin Development' started by Ribesg, Oct 15, 2011.

Thread Status:
Not open for further replies.
  1. Hi.
    I'm creating a cuboid plugin. My problem is about 2 of my flags : mob & pvp
    • mob :
    • prevent mobs from spawining (Works)
    • prevent mobs from damaging players (PROBLEM)
    • pvp : prevent player from damaging players (PROBLEM)
    I'm trying to use the EntityDamageEvent, but there is no method to know "who", which entity caused damage. I can just find that it's an entity that caused the damage.

    Here I'm just trying to prevent mob from damaging players.
    PHP:
    public void onEntityDamage(EntityDamageEvent event) {
            if (
    event.isCancelled()) return;
            if (
    event.getEntity() instanceof Player) {
                if (
    event.getCause().equals(DamageCause.ENTITY_ATTACK)) {
                    final 
    Location loc event.getEntity().getLocation();
                    final 
    Set<Cuboidcubos plugin.cuboidsMap.getByLoc(loc);
                    for (
    Cuboid c cubos) {
                        if (
    c.mobProtection()) {
                            
    event.setCancelled(true);
                        }
                    }
                }
            }
        }
    Any idea ? Should I use another event ?
     
  2. Your event is an EntityDamageByEntityEvent if an entity damaged the other entity.
    That gives you the necessary methods to get the attacker (getDamager()).
    Use the same event handler, just check if your EntityDamageEvent is instanceof EntityDamageByEntityEvent and then cast it.
     
  3. Wow.
    Thank you.
     
Thread Status:
Not open for further replies.

Share This Page