use of org.bukkit.projectiles.ProjectileSource in project TotalFreedomMod by TotalFreedom.
the class PotionBlocker method onThrowPotion.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onThrowPotion(PotionSplashEvent event) {
ProjectileSource source = event.getEntity().getShooter();
if (!(source instanceof Player)) {
event.setCancelled(true);
return;
}
Player thrower = (Player) source;
if (plugin.al.isAdmin(thrower)) {
return;
}
for (Player player : thrower.getWorld().getPlayers()) {
if (thrower.getLocation().distanceSquared(player.getLocation()) < POTION_BLOCK_RADIUS_SQUARED) {
thrower.sendMessage(ChatColor.RED + "You cannot use splash potions close to other players.");
event.setCancelled(true);
return;
}
}
}
use of org.bukkit.projectiles.ProjectileSource 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.projectiles.ProjectileSource in project MagicPlugin by elBukkit.
the class MagicController method getEntityUndo.
@Nullable
public UndoList getEntityUndo(Entity entity) {
UndoList blockList = null;
if (entity == null)
return null;
Mage mage = getRegisteredMage(entity);
if (mage == null && entity instanceof Projectile) {
Projectile projectile = (Projectile) entity;
ProjectileSource source = projectile.getShooter();
if (source instanceof LivingEntity) {
entity = (LivingEntity) source;
mage = getRegisteredMage(entity);
}
}
if (mage != null) {
UndoList undoList = mage.getLastUndoList();
if (undoList != null) {
long now = System.currentTimeMillis();
if (undoList.getModifiedTime() > now - undoTimeWindow) {
blockList = undoList;
}
}
} else {
blockList = com.elmakers.mine.bukkit.block.UndoList.getUndoList(entity);
}
return blockList;
}
use of org.bukkit.projectiles.ProjectileSource in project MagicPlugin by elBukkit.
the class Mage method damagedBy.
@Override
public void damagedBy(@Nonnull Entity damager, double damage) {
if (damagedBy == null)
return;
if (damager instanceof Projectile) {
ProjectileSource source = ((Projectile) damager).getShooter();
if (!(source instanceof Entity))
return;
damager = (Entity) source;
}
// Only tracking players for now.
if (!(damager instanceof Player))
return;
Player damagingPlayer = (Player) damager;
lastDamager = damagedBy.get(damagingPlayer.getUniqueId());
if (lastDamager == null) {
lastDamager = new DamagedBy(damagingPlayer, damage);
damagedBy.put(damagingPlayer.getUniqueId(), lastDamager);
} else {
lastDamager.damage += damage;
}
if (topDamager != null) {
if (topDamager.getEntity() == null || topDamager.damage < lastDamager.damage || !withinRange(topDamager.getEntity())) {
topDamager = lastDamager;
setTarget(damagingPlayer);
}
} else {
topDamager = lastDamager;
setTarget(damagingPlayer);
}
if (entityData != null) {
entityData.onDamage(this, damage);
}
}
use of org.bukkit.projectiles.ProjectileSource in project MagicPlugin by elBukkit.
the class PlayerController method onProjectileLaunch.
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent event) {
if (launching || event.isCancelled())
return;
Projectile projectile = event.getEntity();
ProjectileSource shooter = projectile.getShooter();
// Not really handling magic mobs with magic bows...
if (!(shooter instanceof Player))
return;
Player player = (Player) shooter;
Mage mage = controller.getRegisteredMage(player);
if (mage == null)
return;
Wand wand = mage.getActiveWand();
if (wand == null)
return;
if (wand.getIcon().getMaterial() != Material.BOW)
return;
double minPull = wand.getDouble("cast_min_bowpull");
double pull = Math.min(1.0, projectile.getVelocity().length() / MAX_ARROW_SPEED);
if (minPull > 0 && pull < minPull) {
if (wand.isInventoryOpen())
event.setCancelled(true);
return;
}
Spell spell = wand.getActiveSpell();
if (spell == null) {
if (wand.isInventoryOpen())
event.setCancelled(true);
return;
}
event.setCancelled(true);
String[] parameters = { "bowpull", Double.toString(pull) };
// prevent recursion!
launching = true;
try {
wand.cast(parameters);
} catch (Exception ex) {
controller.getLogger().log(Level.SEVERE, "Error casting bow spell", ex);
}
launching = false;
}
Aggregations