use of org.bukkit.entity.Snowball 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);
}
}
}
}
}
}
use of org.bukkit.entity.Snowball in project Fusion by GummyPvP.
the class SwitchEvent method onSwitch.
@EventHandler
public void onSwitch(EntityDamageByEntityEvent e) {
if (!(e.getEntity() instanceof Player))
return;
if (!(e.getDamager() instanceof Snowball))
return;
if (!(((Snowball) e.getDamager()).getShooter() instanceof Player))
return;
Player shooter = (Player) ((Snowball) e.getDamager()).getShooter();
if (mKitUser.getInstance(shooter).getKit() != KitManager.getInstance().valueOf("Switcher"))
return;
if (mKitUser.getInstance(shooter).isInGladiatorArena())
return;
if (RegionManager.getInstance().isInProtectedRegion(shooter))
return;
if (RegionManager.getInstance().isInProtectedRegion((Player) e.getEntity()))
return;
Location shooterLocation, recieverLocation;
shooterLocation = shooter.getLocation();
recieverLocation = e.getEntity().getLocation();
shooter.teleport(recieverLocation);
e.getEntity().teleport(shooterLocation);
}
use of org.bukkit.entity.Snowball in project EliteMobs by MagmaGuy.
the class FrostCone method createSnowball.
private static Snowball createSnowball(EliteEntity eliteEntity, Location location) {
Projectile snowball = EliteProjectile.create(EntityType.SNOWBALL, eliteEntity.getLivingEntity(), getShotVector(eliteEntity, location), false);
ProjectileTagger.tagProjectileWithCustomDamage(snowball, 2);
snowball.getPersistentDataContainer().set(frostConeSnowballKey, PersistentDataType.STRING, "true");
Bukkit.getScheduler().runTaskLater(MetadataHandler.PLUGIN, snowball::remove, 20L * 3);
return (Snowball) snowball;
}
Aggregations