Turf Wars: Apply knockback on all players when there are only two in the match.

This commit is contained in:
Thanos paravantis 2016-01-04 17:19:40 +02:00
parent f6ce98f65b
commit 47c78bcba1
2 changed files with 211 additions and 318 deletions

1
.gitignore vendored
View File

@ -54,3 +54,4 @@ zSotanna2
/Pocket /Pocket
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_ /.recommenders/index/http___download_eclipse_org_recommenders_models_mars_
/RemoteSystemsTempFiles /RemoteSystemsTempFiles
/.recommenders/caches

View File

@ -62,34 +62,28 @@ import nautilus.game.arcade.stats.BlockShreadStatTracker;
import nautilus.game.arcade.stats.TheComebackStatTracker; import nautilus.game.arcade.stats.TheComebackStatTracker;
import net.minecraft.server.v1_8_R3.EntityArrow; import net.minecraft.server.v1_8_R3.EntityArrow;
public class TurfForts extends TeamGame public class TurfForts extends TeamGame {
{ public static class ShredBlockEvent extends BlockEvent {
public static class ShredBlockEvent extends BlockEvent
{
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() public static HandlerList getHandlerList() {
{
return handlers; return handlers;
} }
@Override @Override
public HandlerList getHandlers() public HandlerList getHandlers() {
{
return getHandlerList(); return getHandlerList();
} }
private final Arrow _arrow; private final Arrow _arrow;
public ShredBlockEvent(Block theBlock, Arrow arrow) public ShredBlockEvent(Block theBlock, Arrow arrow) {
{
super(theBlock); super(theBlock);
_arrow = arrow; _arrow = arrow;
} }
public Arrow getArrow() public Arrow getArrow() {
{
return _arrow; return _arrow;
} }
} }
@ -115,24 +109,13 @@ public class TurfForts extends TeamGame
private Set<UUID> playersThatNeedBlocks = new HashSet<UUID>(); private Set<UUID> playersThatNeedBlocks = new HashSet<UUID>();
public TurfForts(ArcadeManager manager) public TurfForts(ArcadeManager manager) {
{
super(manager, GameType.TurfWars, super(manager, GameType.TurfWars,
new Kit[] new Kit[] { new KitMarksman(manager), new KitInfiltrator(manager), new KitShredder(manager), },
{
new KitMarksman(manager),
new KitInfiltrator(manager),
new KitShredder(manager),
},
new String[] new String[] { "You have 30 seconds to build your Fort!", "", "Each kill advances your turf forwards.",
{ "Take over all the turf to win!" });
"You have 30 seconds to build your Fort!",
"",
"Each kill advances your turf forwards.",
"Take over all the turf to win!"
});
this.StrictAntiHack = true; this.StrictAntiHack = true;
this.HungerSet = 20; this.HungerSet = 20;
@ -144,16 +127,12 @@ public class TurfForts extends TeamGame
this.DamageSelf = false; this.DamageSelf = false;
this.DeathSpectateSecs = 4; this.DeathSpectateSecs = 4;
registerStatTrackers( registerStatTrackers(new BlockShreadStatTracker(this), new BehindEnemyLinesStatTracker(this),
new BlockShreadStatTracker(this), new TheComebackStatTracker(this));
new BehindEnemyLinesStatTracker(this),
new TheComebackStatTracker(this)
);
} }
@Override @Override
public void ParseData() public void ParseData() {
{
_turf = WorldData.GetDataLocs("YELLOW"); _turf = WorldData.GetDataLocs("YELLOW");
_red = WorldData.GetDataLocs("RED").get(0); _red = WorldData.GetDataLocs("RED").get(0);
@ -162,15 +141,18 @@ public class TurfForts extends TeamGame
_blue = WorldData.GetDataLocs("BLUE").get(0); _blue = WorldData.GetDataLocs("BLUE").get(0);
_blueBase = WorldData.GetDataLocs("LIGHT_BLUE").get(0); _blueBase = WorldData.GetDataLocs("LIGHT_BLUE").get(0);
if (_red.getBlockX() > _blue.getBlockX()) xRed = 1; if (_red.getBlockX() > _blue.getBlockX())
else if (_red.getBlockX() < _blue.getBlockX()) xRed = -1; xRed = 1;
else if (_red.getBlockX() < _blue.getBlockX())
xRed = -1;
if (_red.getBlockZ() > _blue.getBlockZ()) zRed = 1; if (_red.getBlockZ() > _blue.getBlockZ())
else if (_red.getBlockZ() < _blue.getBlockZ()) zRed = -1; zRed = 1;
else if (_red.getBlockZ() < _blue.getBlockZ())
zRed = -1;
// Color Turf // Color Turf
for (Location loc : _turf) for (Location loc : _turf) {
{
if (UtilMath.offset(loc, _red) < UtilMath.offset(loc, _blue)) if (UtilMath.offset(loc, _red) < UtilMath.offset(loc, _blue))
MapUtil.QuickChangeBlockAt(loc, 159, (byte) 14); MapUtil.QuickChangeBlockAt(loc, 159, (byte) 14);
else else
@ -179,8 +161,7 @@ public class TurfForts extends TeamGame
} }
@EventHandler @EventHandler
public void PlayerKillAward(CombatDeathEvent event) public void PlayerKillAward(CombatDeathEvent event) {
{
if (!(event.GetEvent().getEntity() instanceof Player)) if (!(event.GetEvent().getEntity() instanceof Player))
return; return;
@ -202,26 +183,19 @@ public class TurfForts extends TeamGame
if (GetTeam(killer).equals(GetTeam(killed))) if (GetTeam(killer).equals(GetTeam(killed)))
return; return;
if (GetTeam(killer).GetColor() == ChatColor.RED) if (GetTeam(killer).GetColor() == ChatColor.RED) {
{
TurfMove(true); TurfMove(true);
} } else {
else
{
TurfMove(false); TurfMove(false);
} }
} }
private void TurfMove(boolean red) private void TurfMove(boolean red) {
{ for (int line = 0; line < GetLinesPerKill(); line++) {
for (int line = 0; line < GetLinesPerKill(); line++) if (red) {
{
if (red)
{
if (xRed != 0) if (xRed != 0)
for (Location loc : _turf) for (Location loc : _turf)
if (loc.getBlockX() == _blue.getBlockX()) if (loc.getBlockX() == _blue.getBlockX()) {
{
MapUtil.QuickChangeBlockAt(loc, 159, (byte) 14); MapUtil.QuickChangeBlockAt(loc, 159, (byte) 14);
for (int i = 1; i < 6; i++) for (int i = 1; i < 6; i++)
@ -229,11 +203,9 @@ public class TurfForts extends TeamGame
MapUtil.QuickChangeBlockAt(loc.clone().add(0, i, 0), 0, (byte) 0); MapUtil.QuickChangeBlockAt(loc.clone().add(0, i, 0), 0, (byte) 0);
} }
if (zRed != 0) if (zRed != 0)
for (Location loc : _turf) for (Location loc : _turf)
if (loc.getBlockZ() == _blue.getBlockZ()) if (loc.getBlockZ() == _blue.getBlockZ()) {
{
MapUtil.QuickChangeBlockAt(loc, 159, (byte) 14); MapUtil.QuickChangeBlockAt(loc, 159, (byte) 14);
for (int i = 1; i < 6; i++) for (int i = 1; i < 6; i++)
@ -243,13 +215,10 @@ public class TurfForts extends TeamGame
_red.subtract(xRed, 0, zRed); _red.subtract(xRed, 0, zRed);
_blue.subtract(xRed, 0, zRed); _blue.subtract(xRed, 0, zRed);
} } else {
else
{
if (xRed != 0) if (xRed != 0)
for (Location loc : _turf) for (Location loc : _turf)
if (loc.getBlockX() == _red.getBlockX()) if (loc.getBlockX() == _red.getBlockX()) {
{
MapUtil.QuickChangeBlockAt(loc, 159, (byte) 3); MapUtil.QuickChangeBlockAt(loc, 159, (byte) 3);
for (int i = 1; i < 6; i++) for (int i = 1; i < 6; i++)
@ -259,8 +228,7 @@ public class TurfForts extends TeamGame
if (zRed != 0) if (zRed != 0)
for (Location loc : _turf) for (Location loc : _turf)
if (loc.getBlockZ() == _red.getBlockZ()) if (loc.getBlockZ() == _red.getBlockZ()) {
{
MapUtil.QuickChangeBlockAt(loc, 159, (byte) 3); MapUtil.QuickChangeBlockAt(loc, 159, (byte) 3);
for (int i = 1; i < 6; i++) for (int i = 1; i < 6; i++)
@ -277,10 +245,8 @@ public class TurfForts extends TeamGame
} }
@EventHandler @EventHandler
public void BowCancel(EntityShootBowEvent event) public void BowCancel(EntityShootBowEvent event) {
{ if (!_fight) {
if (!_fight)
{
UtilPlayer.message(event.getEntity(), F.main("Game", "You cannot attack during Build Time!")); UtilPlayer.message(event.getEntity(), F.main("Game", "You cannot attack during Build Time!"));
event.setCancelled(true); event.setCancelled(true);
@ -289,21 +255,17 @@ public class TurfForts extends TeamGame
} }
@EventHandler @EventHandler
public void BlockBreak(BlockBreakEvent event) public void BlockBreak(BlockBreakEvent event) {
{ if (event.isCancelled()) // this statement might save just a small
if (event.isCancelled()) // this statement might save just a small amount of time // amount of time
return; return;
if (!IsAlive(event.getPlayer())) {
if (!IsAlive(event.getPlayer()))
{
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (UtilPlayer.isSpectator(event.getPlayer())) if (UtilPlayer.isSpectator(event.getPlayer())) {
{
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -313,36 +275,33 @@ public class TurfForts extends TeamGame
GameTeam team = GetTeam(event.getPlayer()); GameTeam team = GetTeam(event.getPlayer());
GameTeam otherTeam = GetOtherTeam(team); GameTeam otherTeam = GetOtherTeam(team);
if (block.getType().equals(Material.WOOL) && (block.getData() == 14 && team.GetColor() != ChatColor.RED) || (block.getData() == 3 && team.GetColor() != ChatColor.AQUA)) if (block.getType().equals(Material.WOOL) && (block.getData() == 14 && team.GetColor() != ChatColor.RED)
{ || (block.getData() == 3 && team.GetColor() != ChatColor.AQUA)) {
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot break the " + F.elem(otherTeam.GetColor() + otherTeam.GetName()) + " team's blocks!")); UtilPlayer.message(event.getPlayer(), F.main("Game",
"You cannot break the " + F.elem(otherTeam.GetColor() + otherTeam.GetName()) + " team's blocks!"));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void BlockPlace(BlockPlaceEvent event) public void BlockPlace(BlockPlaceEvent event) {
{
// Remoeved and replaced by ignoreCancelled = true // Remoeved and replaced by ignoreCancelled = true
// if (event.isCancelled()) // if (event.isCancelled())
// return; // return;
GameTeam team = GetTeam(event.getPlayer()); GameTeam team = GetTeam(event.getPlayer());
if (team == null) if (team == null) {
{
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (!IsAlive(event.getPlayer())) if (!IsAlive(event.getPlayer())) {
{
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (UtilPlayer.isSpectator(event.getPlayer())) if (UtilPlayer.isSpectator(event.getPlayer())) {
{
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -352,17 +311,16 @@ public class TurfForts extends TeamGame
while (block.getTypeId() == 0) while (block.getTypeId() == 0)
block = block.getRelative(BlockFace.DOWN); block = block.getRelative(BlockFace.DOWN);
if (block.getData() != team.GetColorData()) if (block.getData() != team.GetColorData()) {
{ UtilPlayer.message(event.getPlayer(),
UtilPlayer.message(event.getPlayer(), F.main("Game", "You can only build above " + F.elem(team.GetColor() + team.GetName()) + ".")); F.main("Game", "You can only build above " + F.elem(team.GetColor() + team.GetName()) + "."));
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
// Height // Height
boolean aboveTurf = false; boolean aboveTurf = false;
for (int i = 1; i <= 5; i++) for (int i = 1; i <= 5; i++) {
{
if (event.getBlock().getRelative(BlockFace.DOWN, i).getTypeId() != 159) if (event.getBlock().getRelative(BlockFace.DOWN, i).getTypeId() != 159)
continue; continue;
@ -370,8 +328,7 @@ public class TurfForts extends TeamGame
break; break;
} }
if (!aboveTurf) if (!aboveTurf) {
{
UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot build this high above Turf.")); UtilPlayer.message(event.getPlayer(), F.main("Game", "You cannot build this high above Turf."));
event.setCancelled(true); event.setCancelled(true);
return; return;
@ -379,8 +336,7 @@ public class TurfForts extends TeamGame
} }
@EventHandler @EventHandler
public void BlockDamage(ProjectileHitEvent event) public void BlockDamage(ProjectileHitEvent event) {
{
if (event.getEntity().getShooter() == null) if (event.getEntity().getShooter() == null)
return; return;
@ -397,12 +353,9 @@ public class TurfForts extends TeamGame
final Arrow arrow = (Arrow) event.getEntity(); final Arrow arrow = (Arrow) event.getEntity();
Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() Manager.getPlugin().getServer().getScheduler().scheduleSyncDelayedTask(Manager.getPlugin(), new Runnable() {
{ public void run() {
public void run() try {
{
try
{
EntityArrow entityArrow = ((CraftArrow) arrow).getHandle(); EntityArrow entityArrow = ((CraftArrow) arrow).getHandle();
Field fieldX = EntityArrow.class.getDeclaredField("d"); Field fieldX = EntityArrow.class.getDeclaredField("d");
@ -419,27 +372,28 @@ public class TurfForts extends TeamGame
Block block = arrow.getWorld().getBlockAt(x, y, z); Block block = arrow.getWorld().getBlockAt(x, y, z);
if (block.getTypeId() == 35) if (block.getTypeId() == 35) {
{ if (block.getData() == 14 /*
if (block.getData() == 14 /* && team.GetColor() != ChatColor.RED */) * && team.GetColor() !=
{ * ChatColor.RED
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK.getId()); */) {
} block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND,
else if (block.getData() == 3 /* && team.GetColor() != ChatColor.AQUA */) Material.REDSTONE_BLOCK.getId());
{ } else if (block.getData() == 3 /*
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, Material.LAPIS_BLOCK.getId()); * && team.GetColor() !=
* ChatColor.AQUA
*/) {
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND,
Material.LAPIS_BLOCK.getId());
} }
Bukkit.getPluginManager().callEvent(new ShredBlockEvent(block, arrow)); Bukkit.getPluginManager().callEvent(new ShredBlockEvent(block, arrow));
block.setType(Material.AIR); block.setType(Material.AIR);
} }
arrow.remove(); arrow.remove();
} } catch (Exception e) {
catch (Exception e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -447,60 +401,47 @@ public class TurfForts extends TeamGame
} }
@EventHandler @EventHandler
public void Damage(CustomDamageEvent event) public void Damage(CustomDamageEvent event) {
{ if (event.GetCause() == DamageCause.FALL) {
if (event.GetCause() == DamageCause.FALL)
{
event.SetCancelled("No Fall"); event.SetCancelled("No Fall");
return; return;
} }
if (!_fight && (event.GetCause() == DamageCause.PROJECTILE || event.GetCause() == DamageCause.ENTITY_ATTACK)) if (!_fight && (event.GetCause() == DamageCause.PROJECTILE || event.GetCause() == DamageCause.ENTITY_ATTACK)) {
{
event.SetCancelled("Build Time"); event.SetCancelled("Build Time");
return; return;
} }
Player damager = event.GetDamagerPlayer(true); Player damager = event.GetDamagerPlayer(true);
if (damager == null) return; if (damager == null)
return;
if (event.GetCause() == DamageCause.PROJECTILE) if (event.GetCause() == DamageCause.PROJECTILE) {
{
event.AddMod("Turf Forts", "Nullify", -event.GetDamageInitial(), false); event.AddMod("Turf Forts", "Nullify", -event.GetDamageInitial(), false);
if (GetKit(damager).GetName().contains("Shredder")) if (GetKit(damager).GetName().contains("Shredder")) {
{
event.SetCancelled("Shredder"); event.SetCancelled("Shredder");
Manager.GetDamage().NewDamageEvent(event.GetDamageeEntity(), damager, null, Manager.GetDamage().NewDamageEvent(event.GetDamageeEntity(), damager, null, DamageCause.CUSTOM, 9, true,
DamageCause.CUSTOM, 9, true, true, false, true, false, damager.getName(), "Barrage");
damager.getName(), "Barrage");
return; return;
} } else {
else
{
event.AddMod("Turf Forts", "One Hit Kill", 30, false); event.AddMod("Turf Forts", "One Hit Kill", 30, false);
} }
} } else if (event.GetCause() == DamageCause.ENTITY_ATTACK) {
else if (event.GetCause() == DamageCause.ENTITY_ATTACK)
{
event.AddMod("Turf Forts", "Nullify", -event.GetDamageInitial(), false); event.AddMod("Turf Forts", "Nullify", -event.GetDamageInitial(), false);
if (UtilGear.isMat(damager.getItemInHand(), Material.IRON_SWORD)) if (UtilGear.isMat(damager.getItemInHand(), Material.IRON_SWORD)) {
{
event.AddMod("Turf Forts", "One Hit Kill", 12, false); event.AddMod("Turf Forts", "One Hit Kill", 12, false);
} } else {
else
{
event.AddMod("Turf Forts", "One Hit Kill", 6, false); event.AddMod("Turf Forts", "One Hit Kill", 6, false);
} }
} }
} }
@EventHandler @EventHandler
public void ScoreboardTitle(UpdateEvent event) public void ScoreboardTitle(UpdateEvent event) {
{
if (GetState() != GameState.Live) if (GetState() != GameState.Live)
return; return;
@ -512,48 +453,42 @@ public class TurfForts extends TeamGame
return; return;
long time; long time;
if (!_fight) if (!_fight) {
{
time = _buildTime - (System.currentTimeMillis() - _phaseTime); time = _buildTime - (System.currentTimeMillis() - _phaseTime);
if (time <= 0) if (time <= 0) {
{
_fight = true; _fight = true;
_lines++; _lines++;
Announce(" "); Announce(" ");
Announce(C.cWhite + C.Bold + "1 Kill" + C.cWhite + C.Bold + " = " + C.cWhite + C.Bold + GetLinesPerKill() + " Turf Lines"); Announce(C.cWhite + C.Bold + "1 Kill" + C.cWhite + C.Bold + " = " + C.cWhite + C.Bold
Announce(C.cWhite + C.Bold + "90 Seconds of " + C.cYellow + C.Bold + "Combat Time" + C.cWhite + C.Bold + " has begun!"); + GetLinesPerKill() + " Turf Lines");
Announce(C.cWhite + C.Bold + "90 Seconds of " + C.cYellow + C.Bold + "Combat Time" + C.cWhite + C.Bold
+ " has begun!");
Announce(" "); Announce(" ");
_phaseTime = System.currentTimeMillis(); _phaseTime = System.currentTimeMillis();
} }
} }
else else {
{
time = _fightTime - (System.currentTimeMillis() - _phaseTime); time = _fightTime - (System.currentTimeMillis() - _phaseTime);
if (time <= 0) if (time <= 0) {
{
_fight = false; _fight = false;
Announce(" "); Announce(" ");
Announce(C.cWhite + C.Bold + "20 Seconds of " + C.cGreen + C.Bold + "Build Time" + C.cWhite + C.Bold + " has begun!"); Announce(C.cWhite + C.Bold + "20 Seconds of " + C.cGreen + C.Bold + "Build Time" + C.cWhite + C.Bold
+ " has begun!");
Announce(" "); Announce(" ");
_phaseTime = System.currentTimeMillis(); _phaseTime = System.currentTimeMillis();
for (GameTeam team : GetTeamList()) for (GameTeam team : GetTeamList()) {
{ for (Player player : team.GetPlayers(true)) {
for (Player player : team.GetPlayers(true)) if (UtilPlayer.isSpectator(player)) {
{
if (UtilPlayer.isSpectator(player))
{
this.playersThatNeedBlocks.add(player.getUniqueId()); this.playersThatNeedBlocks.add(player.getUniqueId());
} } else {
else
{
addBlocks(team, player); addBlocks(team, player);
} }
} }
@ -562,51 +497,44 @@ public class TurfForts extends TeamGame
} }
} }
public void addBlocks(GameTeam team, Player player) public void addBlocks(GameTeam team, Player player) {
{
player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WOOL, team.GetColorData(), 24)); player.getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WOOL, team.GetColorData(), 24));
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onQuit(PlayerQuitEvent event) public void onQuit(PlayerQuitEvent event) {
{
this.playersThatNeedBlocks.remove(event.getPlayer().getUniqueId()); this.playersThatNeedBlocks.remove(event.getPlayer().getUniqueId());
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onSpawn(PlayerKitGiveEvent event) public void onSpawn(PlayerKitGiveEvent event) {
{
Player player = event.getPlayer(); Player player = event.getPlayer();
if (this.playersThatNeedBlocks.contains(player.getUniqueId())) if (this.playersThatNeedBlocks.contains(player.getUniqueId())) {
{
this.playersThatNeedBlocks.remove(player.getUniqueId()); this.playersThatNeedBlocks.remove(player.getUniqueId());
this.addBlocks(GetTeam(player), player); this.addBlocks(GetTeam(player), player);
} }
} }
@Override @Override
@EventHandler @EventHandler
public void ScoreboardUpdate(UpdateEvent event) public void ScoreboardUpdate(UpdateEvent event) {
{
if (event.getType() != UpdateType.FAST) if (event.getType() != UpdateType.FAST)
return; return;
Scoreboard.Reset(); Scoreboard.Reset();
for (GameTeam team : this.GetTeamList()) for (GameTeam team : this.GetTeamList()) {
{
int lines = 0; int lines = 0;
if (team.GetColor() == ChatColor.RED) lines = GetRedLines(); if (team.GetColor() == ChatColor.RED)
else lines = GetBlueLines(); lines = GetRedLines();
else
lines = GetBlueLines();
Scoreboard.WriteBlank(); Scoreboard.WriteBlank();
Scoreboard.Write(lines + " " + team.GetColor() + team.GetName()); Scoreboard.Write(lines + " " + team.GetColor() + team.GetName());
} }
if (!_fight) if (!_fight) {
{
long time = _buildTime - (System.currentTimeMillis() - _phaseTime); long time = _buildTime - (System.currentTimeMillis() - _phaseTime);
Scoreboard.WriteBlank(); Scoreboard.WriteBlank();
@ -615,8 +543,7 @@ public class TurfForts extends TeamGame
} }
else else {
{
long time = _fightTime - (System.currentTimeMillis() - _phaseTime); long time = _fightTime - (System.currentTimeMillis() - _phaseTime);
Scoreboard.WriteBlank(); Scoreboard.WriteBlank();
@ -627,89 +554,72 @@ public class TurfForts extends TeamGame
Scoreboard.Draw(); Scoreboard.Draw();
} }
public int GetRedLines() public int GetRedLines() {
{
if (!InProgress()) if (!InProgress())
return 0; return 0;
if (xRed != 0) if (xRed != 0) {
{
return Math.abs(_redBase.getBlockX() - _red.getBlockX()); return Math.abs(_redBase.getBlockX() - _red.getBlockX());
} }
return Math.abs(_redBase.getBlockZ() - _red.getBlockZ()); return Math.abs(_redBase.getBlockZ() - _red.getBlockZ());
} }
public int GetBlueLines() public int GetBlueLines() {
{
if (!InProgress()) if (!InProgress())
return 0; return 0;
if (xRed != 0) if (xRed != 0) {
{
return Math.abs(_blueBase.getBlockX() - _blue.getBlockX()); return Math.abs(_blueBase.getBlockX() - _blue.getBlockX());
} }
return Math.abs(_blueBase.getBlockZ() - _blue.getBlockZ()); return Math.abs(_blueBase.getBlockZ() - _blue.getBlockZ());
} }
public int getLines(GameTeam team) public int getLines(GameTeam team) {
{
if (team.GetColor() == ChatColor.RED) if (team.GetColor() == ChatColor.RED)
return GetRedLines(); return GetRedLines();
else else
return GetBlueLines(); return GetBlueLines();
} }
public int GetLinesPerKill() public int GetLinesPerKill() {
{
return _lines; return _lines;
//return Math.min(5, 1 + (int)((System.currentTimeMillis() - GetStateTime() - 30000) / 60000)); // return Math.min(5, 1 + (int)((System.currentTimeMillis() -
// GetStateTime() - 30000) / 60000));
} }
@EventHandler @EventHandler
public void PlayerDeath(PlayerDeathEvent event) public void PlayerDeath(PlayerDeathEvent event) {
{
_enemyTurf.remove(event.getEntity()); _enemyTurf.remove(event.getEntity());
} }
@EventHandler @EventHandler
public void Territory(UpdateEvent event) public void Territory(UpdateEvent event) {
{
if (!IsLive()) if (!IsLive())
return; return;
if (event.getType() != UpdateType.FASTER) if (event.getType() != UpdateType.FASTER)
return; return;
for (GameTeam team : this.GetTeamList()) for (GameTeam team : this.GetTeamList()) {
{ for (Player player : team.GetPlayers(true)) {
for (Player player : team.GetPlayers(true))
{
if (((CraftPlayer) player).getHandle().spectating) if (((CraftPlayer) player).getHandle().spectating)
continue; continue;
Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN); Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
// Apply velocity even if the player is sneaking near turf edges. // Apply velocity even if the player is sneaking near turf
// edges.
if (block.isEmpty()) if (block.isEmpty() && player.isOnGround()) {
{ Block[] nearby = { block.getRelative(BlockFace.NORTH), block.getRelative(BlockFace.SOUTH),
Block[] nearby = { block.getRelative(BlockFace.WEST), block.getRelative(BlockFace.EAST),
block.getRelative(BlockFace.NORTH), block.getRelative(BlockFace.NORTH_EAST), block.getRelative(BlockFace.NORTH_WEST),
block.getRelative(BlockFace.SOUTH), block.getRelative(BlockFace.SOUTH_EAST), block.getRelative(BlockFace.SOUTH_WEST) };
block.getRelative(BlockFace.WEST),
block.getRelative(BlockFace.EAST),
block.getRelative(BlockFace.NORTH_EAST),
block.getRelative(BlockFace.NORTH_WEST),
block.getRelative(BlockFace.SOUTH_EAST),
block.getRelative(BlockFace.SOUTH_WEST)
};
for (Block near : nearby) for (Block near : nearby) {
{ if (near.getType() == Material.STAINED_CLAY || near.getType() == Material.WOOL) {
if (near.getTypeId() == 159)
{
block = near; block = near;
break; break;
} }
@ -725,21 +635,20 @@ public class TurfForts extends TeamGame
byte data = block.getData(); byte data = block.getData();
// Slow // Slow
if (_enemyTurf.containsKey(player)) if (_enemyTurf.containsKey(player)) {
{
int time = (int) ((System.currentTimeMillis() - _enemyTurf.get(player)) / 2500); int time = (int) ((System.currentTimeMillis() - _enemyTurf.get(player)) / 2500);
if (time > 0) if (time > 0)
Manager.GetCondition().Factory().Slow("Infiltrator Slow", player, player, 0.9, time - 1, false, false, false, false); Manager.GetCondition().Factory().Slow("Infiltrator Slow", player, player, 0.9, time - 1, false,
false, false, false);
} }
// On Enemy Turf // On Enemy Turf
if ((team.GetColor() == ChatColor.RED && data == 3) || (team.GetColor() == ChatColor.AQUA && data == 14)) if ((team.GetColor() == ChatColor.RED && data == 3)
{ || (team.GetColor() == ChatColor.AQUA && data == 14)) {
// Infiltrate // Infiltrate
if (_fight && GetKit(player) != null && GetKit(player).GetName().contains("Infil")) if (_fight && GetKit(player) != null && GetKit(player).GetName().contains("Infil")) {
{
if (!_enemyTurf.containsKey(player)) if (!_enemyTurf.containsKey(player))
_enemyTurf.put(player, System.currentTimeMillis()); _enemyTurf.put(player, System.currentTimeMillis());
@ -747,19 +656,22 @@ public class TurfForts extends TeamGame
continue; continue;
} }
if (Recharge.Instance.use(player, "Territory Knockback", 2000, false, false)) if (Recharge.Instance.use(player, "Territory Knockback", 2000, false, false)) {
{ UtilAction.velocity(player, UtilAlg.getTrajectory2d(player.getLocation(), team.GetSpawn()), 2,
UtilAction.velocity(player, UtilAlg.getTrajectory2d(player.getLocation(), team.GetSpawn()), 2, false, 0, 0.8, 1, true); false, 0, 0.8, 1, true);
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 1f); player.playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 1f);
UtilPlayer.message(player, F.main("Game", "You cannot walk on the enemies turf!")); UtilPlayer.message(player, F.main("Game", "You cannot walk on the enemies turf!"));
} }
return; // Looks like that with 'return' if there are only two
// players, one of them will not get knockback.
// return;
} }
// On Own Turf // On Own Turf
else if ((team.GetColor() == ChatColor.RED && data == 14) || (team.GetColor() == ChatColor.AQUA && data == 3)) else if ((team.GetColor() == ChatColor.RED && data == 14)
{ || (team.GetColor() == ChatColor.AQUA && data == 3)) {
_enemyTurf.remove(player); _enemyTurf.remove(player);
} }
} }
@ -767,27 +679,17 @@ public class TurfForts extends TeamGame
} }
/* /*
@EventHandler * @EventHandler public void ItemRemoval(UpdateEvent event) { if (!IsLive())
public void ItemRemoval(UpdateEvent event) * return;
{ *
if (!IsLive()) * if (event.getType() != UpdateType.FAST) return;
return; *
* for (Entity ent : _red.getWorld().getEntities()) { if (!(ent instanceof
if (event.getType() != UpdateType.FAST) * Item)) continue;
return; *
* if (ent.getTicksLived() > 40) ent.remove(); } }
for (Entity ent : _red.getWorld().getEntities())
{
if (!(ent instanceof Item))
continue;
if (ent.getTicksLived() > 40)
ent.remove();
}
}
*/ */
public GameTeam GetOtherTeam(GameTeam team) { public GameTeam GetOtherTeam(GameTeam team) {
return team.GetColor() == ChatColor.RED ? GetTeam(ChatColor.AQUA) : GetTeam(ChatColor.RED); return team.GetColor() == ChatColor.RED ? GetTeam(ChatColor.AQUA) : GetTeam(ChatColor.RED);
} }
@ -800,26 +702,19 @@ public class TurfForts extends TeamGame
} }
@Override @Override
public void EndCheck() public void EndCheck() {
{
if (!IsLive()) if (!IsLive())
return; return;
if (GetRedLines() == 0 || GetTeam(ChatColor.RED).GetPlayers(true).size() == 0) if (GetRedLines() == 0 || GetTeam(ChatColor.RED).GetPlayers(true).size() == 0) {
{
AnnounceEnd(GetTeam(ChatColor.AQUA)); AnnounceEnd(GetTeam(ChatColor.AQUA));
} } else if (GetBlueLines() == 0 || GetTeam(ChatColor.AQUA).GetPlayers(true).size() == 0) {
else if (GetBlueLines() == 0 || GetTeam(ChatColor.AQUA).GetPlayers(true).size() == 0)
{
AnnounceEnd(GetTeam(ChatColor.RED)); AnnounceEnd(GetTeam(ChatColor.RED));
} } else
else
return; return;
for (GameTeam team : GetTeamList()) for (GameTeam team : GetTeamList()) {
{ if (WinnerTeam != null && team.equals(WinnerTeam)) {
if (WinnerTeam != null && team.equals(WinnerTeam))
{
for (Player player : team.GetPlayers(false)) for (Player player : team.GetPlayers(false))
AddGems(player, 10, "Winning Team", false, false); AddGems(player, 10, "Winning Team", false, false);
} }
@ -833,23 +728,20 @@ public class TurfForts extends TeamGame
SetState(GameState.End); SetState(GameState.End);
} }
public Long getEnemyTurfEntranceTime(Player player) public Long getEnemyTurfEntranceTime(Player player) {
{
return _enemyTurf.get(player); return _enemyTurf.get(player);
} }
// Keep ladders placed on ice when block updates occur. // Keep ladders placed on ice when block updates occur.
@EventHandler @EventHandler
public void onBlockPhysics(BlockPhysicsEvent event) public void onBlockPhysics(BlockPhysicsEvent event) {
{
if (!IsLive()) if (!IsLive())
return; return;
Block block = event.getBlock(); Block block = event.getBlock();
if (block.getType() == Material.LADDER) if (block.getType() == Material.LADDER) {
{
event.setCancelled(true); event.setCancelled(true);
} }
} }