private void disguise(Entity entity, Player p) { if ((entity instanceof Animals && disguiseAsAnimal) || (entity instanceof Monster && disguiseAsMonster)) { if (hasAbility(p)) { if (!DisguiseAPI.isDisguised(p)) DisguiseAPI.disguiseToAll( p, new MobDisguise(DisguiseType.valueOf(entity.getType().name()), true)); else { Disguise disguise = DisguiseAPI.getDisguise(p); if (disguise.getType() == DisguiseType.valueOf(entity.getType().name())) return; DisguiseAPI.disguiseToAll( p, new MobDisguise(DisguiseType.valueOf(entity.getType().name()), true)); } p.sendMessage( String.format( chameleonNowDisguised, HungergamesApi.getKitManager().toReadable(entity.getType().getName()))); } } }
@EventHandler public void onEntityDamage(EntityDamageByEntityEvent event) { if (event.isCancelled()) return; Entity damager = event.getDamager(); if (event.getDamager() instanceof Projectile && ((Projectile) damager).getShooter() != null) damager = ((Projectile) damager).getShooter(); if (isChameleon(event.getEntity()) && breakDisguiseOnAttacked) { Player p = (Player) event.getEntity(); if (DisguiseAPI.isDisguised(p)) { DisguiseAPI.undisguiseToAll(p); p.sendMessage(chameleonDisguiseBroken); } } if (isChameleon(damager)) { Player p = (Player) damager; if (event.getEntity() instanceof Player && DisguiseAPI.isDisguised(p)) { if (breakDisguiseOnAttackPlayer) { DisguiseAPI.undisguiseToAll(p); p.sendMessage(chameleonBreakDisguise); } } else disguise(event.getEntity(), p); } }
@EventHandler public void onDeath(PlayerKilledEvent event) { if (DisguiseAPI.isDisguised(event.getKilled().getPlayer())) DisguiseAPI.undisguiseToAll(event.getKilled().getPlayer()); }