Moved GameState Code to more maintainable Classes

This commit is contained in:
steev 2022-06-02 19:28:05 +02:00
parent 3f607b14ab
commit fa687f168f
28 changed files with 388 additions and 219 deletions

View File

@ -1,25 +0,0 @@
# general
prefix: null
minplayers: 2
# The language selected here can only be changed by reloading the plugin
# the language must equal the language file in ../lang
# by default avaiable are: de-ger, en-us
language: "en-us"
autorestart: false
lobby-auto-queue: true
force-on-spawn: true
lobby-server: "lobby"
# spawn points
lobby: null
arena: null
# Permissions
admin:
all: "tw.admin"
setlocation:
all: "tw.admin.setlocation"
lobby: "tw.admin.setlocation.lobby"
arena: "tw.admin.setlocation.arena"
start: "tw.admin.start"
stop: "tw.admin.stop"

View File

@ -1,6 +1,6 @@
package de.steev.Tridentwar.Handlers; package de.steev.Tridentwar.Handlers;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -0,0 +1,42 @@
package de.steev.Tridentwar.States;
import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Objects;
public class Aborting {
private final GameManager gameManager;
public Aborting(GameManager gameManager) {
this.gameManager = gameManager;
}
public void run(){
if(this.gameManager.isWaiting) this.gameManager.isWaiting = false;
this.gameManager.getMessageManager().broadCastTitle(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(this.gameManager.getPlugin().languageDataConfig.getString("titles.aborted.top"))),
ChatColor.translateAlternateColorCodes('&',this.gameManager.getFileHandler().replaceVars(this.gameManager.getPlugin().languageDataConfig.getString("titles.aborted.bottom"), null, "Hub")));
this.gameManager.getPlayerManager().removeKits();
this.gameManager.getTridentManager().clearTasks();
// Move players to Hub
Bukkit.getOnlinePlayers().forEach(player -> this.gameManager.getPlayerManager().moveFromServer(this.gameManager.getPlugin().config.getString("lobby-server"), player));
if (this.gameManager.getPlugin().config.getBoolean("autorestart")) {
new BukkitRunnable() {
private GameManager gameManager = Aborting.this.gameManager;
@Override
public void run() {
Bukkit.getServer().dispatchCommand(this.gameManager.getPlugin().getServer().getConsoleSender(), "restart");
}
}.runTaskLater(this.gameManager.getPlugin(), 120);
}
Bukkit.getOnlinePlayers().forEach(player -> this.gameManager.getScoreBoardManager().removeScoreBoard(player));
this.gameManager.setGameState(GameState.LOBBY);
}
}

View File

@ -0,0 +1,26 @@
package de.steev.Tridentwar.States;
import de.steev.Tridentwar.Manager.GameManager;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
public class Active {
private final GameManager gameManager;
public Active(GameManager gameManager) {
this.gameManager = gameManager;
}
public void run(){
this.gameManager.isWaiting = false;
this.gameManager.getPlayerManager().setGameModes(GameMode.SURVIVAL);
this.gameManager.getPlayerManager().setPlayersHealth(20F);
this.gameManager.getPlayerManager().setAlive(Bukkit.getOnlinePlayers().size());
this.gameManager.getPlayerManager().giveKits();
for (Player p : Bukkit.getOnlinePlayers()) {
this.gameManager.getPlayerManager().setKills(p, 0);
this.gameManager.getScoreBoardManager().updateScoreBoard(p, this.gameManager.getPlayerManager().getAlive(), this.gameManager.getPlayerManager().getKills(p));
}
}
}

View File

@ -0,0 +1,23 @@
package de.steev.Tridentwar.States;
import de.steev.Tridentwar.Manager.GameManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
public class Lobby {
private final GameManager gameManager;
public Lobby(GameManager gameManager) {
this.gameManager = gameManager;
}
public void run(){
this.gameManager.getPlayerManager().setGameModes(GameMode.SURVIVAL);
if(this.gameManager.getPlugin().config.getLocation("arena") == null) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.gameManager.getFileHandler().replaceVars(this.gameManager.getPlugin().languageDataConfig.getString("error.location-not-found"), null, null)));
} else {
this.gameManager.getPlayerManager().teleportPlayers(this.gameManager.getPlugin().config.getLocation("lobby"));
}
}
}

View File

@ -0,0 +1,32 @@
package de.steev.Tridentwar.States;
import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.Manager.GameState;
import de.steev.Tridentwar.Tasks.GameStartCountdownTask;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
public class Starting {
private final GameManager gameManager;
public Starting(GameManager gameManager) {
this.gameManager = gameManager;
}
public void run(){
if(Bukkit.getOnlinePlayers().size() < this.gameManager.getPlugin().config.getInt("minplayers")) {
// Message about minimal player count not beeing reached
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.gameManager.getFileHandler().replaceVars(this.gameManager.getPlugin().languageDataConfig.getString("error.not-enough-players"), null, null)));
this.gameManager.setGameState(GameState.LOBBY);
return;
}
this.gameManager.setLobbyWaitingTask(null);
this.gameManager.setGameStartCountdownTask(new GameStartCountdownTask(this.gameManager));
this.gameManager.getGameStartCountdownTask().runTaskTimer(this.gameManager.getPlugin(), 0 , 20);
if(this.gameManager.getPlugin().config.getLocation("arena") == null) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.gameManager.getFileHandler().replaceVars(this.gameManager.getPlugin().languageDataConfig.getString("error.location-not-found"), null, null)));
} else {
this.gameManager.getPlayerManager().teleportPlayers(this.gameManager.getPlugin().config.getLocation("arena"));
}
}
}

View File

@ -0,0 +1,48 @@
package de.steev.Tridentwar.States;
import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.scheduler.BukkitRunnable;
public class Stopping {
private final GameManager gameManager;
public Stopping(GameManager gameManager) {
this.gameManager = gameManager;
}
public void run(){
if(this.gameManager.isWaiting) this.gameManager.isWaiting = false;
this.gameManager.getMessageManager().broadCastTitle(ChatColor.translateAlternateColorCodes('&',this.gameManager.getPlugin().languageDataConfig.getString("titles.stopping.top")),
ChatColor.translateAlternateColorCodes('&', this.gameManager.getFileHandler().replaceVars(this.gameManager.getPlugin().languageDataConfig.getString("titles.stopping.bottom"), null, "Hub")));
this.gameManager.getPlayerManager().removeKits();
new BukkitRunnable() {
private GameManager gameManager = Stopping.this.gameManager;
@Override
public void run() {
// Move players to Hub
Bukkit.getOnlinePlayers().forEach(player -> this.gameManager.getPlayerManager().moveFromServer(this.gameManager.getPlugin().config.getString("lobby-server"), player));
if (this.gameManager.getPlugin().config.getBoolean("autorestart")) {
new BukkitRunnable() {
private GameManager gameManager = Stopping.this.gameManager;
@Override
public void run() {
Bukkit.getServer().dispatchCommand(this.gameManager.getPlugin().getServer().getConsoleSender(), "restart");
}
}.runTaskLater(this.gameManager.getPlugin(), 120);
}
}
}.runTaskLater(this.gameManager.getPlugin(), 100);
Bukkit.getOnlinePlayers().forEach(player -> this.gameManager.getScoreBoardManager().removeScoreBoard(player));
this.gameManager.setGameState(GameState.LOBBY);
}
}

View File

@ -0,0 +1,24 @@
package de.steev.Tridentwar.States;
import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.Tasks.LobbyWaitingTask;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
public class Waiting {
private final GameManager gameManager;
public Waiting(GameManager gameManager) {
this.gameManager = gameManager;
}
public void run(){
if(!this.gameManager.isWaiting) {
this.gameManager.setLobbyWaitingTask(new LobbyWaitingTask(this.gameManager));
this.gameManager.getLobbyWaitingTask().runTaskTimer(this.gameManager.getPlugin(), 0, 20);
this.gameManager.isWaiting = true;
} else {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.gameManager.getPlugin().languageDataConfig.getString("error.is-already-waiting")));
}
}
}

View File

@ -0,0 +1,41 @@
package de.steev.Tridentwar.States;
import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class Won {
private final GameManager gameManager;
public Won(GameManager gameManager) {
this.gameManager = gameManager;
}
public void run(){
for (Player p : Bukkit.getOnlinePlayers()) {
if(p.getGameMode() == GameMode.SURVIVAL) {
this.gameManager.getMessageManager().broadCastTitle(ChatColor.translateAlternateColorCodes('&',this.gameManager.getPlugin().languageDataConfig.getString("titles.won.top")),
ChatColor.translateAlternateColorCodes('&',this.gameManager.getFileHandler().replaceVars(this.gameManager.getPlugin().languageDataConfig.getString("titles.won.bottom"), p, null)));
}
}
this.gameManager.getTridentManager().clearTasks();
if(this.gameManager.getPlugin().config.getLocation("lobby") == null) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.gameManager.getFileHandler().replaceVars(this.gameManager.getPlugin().languageDataConfig.getString("error.location-not-found"), null, null)));
} else {
this.gameManager.getPlayerManager().teleportPlayers(this.gameManager.getPlugin().config.getLocation("lobby"));
}
new BukkitRunnable() {
private GameManager gameManager = Won.this.gameManager;
@Override
public void run() {
this.gameManager.setGameState(GameState.STOPPING);
}
}.runTaskLater(this.gameManager.getPlugin(), 120);
}
}

View File

@ -1,8 +1,8 @@
package de.steev.Tridentwar; package de.steev.Tridentwar;
import de.steev.Tridentwar.commands.TridentwarCommand; import de.steev.Tridentwar.Commands.TridentwarCommand;
import de.steev.Tridentwar.listeners.*; import de.steev.Tridentwar.Listeners.*;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.commands; package de.steev.Tridentwar.Commands;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.listeners; package de.steev.Tridentwar.Listeners;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Sound; import org.bukkit.Sound;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.listeners; package de.steev.Tridentwar.Listeners;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Effect; import org.bukkit.Effect;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Material; import org.bukkit.Material;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.listeners; package de.steev.Tridentwar.Listeners;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.listeners; package de.steev.Tridentwar.Listeners;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Sound; import org.bukkit.Sound;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.listeners; package de.steev.Tridentwar.Listeners;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;

View File

@ -1,9 +1,9 @@
package de.steev.Tridentwar.listeners; package de.steev.Tridentwar.Listeners;
import de.steev.Tridentwar.Tridentwar; import de.steev.Tridentwar.Tridentwar;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import de.steev.Tridentwar.tasks.TridentResetTask; import de.steev.Tridentwar.Tasks.TridentResetTask;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;

View File

@ -1,14 +1,17 @@
package de.steev.Tridentwar.manager; package de.steev.Tridentwar.Manager;
import de.steev.Tridentwar.Handlers.FileHandler; import de.steev.Tridentwar.Handlers.FileHandler;
import de.steev.Tridentwar.States.*;
import de.steev.Tridentwar.Tridentwar; import de.steev.Tridentwar.Tridentwar;
import de.steev.Tridentwar.tasks.GameStartCountdownTask; import de.steev.Tridentwar.Tasks.GameStartCountdownTask;
import de.steev.Tridentwar.tasks.LobbyWaitingTask; import de.steev.Tridentwar.Tasks.LobbyWaitingTask;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.checkerframework.checker.units.qual.A;
import java.io.File; import java.io.File;
import java.util.Objects;
public class GameManager { public class GameManager {
private final Tridentwar plugin; private final Tridentwar plugin;
@ -18,11 +21,23 @@ public class GameManager {
private MessageManager messageManager; private MessageManager messageManager;
private FileHandler fileHandler; private FileHandler fileHandler;
private LobbyWaitingTask lobbyWaitingTask; private LobbyWaitingTask lobbyWaitingTask;
private boolean isWaiting = false; public static boolean isWaiting = false;
private Effect record; private Effect record;
private ScoreBoardManager scoreBoardManager; private ScoreBoardManager scoreBoardManager;
public GameState gameState = GameState.LOBBY; public GameState gameState = GameState.LOBBY;
/**
* Game States
*/
private Active activeState;
private Starting startingState;
private Waiting waitingState;
private Lobby lobbyState;
private Won wonState;
private Stopping stoppingState;
private Aborting abortingState;
/** /**
* Handles the entire Game * Handles the entire Game
* @param plugin the local plugin insance * @param plugin the local plugin insance
@ -35,6 +50,15 @@ public class GameManager {
this.fileHandler = new FileHandler(this); this.fileHandler = new FileHandler(this);
this.scoreBoardManager = new ScoreBoardManager(this); this.scoreBoardManager = new ScoreBoardManager(this);
this.lobbyWaitingTask = null; this.lobbyWaitingTask = null;
// Initialize Game States
this.activeState = new Active(this);
this.startingState = new Starting(this);
this.waitingState = new Waiting(this);
this.lobbyState = new Lobby(this);
this.wonState = new Won(this);
this.stoppingState = new Stopping(this);
this.abortingState = new Aborting(this);
} }
/** /**
@ -45,131 +69,25 @@ public class GameManager {
if(this.gameState == GameState.ACTIVE && gameState == GameState.STARTING) return; if(this.gameState == GameState.ACTIVE && gameState == GameState.STARTING) return;
this.gameState = gameState; this.gameState = gameState;
/**
* Runs run method from state reference
* Add new case and call run method to expand on this
*/
switch (gameState){ switch (gameState){
case ACTIVE: case ACTIVE -> this.activeState.run();
isWaiting = false; case STARTING -> this.startingState.run();
this.playerManager.setGameModes(GameMode.SURVIVAL); case WAITING -> this.waitingState.run();
this.playerManager.setPlayersHealth(20F); case LOBBY -> this.lobbyState.run();
this.playerManager.setAlive(Bukkit.getOnlinePlayers().size()); case WON -> this.wonState.run();
this.playerManager.giveKits(); case STOPPING -> this.stoppingState.run();
for (Player p : Bukkit.getOnlinePlayers()) { case ABORTING -> this.abortingState.run();
this.playerManager.setKills(p, 0);
this.scoreBoardManager.updateScoreBoard(p, this.getPlayerManager().getAlive(), this.playerManager.getKills(p));
}
break;
case STARTING:
if(Bukkit.getOnlinePlayers().size() < this.plugin.config.getInt("minplayers")) {
// Message about minimal player count not beeing reached
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.fileHandler.replaceVars(this.plugin.languageDataConfig.getString("error.not-enough-players"), null, null)));
this.setGameState(GameState.LOBBY);
return;
}
this.lobbyWaitingTask = null;
this.gameStartCountdownTask = new GameStartCountdownTask(this);
this.gameStartCountdownTask.runTaskTimer(plugin, 0 , 20);
if(this.plugin.config.getLocation("arena") == null) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.fileHandler.replaceVars(this.plugin.languageDataConfig.getString("error.location-not-found"), null, null)));
} else {
playerManager.teleportPlayers(this.plugin.config.getLocation("arena"));
}
break;
case WAITING:
if(!isWaiting) {
lobbyWaitingTask = new LobbyWaitingTask(this);
lobbyWaitingTask.runTaskTimer(plugin, 0, 20);
isWaiting = true;
} else {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',plugin.languageDataConfig.getString("error.is-already-waiting")));
}
break;
case LOBBY:
playerManager.setGameModes(GameMode.SURVIVAL);
if(this.plugin.config.getLocation("arena") == null) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.fileHandler.replaceVars(this.plugin.languageDataConfig.getString("error.location-not-found"), null, null)));
} else {
playerManager.teleportPlayers(this.plugin.config.getLocation("lobby"));
}
break;
case WON:
for (Player p : Bukkit.getOnlinePlayers()) {
if(p.getGameMode() == GameMode.SURVIVAL) {
this.messageManager.broadCastTitle(ChatColor.translateAlternateColorCodes('&',this.plugin.languageDataConfig.getString("titles.won.top")),
ChatColor.translateAlternateColorCodes('&',this.fileHandler.replaceVars(this.plugin.languageDataConfig.getString("titles.won.bottom"), p, null)));
}
}
tridentManager.clearTasks();
if(this.plugin.config.getLocation("lobby") == null) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',this.fileHandler.replaceVars(this.plugin.languageDataConfig.getString("error.location-not-found"), null, null)));
} else {
playerManager.teleportPlayers(this.plugin.config.getLocation("lobby"));
}
new BukkitRunnable() {
@Override
public void run() {
setGameState(GameState.STOPPING);
}
}.runTaskLater(plugin, 120);
break;
case STOPPING:
if(isWaiting) isWaiting = false;
this.messageManager.broadCastTitle(ChatColor.translateAlternateColorCodes('&',this.plugin.languageDataConfig.getString("titles.stopping.top")),
ChatColor.translateAlternateColorCodes('&', this.fileHandler.replaceVars(this.plugin.languageDataConfig.getString("titles.stopping.bottom"), null, "Hub")));
this.playerManager.removeKits();
new BukkitRunnable() {
@Override
public void run() {
// Move players to Hub
Bukkit.getOnlinePlayers().forEach(player -> playerManager.moveFromServer(plugin.config.getString("lobby-server"), player));
if (plugin.config.getBoolean("autorestart")) {
new BukkitRunnable() {
@Override
public void run() {
Bukkit.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "restart");
}
}.runTaskLater(plugin, 120);
}
}
}.runTaskLater(plugin, 100);
Bukkit.getOnlinePlayers().forEach(player -> this.scoreBoardManager.removeScoreBoard(player));
this.setGameState(GameState.LOBBY);
break;
case ABORTING:
if(isWaiting) isWaiting = false;
this.messageManager.broadCastTitle(ChatColor.translateAlternateColorCodes('&',this.plugin.languageDataConfig.getString("titles.aborted.top")),
ChatColor.translateAlternateColorCodes('&',this.fileHandler.replaceVars(this.plugin.languageDataConfig.getString("titles.aborted.bottom"), null, "Hub")));
this.playerManager.removeKits();
tridentManager.clearTasks();
// Move players to Hub
Bukkit.getOnlinePlayers().forEach(player -> playerManager.moveFromServer(this.plugin.config.getString("lobby-server"), player));
if (plugin.config.getBoolean("autorestart")) {
new BukkitRunnable() {
@Override
public void run() {
Bukkit.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), "restart");
}
}.runTaskLater(plugin, 120);
}
Bukkit.getOnlinePlayers().forEach(player -> this.scoreBoardManager.removeScoreBoard(player));
this.setGameState(GameState.LOBBY);
break;
} }
} }
/**
* Clean up Routine, called when the games closes
*/
public void cleanup(){ public void cleanup(){
String worldName = "world"; String worldName = "world";
File playerFilesDir = new File(worldName + "/playerdata"); File playerFilesDir = new File(worldName + "/playerdata");
@ -194,6 +112,23 @@ public class GameManager {
*/ */
public MessageManager getMessageManager() { return messageManager; } public MessageManager getMessageManager() { return messageManager; }
/**
* Assigns Game Countdown Task
* @param gameStartCountdownTask Gamecountdown Task
*/
public void setGameStartCountdownTask(GameStartCountdownTask gameStartCountdownTask) {
this.gameStartCountdownTask = gameStartCountdownTask;
}
/**
* returns game countdown task
* @return Gamecountdown Task
*/
public GameStartCountdownTask getGameStartCountdownTask() {
return gameStartCountdownTask;
}
/** /**
* sets the active lobbywaiting task * sets the active lobbywaiting task
* @param lobbyWaitingTask the current task for waiting in the lobby * @param lobbyWaitingTask the current task for waiting in the lobby

View File

@ -1,4 +1,4 @@
package de.steev.Tridentwar.manager; package de.steev.Tridentwar.Manager;
public enum GameState { public enum GameState {
LOBBY, WAITING, STARTING, ACTIVE, WON, RESTARTING, STOPPING, ABORTING; LOBBY, WAITING, STARTING, ACTIVE, WON, RESTARTING, STOPPING, ABORTING;

View File

@ -1,13 +1,10 @@
package de.steev.Tridentwar.manager; package de.steev.Tridentwar.Manager;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.awt.*;
public class MessageManager { public class MessageManager {
private GameManager gameManager; private GameManager gameManager;

View File

@ -1,4 +1,4 @@
package de.steev.Tridentwar.manager; package de.steev.Tridentwar.Manager;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;

View File

@ -1,13 +1,12 @@
package de.steev.Tridentwar.manager; package de.steev.Tridentwar.Manager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scoreboard.*; import org.bukkit.scoreboard.*;
public class ScoreBoardManager { public class ScoreBoardManager {
private GameManager gameManager; private GameManager gameManager;
private ScoreboardManager manager; private final ScoreboardManager manager;
/** /**
* Manages Scoreboards created by the plugin * Manages Scoreboards created by the plugin
@ -22,24 +21,26 @@ public class ScoreBoardManager {
* @param kills how many kills the player got * @param kills how many kills the player got
*/ */
public void createScoreBoard(Player player, int alive, int kills) { public void createScoreBoard(Player player, int alive, int kills) {
Scoreboard scoreboard = manager.getNewScoreboard(); // Create board instance
Objective objective = scoreboard.registerNewObjective("TridentWar","dummy", ChatColor.translateAlternateColorCodes('&',"&7&l<< &bTridentWar &7&l>>")); Scoreboard board = manager.getNewScoreboard();
objective.setDisplaySlot(DisplaySlot.SIDEBAR);
Score splitter = objective.getScore("=-=-=-=-=-=-=-=-=-=-="); // Create Board Objective
splitter.setScore(6); Objective obj = board.registerNewObjective("Tridentwar", "dummy", "SLPNetwork");
Score playername = objective.getScore(ChatColor.translateAlternateColorCodes('&',"&ePlayer: " + ChatColor.WHITE + ChatColor.BOLD + player.getDisplayName())); obj.setDisplaySlot(DisplaySlot.SIDEBAR);
playername.setScore(5);
Score empty2 = objective.getScore(""); // Create Scores
empty2.setScore(4); Score splitter = obj.getScore("=-=-=-=-=-=-=-=-=-=-=");
Score aliveScore = objective.getScore(ChatColor.translateAlternateColorCodes('&',"&eAlive: " + ChatColor.WHITE + ChatColor.BOLD + alive)); splitter.setScore(5);
Score playerName = obj.getScore("Player: " + player.getDisplayName());
playerName.setScore(4);
Score aliveScore = obj.getScore("Alive: " + alive);
aliveScore.setScore(3); aliveScore.setScore(3);
Score killScore = objective.getScore(ChatColor.translateAlternateColorCodes('&',"&eKills: " + ChatColor.WHITE + ChatColor.BOLD + kills)); Score killsScore = obj.getScore("Kills: " + kills);
killScore.setScore(2); killsScore.setScore(2);
Score empty = objective.getScore(""); Score blankScore = obj.getScore("");
empty.setScore(1); blankScore.setScore(1);
Score address = objective.getScore("play.slpnetwork.de"); Score hostScore = obj.getScore("play.slpnetwork.de");
address.setScore(0); hostScore.setScore(0);
player.setScoreboard(scoreboard);
} }
/** /**
@ -47,10 +48,34 @@ public class ScoreBoardManager {
* @param player the player * @param player the player
* @param alive how many players are alive * @param alive how many players are alive
* @param kills how many kills the player got * @param kills how many kills the player got
* TODO: add time
*/ */
public void updateScoreBoard(Player player, int alive, int kills){ public void updateScoreBoard(Player player, int alive, int kills){
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR); // Grab Scoreboard from Player
Scoreboard board = player.getScoreboard();
// Detect if a Scoreboard has been created
if(board == null) {
// If there is none, create one
createScoreBoard(player, alive, kills); createScoreBoard(player, alive, kills);
} else {
// Fetch objective from existing scoreboard
Objective obj = board.getObjective(DisplaySlot.SIDEBAR);
// Replace Scores present on the Screen
Score splitter = obj.getScore("=-=-=-=-=-=-=-=-=-=-=");
splitter.setScore(5);
Score playerName = obj.getScore("Player: " + player.getDisplayName());
playerName.setScore(4);
Score aliveScore = obj.getScore("Alive: " + alive);
aliveScore.setScore(3);
Score killsScore = obj.getScore("Kills: " + kills);
killsScore.setScore(2);
Score blankScore = obj.getScore("");
blankScore.setScore(1);
Score hostScore = obj.getScore("play.slpnetwork.de");
hostScore.setScore(0);
}
} }
/** /**

View File

@ -1,4 +1,4 @@
package de.steev.Tridentwar.manager; package de.steev.Tridentwar.Manager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Sound; import org.bukkit.Sound;

View File

@ -1,6 +1,6 @@
package de.steev.Tridentwar.manager; package de.steev.Tridentwar.Manager;
import de.steev.Tridentwar.tasks.TridentResetTask; import de.steev.Tridentwar.Tasks.TridentResetTask;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.HashMap; import java.util.HashMap;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.tasks; package de.steev.Tridentwar.Tasks;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;

View File

@ -1,7 +1,7 @@
package de.steev.Tridentwar.tasks; package de.steev.Tridentwar.Tasks;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState; import de.steev.Tridentwar.Manager.GameState;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
@ -29,6 +29,10 @@ public class LobbyWaitingTask extends BukkitRunnable {
} else if(timeLeft <= 10) { } else if(timeLeft <= 10) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', this.gameManager.getPlugin().languageDataConfig.getString("game.countdown") + timeLeft)); Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', this.gameManager.getPlugin().languageDataConfig.getString("game.countdown") + timeLeft));
/**
* Checks if the time has run out and messages the Players about game beeing aborted
* proceeds then to abort the game and change gamestate accordingly
*/
if(timeLeft <= 0) { if(timeLeft <= 0) {
if(Bukkit.getOnlinePlayers().size() < this.gameManager.getPlugin().config.getInt("minplayers")) { if(Bukkit.getOnlinePlayers().size() < this.gameManager.getPlugin().config.getInt("minplayers")) {
Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&',

View File

@ -1,9 +1,6 @@
package de.steev.Tridentwar.tasks; package de.steev.Tridentwar.Tasks;
import de.steev.Tridentwar.manager.GameManager; import de.steev.Tridentwar.Manager.GameManager;
import de.steev.Tridentwar.manager.GameState;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;