Deregister stat trackers from listener

This commit is contained in:
Chiss 2014-09-06 22:01:05 +10:00
parent 644d3da050
commit f138a4108b
2 changed files with 77 additions and 60 deletions

View File

@ -112,7 +112,7 @@ public class MineStrike extends TeamGame
private int _bulletInstant = 2; //0 = Slow, 1 = Instant, 2 = Mix
private boolean _customHitbox = true;
private boolean _bulletAlternate = false;
//Map Data
private ArrayList<Location> _bombSites;
@ -772,13 +772,13 @@ public class MineStrike extends TeamGame
gun.reduceCone();
}
}
@EventHandler
public void slowBulletHit(final ProjectileHitEvent event)
{
if (!(event.getEntity() instanceof Snowball))
return;
Bullet bullet = _bullets.get(event.getEntity());
//Particle
@ -787,21 +787,21 @@ public class MineStrike extends TeamGame
//Hit Block Sound
event.getEntity().getWorld().playSound(event.getEntity().getLocation(), Sound.ENDERMAN_HIT, 1f, 1f);
//Block Particle
Location loc = event.getEntity().getLocation().add(event.getEntity().getVelocity().multiply(0.8));
Block block = loc.getBlock();
if (block.getType() == Material.AIR)
{
Block closest = null;
double closestDist = 0;
for (Block other : UtilBlock.getSurrounding(block, true))
{
if (other.getType() == Material.AIR)
continue;
double dist = UtilMath.offset(loc, other.getLocation().add(0.5, 0.5, 0.5));
if (closest == null || dist < closestDist)
@ -810,30 +810,30 @@ public class MineStrike extends TeamGame
closestDist = dist;
}
}
if (closest != null)
block = closest;
}
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getType());
}
@EventHandler
public void slowBulletWhizz(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Entity ent : _bullets.keySet())
{
if (ent instanceof Snowball)
continue;
if (ent.getTicksLived() < 10)
continue;
Bullet bullet = _bullets.get(ent);
for (Player player : UtilServer.getPlayers())
{
if (UtilMath.offset(ent, player) < 4)
@ -946,16 +946,16 @@ public class MineStrike extends TeamGame
}
}
@EventHandler(priority=EventPriority.MONITOR)
public void removeArrowsFromPlayer(CustomDamageEvent event)
{
if (event.GetDamageePlayer() != null)
((CraftPlayer) event.GetDamageePlayer()).getHandle().p(0);
}
@EventHandler(priority=EventPriority.HIGH)
public void damage(CustomDamageEvent event)
{
@ -1032,7 +1032,7 @@ public class MineStrike extends TeamGame
//Get Hit Area
int hitArea = 0;
if (_customHitbox)
{
if (event.GetProjectile() instanceof Arrow)
@ -1040,14 +1040,14 @@ public class MineStrike extends TeamGame
else
hitArea = getSnowballHitArea(event.GetDamageePlayer(), event.GetProjectile());
}
if (hitArea == -1)
{
event.SetCancelled("Miss");
return;
}
//Bullet Whiz Sound
if (event.GetProjectile() instanceof Arrow)
instantBulletWhizz(event.GetDamageePlayer().getEyeLocation(), bullet);
@ -1064,7 +1064,7 @@ public class MineStrike extends TeamGame
//Damage + Dropoff
double damage = bullet.getDamage();
double damageDropoff = bullet.getDamageDropoff(event.GetDamageeEntity().getLocation());
//Add Damages
event.AddMod(bullet.Shooter.getName(), bullet.Gun.getName(), damage, true);
event.AddMod(bullet.Shooter.getName(), "Distance Dropoff", damageDropoff, false);
@ -1073,21 +1073,21 @@ public class MineStrike extends TeamGame
if (hitArea == 1)
{
event.AddMod(bullet.Shooter.getName(), "Headshot", damage*2, true);
//Wearing Helmet
if (Armor.isArmor(event.GetDamageePlayer().getInventory().getHelmet()) ||
(_scoped.containsKey(event.GetDamageePlayer()) && UtilGear.isMat(_scoped.get(event.GetDamageePlayer()), Material.LEATHER_HELMET)))
(_scoped.containsKey(event.GetDamageePlayer()) && UtilGear.isMat(_scoped.get(event.GetDamageePlayer()), Material.LEATHER_HELMET)))
{
event.AddMod(event.GetDamageePlayer().getName(), "Helmet", -damage*1, false);
event.GetDamageePlayer().getWorld().playSound(event.GetDamageePlayer().getEyeLocation(), Sound.SPIDER_DEATH, 1f, 1f);
}
else
{
event.GetDamageePlayer().getWorld().playSound(event.GetDamageePlayer().getEyeLocation(), Sound.SLIME_ATTACK, 1f, 1f);
}
}
//Kevlar - Body Hit
if (hitArea == 0 && Armor.isArmor(event.GetDamageePlayer().getInventory().getChestplate()))
{
@ -1105,56 +1105,68 @@ public class MineStrike extends TeamGame
event.SetIgnoreRate(true);
event.SetIgnoreArmor(true);
}
public int getArrowHitArea(Player damagee, Location origin, Vector trajectory)
{
System.out.println("Getting Area");
//Move to near-player
Location start = origin.clone().add(trajectory.multiply(UtilMath.offset(origin, damagee.getEyeLocation()) - 2));
Location start = origin.clone().add(trajectory.clone().multiply(UtilMath.offset(origin, damagee.getEyeLocation()) - 2));
Location loc = start.clone();
while (!hitHead(damagee, loc) && !hitBody(damagee, loc) && UtilMath.offset(damagee.getLocation(), loc) < 6)
{
UtilParticle.PlayParticle(ParticleType.HAPPY_VILLAGER, loc, 0, 0, 0, 0, 1);
loc.add(trajectory.clone().multiply(0.1));
}
if (hitHead(damagee, loc))
{
System.out.println("Head");
return 1;
}
if (hitBody(damagee, loc))
{
System.out.println("Body");
return 0;
}
System.out.println("Miss");
return -1;
}
public int getSnowballHitArea(Player damagee, Projectile snowball)
{
//Move to near-player
Location start = snowball.getLocation();
Location loc = start.clone();
while (!hitHead(damagee, loc) && !hitBody(damagee, loc) && UtilMath.offset(damagee.getLocation(), loc) < 6)
{
loc.add(snowball.getVelocity().clone().multiply(0.1));
}
if (hitHead(damagee, loc))
return 1;
if (hitBody(damagee, loc))
return 0;
return -1;
}
public boolean hitBody(Player player, Location loc)
{
return UtilMath.offset2d(loc, player.getLocation()) < 0.6 && //0.6 is ideal
loc.getY() > player.getLocation().getY() &&
loc.getY() < player.getEyeLocation().getY() - 0.2;
}
public boolean hitHead(Player player, Location loc)
{
return UtilMath.offset2d(loc, player.getLocation()) < 0.3 && //0.3 is ideal
@ -1418,7 +1430,7 @@ public class MineStrike extends TeamGame
_bombDefuser.setExp(0f);
UtilPlayer.message(player, F.main("Game", "You are defusing the Bomb."));
_bombDefuser.getWorld().playSound(_bombDefuser.getLocation(), Sound.PISTON_RETRACT, 2f, 1f);
}
@ -1711,7 +1723,7 @@ public class MineStrike extends TeamGame
{
player.playSound(player.getLocation(), Sound.HORSE_ARMOR, 1f, 2f);
Manager.GetCondition().Factory().Blind("Respawn", player, null, 2, 0, false, false, false);
UtilPlayer.message(player, F.main("Game", "You have " + F.elem(C.cGreen + "$" + _shopManager.getMoney(player)) + "."));
UtilPlayer.message(player, F.main("Game", "You have " + F.elem(C.cGreen + "$" + _shopManager.getMoney(player)) + ". Open your Inventory to spend it."));
}
//Give Bomb
@ -1722,21 +1734,21 @@ public class MineStrike extends TeamGame
for (GameTeam team : GetTeamList())
for (Player teamMember : team.GetPlayers(true))
GetScoreboard().SetPlayerTeam(teamMember, team.GetName().toUpperCase());
//Alternate Bullets
if (_bulletAlternate)
_bulletInstant = (_bulletInstant + 1)%3;
//Debug Details
if (_debug)
{
Announce(C.cDPurple + C.Bold + "ROUND SETTINGS:");
if (_customHitbox)
Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Accurate with Headshots");
else
Announce(C.cPurple + C.Bold + "Hitbox: " + ChatColor.RESET + "Default with No Headshot");
if (_bulletInstant == 0)
Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible");
else if (_bulletInstant == 1)
@ -1835,11 +1847,11 @@ public class MineStrike extends TeamGame
//Restock Ammo
for (Gun gun : _gunsEquipped.keySet())
gun.restockAmmo(_gunsEquipped.get(gun));
//Health
for (Player player : UtilServer.getPlayers())
player.setHealth(20);
//Reset Shop
for (Player player : UtilServer.getPlayers())
_shopManager.leaveShop(player, false, false);
@ -2062,16 +2074,16 @@ public class MineStrike extends TeamGame
{
if (event.getType() != UpdateType.TICK)
return;
if (_bombItem == null)
return;
if (!_bombItem.isValid())
{
Location loc = _bombItem.getLocation();
_bombItem.remove();
_bombItem = loc.getWorld().dropItemNaturally(loc, new ItemStack(Material.GOLD_SWORD));
}
}
@ -2267,7 +2279,7 @@ public class MineStrike extends TeamGame
{
if (!IsLive())
return;
if (event.getType() != UpdateType.TICK)
return;
@ -2371,7 +2383,7 @@ public class MineStrike extends TeamGame
_shopManager.addMoney(event.getPlayer(), 16000, "Debug");
event.setCancelled(true);
}
if (event.getMessage().contains("instant"))
{
_bulletInstant = (_bulletInstant + 1)%3;
@ -2382,11 +2394,11 @@ public class MineStrike extends TeamGame
Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Instant and Invisible");
else
Announce(C.cPurple + C.Bold + "Bullets: " + ChatColor.RESET + "Slow and Visible with Instant Sniper");
event.setCancelled(true);
}
if (event.getMessage().contains("hitbox"))
{
_customHitbox = !_customHitbox;
@ -2398,7 +2410,7 @@ public class MineStrike extends TeamGame
event.setCancelled(true);
}
if (event.getMessage().contains("alternate"))
{
_bulletAlternate = !_bulletAlternate;
@ -2407,16 +2419,16 @@ public class MineStrike extends TeamGame
event.setCancelled(true);
}
if (event.getMessage().contains("god"))
{
if (HealthSet == 20)
HealthSet = -1;
else
HealthSet = 20;
Announce(C.cPurple + C.Bold + "God Mode: " + ChatColor.RESET + (HealthSet == 20));
event.setCancelled(true);
}

View File

@ -14,6 +14,7 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.stats.StatTracker;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@ -92,8 +93,12 @@ public class GameCreationManager implements Listener
{
Game game = gameIterator.next();
HandlerList.unregisterAll(game);
for (StatTracker tracker : game.getStatTrackers())
HandlerList.unregisterAll(tracker);
TimingManager.start("GameCreationManager - Attempting Removal - " + game.GetName());
//Cleaned