use of org.bukkit.entity.EnderPearl in project Parties by AlessioDP.
the class FightListener method onPlayerHit.
@EventHandler
public void onPlayerHit(EntityDamageByEntityEvent event) {
if (ConfigParties.FRIENDLYFIRE_ENABLE && event.getEntity() instanceof Player) {
Player victim = (Player) event.getEntity();
Player attacker = null;
// 0=Basic, 1=Arrow, 2=EnderPearl, 3=Snowball
DamageType type = DamageType.UNSUPPORTED;
if (event.getDamager() instanceof Player)
type = DamageType.PLAYER;
else if (event.getDamager() instanceof Arrow)
type = DamageType.ARROW;
else if (event.getDamager() instanceof EnderPearl)
type = DamageType.ENDERPEARL;
else if (event.getDamager() instanceof Snowball)
type = DamageType.SNOWBALL;
if (!type.equals(DamageType.UNSUPPORTED)) {
ProjectileSource shooterSource;
switch(type) {
case PLAYER:
attacker = (Player) event.getDamager();
break;
case ARROW:
shooterSource = ((Arrow) event.getDamager()).getShooter();
if (shooterSource instanceof Player)
attacker = (Player) shooterSource;
break;
case ENDERPEARL:
shooterSource = ((EnderPearl) event.getDamager()).getShooter();
if (shooterSource instanceof Player)
attacker = (Player) shooterSource;
break;
case SNOWBALL:
shooterSource = ((Snowball) event.getDamager()).getShooter();
if (shooterSource instanceof Player)
attacker = (Player) shooterSource;
break;
case UNSUPPORTED:
}
if (attacker != null) {
// Found right attacker
if (!victim.getUniqueId().equals(attacker.getUniqueId()) && (ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains("*") || ConfigParties.FRIENDLYFIRE_LISTWORLDS.contains(victim.getWorld().getName()))) {
// Friendly fire not allowed here
PartyPlayerEntity ppVictim = plugin.getPlayerManager().getPlayer(victim.getUniqueId());
PartyPlayerEntity ppAttacker = plugin.getPlayerManager().getPlayer(attacker.getUniqueId());
if (!ppVictim.getPartyName().isEmpty() && ppVictim.getPartyName().equalsIgnoreCase(ppAttacker.getPartyName())) {
// Calling API event
PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(ppVictim, ppAttacker, event);
Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
if (!partiesFriendlyFireEvent.isCancelled()) {
// Friendly fire confirmed
PartyEntity party = plugin.getPartyManager().getParty(ppVictim.getPartyName());
ppAttacker.sendMessage(Messages.OTHER_FRIENDLYFIRE_CANTHIT);
party.sendFriendlyFireWarn(ppVictim, ppAttacker);
event.setCancelled(true);
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_FRIENDLYFIRE_DENIED.replace("{type}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
} else
LoggerManager.log(LogLevel.DEBUG, Constants.DEBUG_API_FRIENDLYFIREEVENT_DENY.replace("{type}", type.name()).replace("{player}", attacker.getName()).replace("{victim}", victim.getName()), true);
}
}
}
}
}
}
Aggregations