diff --git a/.recommenders/caches/identified-project-coordinates.json b/.recommenders/caches/identified-project-coordinates.json index 19b8ebad9..6ae9d225e 100644 --- a/.recommenders/caches/identified-project-coordinates.json +++ b/.recommenders/caches/identified-project-coordinates.json @@ -1 +1 @@ -[[{"location":"C:\\@Thanos\\Documents\\Minecraft\\Mineplex\\projects\\Mineplex\\Plugins\\Nautilus.Game.Arcade","type":"PROJECT","hints":{"PROJECT_NAME":"Nautilus.Game.Arcade"}},"ABSENT"],[{"location":"C:\\Program Files\\Java\\jre1.8.0_51","type":"JRE","hints":{}},"jre:jre:1.8.0"],[{"location":"C:\\@Thanos\\Documents\\Minecraft\\Mineplex\\projects\\Mineplex\\Plugins\\Libraries\\craftbukkit.jar","type":"JAR","hints":{}},"ABSENT"]] \ No newline at end of file +[[{"location":"C:\\@Thanos\\Documents\\Minecraft\\Mineplex\\projects\\Mineplex\\Plugins\\Libraries\\craftbukkit.jar","type":"JAR","hints":{}},"ABSENT"],[{"location":"C:\\@Thanos\\Documents\\Minecraft\\Mineplex\\projects\\Mineplex\\Plugins\\Nautilus.Game.Arcade","type":"PROJECT","hints":{"PROJECT_NAME":"Nautilus.Game.Arcade"}},"ABSENT"],[{"location":"C:\\@Thanos\\Documents\\Minecraft\\Mineplex\\projects\\Mineplex\\Plugins\\Mineplex.Core.Common","type":"PROJECT","hints":{"PROJECT_NAME":"Mineplex.Core.Common"}},"ABSENT"]] \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/.settings/org.eclipse.jdt.core.prefs b/Plugins/Nautilus.Game.Arcade/.settings/org.eclipse.jdt.core.prefs index 0dac3f111..2f1ef8858 100644 --- a/Plugins/Nautilus.Game.Arcade/.settings/org.eclipse.jdt.core.prefs +++ b/Plugins/Nautilus.Game.Arcade/.settings/org.eclipse.jdt.core.prefs @@ -75,8 +75,8 @@ org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 +org.eclipse.jdt.core.formatter.continuation_indentation=1 +org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=1 org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java index e32e9d199..262436f13 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/Challenge.java @@ -145,7 +145,7 @@ public abstract class Challenge implements Listener _places = (int) Math.ceil(getChallengers().size() / 2D); } - public boolean finish() + public boolean canFinish() { boolean maxTimeReached = UtilTime.elapsed(_startTime, _duration); ArrayList players = getChallengers(); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java index 5f78cb7c8..17d4e0995 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/MineWare.java @@ -1,5 +1,6 @@ package nautilus.game.arcade.game.games.mineware; +import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -130,7 +131,7 @@ public class MineWare extends TeamGame implements IThrown private HashMap _lives = new HashMap(); private boolean _crumbling = false; - private boolean _waitingChallenge = true; + private boolean _waiting = true; private boolean _messagesSent = false; private boolean _sendingMessages = false; private boolean _challengeStarted = false; @@ -142,14 +143,14 @@ public class MineWare extends TeamGame implements IThrown public MineWare(ArcadeManager manager) { super(manager, - GameType.MineWare, - new Kit[] { new KitBawksFood(manager) }, - new String[] { - "Follow the orders given in chat!", - "First half to follow it win the round.", - "Other players lose one life.", - "Last player with lives wins!" - }); + GameType.MineWare, + new Kit[] { new KitBawksFood(manager) }, + new String[] { + "Follow the orders given in chat!", + "First half to follow it win the round.", + "Other players lose one life.", + "Last player with lives wins!" + }); DamageSelf = false; DamageTeamSelf = true; @@ -172,13 +173,13 @@ public class MineWare extends TeamGame implements IThrown populateChallenges(); registerStatTrackers( - new MinewareVeteranTracker(this), - new MinewareSurfUpTracker(this), - new MinewareLauraCraftTracker(this), - new MinewareMilkManTracker(this), - new MinewarePinataMasterTracker(this), - new MinewareTagMasterTracker(this), - new MinewareKangarooAtHeart(this)); + new MinewareVeteranTracker(this), + new MinewareSurfUpTracker(this), + new MinewareLauraCraftTracker(this), + new MinewareMilkManTracker(this), + new MinewarePinataMasterTracker(this), + new MinewareTagMasterTracker(this), + new MinewareKangarooAtHeart(this)); } public void populateChallenges() @@ -248,42 +249,48 @@ public class MineWare extends TeamGame implements IThrown { for (int i = 0; i < _challenges.size() * 4; i++) { - try + if (_challengesCopy.isEmpty()) + _challengesCopy.addAll(_challenges); + + Challenge challenge = getChallengeInstance(); + + if (getChallengers().size() >= challenge.getMinPlayers()) { - if (_challengesCopy.isEmpty()) - _challengesCopy.addAll(_challenges); + if (getChallengers().size() >= challenge.getMaxPlayers()) + continue; - Challenge challenge = UtilMath.randomElement(_challengesCopy).getConstructor(MineWare.class) - .newInstance(this); - - if (getChallengers().size() >= challenge.getMinPlayers()) - { - if (getChallengers().size() >= challenge.getMaxPlayers()) + if (challenge.isTeamBased()) + if (!(getChallengers().size() % 2 == 0)) continue; - if (challenge.isTeamBased()) - if (!(getChallengers().size() % 2 == 0)) - continue; - - _challengesCopy.remove(challenge.getClass()); - return challenge; - } - else - { - continue; - } + _challengesCopy.remove(challenge.getClass()); + return challenge; } - catch (Exception e) + else { - System.out.println("There was a problem loading a new challenge."); - System.out.println("Error: " + e.getMessage()); + continue; } } return null; } - @SuppressWarnings("deprecation") + private Challenge getChallengeInstance() + { + try + { + return UtilMath.randomElement(_challengesCopy).getConstructor(MineWare.class).newInstance(this); + } + catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException + | SecurityException e) + { + System.out.println("There was a problem loading a new challenge."); + System.out.println("Error: " + e.getMessage()); + } + + return null; + } + @EventHandler public void onChallengeUpdate(UpdateEvent event) { @@ -305,50 +312,20 @@ public class MineWare extends TeamGame implements IThrown if (!UtilTime.elapsed(_challengeTime, 1500)) return; - for (Player player : GetPlayers(false)) - if (_lives.containsKey(player) && _lives.get(player) > 0) - Manager.Clear(player); + resetDeadPlayers(); _challenge = selectChallenge(); - if (_challenge == null) - { - UtilServer.broadcast(F.main(GetName(), - "No suitable challenge, " + _challengesCopy.size() + " challenges remaining.")); + keepSearchingIfNull(_challenge); - _challengesCopy.clear(); - _challengesCopy.addAll(_challenges); - _challenge = selectChallenge(); - - if (_challenge == null) - { - SetState(GameState.Dead); - return; - } - } - - for (Block block : _lastOrderBlocks) - { - if (block.getState() instanceof InventoryHolder) - { - InventoryHolder holder = (InventoryHolder) block.getState(); - holder.getInventory().clear(); - } - - block.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false); - } - - // if (_currentCrumble == true) + resetLastChallengeMap(); _crumbling = false; _deathEffect.removeSpawnedEntities(); _challenge.generateRoom(); - ArrayList spawns = _challenge.getSpawns(); - _playersTeam.SetSpawns(_challenge.getSpawns()); - SpectatorSpawn = UtilWorld.averageLocation(spawns).add(0, 7, 0); - - ArrayList toTeleport = new ArrayList(); + ArrayList spawns = setupChallengeSpawnLocations(); + ArrayList selectedSpawnpoints = new ArrayList(); for (int i = 0; i < spawns.size(); i++) { @@ -357,12 +334,12 @@ public class MineWare extends TeamGame implements IThrown for (Location spawn : spawns) { - if (toTeleport.contains(spawn)) + if (selectedSpawnpoints.contains(spawn)) continue; double dist = 0; - for (Location loc : toTeleport) + for (Location loc : selectedSpawnpoints) dist += loc.distance(spawn); if (furthest == null || furthestDist < dist) @@ -372,28 +349,11 @@ public class MineWare extends TeamGame implements IThrown } } - toTeleport.add(furthest); + selectedSpawnpoints.add(furthest); } - int i = 0; - - for (Player player : getChallengers()) - { - player.teleport(toTeleport.get(i++)); - - if (i >= toTeleport.size()) - i = 0; - } - - for (Player player : GetPlayers(false)) - if (!IsAlive(player)) - { - if (_chickenTeam != null) - if (_chickenTeam.HasPlayer(player)) - continue; - - player.teleport(SpectatorSpawn); - } + teleportPlayersToSpawnpoints(selectedSpawnpoints); + teleportSpectatorsToSpawn(); if (_challenge instanceof ChallengeSeperateRooms) { @@ -402,46 +362,24 @@ public class MineWare extends TeamGame implements IThrown } _challengeTime = System.currentTimeMillis(); - _waitingChallenge = true; + _waiting = true; } - else if (_waitingChallenge) + else if (_waiting) { if (!UtilTime.elapsed(_challengeTime, 1000)) return; if (!_sendingMessages && !_messagesSent) { - 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)); - } + startChallengeDescriptionThread(); - Thread newThread = new Thread(new Runnable() - { - @Override - public void run() - { - showChallengeDescription(_challenge); - } - }); - - newThread.start(); - return; + // return; } - - if (_messagesSent) + else if (_messagesSent) { - for (Player player : GetPlayers(true)) - { - if (player.hasPotionEffect(PotionEffectType.BLINDNESS)) - { - player.removePotionEffect(PotionEffectType.BLINDNESS); - player.removePotionEffect(PotionEffectType.NIGHT_VISION); - } - } + removeEffectsFromPlayers(); - _waitingChallenge = false; + _waiting = false; _challengeStarted = true; _challenge.start(); @@ -453,11 +391,11 @@ public class MineWare extends TeamGame implements IThrown } else { - if (_challenge.finish()) + if (_challenge.canFinish()) { - if (_challenge.canCrumble() && !_challenge.getModifiedBlocks().isEmpty()) + if (canStartCrumbling()) { - if (!_crumbling && _challenge.getLost().size() >= _challenge.getCurrentPlaying().size() / 2) + if (justStartedCrumbling()) { _crumbling = true; @@ -466,15 +404,12 @@ public class MineWare extends TeamGame implements IThrown for (Player player : UtilServer.getPlayers()) if (IsAlive(player)) UtilPlayer.message(player, - F.main(GetName(), "Challenge ends when there's only 1 player alive.")); + F.main(GetName(), "Challenge ends when there's only 1 player alive.")); } - else + else if (canEndChallengeFromCrumble()) { - if ((_challenge.getCurrentPlaying().size() - _challenge.getLost().size()) <= 1 && _crumbling) - { - endCurrentChallenge(); - _crumbling = false; - } + endCurrentChallenge(); + _crumbling = false; } } else @@ -484,22 +419,144 @@ public class MineWare extends TeamGame implements IThrown } else { - for (Player player : UtilServer.getPlayers()) - { - if (_challenge instanceof ChallengeSeperateRooms) - { - UtilTextTop.display(C.cYellow + C.Bold + _challenge.getGameMessages()[0], player); - player.setLevel(_challenge.getRemainingPlaces()); - player.setExp(_challenge.getTimeLeftPercent()); - } - else - { - UtilTextTop.displayTextBar(player, _challenge.getTimeLeftPercent(), - C.cYellow + C.Bold + _challenge.getName()); - player.setLevel(_challenge.getRemainingPlaces()); - player.setExp(_challenge.getTimeLeftPercent()); - } - } + updateChallengeTimer(); + } + } + } + + private void resetDeadPlayers() + { + for (Player player : GetPlayers(false)) + if (_lives.containsKey(player) && _lives.get(player) > 0) + Manager.Clear(player); + } + + @SuppressWarnings("deprecation") + private void resetLastChallengeMap() + { + for (Block block : _lastOrderBlocks) + { + if (block.getState() instanceof InventoryHolder) + { + InventoryHolder holder = (InventoryHolder) block.getState(); + holder.getInventory().clear(); + } + + block.setTypeIdAndData(Material.AIR.getId(), (byte) 0, false); + } + } + + private ArrayList setupChallengeSpawnLocations() + { + ArrayList spawns = _challenge.getSpawns(); + _playersTeam.SetSpawns(spawns); + SpectatorSpawn = UtilWorld.averageLocation(spawns).add(0, 7.0D, 0); + return spawns; + } + + private void teleportSpectatorsToSpawn() + { + for (Player player : GetPlayers(false)) + { + if (!IsAlive(player)) + { + if (_chickenTeam != null) + if (_chickenTeam.HasPlayer(player)) + continue; + + player.teleport(SpectatorSpawn); + } + } + } + + private void keepSearchingIfNull(Challenge challenge) + { + if (_challenge == null) + { + UtilServer.broadcast(F.main(GetName(), "No suitable challenge was found.")); + + _challengesCopy.clear(); + _challengesCopy.addAll(_challenges); + _challenge = selectChallenge(); + + if (_challenge == null) + { + SetState(GameState.Dead); + return; + } + } + } + + private void teleportPlayersToSpawnpoints(ArrayList spawnpoints) + { + int i = 0; + + for (Player player : getChallengers()) + { + player.teleport(spawnpoints.get(i++)); + + if (i >= spawnpoints.size()) + i = 0; + } + } + + 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 boolean canStartCrumbling() + { + return _challenge.canCrumble() && !_challenge.getModifiedBlocks().isEmpty(); + } + + private boolean justStartedCrumbling() + { + return !_crumbling && _challenge.getLost().size() >= _challenge.getCurrentPlaying().size() / 2; + } + + private boolean canEndChallengeFromCrumble() + { + return (_challenge.getCurrentPlaying().size() - _challenge.getLost().size()) <= 1 && _crumbling; + } + + private void updateChallengeTimer() + { + for (Player player : UtilServer.getPlayers()) + { + if (_challenge instanceof ChallengeSeperateRooms) + { + UtilTextTop.display(C.cYellow + C.Bold + _challenge.getGameMessages()[0], player); + player.setLevel(_challenge.getRemainingPlaces()); + player.setExp(_challenge.getTimeLeftPercent()); + } + else + { + UtilTextTop.displayTextBar(player, _challenge.getTimeLeftPercent(), + C.cYellow + C.Bold + _challenge.getName()); + player.setLevel(_challenge.getRemainingPlaces()); + player.setExp(_challenge.getTimeLeftPercent()); } } } @@ -508,6 +565,22 @@ public class MineWare extends TeamGame implements IThrown { _challengeTime = System.currentTimeMillis(); + resetPlayersOnChallengeEnding(); + + Manager.getPluginManager().callEvent(new ChallengeEndEvent(_challenge)); + HandlerList.unregisterAll(_challenge); + + _challenge.end(); + _challengeStarted = false; + + sortLastChallengeBlocks(); + + _challenge = null; + EndCheck(); + } + + private void resetPlayersOnChallengeEnding() + { for (Player player : getChallengers()) { Manager.GetDisguise().undisguise(player); @@ -519,13 +592,10 @@ public class MineWare extends TeamGame implements IThrown if (_challenge.isCompleted(player)) AddGems(player, 3, "Completed Challenge", true, true); } + } - Manager.getPluginManager().callEvent(new ChallengeEndEvent(_challenge)); - HandlerList.unregisterAll(_challenge); - - _challenge.end(); - _challengeStarted = false; - + private void sortLastChallengeBlocks() + { _lastOrderBlocks = new ArrayList(_challenge.getModifiedBlocks()); Collections.sort(_lastOrderBlocks, new Comparator() @@ -536,9 +606,6 @@ public class MineWare extends TeamGame implements IThrown return new Integer(o2.getY()).compareTo(o1.getY()); } }); - - _challenge = null; - EndCheck(); } @EventHandler @@ -550,7 +617,7 @@ public class MineWare extends TeamGame implements IThrown if (_challenge == null) return; - if (_waitingChallenge) + if (_waiting) return; Manager.getPluginManager().callEvent(new ChallengeEndEvent(_challenge)); @@ -716,10 +783,10 @@ public class MineWare extends TeamGame implements IThrown int looped = 0; List messages = Arrays.asList( - C.cRed + C.Bold + "3", - C.cYellow + C.Bold + "2", - C.cGreen + C.Bold + "1", - C.cGreen + C.Bold + "GO!"); + C.cRed + C.Bold + "3", + C.cYellow + C.Bold + "2", + C.cGreen + C.Bold + "1", + C.cGreen + C.Bold + "GO!"); @Override public void run() @@ -762,7 +829,7 @@ public class MineWare extends TeamGame implements IThrown player.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1)); } } - + @EventHandler public void onPlayerMove(PlayerMoveEvent event) { @@ -775,7 +842,7 @@ public class MineWare extends TeamGame implements IThrown if (!PrepareFreeze) return; - if (!_waitingChallenge) + if (!_waiting) return; Location from = event.getFrom(); @@ -879,7 +946,7 @@ public class MineWare extends TeamGame implements IThrown if (GetState() == GameState.Recruit && GetCountdown() >= 0 && GetPlayers(false).size() < 2) { UtilServer - .broadcast(F.main(GetName(), C.cRed + "This game requires at least 2 players to start.")); + .broadcast(F.main(GetName(), C.cRed + "This game requires at least 2 players to start.")); SetCountdown(-1); Manager.GetLobby().DisplayWaiting(); } @@ -931,7 +998,7 @@ public class MineWare extends TeamGame implements IThrown try { Class result = (Class) Class - .forName("nautilus.game.arcade.game.games.mineware.challenges.Challenge" + rawClass); + .forName("nautilus.game.arcade.game.games.mineware.challenges.Challenge" + rawClass); Announce(C.cAqua + C.Bold + GetName() + " restricted to " + rawClass + " challenge."); @@ -941,12 +1008,12 @@ public class MineWare extends TeamGame implements IThrown catch (ClassNotFoundException e) { UtilPlayer.message(player, F.main(GetName(), - "Could not match " + F.elem(rawClass) + " with any challenges.")); + "Could not match " + F.elem(rawClass) + " with any challenges.")); } catch (ClassCastException e) { UtilPlayer.message(player, - F.main(GetName(), F.elem(rawClass) + "is not a challenge!")); + F.main(GetName(), F.elem(rawClass) + "is not a challenge!")); } } else @@ -970,7 +1037,7 @@ public class MineWare extends TeamGame implements IThrown else { UtilPlayer.message(player, - F.main(GetName(), "You cannot skip a challenge if the game is not started.")); + F.main(GetName(), "You cannot skip a challenge if the game is not started.")); } event.setCancelled(true); @@ -1040,10 +1107,10 @@ public class MineWare extends TeamGame implements IThrown // TODO: Retrieve center and corners from map data. _chickenAttack = new ChickenAttack( - this, - new Location(WorldData.World, 50, 0, 0), - new Location(WorldData.World, 47, 0, -3), - new Location(WorldData.World, 53, 0, 3)); + this, + new Location(WorldData.World, 50, 0, 0), + new Location(WorldData.World, 47, 0, -3), + new Location(WorldData.World, 53, 0, 3)); } @EventHandler @@ -1076,7 +1143,7 @@ public class MineWare extends TeamGame implements IThrown @EventHandler public void onPlayerInteract(PlayerInteractEvent event) { - if (!_waitingChallenge) + if (!_waiting) return; event.setCancelled(true); @@ -1097,7 +1164,7 @@ public class MineWare extends TeamGame implements IThrown @Override public boolean isInsideMap(Player player) { - if (_challenge != null && !_waitingChallenge) + if (_challenge != null && !_waiting) return _challenge.isInsideMap(player); return true; @@ -1218,7 +1285,7 @@ public class MineWare extends TeamGame implements IThrown public boolean isWaitingChallenge() { - return _waitingChallenge; + return _waiting; } public boolean areMessagesSent()