Implement game settings and challenge list. Add isChallengeValid and isPlayerValid for event checks.

This commit is contained in:
Thanos paravantis 2016-03-04 20:01:08 +02:00
parent 9e09d8c477
commit 51d4db5e46
21 changed files with 333 additions and 261 deletions

View File

@ -37,7 +37,7 @@ public class AntiHackFix implements Listener
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (!_host.IsLive() || !_host.isChallengeStarted())
if (!_host.IsLive() || !_host.getSettings().isChallengeStarted())
return;
Player player = event.getPlayer();

View File

@ -14,7 +14,7 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Entity;
@ -75,6 +75,7 @@ import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.GameTeam.PlayerState;
import nautilus.game.arcade.game.TeamGame;
import nautilus.game.arcade.game.games.mineware.challenge.Challenge;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeList;
import nautilus.game.arcade.game.games.mineware.challenge.ChallengeType;
import nautilus.game.arcade.game.games.mineware.challenge.other.ChallengeSeperateRooms;
import nautilus.game.arcade.game.games.mineware.challenge.type.ChallengeAnvilDance;
@ -128,6 +129,10 @@ import nautilus.game.arcade.kit.Kit;
public class BawkBawkBattles extends TeamGame implements IThrown
{
private BawkBawkBattlesSettings _settings = new BawkBawkBattlesSettings();
private ChallengeList _list = new ChallengeList();
private HashMap<Player, Integer> _lives = new HashMap<Player, Integer>();
private int _livesAmount = 2;
private String _restrictCommand = "restrict";
@ -141,16 +146,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private ArrayList<Block> _lastOrderBlocks;
private ArrayList<Player> _places = new ArrayList<Player>();
private ArrayList<Class<? extends Challenge>> _challenges = new ArrayList<Class<? extends Challenge>>();
private ArrayList<Class<? extends Challenge>> _challengesCopy = new ArrayList<Class<? extends Challenge>>();
private HashMap<Player, Integer> _lives = new HashMap<Player, Integer>();
private boolean _crumbling = false;
private boolean _waiting = true;
private boolean _messagesSent = false;
private boolean _sendingMessages = false;
private boolean _challengeStarted = false;
private DeathEffect _deathEffect = new DeathEffect(this);
private ChickenAttack _chickenAttack;
@ -204,52 +199,44 @@ public class BawkBawkBattles extends TeamGame implements IThrown
new MinewareKangarooAtHeart(this));
}
@SuppressWarnings("unchecked")
public void populateChallenges()
{
_challenges.add(ChallengeAnvilDance.class); // Playable - Refactored
_challenges.add(ChallengeArrowRampage.class); // Playable - Refactored
_challenges.add(ChallengeBlockLobbers.class); // Playable - Refactored
_challenges.add(ChallengeBouncingBlock.class); // Playable - Refactored
_challenges.add(ChallengeBuildRace.class); // Playable - Refactored
_challenges.add(ChallengeDiamondSeeker.class); // Playable - Refactored
_challenges.add(ChallengeCloudFall.class); // Test Needed
_challenges.add(ChallengeDogsVersusCats.class); // Playable - Refactored
_challenges.add(ChallengeDragonEgg.class); // Playable
_challenges.add(ChallengeFallingBlocks.class); // Playable
_challenges.add(ChallengeFastFood.class); // Playable
_challenges.add(ChallengeFishingDay.class); // Playable
_challenges.add(ChallengeWaterHorror.class); // Playable
_challenges.add(ChallengeInfestation.class); // Playable
_challenges.add(ChallengeKangarooJump.class); // Playable
_challenges.add(ChallengeKingOfTheHill.class); // Playable- Improve map.
_challenges.add(ChallengeLavaRun.class); // Playable
_challenges.add(ChallengeMilkACow.class); // Playable- Check cow names.
_challenges.add(ChallengeMineADiamond.class); // Playable
_challenges.add(ChallengeMinecartDance.class); // Playable
_challenges.add(ChallengeMiniOneInTheQuiver.class); // Playable
_challenges.add(ChallengeNavigateMaze.class); // Broken
_challenges.add(ChallengePickASide.class); // Playable
_challenges.add(ChallengePunchThePig.class); // Playable
_challenges.add(ChallengeRedLightGreenLight.class); // Broken - Villager, Fireworks
_challenges.add(ChallengeReverseTag.class); // Playable
_challenges.add(ChallengeRushPush.class); // Testing Needed
_challenges.add(ChallengeShootChickens.class); // Playable
_challenges.add(ChallengeSmashOff.class); // Playable
_challenges.add(ChallengeStandOnColor.class); // Playable
_challenges.add(ChallengeTntLauncher.class); // Playable
_challenges.add(ChallengeTreasureDigger.class); // Testing Needed
_challenges.add(ChallengeVolleyPig.class); // Playable
_challenges.add(ChallengeWaveCrush.class); // Broken
// These challenges are currently not used.
// _challenges.add(ChallengeBlockShot.class);
// _challenges.add(ChallengeDiamondFall.class);
// _challenges.add(ChallengeHitTargets.class);
// _challenges.add(ChallengeNameThatSound.class);
// _challenges.add(ChallengeSimonSays.class);
// _challenges.add(ChallengeSkyFall.class);
// _challenges.add(ChallengeTameTheWolf.class);
_list.add(
ChallengeAnvilDance.class, // Playable - Refactored
ChallengeArrowRampage.class, // Playable - Refactored
ChallengeBlockLobbers.class, // Playable - Refactored
ChallengeBouncingBlock.class, // Playable - Refactored
ChallengeBuildRace.class, // Playable - Refactored
ChallengeDiamondSeeker.class, // Playable - Refactored
ChallengeCloudFall.class, // Test Needed
ChallengeDogsVersusCats.class, // Playable - Refactored
ChallengeDragonEgg.class, // Playable
ChallengeFallingBlocks.class, // Playable
ChallengeFastFood.class, // Playable
ChallengeFishingDay.class, // Playable
ChallengeWaterHorror.class, // Playable
ChallengeInfestation.class, // Playable
ChallengeKangarooJump.class, // Playable
ChallengeKingOfTheHill.class, // Playable- Improve map.
ChallengeLavaRun.class, // Playable
ChallengeMilkACow.class, // Playable- Check cow names.
ChallengeMineADiamond.class, // Playable
ChallengeMinecartDance.class, // Playable
ChallengeMiniOneInTheQuiver.class, // Playable
ChallengeNavigateMaze.class, // Broken
ChallengePickASide.class, // Playable
ChallengePunchThePig.class, // Playable
ChallengeRedLightGreenLight.class, // Broken - Villager, Fireworks
ChallengeReverseTag.class, // Playable
ChallengeRushPush.class, // Testing Needed
ChallengeShootChickens.class, // Playable
ChallengeSmashOff.class, // Playable
ChallengeStandOnColor.class, // Playable
ChallengeTntLauncher.class, // Playable
ChallengeTreasureDigger.class, // Testing Needed
ChallengeVolleyPig.class, // Playable
ChallengeWaveCrush.class); // Broken
}
@Override
@ -276,10 +263,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
public Challenge selectChallenge()
{
for (int i = 0; i < _challenges.size() * 4; i++)
for (int i = 0; i < _list.size() * 4; i++)
{
if (_challengesCopy.isEmpty())
_challengesCopy.addAll(_challenges);
_list.copy();
Challenge challenge = getChallengeInstance();
@ -292,7 +278,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (!(getChallengers().size() % 2 == 0))
continue;
_challengesCopy.remove(challenge.getClass());
_list.removeCopy(challenge.getClass());
return challenge;
}
else
@ -308,7 +294,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
try
{
return UtilMath.randomElement(_challengesCopy).getConstructor(BawkBawkBattles.class).newInstance(this);
return _list.getRandomCopy().getConstructor(BawkBawkBattles.class).newInstance(this);
}
catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException
| SecurityException e)
@ -329,13 +315,6 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (!IsLive())
return;
if (_challenge != null)
{
for (Player player : GetPlayers(true))
if (!_challenge.getData().isDone(player) && ((CraftPlayer) player).getHandle().spectating)
return;
}
if (_challenge == null)
{
if (!UtilTime.elapsed(_challengeTime, 1500))
@ -345,43 +324,14 @@ public class BawkBawkBattles extends TeamGame implements IThrown
_challenge = selectChallenge();
keepSearchingIfNull(_challenge);
keepSearchingWhenNull(_challenge);
resetLastChallengeMap();
_crumbling = false;
_deathEffect.removeSpawnedEntities();
_challenge.createMap();
ArrayList<Location> spawns = setupChallengeSpawnLocations();
ArrayList<Location> selectedSpawnpoints = new ArrayList<Location>();
for (int i = 0; i < spawns.size(); i++)
{
Location furthest = null;
double furthestDist = 0;
for (Location spawn : spawns)
{
if (selectedSpawnpoints.contains(spawn))
continue;
double dist = 0;
for (Location loc : selectedSpawnpoints)
dist += loc.distance(spawn);
if (furthest == null || furthestDist < dist)
{
furthest = spawn;
furthestDist = dist;
}
}
selectedSpawnpoints.add(furthest);
}
teleportPlayersToSpawnpoints(selectedSpawnpoints);
teleportPlayersToSpawnpoints(getBestSpawnLocations());
teleportSpectatorsToSpawn();
if (_challenge instanceof ChallengeSeperateRooms)
@ -391,32 +341,30 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
_challengeTime = System.currentTimeMillis();
_waiting = true;
_settings.setWaiting(true);
}
else if (_waiting)
else if (_settings.isWaiting())
{
if (!UtilTime.elapsed(_challengeTime, 1000))
return;
if (!_sendingMessages && !_messagesSent)
if (!_settings.areMessagesBeingSent() && !_settings.areMessagesSent())
{
addEffectsToPlayers();
startChallengeDescriptionThread();
// return;
}
else if (_messagesSent)
else if (_settings.areMessagesSent())
{
removeEffectsFromPlayers();
_waiting = false;
_challengeStarted = true;
_settings.setWaiting(false);
_settings.setChallengeStarted(true);
_challenge.start();
Bukkit.getServer().getPluginManager().callEvent(new ChallengeStartEvent(_challenge));
Manager.getPluginManager().registerEvents(_challenge, Manager.getPlugin());
_messagesSent = false;
_settings.markMessagesAsSent(false);
}
}
else
@ -427,20 +375,13 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
if (justStartedCrumbling())
{
_crumbling = true;
for (Player player : UtilServer.getPlayers())
{
if (!_chickenTeam.HasPlayer(player))
{
UtilPlayer.message(player, F.main("Game", "The map has started to crumble."));
}
}
_settings.setCrumbling(true);
announceCrumbling();
}
else if (canEndChallengeFromCrumble())
{
endCurrentChallenge();
_crumbling = false;
_settings.setCrumbling(false);
}
}
else
@ -455,6 +396,50 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
private void announceCrumbling()
{
for (Player player : UtilServer.getPlayers())
{
if (!_chickenTeam.HasPlayer(player))
{
UtilPlayer.message(player, F.main("Game", "The map has started to crumble."));
}
}
}
private ArrayList<Location> getBestSpawnLocations()
{
ArrayList<Location> available = setupChallengeSpawnLocations();
ArrayList<Location> selected = new ArrayList<Location>();
for (int i = 0; i < available.size(); i++)
{
Location furthest = null;
double furthestDist = 0;
for (Location spawn : available)
{
if (selected.contains(spawn))
continue;
double dist = 0;
for (Location loc : selected)
dist += loc.distance(spawn);
if (furthest == null || furthestDist < dist)
{
furthest = spawn;
furthestDist = dist;
}
}
selected.add(furthest);
}
return selected;
}
private void resetDeadPlayers()
{
for (Player player : GetPlayers(false))
@ -465,9 +450,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
@SuppressWarnings("deprecation")
private void resetLastChallengeMap()
{
// TODO: May need to remove this check
if (_lastOrderBlocks == null)
return;
_settings.setCrumbling(false);
for (Block block : _lastOrderBlocks)
{
@ -504,14 +487,13 @@ public class BawkBawkBattles extends TeamGame implements IThrown
}
}
private void keepSearchingIfNull(Challenge challenge)
private void keepSearchingWhenNull(Challenge challenge)
{
if (_challenge == null)
{
UtilServer.broadcast(F.main(GetName(), "No suitable challenge was found."));
_challengesCopy.clear();
_challengesCopy.addAll(_challenges);
_list.resetCopy();
_challenge = selectChallenge();
if (_challenge == null)
@ -577,12 +559,12 @@ public class BawkBawkBattles extends TeamGame implements IThrown
private boolean justStartedCrumbling()
{
return !_crumbling && _challenge.getData().getLostPlayers().size() >= _challenge.getData().getCurrentPlaying().size() / 2;
return !_settings.isCrumbling() && _challenge.getData().getLostPlayers().size() >= _challenge.getData().getCurrentPlaying().size() / 2;
}
private boolean canEndChallengeFromCrumble()
{
return (_challenge.getData().getCurrentPlaying().size() - _challenge.getData().getLostPlayers().size()) <= 1 && _crumbling;
return (_challenge.getData().getCurrentPlaying().size() - _challenge.getData().getLostPlayers().size()) <= 1 && _settings.isCrumbling();
}
private void updateChallengeTimer()
@ -591,7 +573,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
{
if (_challenge instanceof ChallengeSeperateRooms)
{
UtilTextTop.display(C.cYellow + C.Bold + _challenge.getGameMessages()[0], player);
UtilTextTop.display(C.cYellow + C.Bold + _challenge.getDescription()[0], player);
player.setLevel(_challenge.getRemainingPlaces());
player.setExp(_challenge.getTimeLeftPercent());
}
@ -615,7 +597,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
HandlerList.unregisterAll(_challenge);
_challenge.end();
_challengeStarted = false;
_settings.setChallengeStarted(false);
sortLastChallengeBlocks();
@ -667,14 +649,14 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (_challenge == null)
return;
if (_waiting)
if (_settings.isWaiting())
return;
Manager.getPluginManager().callEvent(new ChallengeEndEvent(_challenge));
HandlerList.unregisterAll(_challenge);
_challenge.end();
_challengeStarted = false;
_settings.setChallengeStarted(false);
}
@Override
@ -699,7 +681,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
Scoreboard.Write(C.cYellow + C.Bold + "Players");
Scoreboard.Write(alive + " ");
boolean check = _challenge != null && _challengeStarted;
boolean check = _challenge != null && _settings.isChallengeStarted();
Scoreboard.WriteBlank();
@ -782,12 +764,12 @@ public class BawkBawkBattles extends TeamGame implements IThrown
public void showChallengeDescription(final Challenge challenge)
{
_sendingMessages = true;
_messagesSent = false;
_settings.markMessagesAsSending(true);
_settings.markMessagesAsSent(false);
int looped = 0;
List<String> messages = Arrays.asList(challenge.getGameMessages());
List<String> messages = Arrays.asList(challenge.getDescription());
String type = challenge.getType().toString();
@ -834,7 +816,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
catch (InterruptedException e)
{
System.out.println("There was a problem initiating countdown.");
System.out.println("Error: " + e.getMessage());
e.printStackTrace();
}
looped++;
@ -875,8 +857,8 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (looped == messages.size() - 1)
{
_messagesSent = true;
_sendingMessages = false;
_settings.markMessagesAsSent(true);
_settings.markMessagesAsSending(false);
cancel();
}
@ -912,7 +894,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (!PrepareFreeze)
return;
if (!_waiting)
if (!_settings.isWaiting())
return;
Location from = event.getFrom();
@ -1083,8 +1065,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
UtilEnt.CreatureLook(chicken, player);
//UtilAction.velocity(chicken, UtilAlg.calculateVelocity(player.getVelocity(), chicken.getVelocity(), 1.0D));
UtilAction.velocity(chicken, UtilAlg.getTrajectory(chicken, player).setY(0.3D));
UtilAction.velocity(chicken, UtilAlg.getTrajectory(chicken, player).multiply(1.5D).setY(0.3D));
Manager.GetProjectile().AddThrow(
chicken,
@ -1110,7 +1091,9 @@ public class BawkBawkBattles extends TeamGame implements IThrown
for (Chicken chicken : _chickenAttack.getChickens())
{
if (!chicken.isOnGround())
Block below = chicken.getLocation().getBlock().getRelative(BlockFace.DOWN); // Detect when falling into the void.
if (!chicken.isOnGround() && !below.isEmpty())
{
UtilParticle.PlayParticle(ParticleType.FLAME, chicken.getLocation(), 0.1F, 0.1F, 0.1F, 0.02F, 1, ViewDist.NORMAL);
}
@ -1248,8 +1231,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
Announce(C.cAqua + C.Bold + GetName() + " restricted to " + rawClass + " challenge.");
_challenges.clear();
_challenges.add(result);
_list.restrict(result);
}
catch (ClassNotFoundException e)
{
@ -1265,7 +1247,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
else
{
Announce(C.cAqua + C.Bold + GetName() + " challenge restrictions were cleared.");
_challenges.clear();
_list.getChallenges().clear();
populateChallenges();
}
@ -1276,7 +1258,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (IsLive())
{
endCurrentChallenge();
_crumbling = false;
_settings.setCrumbling(false);
Announce(C.cAqua + C.Bold + player.getName() + " skipped this challenge.");
}
@ -1364,7 +1346,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
if (event.GetState() != GameState.End)
return;
if (_challengeStarted)
if (_settings.isChallengeStarted())
return;
for (Player player : GetPlayers(true))
@ -1404,7 +1386,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!_waiting)
if (!_settings.isWaiting())
return;
event.setCancelled(true);
@ -1425,7 +1407,7 @@ public class BawkBawkBattles extends TeamGame implements IThrown
@Override
public boolean isInsideMap(Player player)
{
if (_challenge != null && !_waiting)
if (_challenge != null && !_settings.isWaiting())
return _challenge.isInsideMap(player);
return true;
@ -1533,34 +1515,14 @@ public class BawkBawkBattles extends TeamGame implements IThrown
return _lives;
}
public void setCrumbling(boolean crumbling)
public BawkBawkBattlesSettings getSettings()
{
_crumbling = crumbling;
return _settings;
}
public boolean isCrumbling()
public ChallengeList getChallengeList()
{
return _crumbling;
}
public boolean isWaitingChallenge()
{
return _waiting;
}
public boolean areMessagesSent()
{
return _messagesSent;
}
public boolean isChallengeStarted()
{
return _challengeStarted;
}
public ArrayList<Class<? extends Challenge>> getRegisteredChallenges()
{
return _challenges;
return _list;
}
public DeathEffect getDeathEffect()

View File

@ -0,0 +1,60 @@
package nautilus.game.arcade.game.games.mineware;
public class BawkBawkBattlesSettings
{
private boolean _crumbling = false;
private boolean _waiting = true;
private boolean _messagesSent = false;
private boolean _sendingMessages = false;
private boolean _challengeStarted = false;
public void setCrumbling(boolean flag)
{
_crumbling = flag;
}
public boolean isCrumbling()
{
return _crumbling;
}
public void setWaiting(boolean flag)
{
_waiting = flag;
}
public boolean isWaiting()
{
return _waiting;
}
public void markMessagesAsSent(boolean flag)
{
_messagesSent = flag;
}
public boolean areMessagesSent()
{
return _messagesSent;
}
public void markMessagesAsSending(boolean flag)
{
_sendingMessages = flag;
}
public boolean areMessagesBeingSent()
{
return _sendingMessages;
}
public void setChallengeStarted(boolean flag)
{
_challengeStarted = flag;
}
public boolean isChallengeStarted()
{
return _challengeStarted;
}
}

View File

@ -159,6 +159,16 @@ public abstract class Challenge implements Listener
}
}
protected boolean isChallengeValid()
{
return Host.IsLive() && Host.getSettings().isChallengeStarted();
}
protected boolean isPlayerValid(Player player)
{
return getChallengers().contains(player) && Host.IsAlive(player) && !Data.isDone(player);
}
public void start()
{
Data.setCurrentPlaying(Host.getChallengers());
@ -239,7 +249,7 @@ public abstract class Challenge implements Listener
if (Data.isDone(player))
return;
if (!Host.isCrumbling())
if (!Host.getSettings().isCrumbling())
Data.addLostPlayer(player);
if (cloak)
@ -323,7 +333,7 @@ public abstract class Challenge implements Listener
if (!Settings.canCrumble())
return;
if (!Host.isCrumbling())
if (!Host.getSettings().isCrumbling())
return;
Block qualifiedBlock = null;
@ -331,7 +341,7 @@ public abstract class Challenge implements Listener
if (Data.getModifiedBlocks().isEmpty())
{
Host.setCrumbling(false);
Host.getSettings().setCrumbling(false);
return;
}
@ -467,21 +477,4 @@ public abstract class Challenge implements Listener
{
return Data;
}
/**
* @deprecated
*/
public String[] getGameMessages()
{
List<String> description = new ArrayList<String>();
for (String strings : _description)
{
description.add(strings);
}
description.add("");
return description.toArray(new String[description.size()]);
}
}

View File

@ -0,0 +1,62 @@
package nautilus.game.arcade.game.games.mineware.challenge;
import java.util.ArrayList;
import mineplex.core.common.util.UtilMath;
public class ChallengeList
{
private ArrayList<Class<? extends Challenge>> _wrapper = new ArrayList<Class<? extends Challenge>>();
private ArrayList<Class<? extends Challenge>> _wrapperCopy = new ArrayList<Class<? extends Challenge>>();
public void add(Class<? extends Challenge>... challenges)
{
for (Class<? extends Challenge> challenge : challenges)
{
_wrapper.add(challenge);
}
}
public void restrict(Class<? extends Challenge> challenge)
{
_wrapper.clear();
_wrapper.add(challenge);
}
public void resetCopy()
{
_wrapperCopy.clear();
_wrapperCopy.addAll(_wrapper);
}
public void copy()
{
if (_wrapperCopy.isEmpty())
_wrapperCopy.addAll(_wrapper);
}
public void removeCopy(Class<? extends Challenge> challenge)
{
_wrapperCopy.remove(challenge);
}
public int size()
{
return _wrapper.size();
}
public Class<? extends Challenge> getRandomCopy()
{
return UtilMath.randomElement(_wrapperCopy);
}
public ArrayList<Class<? extends Challenge>> getChallenges()
{
return _wrapper;
}
public ArrayList<Class<? extends Challenge>> getCopiedChallenges()
{
return _wrapperCopy;
}
}

View File

@ -131,13 +131,16 @@ public class ChallengeAnvilDance extends Challenge
@EventHandler
public void onItemSpawn(ItemSpawnEvent event)
{
if (!isChallengeValid())
return;
event.setCancelled(true);
}
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!isChallengeValid())
return;
if (event.getEntity() instanceof FallingBlock)
@ -159,7 +162,7 @@ public class ChallengeAnvilDance extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!isChallengeValid())
{
cancel();
return;
@ -187,7 +190,7 @@ public class ChallengeAnvilDance extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!isChallengeValid())
{
cancel();
return;
@ -208,7 +211,7 @@ public class ChallengeAnvilDance extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!isChallengeValid())
{
cancel();
return;
@ -306,7 +309,7 @@ public class ChallengeAnvilDance extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
{
cancel();
return;
@ -337,7 +340,7 @@ public class ChallengeAnvilDance extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !block.isValid() || block.isOnGround() || !Host.isChallengeStarted())
if (!isChallengeValid() || !block.isValid() || block.isOnGround())
{
cancel();
return;
@ -351,9 +354,7 @@ public class ChallengeAnvilDance extends Challenge
{
Player player = (Player) entity;
if (Data.isDone(player))
return;
if (!Host.IsAlive(player))
if (!isPlayerValid(player))
return;
player.damage(player.getHealth());

View File

@ -128,7 +128,7 @@ public class ChallengeArrowRampage extends Challenge
@EventHandler
public void onEntityShootBow(EntityShootBowEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
if (!(event.getEntity() instanceof Player))
@ -143,7 +143,7 @@ public class ChallengeArrowRampage extends Challenge
@EventHandler
public void onArrowHit(ProjectileHitEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
if (!(event.getEntity() instanceof Arrow))

View File

@ -85,7 +85,7 @@ public class ChallengeBlockLobbers extends Challenge
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
if (event.getType() != UpdateType.FAST)
@ -125,12 +125,12 @@ public class ChallengeBlockLobbers extends Challenge
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (Data.isDone(player))
if (isPlayerValid(player))
return;
switchToAvailableSlot(player);
@ -151,7 +151,7 @@ public class ChallengeBlockLobbers extends Challenge
@EventHandler
public void onEntityChangeBlock(EntityChangeBlockEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
Entity entity = event.getEntity();
@ -180,7 +180,7 @@ public class ChallengeBlockLobbers extends Challenge
if (!(target instanceof Player))
return;
if (Data.isCompleted((Player) target))
if (!isPlayerValid((Player) target))
return;
if (target.equals(data.GetThrower()))

View File

@ -114,15 +114,12 @@ public class ChallengeBouncingBlock extends Challenge
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!Host.IsAlive(player))
return;
if (Data.isDone(player))
if (!isPlayerValid(player))
return;
if (event.getClickedBlock() == null || event.getClickedBlock().getType() == Material.AIR)
@ -149,7 +146,7 @@ public class ChallengeBouncingBlock extends Challenge
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
if (event.getType() != UpdateType.TICK)
@ -167,12 +164,12 @@ public class ChallengeBouncingBlock extends Challenge
@EventHandler
public void redWoolHandler(PlayerMoveEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (Data.isDone(player))
if (!isPlayerValid(player))
return;
if (event.getFrom().getX() == event.getTo().getX() && event.getFrom().getZ() == event.getTo().getZ())

View File

@ -109,15 +109,12 @@ public class ChallengeBuildRace extends Challenge
@EventHandler
public void onBlockPlace(BlockPlaceEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (Data.isDone(player))
return;
if (Data.isCompleted(player))
if (!isPlayerValid(player))
{
event.setCancelled(true);
return;

View File

@ -148,7 +148,7 @@ public class ChallengeCloudFall extends Challenge
@EventHandler
public void onCustomDamage(CustomDamageEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
if (!(event.GetDamageeEntity() instanceof Player))
@ -157,7 +157,7 @@ public class ChallengeCloudFall extends Challenge
if (event.GetCause() != DamageCause.FALL)
return;
if (Data.isDone(event.GetDamageePlayer()))
if (!isPlayerValid(event.GetDamageePlayer()))
return;
if (Math.round(event.GetDamageePlayer().getLocation().getY()) == 3)

View File

@ -123,7 +123,7 @@ public class ChallengeDiamondSeeker extends Challenge
@EventHandler
public void onInventoryClick(InventoryClickEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
InventoryHolder holder = event.getInventory().getHolder();
@ -131,6 +131,9 @@ public class ChallengeDiamondSeeker extends Challenge
if (!(holder instanceof Player))
{
if (!isPlayerValid(player))
return;
event.setCancelled(true);
if (holder instanceof DoubleChest || holder instanceof Chest)

View File

@ -176,7 +176,7 @@ public class ChallengeDogsVersusCats extends Challenge
if (event.getType() != UpdateType.TICK)
return;
if (!Host.IsLive())
if (!isChallengeValid())
return;
int catScore = calculateScore(_catTeam);
@ -204,15 +204,12 @@ public class ChallengeDogsVersusCats extends Challenge
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
Player player = event.getPlayer();
if (!Host.IsAlive(player))
return;
if (Data.isCompleted(player))
if (!isPlayerValid(player))
return;
if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK)
@ -241,7 +238,7 @@ public class ChallengeDogsVersusCats extends Challenge
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!Host.IsLive())
if (!isChallengeValid())
return;
Player player = event.getPlayer();

View File

@ -167,7 +167,7 @@ public class ChallengeFallingBlocks extends Challenge
@EventHandler
public void onEntityChangeBlockEvent(final EntityChangeBlockEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getEntity() instanceof FallingBlock)
@ -180,7 +180,7 @@ public class ChallengeFallingBlocks extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
{
cancel();
return;
@ -199,7 +199,7 @@ public class ChallengeFallingBlocks extends Challenge
@EventHandler
public void onBlockFade(BlockFadeEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getNewState().getType() == Material.DIRT || event.getNewState().getType() == Material.GRASS)
@ -213,7 +213,7 @@ public class ChallengeFallingBlocks extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
{
cancel();
return;
@ -231,7 +231,7 @@ public class ChallengeFallingBlocks extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
{
cancel();
return;
@ -318,7 +318,7 @@ public class ChallengeFallingBlocks extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !block.isValid() || block.isOnGround() || !Host.isChallengeStarted())
if (!Host.IsLive() || !block.isValid() || block.isOnGround() || !Host.getSettings().isChallengeStarted())
{
cancel();
return;

View File

@ -121,7 +121,7 @@ public class ChallengeFastFood extends Challenge
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
Player player = event.getPlayer();
@ -147,7 +147,7 @@ public class ChallengeFastFood extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
{
cancel();
return;
@ -234,7 +234,7 @@ public class ChallengeFastFood extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted() || !item.isValid() || item.isDead())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted() || !item.isValid() || item.isDead())
{
cancel();
return;

View File

@ -222,7 +222,7 @@ public class ChallengeFishingDay extends Challenge
{
Player fisher = event.getPlayer();
if (Data.isDone(fisher) || !Host.IsLive() || !Host.isChallengeStarted())
if (Data.isDone(fisher) || !Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
Fish hook = event.getHook();
@ -271,7 +271,7 @@ public class ChallengeFishingDay extends Challenge
@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getEntity() instanceof Player && event.getDamager() instanceof FishHook)
@ -281,7 +281,7 @@ public class ChallengeFishingDay extends Challenge
@EventHandler
public void onItemHeld(PlayerItemHeldEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (!Data.isDone(event.getPlayer()))
@ -293,7 +293,7 @@ public class ChallengeFishingDay extends Challenge
@EventHandler
public void onPlayerMove(PlayerMoveEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (!Data.isDone(event.getPlayer()))
@ -320,7 +320,7 @@ public class ChallengeFishingDay extends Challenge
@EventHandler
public void onEntityExplode(EntityExplodeEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
Location dropsite = event.getLocation();

View File

@ -122,7 +122,7 @@ public class ChallengeKangarooJump extends Challenge
{
return;
}
if (!Host.isChallengeStarted())
if (!Host.getSettings().isChallengeStarted())
{
return;
}

View File

@ -196,7 +196,7 @@ public class ChallengePunchThePig extends Challenge
{
return;
}
if (!Host.isChallengeStarted())
if (!Host.getSettings().isChallengeStarted())
{
return;
}

View File

@ -137,7 +137,7 @@ public class ChallengeRushPush extends Challenge
onRed++;
}
}
if ((onBlue == 0 || onRed == 0) && Host.isCrumbling() == false)
if ((onBlue == 0 || onRed == 0) && !Host.getSettings().isCrumbling())
{
UtilTextMiddle.display(onBlue == 0 ? C.cBlue + "Blue Team won!" : C.cRed + "Red Team won!", "Friendly fire enabled!", 20, 60, 20);
}
@ -159,7 +159,7 @@ public class ChallengeRushPush extends Challenge
event.SetCancelled("Player out of the game");
return;
}
if (!Host.isCrumbling())
if (!Host.getSettings().isCrumbling())
{
if (_teams.containsKey(event.GetDamagerPlayer(false).getName()))
{

View File

@ -192,7 +192,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onUpdateEntityTrail(UpdateEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getType() != UpdateType.TICK)
@ -225,7 +225,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onUpdateSpawnerParticle(UpdateEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getType() != UpdateType.TICK)
@ -239,7 +239,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onEntityDismount(EntityDismountEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getEntity() instanceof Boat)
@ -251,7 +251,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onVehicleDestroy(VehicleDestroyEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getVehicle() instanceof Boat)
@ -261,7 +261,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onExplosion(ExplosionEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
event.GetBlocks().clear();
@ -270,7 +270,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onBlockFromTo(BlockFromToEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
if (event.getBlock().getType() == Material.ICE)
@ -280,7 +280,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onPlayerDeath(PlayerDeathEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
Player player = event.getEntity();
@ -299,7 +299,7 @@ public class ChallengeWaterHorror extends Challenge
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event)
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
return;
Player player = event.getPlayer();
@ -322,7 +322,7 @@ public class ChallengeWaterHorror extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
{
cancel();
return;

View File

@ -383,7 +383,7 @@ public class ChallengeSimonSays extends Challenge
@Override
public void run()
{
if (!Host.IsLive() || !Host.isChallengeStarted())
if (!Host.IsLive() || !Host.getSettings().isChallengeStarted())
{
this.cancel();
}