Continue refactoring and comment main class

This commit is contained in:
Thanos Paravantis 2016-04-28 13:11:27 +03:00
parent 6cc8f854c4
commit 3a5ec7dc5d
1 changed files with 182 additions and 159 deletions

View File

@ -491,6 +491,27 @@ public class BawkBawkBattles extends TeamGame implements IThrown
removeSolidBlockForPlayers();
}
private void removeSolidBlockForPlayers()
{
for (Player player : GetPlayers(true))
{
removeSolidBlock(player.getLocation());
}
}
@SuppressWarnings("deprecation")
private void removeSolidBlock(Location location)
{
Block block = location.getBlock();
if (!block.isEmpty() && _challenge.getData().isModifiedBlock(block))
{
block.setType(Material.AIR);
block.setData((byte) 0);
_challenge.getData().removeModifiedBlock(block);
}
}
private void teamTeleport(boolean firstRun)
{
TeamChallenge teamChallenge = (TeamChallenge) _challenge;
@ -547,12 +568,12 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
@EventHandler
public void hideMapDuringCountdown(GamePrepareCountdownCommence event)
public void addEffectsDuringCountdown(GamePrepareCountdownCommence event)
{
for (Player player : GetPlayers(true))
{
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Integer.MAX_VALUE, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1));
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Integer.MAX_VALUE, 2));
player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 2));
}
}
@ -681,6 +702,18 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
private void removeEffectsFromPlayers()
{
for (Player player : GetPlayers(true))
{
if (player.hasPotionEffect(PotionEffectType.BLINDNESS) && player.hasPotionEffect(PotionEffectType.NIGHT_VISION))
{
player.removePotionEffect(PotionEffectType.BLINDNESS);
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
}
}
}
private void addEffectsToPlayers()
{
for (Player player : GetPlayers(true))
@ -880,6 +913,91 @@ public class BawkBawkBattles extends TeamGame implements IThrown
EndCheck();
}
private void killRemainingPlayers()
{
for (Player player : getPlayersAlive())
{
if (_challenge.getData().hasAnyoneCompleted() && !_challenge.getData().isCompleted(player))
{
int lives = lives(player) - 1;
if (lives > 0)
{
_challenge.setLost(player);
}
else
{
handleDeath(player);
}
}
addChallengeGemReward(player);
}
}
private void addChallengeGemReward(Player player)
{
if (_challenge.getData().isCompleted(player))
{
AddGems(player, 3, "Completed Challenge", true, true);
}
}
private void sortLastChallengeBlocks()
{
_lastChallengeBlocks = new ArrayList<Block>(_challenge.getData().getModifiedBlocks());
Collections.sort(_lastChallengeBlocks, new Comparator<Block>()
{
@Override
public int compare(Block o1, Block o2)
{
return new Integer(o2.getY()).compareTo(o1.getY());
}
});
}
@Override
public void EndCheck()
{
if (!IsLive())
return;
if (getPlayersWithRemainingLives() <= 1)
{
if (getPlayersAlive().get(0) != null)
{
_winners.add(0, getPlayersAlive().get(0));
}
if (_winners.size() > 2)
{
Collections.swap(_winners, 2, 1);
}
if (_winners.size() >= 1)
{
AddGems(_winners.get(0), 40, "First Place", false, false);
if (_winners.size() >= 2)
{
AddGems(_winners.get(1), 30, "Second Place", false, false);
if (_winners.size() >= 3)
{
AddGems(_winners.get(2), 20, "Third Place", false, false);
}
}
}
for (Player player : super.GetPlayers(false))
AddGems(player, 10, "Participation", false, false);
AnnounceEnd(_winners);
SetState(GameState.End);
}
}
private void updateChallengeTimer()
{
for (Player player : UtilServer.getPlayers())
@ -914,6 +1032,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
/*
* Death
*/
@EventHandler(priority = EventPriority.MONITOR)
public void death(PlayerDeathEvent event)
{
@ -1015,6 +1137,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2.0F, 1.0F);
}
/*
* End reset
*/
@EventHandler
public void end(GameStateChangeEvent event)
{
@ -1031,6 +1157,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
/*
* Chicken attack
*/
@EventHandler
public void chickenAttack(UpdateEvent event)
{
@ -1107,6 +1237,28 @@ public class BawkBawkBattles extends TeamGame implements IThrown
_chickenAttack.kill(player);
}
@EventHandler
public void blockChickenAttackMemberDamage(EntityDamageEvent event)
{
if (!IsLive())
return;
if (event.getEntity() instanceof Chicken)
{
Chicken chicken = (Chicken) event.getEntity();
if (_chickenAttack.isGroupMember(chicken))
{
event.setCancelled(true);
}
if (event.getCause() == DamageCause.VOID)
{
chicken.teleport(_chickenAttack.getPlatformCenter());
}
}
}
@EventHandler
public void spectatorApproachPlayer(UpdateEvent event)
{
@ -1139,6 +1291,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
/*
* Completed players
*/
@EventHandler
public void preventVoidDeath(PlayerMoveEvent event)
{
@ -1182,6 +1338,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
event.setCancelled(true);
}
/*
* Cancel/Quit
*/
@EventHandler
public void cancel(GameStateChangeEvent event)
{
@ -1226,6 +1386,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
/*
* Miscellaneous
*/
@EventHandler
public void blockTeleport(MineplexTeleportEvent event)
{
@ -1253,28 +1417,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
@EventHandler
public void blockChickenAttackMemberDamage(EntityDamageEvent event)
{
if (!IsLive())
return;
if (event.getEntity() instanceof Chicken)
{
Chicken chicken = (Chicken) event.getEntity();
if (_chickenAttack.isGroupMember(chicken))
{
event.setCancelled(true);
}
if (event.getCause() == DamageCause.VOID)
{
chicken.teleport(_chickenAttack.getPlatformCenter());
}
}
}
@SuppressWarnings("deprecation")
@EventHandler
public void blockBlood(ItemSpawnEvent event)
@ -1345,10 +1487,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
@EventHandler
public void removeFeetBlocks(GamePrepareCountdownCommence event)
{
for (Player player : GetPlayers(true))
{
removeSolidBlock(player.getLocation());
}
removeSolidBlockForPlayers();
}
// Debug Only
@ -1524,96 +1663,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
Scoreboard.Draw();
}
private void removeSolidBlockForPlayers()
{
for (Player player : GetPlayers(true))
{
removeSolidBlock(player.getLocation());
}
}
@SuppressWarnings("deprecation")
private void removeSolidBlock(Location location)
{
Block block = location.getBlock();
if (!block.isEmpty() && _challenge.getData().isModifiedBlock(block))
{
block.setType(Material.AIR);
block.setData((byte) 0);
_challenge.getData().removeModifiedBlock(block);
}
}
// private void startChallengeDescriptionThread()
// {
// Thread thread = new Thread(new Runnable()
// {
// @Override
// public void run()
// {
// showChallengeDescription(_challenge);
// }
// });
//
// thread.start();
// }
private void removeEffectsFromPlayers()
{
for (Player player : GetPlayers(true))
{
if (player.hasPotionEffect(PotionEffectType.BLINDNESS) && player.hasPotionEffect(PotionEffectType.NIGHT_VISION))
{
player.removePotionEffect(PotionEffectType.BLINDNESS);
player.removePotionEffect(PotionEffectType.NIGHT_VISION);
}
}
}
private void killRemainingPlayers()
{
for (Player player : getPlayersAlive())
{
if (_challenge.getData().hasAnyoneCompleted() && !_challenge.getData().isCompleted(player))
{
int lives = lives(player) - 1;
if (lives > 0)
{
_challenge.setLost(player);
}
else
{
handleDeath(player);
}
}
addChallengeGemReward(player);
}
}
private void addChallengeGemReward(Player player)
{
if (_challenge.getData().isCompleted(player))
{
AddGems(player, 3, "Completed Challenge", true, true);
}
}
private void sortLastChallengeBlocks()
{
_lastChallengeBlocks = new ArrayList<Block>(_challenge.getData().getModifiedBlocks());
Collections.sort(_lastChallengeBlocks, new Comparator<Block>()
{
@Override
public int compare(Block o1, Block o2)
{
return new Integer(o2.getY()).compareTo(o1.getY());
}
});
}
/*
* Helper methods
*/
@Override
public boolean isInsideMap(Player player)
@ -1632,46 +1684,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return _lives.get(player);
}
@Override
public void EndCheck()
{
if (!IsLive())
return;
if (getPlayersWithRemainingLives() <= 1)
{
if (getPlayersAlive().get(0) != null)
{
_winners.add(0, getPlayersAlive().get(0));
}
if (_winners.size() > 2)
{
Collections.swap(_winners, 2, 1);
}
if (_winners.size() >= 1)
{
AddGems(_winners.get(0), 40, "First Place", false, false);
if (_winners.size() >= 2)
{
AddGems(_winners.get(1), 30, "Second Place", false, false);
if (_winners.size() >= 3)
{
AddGems(_winners.get(2), 20, "Third Place", false, false);
}
}
}
for (Player player : super.GetPlayers(false))
AddGems(player, 10, "Participation", false, false);
AnnounceEnd(_winners);
SetState(GameState.End);
}
}
/*
* Getter methods
*/
public GameTeam getPlayerTeam()
{
@ -1724,6 +1739,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return _chickenAttack;
}
/*
* Player related getter methods
*/
/**
* Returns the list of players contained on the player's team.
*
@ -1776,6 +1795,10 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return amount;
}
/*
* Inherited methods
*/
@Override
public void Collide(LivingEntity target, Block block, ProjectileUser data)
{