|
@@ -21,9 +21,9 @@ package de.butzlabben.missilewars.game;
|
|
|
import de.butzlabben.missilewars.Logger;
|
|
|
import de.butzlabben.missilewars.MissileWars;
|
|
|
import de.butzlabben.missilewars.configuration.Config;
|
|
|
-import de.butzlabben.missilewars.configuration.Messages;
|
|
|
-import de.butzlabben.missilewars.configuration.arena.Arena;
|
|
|
-import de.butzlabben.missilewars.configuration.lobby.Lobby;
|
|
|
+import de.butzlabben.missilewars.configuration.PluginMessages;
|
|
|
+import de.butzlabben.missilewars.configuration.arena.ArenaConfig;
|
|
|
+import de.butzlabben.missilewars.configuration.game.GameConfig;
|
|
|
import de.butzlabben.missilewars.event.GameStartEvent;
|
|
|
import de.butzlabben.missilewars.event.GameStopEvent;
|
|
|
import de.butzlabben.missilewars.game.enums.GameResult;
|
|
@@ -33,7 +33,6 @@ import de.butzlabben.missilewars.game.equipment.EquipmentManager;
|
|
|
import de.butzlabben.missilewars.game.misc.MotdManager;
|
|
|
import de.butzlabben.missilewars.game.misc.ScoreboardManager;
|
|
|
import de.butzlabben.missilewars.game.misc.TeamSpawnProtection;
|
|
|
-import de.butzlabben.missilewars.game.schematics.SchematicFacing;
|
|
|
import de.butzlabben.missilewars.game.schematics.objects.Missile;
|
|
|
import de.butzlabben.missilewars.game.schematics.objects.Shield;
|
|
|
import de.butzlabben.missilewars.game.signs.MWSign;
|
|
@@ -47,10 +46,10 @@ import de.butzlabben.missilewars.listener.game.GameBoundListener;
|
|
|
import de.butzlabben.missilewars.listener.game.GameListener;
|
|
|
import de.butzlabben.missilewars.listener.game.LobbyListener;
|
|
|
import de.butzlabben.missilewars.player.MWPlayer;
|
|
|
-import de.butzlabben.missilewars.util.PlayerUtil;
|
|
|
import de.butzlabben.missilewars.util.geometry.GameArea;
|
|
|
import de.butzlabben.missilewars.util.geometry.Geometry;
|
|
|
import de.butzlabben.missilewars.util.serialization.Serializer;
|
|
|
+import de.redstoneworld.redutilities.player.Teleport;
|
|
|
import lombok.Getter;
|
|
|
import lombok.Setter;
|
|
|
import lombok.ToString;
|
|
@@ -73,15 +72,15 @@ import java.util.function.Consumer;
|
|
|
*/
|
|
|
|
|
|
@Getter
|
|
|
-@ToString(of = {"gameWorld", "players", "lobby", "arena", "state"})
|
|
|
+@ToString(of = {"state", "gameConfig", "players", "gameWorld", "gameArea"})
|
|
|
public class Game {
|
|
|
|
|
|
@Setter private GameState state = GameState.LOBBY;
|
|
|
+ private final GameConfig gameConfig;
|
|
|
private static final Map<String, Integer> cycles = new HashMap<>();
|
|
|
private static int fights = 0;
|
|
|
private final Map<UUID, MWPlayer> players = new HashMap<>();
|
|
|
private final MapVoting mapVoting = new MapVoting(this);
|
|
|
- private final Lobby lobby;
|
|
|
private final Map<UUID, BukkitTask> playerTasks = new HashMap<>();
|
|
|
private final List<Location> portalBlocks = new ArrayList<>();
|
|
|
private TeamManager teamManager;
|
|
@@ -91,7 +90,7 @@ public class Game {
|
|
|
private GameArea gameArea;
|
|
|
private GameArea innerGameArea;
|
|
|
private long timestart;
|
|
|
- private Arena arena;
|
|
|
+ private ArenaConfig arenaConfig;
|
|
|
private ScoreboardManager scoreboardManager;
|
|
|
private GameJoinManager gameJoinManager;
|
|
|
private GameLeaveManager gameLeaveManager;
|
|
@@ -100,30 +99,30 @@ public class Game {
|
|
|
private TaskManager taskManager;
|
|
|
private int remainingGameDuration;
|
|
|
|
|
|
- public Game(Lobby lobby) {
|
|
|
- Logger.BOOT.log("Loading lobby \"" + lobby.getName() + "\".");
|
|
|
- this.lobby = lobby;
|
|
|
+ public Game(GameConfig game) {
|
|
|
+ Logger.BOOT.log("Loading game \"" + game.getName() + "\".");
|
|
|
+ this.gameConfig = game;
|
|
|
|
|
|
- if (lobby.getBukkitWorld() == null) {
|
|
|
- Logger.ERROR.log("Lobby world \"" + lobby.getName() + "\" must not be null");
|
|
|
+ if (gameConfig.getLobbyConfig().getBukkitWorld() == null) {
|
|
|
+ Logger.ERROR.log("Lobby world of the game \"" + gameConfig.getName() + "\" can not be null.");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- Serializer.setWorldAtAllLocations(lobby, lobby.getBukkitWorld());
|
|
|
+ Serializer.setWorldAtAllLocations(gameConfig, gameConfig.getLobbyConfig().getBukkitWorld());
|
|
|
} catch (Exception exception) {
|
|
|
- Logger.ERROR.log("Could not inject world object at lobby \"" + lobby.getName() + "\".");
|
|
|
+ Logger.ERROR.log("Could not inject world object from game \"" + gameConfig.getName() + "\".");
|
|
|
exception.printStackTrace();
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (lobby.getPossibleArenas().isEmpty()) {
|
|
|
- Logger.ERROR.log("At least one valid arena must be set at lobby \"" + lobby.getName() + "\".");
|
|
|
+ if (gameConfig.getPossibleArenas().isEmpty()) {
|
|
|
+ Logger.ERROR.log("No valid arena found in game \"" + gameConfig.getName() + "\".");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (lobby.getPossibleArenas().stream().noneMatch(Arenas::existsArena)) {
|
|
|
- Logger.ERROR.log("None of the specified arenas match a real arena for the lobby \"" + lobby.getName() + "\".");
|
|
|
+ if (gameConfig.getPossibleArenas().stream().noneMatch(Arenas::existsArena)) {
|
|
|
+ Logger.ERROR.log("None of the specified arenas match a real arena for the game \"" + gameConfig.getName() + "\".");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -138,14 +137,14 @@ public class Game {
|
|
|
taskManager = new TaskManager(this);
|
|
|
taskManager.stopTimer();
|
|
|
updateGameListener(new LobbyListener(this));
|
|
|
- taskManager.setTimer(new LobbyTimer(this, lobby.getLobbyTime()));
|
|
|
+ taskManager.setTimer(new LobbyTimer(this, gameConfig.getLobbyConfig().getLobbyTime()));
|
|
|
taskManager.runTimer(0, 20);
|
|
|
state = GameState.LOBBY;
|
|
|
|
|
|
Bukkit.getScheduler().runTaskLater(MissileWars.getInstance(), () -> applyForAllPlayers(player -> gameJoinManager.runTeleportEventForPlayer(player)), 2);
|
|
|
|
|
|
if (Config.isSetup()) {
|
|
|
- Logger.WARN.log("Did not fully initialize lobby \"" + lobby.getName() + "\" as the plugin is in setup mode");
|
|
|
+ Logger.WARN.log("Did not fully initialize game \"" + gameConfig.getName() + "\" as the plugin is in setup mode");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -154,22 +153,22 @@ public class Game {
|
|
|
gameLeaveManager = new GameLeaveManager(this);
|
|
|
|
|
|
// choose the game arena
|
|
|
- if (lobby.getMapChooseProcedure() == MapChooseProcedure.FIRST) {
|
|
|
- setArena(lobby.getArenas().get(0));
|
|
|
+ if (gameConfig.getMapChooseProcedure() == MapChooseProcedure.FIRST) {
|
|
|
+ setArena(gameConfig.getArenas().get(0));
|
|
|
prepareGame();
|
|
|
|
|
|
- } else if (lobby.getMapChooseProcedure() == MapChooseProcedure.MAPCYCLE) {
|
|
|
- final int lastMapIndex = cycles.getOrDefault(lobby.getName(), -1);
|
|
|
- List<Arena> arenas = lobby.getArenas();
|
|
|
+ } else if (gameConfig.getMapChooseProcedure() == MapChooseProcedure.MAPCYCLE) {
|
|
|
+ final int lastMapIndex = cycles.getOrDefault(gameConfig.getName(), -1);
|
|
|
+ List<ArenaConfig> arenas = gameConfig.getArenas();
|
|
|
int index = lastMapIndex >= arenas.size() - 1 ? 0 : lastMapIndex + 1;
|
|
|
- cycles.put(lobby.getName(), index);
|
|
|
+ cycles.put(gameConfig.getName(), index);
|
|
|
setArena(arenas.get(index));
|
|
|
prepareGame();
|
|
|
|
|
|
- } else if (lobby.getMapChooseProcedure() == MapChooseProcedure.MAPVOTING) {
|
|
|
+ } else if (gameConfig.getMapChooseProcedure() == MapChooseProcedure.MAPVOTING) {
|
|
|
if (mapVoting.onlyOneArenaFound()) {
|
|
|
- setArena(lobby.getArenas().get(0));
|
|
|
- Logger.WARN.log("Only one arena was found for the lobby \"" + lobby.getName() + "\". The configured map voting was skipped.");
|
|
|
+ setArena(gameConfig.getArenas().get(0));
|
|
|
+ Logger.WARN.log("Only one arena was found for the game \"" + gameConfig.getName() + "\". The configured map voting was skipped.");
|
|
|
prepareGame();
|
|
|
} else {
|
|
|
mapVoting.startVote();
|
|
@@ -186,7 +185,7 @@ public class Game {
|
|
|
* now already defined.
|
|
|
*/
|
|
|
public void prepareGame() {
|
|
|
- if (this.arena == null) {
|
|
|
+ if (this.arenaConfig == null) {
|
|
|
throw new IllegalStateException("The arena is not yet set");
|
|
|
}
|
|
|
|
|
@@ -219,7 +218,7 @@ public class Game {
|
|
|
}
|
|
|
|
|
|
private void updateMOTD() {
|
|
|
- if (!Config.isMultipleLobbies()) {
|
|
|
+ if (!Config.useMultipleGames()) {
|
|
|
MotdManager.getInstance().updateMOTD(this);
|
|
|
}
|
|
|
}
|
|
@@ -233,7 +232,7 @@ public class Game {
|
|
|
World world = gameWorld.getWorld();
|
|
|
|
|
|
if (world == null) {
|
|
|
- Logger.ERROR.log("Could not start game in arena \"" + arena.getName() + "\". World is null");
|
|
|
+ Logger.ERROR.log("Could not start game in arena \"" + arenaConfig.getName() + "\". World is null");
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -281,7 +280,7 @@ public class Game {
|
|
|
|
|
|
updateMOTD();
|
|
|
|
|
|
- if (arena.isSaveStatistics()) {
|
|
|
+ if (arenaConfig.isSaveStatistics()) {
|
|
|
FightStats stats = new FightStats(this);
|
|
|
stats.insert();
|
|
|
}
|
|
@@ -298,7 +297,7 @@ public class Game {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- GameManager.getInstance().restartGame(lobby, false);
|
|
|
+ GameManager.getInstance().restartGame(gameConfig, false);
|
|
|
}
|
|
|
|
|
|
public void appendRestart() {
|
|
@@ -352,7 +351,7 @@ public class Game {
|
|
|
* @return true, if it's in the Lobby-Area
|
|
|
*/
|
|
|
public boolean isInLobbyArea(Location location) {
|
|
|
- return Geometry.isInsideIn(location, lobby.getArea());
|
|
|
+ return Geometry.isInsideIn(location, gameConfig.getArea());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -458,10 +457,10 @@ public class Game {
|
|
|
public void spawnMissile(Player player, ItemStack itemStack) {
|
|
|
|
|
|
// Are missiles only allowed to spawn inside the arena, between the two arena spawn points?
|
|
|
- boolean isOnlyBetweenSpawnPlaceable = this.arena.getMissileConfiguration().isOnlyBetweenSpawnPlaceable();
|
|
|
+ boolean isOnlyBetweenSpawnPlaceable = this.arenaConfig.getMissileConfig().isOnlyBetweenSpawnPlaceable();
|
|
|
if (isOnlyBetweenSpawnPlaceable) {
|
|
|
if (!isInInnerGameArea(player.getLocation())) {
|
|
|
- player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.ARENA_MISSILE_PLACE_DENY));
|
|
|
+ player.sendMessage(PluginMessages.getMessage(true, PluginMessages.MessageEnum.ARENA_MISSILE_PLACE_DENY));
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
@@ -469,9 +468,9 @@ public class Game {
|
|
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
|
if (itemMeta == null) return;
|
|
|
|
|
|
- Missile missile = (Missile) this.arena.getMissileConfiguration().getSchematicFromDisplayName(itemMeta.getDisplayName());
|
|
|
+ Missile missile = (Missile) this.arenaConfig.getMissileConfig().getSchematicFromDisplayName(itemMeta.getDisplayName());
|
|
|
if (missile == null) {
|
|
|
- player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_MISSILE)
|
|
|
+ player.sendMessage(PluginMessages.getMessage(true, PluginMessages.MessageEnum.COMMAND_INVALID_MISSILE)
|
|
|
.replace("%input%", itemMeta.getDisplayName()));
|
|
|
return;
|
|
|
}
|
|
@@ -492,9 +491,9 @@ public class Game {
|
|
|
ItemMeta itemMeta = ball.getItem().getItemMeta();
|
|
|
if (itemMeta == null) return;
|
|
|
|
|
|
- Shield shield = (Shield) this.arena.getShieldConfiguration().getSchematicFromDisplayName(itemMeta.getDisplayName());
|
|
|
+ Shield shield = (Shield) this.arenaConfig.getShieldConfig().getSchematicFromDisplayName(itemMeta.getDisplayName());
|
|
|
if (shield == null) {
|
|
|
- player.sendMessage(Messages.getMessage(true, Messages.MessageEnum.COMMAND_INVALID_SHIELD)
|
|
|
+ player.sendMessage(PluginMessages.getMessage(true, PluginMessages.MessageEnum.COMMAND_INVALID_SHIELD)
|
|
|
.replace("%input%", itemMeta.getDisplayName()));
|
|
|
return;
|
|
|
}
|
|
@@ -521,26 +520,26 @@ public class Game {
|
|
|
fb.setBounce(false);
|
|
|
}
|
|
|
|
|
|
- public void setArena(Arena arena) {
|
|
|
- if (this.arena != null) {
|
|
|
+ public void setArena(ArenaConfig arenaConfig) {
|
|
|
+ if (this.arenaConfig != null) {
|
|
|
throw new IllegalStateException("Arena already set");
|
|
|
}
|
|
|
|
|
|
- arena.getMissileConfiguration().check();
|
|
|
- arena.getShieldConfiguration().check();
|
|
|
+ arenaConfig.getMissileConfig().check();
|
|
|
+ arenaConfig.getShieldConfig().check();
|
|
|
|
|
|
- this.arena = arena.clone();
|
|
|
- gameWorld = new GameWorld(this, arena.getTemplateWorld());
|
|
|
+ this.arenaConfig = arenaConfig.clone();
|
|
|
+ gameWorld = new GameWorld(this, arenaConfig.getTemplateWorld());
|
|
|
gameWorld.load();
|
|
|
- gameArea = new GameArea(gameWorld.getWorld(), arena.getAreaConfig());
|
|
|
+ gameArea = new GameArea(gameWorld.getWorld(), arenaConfig.getAreaConfig());
|
|
|
|
|
|
try {
|
|
|
- Serializer.setWorldAtAllLocations(this.arena, gameWorld.getWorld());
|
|
|
- teamManager.getTeam1().setSpawn(this.arena.getTeam1Spawn());
|
|
|
- teamManager.getTeam2().setSpawn(this.arena.getTeam2Spawn());
|
|
|
- teamManager.getTeamSpec().setSpawn(this.arena.getSpectatorSpawn());
|
|
|
+ Serializer.setWorldAtAllLocations(this.arenaConfig, gameWorld.getWorld());
|
|
|
+ teamManager.getTeam1().setSpawn(this.arenaConfig.getTeam1Spawn());
|
|
|
+ teamManager.getTeam2().setSpawn(this.arenaConfig.getTeam2Spawn());
|
|
|
+ teamManager.getTeamSpec().setSpawn(this.arenaConfig.getSpectatorSpawn());
|
|
|
} catch (Exception exception) {
|
|
|
- Logger.ERROR.log("Could not inject world object at arena " + this.arena.getName());
|
|
|
+ Logger.ERROR.log("Could not inject world object at arena " + this.arenaConfig.getName());
|
|
|
exception.printStackTrace();
|
|
|
return;
|
|
|
}
|
|
@@ -656,7 +655,7 @@ public class Game {
|
|
|
* @return (boolean) 'true' if to few players are in the lobby
|
|
|
*/
|
|
|
public boolean areToFewPlayers() {
|
|
|
- int minSize = lobby.getMinPlayers();
|
|
|
+ int minSize = gameConfig.getMinPlayers();
|
|
|
int currentSize = teamManager.getTeam1().getMembers().size() + teamManager.getTeam2().getMembers().size();
|
|
|
return currentSize < minSize;
|
|
|
}
|
|
@@ -669,7 +668,7 @@ public class Game {
|
|
|
* @return (boolean) 'true' if to many players are in the lobby
|
|
|
*/
|
|
|
public boolean areTooManyPlayers() {
|
|
|
- int maxSize = lobby.getMaxPlayers();
|
|
|
+ int maxSize = gameConfig.getMaxPlayers();
|
|
|
|
|
|
if (maxSize == -1) return false;
|
|
|
|
|
@@ -683,7 +682,7 @@ public class Game {
|
|
|
* @return (boolean) 'true' if to many spectators are in the lobby
|
|
|
*/
|
|
|
public boolean areTooManySpectators() {
|
|
|
- int maxSize = lobby.getMaxSpectators();
|
|
|
+ int maxSize = gameConfig.getMaxSpectators();
|
|
|
|
|
|
if (maxSize == -1) return false;
|
|
|
|
|
@@ -693,11 +692,11 @@ public class Game {
|
|
|
|
|
|
public int getGameDuration() {
|
|
|
int time = 0;
|
|
|
- if (arena == null) return time;
|
|
|
+ if (arenaConfig == null) return time;
|
|
|
|
|
|
if (state == GameState.LOBBY) {
|
|
|
// Show the planned duration of the next game:
|
|
|
- time = arena.getGameDuration();
|
|
|
+ time = arenaConfig.getGameDuration();
|
|
|
} else if (state == GameState.INGAME) {
|
|
|
// Show the remaining duration of the running game:
|
|
|
time = getTaskManager().getTimer().getSeconds() / 60;
|
|
@@ -733,19 +732,19 @@ public class Game {
|
|
|
}
|
|
|
|
|
|
public void teleportToFallbackSpawn(Player player) {
|
|
|
- PlayerUtil.teleportSafely(player, Config.getFallbackSpawn());
|
|
|
+ Teleport.teleportSafely(player, Config.getFallbackSpawn());
|
|
|
}
|
|
|
|
|
|
public void teleportToLobbySpawn(Player player) {
|
|
|
- PlayerUtil.teleportSafely(player, lobby.getSpawnPoint());
|
|
|
+ Teleport.teleportSafely(player, gameConfig.getLobbyConfig().getSpawnPoint());
|
|
|
}
|
|
|
|
|
|
public void teleportToArenaSpectatorSpawn(Player player) {
|
|
|
- PlayerUtil.teleportSafely(player, arena.getSpectatorSpawn());
|
|
|
+ Teleport.teleportSafely(player, arenaConfig.getSpectatorSpawn());
|
|
|
}
|
|
|
|
|
|
public void teleportToAfterGameSpawn(Player player) {
|
|
|
- PlayerUtil.teleportSafely(player, lobby.getAfterGameSpawn());
|
|
|
+ Teleport.teleportSafely(player, gameConfig.getLobbyConfig().getAfterGameSpawn());
|
|
|
}
|
|
|
|
|
|
/**
|