- Fixed up for more universal damage switching

This commit is contained in:
AlexTheCoder 2016-02-13 12:46:57 -05:00
parent 8b39d7ba43
commit 138c900484
3 changed files with 208 additions and 61 deletions

View File

@ -985,67 +985,6 @@ public class MinecraftLeague extends TeamGame
Manager.GetCreature().SpawnEntity(event.getLocation(), EntityType.SPIDER);
}
@EventHandler(priority = EventPriority.LOWEST)
public void controlPvP(EntityDamageByEntityEvent event)
{
if (!IsLive())
return;
Player entity = null;
Player damager = null;
if (event.getEntity() instanceof Player)
{
entity = (Player)event.getEntity();
if (UtilPlayer.isSpectator(entity))
{
event.setCancelled(true);
return;
}
}
if (event.getDamager() instanceof Player)
{
damager = (Player)event.getDamager();
if (UtilPlayer.isSpectator(damager))
{
event.setCancelled(true);
return;
}
}
if (event.getDamager() instanceof Projectile)
{
Projectile proj = (Projectile)event.getDamager();
if (proj.getShooter() instanceof Player)
{
damager = (Player)proj.getShooter();
if (UtilPlayer.isSpectator(damager))
{
event.setCancelled(true);
return;
}
}
}
if ((entity != null) && (damager != null))
{
if (GetTeam(entity).GetColor() == GetTeam(damager).GetColor())
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.LOWEST)
public void protectSpectators(EntityDamageEvent event)
{
if (!IsLive())
return;
if (event.getEntity() instanceof Player)
{
Player ent = (Player)event.getEntity();
if (UtilPlayer.isSpectator(ent))
event.setCancelled(true);
}
}
@EventHandler
public void editHealth(GameStateChangeEvent event)
{

View File

@ -43,6 +43,7 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBurnEvent;
@ -71,6 +72,7 @@ import org.bukkit.util.Vector;
public class GameFlagManager implements Listener
{
ArcadeManager Manager;
SecondaryDamageManager Secondary;
public GameFlagManager(ArcadeManager manager)
{
@ -78,6 +80,30 @@ public class GameFlagManager implements Listener
Manager.getPluginManager().registerEvents(this, Manager.getPlugin());
}
@EventHandler
public void triggerSecondary(UpdateEvent event)
{
if (event.getType() != UpdateType.FASTEST)
return;
if (Secondary == null)
{
if (!Manager.GetDamage().IsEnabled())
{
Secondary = new SecondaryDamageManager(Manager);
Bukkit.getPluginManager().registerEvents(Secondary, Manager.getPlugin());
}
}
else
{
if (Manager.GetDamage().IsEnabled())
{
HandlerList.unregisterAll(Secondary);
Secondary = null;
}
}
}
@EventHandler(priority = EventPriority.LOW)
public void DamageEvent(CustomDamageEvent event)

View File

@ -0,0 +1,182 @@
package nautilus.game.arcade.managers;
import mineplex.minecraft.game.core.condition.Condition.ConditionType;
import mineplex.minecraft.game.core.condition.events.ConditionApplyEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
public class SecondaryDamageManager implements Listener
{
ArcadeManager Manager;
public SecondaryDamageManager(ArcadeManager manager)
{
Manager = manager;
}
@EventHandler(priority = EventPriority.LOW)
public void EntDamage(EntityDamageEvent event)
{
Game game = Manager.GetGame();
if (game == null)
{
event.setCancelled(true);
return;
}
LivingEntity ent = (LivingEntity) event.getEntity();
if (ent.getWorld().getName().equals("world"))
{
event.setCancelled(true);
if (event.getCause() == DamageCause.VOID)
ent.teleport(Manager.GetLobby().GetSpawn());
return;
}
if (Manager.isSpectator(ent))
{
event.setCancelled(true);
if (ent.getFireTicks() > 0)
{
ent.setFireTicks(-1);
}
return;
}
if (game.GetState() != GameState.Live)
{
event.setCancelled(true);
return;
}
if (!game.Damage)
{
event.setCancelled(true);
return;
}
if (ent instanceof Player)
{
if (!game.IsAlive((Player)ent))
{
event.setCancelled(true);
return;
}
}
if (event.getCause() == DamageCause.FALL)
{
if (!game.DamageFall)
{
event.setCancelled(true);
return;
}
}
}
@EventHandler(priority = EventPriority.LOW)
public void DamageEvent(EntityDamageByEntityEvent event)
{
Game game = Manager.GetGame();
if (game == null)
return;
LivingEntity damagee = (LivingEntity)event.getEntity();
if (event.getDamager() instanceof LivingEntity || event.getDamager() instanceof Projectile)
{
LivingEntity damager = null;
if (event.getDamager() instanceof LivingEntity)
{
damager = (LivingEntity)event.getDamager();
}
else
{
if (((Projectile)event.getDamager()).getShooter() instanceof LivingEntity)
{
damager = (LivingEntity)((Projectile)event.getDamager()).getShooter();
}
}
//Damager Spec
if (damager != null && Manager.isSpectator(damager))
{
event.setCancelled(true);
return;
}
if (damager != null && damager instanceof Player && !game.IsAlive((Player)damager))
{
event.setCancelled(true);
return;
}
//Entity vs Entity
if (damagee != null && damager != null)
{
//PvP
if (damagee instanceof Player && damager instanceof Player)
{
if (!Manager.canHurt((Player)damagee, (Player)damager))
{
event.setCancelled(true);
return;
}
}
//PvE
else if (damager instanceof Player)
{
if (!game.DamagePvE)
{
event.setCancelled(true);
return;
}
}
//EvP
else if (damagee instanceof Player)
{
if (!game.DamageEvP)
{
event.setCancelled(true);
return;
}
}
}
}
}
@EventHandler(priority = EventPriority.HIGH)
public void DamageExplosion(ConditionApplyEvent event)
{
if (event.isCancelled())
return;
if (event.GetCondition().GetType() != ConditionType.EXPLOSION)
return;
LivingEntity damagee = event.GetCondition().GetEnt();
if (damagee == null) return;
if (!(damagee instanceof Player)) return;
LivingEntity damager = event.GetCondition().GetSource();
if (damager == null) return;
if (!(damager instanceof Player)) return;
if (Manager.canHurt((Player)damagee, (Player)damager))
return;
event.setCancelled(true);
}
}