diff --git a/.github/workflows/beta.yml b/.github/workflows/beta.yml
index 5cf7218..80db5b7 100644
--- a/.github/workflows/beta.yml
+++ b/.github/workflows/beta.yml
@@ -30,7 +30,7 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- - name: Upload artificats
+ - name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: artifacts-beta
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 49eb107..1e992d6 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,13 +1,14 @@
+
## Contributing Guidelines
- Do not send any pull requests to the master branch
- Any pull requests sent to master will be closed
- - Send pull requets to the current beta branch (usually named as an unreleased version)
-- Please tell us why you think this change is nessessary
- - We dont want to spend lots of time browsing through your code changes
+ - Send pull requests to the current beta branch (usually named as an unreleased version)
+- Please tell us why you think this change is necessary
+ - We don't want to spend lots of time browsing through your code changes
- Describe your changes
-- Do not repoen a pull request if we closed it for not being a nessary feature
+- Do not reopen a pull request if we closed it for not being a necessary feature
- Do not change credits in any of the files
-- If making a new language file, follow the local naming convencion
- - localization-[LANGUAGE](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes#)_[TERROTORY](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements).yml. You can find the 2 letter codes in the links.
+- If making a new language file, follow the local naming convention
+ - localization-[LANGUAGE](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes#)_[TERRITORY](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements).yml. You can find the 2-letter codes in the links.
- Common sense, please...
- File subject to change in the future
diff --git a/pom.xml b/pom.xml
index e6bab08..7e1be5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,7 +1,7 @@
4.0.0
net.tylermurphy
- HideAndSeek
- 1.4.2
+ KenshinsHideAndSeek
+ 1.5.0
Hide and Seek Plugin
UTF-8
@@ -30,19 +30,22 @@
-
- org.spigotmc:spigot-api
- com.comphenix.protocol:ProtocolLib
- org.jetbrains:annotations
- net.bytebuddy:byte-buddy
-
+
+ com.github.cryptomorin:XSeries
+ org.xerial:sqlite-jdbc
+ org.mariadb.jdbc:mariadb-java-client
+ com.zaxxer:HikariCP
+
*:*
META-INF/*.MF
- META-INF
+ META-INF/*.MD
+ META-INF/*.SF
+ META-INF/*.DSA
+ META-INF/*.RSA
sqlite-jdbc.properties
@@ -74,6 +77,10 @@
dmulloy2-repo
https://repo.dmulloy2.net/repository/public/
+
+ placeholderapi
+ https://repo.extendedclip.com/content/repositories/placeholderapi/
+
@@ -103,5 +110,21 @@
XSeries
8.7.1
+
+ me.clip
+ placeholderapi
+ 2.11.1
+ provided
+
+
+ com.zaxxer
+ HikariCP
+ 4.0.3
+
+
+ org.mariadb.jdbc
+ mariadb-java-client
+ 2.7.2
+
\ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/Main.java b/src/main/java/net/tylermurphy/hideAndSeek/Main.java
index ac6c2d5..1248551 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/Main.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/Main.java
@@ -19,68 +19,125 @@
package net.tylermurphy.hideAndSeek;
-import java.io.File;
-import java.util.List;
-
+import net.tylermurphy.hideAndSeek.configuration.Config;
+import net.tylermurphy.hideAndSeek.configuration.Items;
+import net.tylermurphy.hideAndSeek.configuration.Localization;
import net.tylermurphy.hideAndSeek.database.Database;
-import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
+import net.tylermurphy.hideAndSeek.game.Board;
+import net.tylermurphy.hideAndSeek.game.PlayerLoader;
+import net.tylermurphy.hideAndSeek.game.util.Status;
+import net.tylermurphy.hideAndSeek.util.CommandHandler;
+import net.tylermurphy.hideAndSeek.game.Game;
+import net.tylermurphy.hideAndSeek.game.listener.*;
+import net.tylermurphy.hideAndSeek.util.PAPIExpansion;
+import net.tylermurphy.hideAndSeek.util.TabCompleter;
import org.bukkit.Bukkit;
-
+import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;
-import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
-import org.bukkit.plugin.messaging.PluginMessageListener;
-import org.bukkit.scheduler.BukkitTask;
-
-import net.tylermurphy.hideAndSeek.game.CommandHandler;
-import net.tylermurphy.hideAndSeek.game.EventListener;
-import net.tylermurphy.hideAndSeek.util.TabCompleter;
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.configuration.Config;
-import net.tylermurphy.hideAndSeek.configuration.Localization;
-import net.tylermurphy.hideAndSeek.configuration.Items;
-import net.tylermurphy.hideAndSeek.game.Board;
+import org.bukkit.plugin.java.JavaPluginLoader;
import org.jetbrains.annotations.NotNull;
+import java.io.File;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition;
+import static net.tylermurphy.hideAndSeek.configuration.Config.exitWorld;
+
public class Main extends JavaPlugin implements Listener {
- public static Main plugin;
- public static File root, data;
- private int onTickTask;
+ private static Main instance;
+ private static int version;
- public void onEnable() {
- plugin = this;
- root = this.getServer().getWorldContainer();
- data = this.getDataFolder();
- getServer().getPluginManager().registerEvents(new EventListener(), this);
+ private final Database database;
+ private final Board board;
+
+ private Game game;
+
+ public Main() {
+ super();
+ onConstructed();
+
+ board = new Board();
+ database = new Database();
+ }
+
+ protected Main(JavaPluginLoader loader, PluginDescriptionFile description, File dataFolder, File file) {
+ super(loader, description, dataFolder, file);
+ onConstructed();
+
+ board = new Board();
+ database = new Database();
+ }
+
+ private void onConstructed(){
+
+ instance = this;
+
+ Matcher matcher = Pattern.compile("MC: \\d\\.(\\d+)").matcher(Bukkit.getVersion());
+ if (matcher.find()) {
+ version = Integer.parseInt(matcher.group(1));
+ } else {
+ throw new IllegalArgumentException("Failed to parse server version from: " + Bukkit.getVersion());
+ }
Config.loadConfig();
Localization.loadLocalization();
Items.loadItems();
- CommandHandler.registerCommands();
- Board.reload();
- Database.init();
- UUIDFetcher.init();
+ }
- onTickTask = Bukkit.getServer().getScheduler().runTaskTimer(this, () -> {
- try{
- Game.onTick();
- } catch (Exception e) {
- e.printStackTrace();
- }
- },0,1).getTaskId();
+ public void onEnable() {
+
+ this.registerListeners();
+
+ CommandHandler.registerCommands();
+
+ game = new Game(board);
+
+ getServer().getScheduler().runTaskTimer(this, this::onTick,0,1).getTaskId();
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
+
+ if (getServer().getPluginManager().getPlugin("PlaceholderAPI") != null) {
+ new PAPIExpansion().register();
+ }
}
-
+
public void onDisable() {
- Main.plugin.getServer().getScheduler().cancelTask(onTickTask);
+
+ version = 0;
+
+ board.getPlayers().forEach(player -> {
+ board.removeBoard(player);
+ PlayerLoader.unloadPlayer(player);
+ player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
+ });
+
Bukkit.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
- UUIDFetcher.cleanup();
- Board.cleanup();
+ board.cleanup();
+ }
+
+ private void onTick() {
+ if(game.getStatus() == Status.ENDED) game = new Game(board);
+ game.onTick();
+ }
+
+ private void registerListeners() {
+ getServer().getPluginManager().registerEvents(new BlockedCommandHandler(), this);
+ getServer().getPluginManager().registerEvents(new ChatHandler(), this);
+ getServer().getPluginManager().registerEvents(new DamageHandler(), this);
+ getServer().getPluginManager().registerEvents(new InteractHandler(), this);
+ getServer().getPluginManager().registerEvents(new InventoryHandler(), this);
+ getServer().getPluginManager().registerEvents(new JoinLeaveHandler(), this);
+ getServer().getPluginManager().registerEvents(new MovementHandler(), this);
+ getServer().getPluginManager().registerEvents(new PlayerHandler(), this);
+ getServer().getPluginManager().registerEvents(new RespawnHandler(), this);
}
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String label, String[] args) {
@@ -90,5 +147,29 @@ public class Main extends JavaPlugin implements Listener {
public List onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, String[] args) {
return TabCompleter.handleTabComplete(sender, args);
}
+
+ public static Main getInstance() {
+ return instance;
+ }
+
+ public File getWorldContainer() {
+ return this.getServer().getWorldContainer();
+ }
+
+ public Database getDatabase() {
+ return database;
+ }
+
+ public Board getBoard(){
+ return board;
+ }
+
+ public Game getGame(){
+ return game;
+ }
+
+ public boolean supports(int v){
+ return version >= v;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java
index 756a8e1..bda6016 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/About.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/About.java
@@ -20,13 +20,13 @@
package net.tylermurphy.hideAndSeek.command;
import org.bukkit.ChatColor;
-import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
public class About implements ICommand {
- public void execute(CommandSender sender, String[] args) {
+ public void execute(Player sender, String[] args) {
sender.sendMessage(
- String.format("%s%sHide and Seek %s(%s1.4.2%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
+ String.format("%s%sHide and Seek %s(%s1.5.0%s)\n", ChatColor.AQUA, ChatColor.BOLD, ChatColor.GRAY,ChatColor.WHITE,ChatColor.GRAY) +
String.format("%sAuthor: %s[KenshinEto]\n", ChatColor.GRAY, ChatColor.WHITE) +
String.format("%sHelp Command: %s/hs %shelp", ChatColor.GRAY, ChatColor.AQUA, ChatColor.WHITE)
);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java
new file mode 100644
index 0000000..1275ceb
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java
@@ -0,0 +1,112 @@
+package net.tylermurphy.hideAndSeek.command;
+
+import com.cryptomorin.xseries.XMaterial;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.PlayerLoader;
+import net.tylermurphy.hideAndSeek.game.util.Status;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.ItemMeta;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.exitPosition;
+
+public class Debug implements ICommand {
+
+ private static final Map> debugMenuFunctions = new HashMap<>();
+ private Inventory debugMenu;
+
+ public void execute(Player sender, String[] args) {
+ if(debugMenu == null) createMenu();
+ sender.openInventory(debugMenu);
+ }
+
+ private void createMenu(){
+ debugMenu = Main.getInstance().getServer().createInventory(null, 9, "Debug Menu");
+ debugMenu.setItem(0, createOption(0, XMaterial.LEATHER_CHESTPLATE.parseMaterial(), "&6Become a &lHider", 1, player -> {
+ if(mapSaveEnabled) {
+ if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap();
+ }
+ Main.getInstance().getBoard().addHider(player);
+ PlayerLoader.loadHider(player, Main.getInstance().getGame().getGameWorld());
+ if(Main.getInstance().getGame().getStatus() != Status.STARTING)
+ PlayerLoader.resetPlayer(player, Main.getInstance().getBoard());
+ }));
+ debugMenu.setItem(1, createOption(1, XMaterial.GOLDEN_CHESTPLATE.parseMaterial(), "&cBecome a &lSeeker", 1, player -> {
+ if(mapSaveEnabled) {
+ if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap();
+ }
+ Main.getInstance().getBoard().addSeeker(player);
+ PlayerLoader.loadSeeker(player, Main.getInstance().getGame().getGameWorld());
+ if(Main.getInstance().getGame().getStatus() != Status.STARTING)
+ PlayerLoader.resetPlayer(player, Main.getInstance().getBoard());
+ }));
+ debugMenu.setItem(2, createOption(2, XMaterial.IRON_CHESTPLATE.parseMaterial(), "&8Become a &lSpectator", 1, player -> {
+ if(mapSaveEnabled) {
+ if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap();
+ }
+ Main.getInstance().getBoard().addSpectator(player);
+ PlayerLoader.loadSpectator(player, Main.getInstance().getGame().getGameWorld());
+ }));
+ debugMenu.setItem(3, createOption(3, XMaterial.BARRIER.parseMaterial(), "&cUnload from Game", 1, player -> {
+ Main.getInstance().getBoard().remove(player);
+ PlayerLoader.unloadPlayer(player);
+ player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
+ }));
+ debugMenu.setItem(4, createOption(4, XMaterial.BARRIER.parseMaterial(), "&cDie In Game", 2, player -> {
+ if((Main.getInstance().getBoard().isSeeker(player) || Main.getInstance().getBoard().isHider(player)) && Main.getInstance().getGame().getStatus() == Status.PLAYING){
+ player.setHealth(0.1);
+ }
+ }));
+ debugMenu.setItem(6, createOption(6, Material.ENDER_PEARL, "&d&lTeleport: &fGame spawn", 1, player -> {
+ if(mapSaveEnabled) {
+ if(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()) == null) Main.getInstance().getGame().getWorldLoader().loadMap();
+ }
+ player.teleport(new Location(Bukkit.getWorld(Main.getInstance().getGame().getGameWorld()), spawnPosition.getX(), spawnPosition.getY(), spawnPosition.getZ()));
+ }));
+ debugMenu.setItem(7, createOption(7, Material.ENDER_PEARL, "&d&lTeleport: &fLobby", 2, player -> {
+ player.teleport(new Location(Bukkit.getWorld(lobbyWorld), lobbyPosition.getX(), lobbyPosition.getY(), lobbyPosition.getZ()));
+ }));
+ debugMenu.setItem(8, createOption(8, Material.ENDER_PEARL, "&d&lTeleport: &fExit", 3, player -> {
+ player.teleport(new Location(Bukkit.getWorld(exitWorld), exitPosition.getX(), exitPosition.getY(), exitPosition.getZ()));
+ }));
+ }
+
+ private ItemStack createOption(int slow, Material material, String name, int amount, Consumer callback){
+ ItemStack temp = new ItemStack(material, amount);
+ ItemMeta meta = temp.getItemMeta();
+ meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
+ temp.setItemMeta(meta);
+ debugMenuFunctions.put(slow, callback);
+ return temp;
+ }
+
+ public static void handleOption(Player player, int slotId){
+ Main.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Main.getInstance(), () -> {
+ Consumer callback = debugMenuFunctions.get(slotId);
+ if(callback != null) callback.accept(player);
+ }, 0);
+ }
+
+ public String getLabel() {
+ return "debug";
+ }
+
+ public String getUsage() {
+ return "";
+ }
+
+ public String getDescription() {
+ return "Run debug commands";
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java
index c1934a9..97224d7 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Help.java
@@ -19,14 +19,13 @@
package net.tylermurphy.hideAndSeek.command;
-import org.bukkit.command.CommandSender;
-
import net.md_5.bungee.api.ChatColor;
-import net.tylermurphy.hideAndSeek.game.CommandHandler;
+import net.tylermurphy.hideAndSeek.util.CommandHandler;
+import org.bukkit.entity.Player;
public class Help implements ICommand {
- public void execute(CommandSender sender, String[] args) {
+ public void execute(Player sender, String[] args) {
StringBuilder message = new StringBuilder();
for(ICommand command : CommandHandler.COMMAND_REGISTER.values()) {
message.append(String.format("%s/hs %s%s %s%s\n %s%s%s", ChatColor.AQUA, ChatColor.WHITE, command.getLabel().toLowerCase(), ChatColor.BLUE, command.getUsage(), ChatColor.GRAY, ChatColor.ITALIC, command.getDescription() + "\n"));
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java
index 6404c22..275d189 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java
@@ -19,11 +19,11 @@
package net.tylermurphy.hideAndSeek.command;
-import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
public interface ICommand {
- void execute(CommandSender sender, String[] args);
+ void execute(Player sender, String[] args);
String getLabel();
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java
index 0ca21d1..941cec0 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Join.java
@@ -19,34 +19,31 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Board;
-import net.tylermurphy.hideAndSeek.game.Game;
+import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Join implements ICommand {
- public void execute(CommandSender sender, String[] args) {
- if(Game.isNotSetup()) {
+ public void execute(Player sender, String[] args) {
+ if (Main.getInstance().getGame().isNotSetup()) {
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
return;
}
Player player = Bukkit.getServer().getPlayer(sender.getName());
- if(player == null) {
+ if (player == null) {
sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
return;
}
- if(Board.isPlayer(player)){
+ if (Main.getInstance().getBoard().contains(player)) {
sender.sendMessage(errorPrefix + message("GAME_INGAME"));
return;
}
- Game.join(player);
+ Main.getInstance().getGame().join(player);
}
public String getLabel() {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java
index 8d8cf76..092ff50 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java
@@ -19,35 +19,30 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Board;
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Leave implements ICommand {
- public void execute(CommandSender sender, String[] args) {
- if(Game.isNotSetup()) {
+ public void execute(Player sender, String[] args) {
+ if (Main.getInstance().getGame().isNotSetup()) {
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
return;
}
Player player = Bukkit.getServer().getPlayer(sender.getName());
- if(player == null) {
+ if (player == null) {
sender.sendMessage(errorPrefix + message("COMMAND_ERROR"));
return;
}
- if(!Board.isPlayer(player)) {
+ if (!Main.getInstance().getBoard().contains(player)) {
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
return;
}
- Game.leave(player);
+ Main.getInstance().getGame().leave(player);
}
public String getLabel() {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java
index fc2592b..56f4517 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java
@@ -19,23 +19,22 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.configuration.Items;
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import org.bukkit.command.CommandSender;
-
+import net.tylermurphy.hideAndSeek.Main;
import net.tylermurphy.hideAndSeek.configuration.Config;
+import net.tylermurphy.hideAndSeek.configuration.Items;
import net.tylermurphy.hideAndSeek.configuration.Localization;
+import net.tylermurphy.hideAndSeek.game.util.Status;
+import org.bukkit.entity.Player;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Config.messagePrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Reload implements ICommand {
- public void execute(CommandSender sender, String[] args) {
+ public void execute(Player sender, String[] args) {
- if(Game.status != Status.STANDBY) {
+ if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java
index c48e1c6..1e66395 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java
@@ -19,47 +19,49 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.Bukkit;
import org.bukkit.World;
-import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
-import net.tylermurphy.hideAndSeek.Main;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class SaveMap implements ICommand {
public static boolean runningBackup = false;
- public void execute(CommandSender sender, String[] args) {
- if(Game.status != Status.STANDBY) {
+ public void execute(Player sender, String[] args) {
+ if (!mapSaveEnabled) {
+ sender.sendMessage(errorPrefix + message("MAPSAVE_DISABLED"));
+ return;
+ }
+ if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
- if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
+ if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
return;
}
sender.sendMessage(messagePrefix + message("MAPSAVE_START"));
sender.sendMessage(warningPrefix + message("MAPSAVE_WARNING"));
World world = Bukkit.getServer().getWorld(spawnWorld);
- if(world == null){
+ if (world == null) {
throw new RuntimeException("Unable to get world: " + spawnWorld);
}
world.save();
BukkitRunnable runnable = new BukkitRunnable() {
public void run() {
sender.sendMessage(
- Game.worldLoader.save()
+ Main.getInstance().getGame().getWorldLoader().save()
);
runningBackup = false;
}
};
- runnable.runTaskAsynchronously(Main.plugin);
+ runnable.runTaskAsynchronously(Main.getInstance());
runningBackup = true;
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java
index 798b99f..45e66b9 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java
@@ -19,33 +19,31 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import org.bukkit.command.CommandSender;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class SetBorder implements ICommand {
- public void execute(CommandSender sender, String[] args) {
- if(Game.status != Status.STANDBY) {
+ public void execute(Player sender, String[] args) {
+ if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
- if(spawnPosition == null) {
+ if (spawnPosition == null) {
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
return;
}
- if(args.length < 3) {
- worldborderEnabled = false;
+ if (args.length < 3) {
+ worldBorderEnabled = false;
addToConfig("worldBorder.enabled",false);
saveConfig();
sender.sendMessage(messagePrefix + message("WORLDBORDER_DISABLE"));
- Game.resetWorldborder(spawnWorld);
+ Main.getInstance().getGame().getBorder().resetWorldBorder(spawnWorld);
return;
}
int num,delay,change;
@@ -61,37 +59,37 @@ public class SetBorder implements ICommand {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[2]));
return;
}
- if(num < 100) {
+ if (num < 100) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_MIN_SIZE"));
return;
}
- if(change < 1) {
+ if (change < 1) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_CHANGE_SIZE"));
return;
}
- Vector newWorldborderPosition = new Vector();
+ Vector vec = new Vector();
Player player = (Player) sender;
- newWorldborderPosition.setX(player.getLocation().getBlockX());
- newWorldborderPosition.setY(0);
- newWorldborderPosition.setZ(player.getLocation().getBlockZ());
- if(spawnPosition.distance(newWorldborderPosition) > 100) {
+ vec.setX(player.getLocation().getBlockX());
+ vec.setY(0);
+ vec.setZ(player.getLocation().getBlockZ());
+ if (spawnPosition.distance(vec) > 100) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
return;
}
- worldborderPosition = newWorldborderPosition;
- worldborderSize = num;
- worldborderDelay = delay;
- worldborderChange = change;
- worldborderEnabled = true;
- addToConfig("worldBorder.x", worldborderPosition.getBlockX());
- addToConfig("worldBorder.z", worldborderPosition.getBlockZ());
- addToConfig("worldBorder.delay", worldborderDelay);
- addToConfig("worldBorder.size", worldborderSize);
+ worldBorderPosition = vec;
+ worldBorderSize = num;
+ worldBorderDelay = delay;
+ worldBorderChange = change;
+ worldBorderEnabled = true;
+ addToConfig("worldBorder.x", worldBorderPosition.getBlockX());
+ addToConfig("worldBorder.z", worldBorderPosition.getBlockZ());
+ addToConfig("worldBorder.delay", worldBorderDelay);
+ addToConfig("worldBorder.size", worldBorderSize);
addToConfig("worldBorder.enabled", true);
- addToConfig("worldBorder.move", worldborderChange);
+ addToConfig("worldBorder.move", worldBorderChange);
sender.sendMessage(messagePrefix + message("WORLDBORDER_ENABLE").addAmount(num).addAmount(delay));
saveConfig();
- Game.resetWorldborder(spawnWorld);
+ Main.getInstance().getGame().getBorder().resetWorldBorder(spawnWorld);
}
public String getLabel() {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java
index 9f4101a..90ecb28 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java
@@ -19,43 +19,41 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import org.bukkit.command.CommandSender;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.util.Status;
import org.bukkit.entity.Player;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class SetBounds implements ICommand {
- public void execute(CommandSender sender, String[] args) {
- if(Game.status != Status.STANDBY) {
+ public void execute(Player sender, String[] args) {
+ if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
- if(spawnPosition == null) {
+ if (spawnPosition == null) {
sender.sendMessage(errorPrefix + message("ERROR_GAME_SPAWN"));
return;
}
Player player = (Player) sender;
- if(!player.getWorld().getName().equals(spawnWorld)){
+ if (!player.getWorld().getName().equals(spawnWorld)) {
sender.sendMessage(errorPrefix + message("BOUNDS_WRONG_WORLD"));
return;
}
- if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0){
+ if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0) {
sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
return;
}
boolean first = true;
- if(saveMinX != 0 && saveMinZ != 0 && saveMaxX != 0 && saveMaxZ != 0) {
+ if (saveMinX != 0 && saveMinZ != 0 && saveMaxX != 0 && saveMaxZ != 0) {
saveMinX = 0; saveMinZ= 0; saveMaxX = 0; saveMaxZ = 0;
}
- if(saveMaxX == 0) {
+ if (saveMaxX == 0) {
addToConfig("bounds.max.x", player.getLocation().getBlockX());
saveMaxX = player.getLocation().getBlockX();
- } else if(saveMaxX < player.getLocation().getBlockX()) {
+ } else if (saveMaxX < player.getLocation().getBlockX()) {
first = false;
addToConfig("bounds.max.x", player.getLocation().getBlockX());
addToConfig("bounds.min.x", saveMaxX);
@@ -66,10 +64,10 @@ public class SetBounds implements ICommand {
addToConfig("bounds.min.x", player.getLocation().getBlockX());
saveMinX = player.getLocation().getBlockX();
}
- if(saveMaxZ == 0) {
+ if (saveMaxZ == 0) {
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
saveMaxZ = player.getLocation().getBlockZ();
- } else if(saveMaxZ < player.getLocation().getBlockZ()) {
+ } else if (saveMaxZ < player.getLocation().getBlockZ()) {
first = false;
addToConfig("bounds.max.z", player.getLocation().getBlockZ());
addToConfig("bounds.min.z", saveMaxZ);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java
deleted file mode 100644
index 7461767..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package net.tylermurphy.hideAndSeek.command;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import org.bukkit.World;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.util.Vector;
-
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
-
-public class SetExitLocation implements ICommand {
-
- public void execute(CommandSender sender, String[] args) {
- if(Game.status != Status.STANDBY) {
- sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
- return;
- }
- Vector newExitPosition = new Vector();
- Player player = (Player) sender;
- if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
- sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
- return;
- }
- newExitPosition.setX(player.getLocation().getBlockX());
- newExitPosition.setY(player.getLocation().getBlockY());
- newExitPosition.setZ(player.getLocation().getBlockZ());
- World world = player.getLocation().getWorld();
- if(world == null){
- throw new RuntimeException("Unable to get world: " + spawnWorld);
- }
- exitWorld = world.getName();
- exitPosition = newExitPosition;
- sender.sendMessage(messagePrefix + message("EXIT_SPAWN"));
- addToConfig("spawns.exit.x", exitPosition.getX());
- addToConfig("spawns.exit.y", exitPosition.getY());
- addToConfig("spawns.exit.z", exitPosition.getZ());
- addToConfig("spawns.exit.world", player.getLocation().getWorld().getName());
- saveConfig();
- }
-
- public String getLabel() {
- return "setexit";
- }
-
- public String getUsage() {
- return "";
- }
-
- public String getDescription() {
- return "Sets hide and seeks exit location to current position and world";
- }
-
-}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java
deleted file mode 100644
index 69e5e52..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package net.tylermurphy.hideAndSeek.command;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import org.bukkit.World;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.util.Vector;
-
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
-
-public class SetLobbyLocation implements ICommand {
-
- public void execute(CommandSender sender, String[] args) {
- if(Game.status != Status.STANDBY) {
- sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
- return;
- }
- Vector newLobbyPosition = new Vector();
- Player player = (Player) sender;
- if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
- sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
- return;
- }
- newLobbyPosition.setX(player.getLocation().getBlockX());
- newLobbyPosition.setY(player.getLocation().getBlockY());
- newLobbyPosition.setZ(player.getLocation().getBlockZ());
- World world = player.getLocation().getWorld();
- if(world == null){
- throw new RuntimeException("Unable to get world: " + spawnWorld);
- }
- lobbyWorld = world.getName();
- lobbyPosition = newLobbyPosition;
- sender.sendMessage(messagePrefix + message("LOBBY_SPAWN"));
- addToConfig("spawns.lobby.x", lobbyPosition.getX());
- addToConfig("spawns.lobby.y", lobbyPosition.getY());
- addToConfig("spawns.lobby.z", lobbyPosition.getZ());
- addToConfig("spawns.lobby.world", player.getLocation().getWorld().getName());
- saveConfig();
- }
-
- public String getLabel() {
- return "setlobby";
- }
-
- public String getUsage() {
- return "";
- }
-
- public String getDescription() {
- return "Sets hide and seeks lobby location to current position";
- }
-
-}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java
deleted file mode 100644
index 7afe861..0000000
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * This file is part of Kenshins Hide and Seek
- *
- * Copyright (c) 2021 Tyler Murphy.
- *
- * Kenshins Hide and Seek free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * he Free Software Foundation version 3.
- *
- * Kenshins Hide and Seek is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- *
- */
-
-package net.tylermurphy.hideAndSeek.command;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import net.tylermurphy.hideAndSeek.world.WorldLoader;
-import org.bukkit.World;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.util.Vector;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.addToConfig;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
-
-public class SetSpawnLocation implements ICommand {
-
- public void execute(CommandSender sender, String[] args) {
- if(Game.status != Status.STANDBY) {
- sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
- return;
- }
- Vector newSpawnPosition = new Vector();
- Player player = (Player) sender;
- if(player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
- sender.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
- return;
- }
- newSpawnPosition.setX(player.getLocation().getBlockX());
- newSpawnPosition.setY(player.getLocation().getBlockY());
- newSpawnPosition.setZ(player.getLocation().getBlockZ());
- if(worldborderEnabled && newSpawnPosition.distance(worldborderPosition) > 100) {
- sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
- return;
- }
- World world = player.getLocation().getWorld();
- if(world == null){
- throw new RuntimeException("Unable to get world: " + spawnWorld);
- }
- if(!world.getName().equals(spawnWorld)){
- Game.worldLoader.unloadMap();
- Game.worldLoader = new WorldLoader(world.getName());
- }
- spawnWorld = world.getName();
- spawnPosition = newSpawnPosition;
- sender.sendMessage(messagePrefix + message("GAME_SPAWN"));
- addToConfig("spawns.game.x", spawnPosition.getX());
- addToConfig("spawns.game.y", spawnPosition.getY());
- addToConfig("spawns.game.z", spawnPosition.getZ());
- addToConfig("spawns.game.world", player.getLocation().getWorld().getName());
- saveConfig();
- }
-
- public String getLabel() {
- return "setspawn";
- }
-
- public String getUsage() {
- return "";
- }
-
- public String getDescription() {
- return "Sets hide and seeks spawn location to current position";
- }
-
-}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java
index 74c29bf..7b29f79 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java
@@ -19,44 +19,45 @@
package net.tylermurphy.hideAndSeek.command;
-import org.bukkit.command.CommandSender;
-
import net.tylermurphy.hideAndSeek.Main;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import org.bukkit.entity.Player;
import java.io.File;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Setup implements ICommand {
- public void execute(CommandSender sender, String[] args) {
+ public void execute(Player sender, String[] args) {
String msg = message("SETUP").toString();
int count = 0;
- if(spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
+ if (spawnPosition.getBlockX() == 0 && spawnPosition.getBlockY() == 0 && spawnPosition.getBlockZ() == 0) {
msg = msg + "\n" + message("SETUP_GAME");
count++;
}
- if(lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) {
+ if (lobbyPosition.getBlockX() == 0 && lobbyPosition.getBlockY() == 0 && lobbyPosition.getBlockZ() == 0) {
msg = msg + "\n" + message("SETUP_LOBBY");
count++;
}
- if(exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) {
+ if (exitPosition.getBlockX() == 0 && exitPosition.getBlockY() == 0 && exitPosition.getBlockZ() == 0) {
msg = msg + "\n" + message("SETUP_EXIT");
count++;
}
- if(saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) {
+ if (saveMinX == 0 || saveMinZ == 0 || saveMaxX == 0 || saveMaxZ == 0) {
msg = msg + "\n" + message("SETUP_BOUNDS");
count++;
}
- File destenation = new File(Main.root+File.separator+"hideandseek_"+spawnWorld);
- if(!destenation.exists()) {
- msg = msg + "\n" + message("SETUP_SAVEMAP");
- count++;
+ if (mapSaveEnabled) {
+ File destenation = new File(Main.getInstance().getWorldContainer() + File.separator + Main.getInstance().getGame().getGameWorld());
+ if (!destenation.exists()) {
+ msg = msg + "\n" + message("SETUP_SAVEMAP");
+ count++;
+ }
}
- if(count < 1) {
+ if (count < 1) {
sender.sendMessage(messagePrefix + message("SETUP_COMPLETE"));
} else {
sender.sendMessage(msg);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java
index 8605764..18bcbba 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Start.java
@@ -19,46 +19,42 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
-
-import net.tylermurphy.hideAndSeek.game.Board;
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
import net.tylermurphy.hideAndSeek.Main;
-
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import net.tylermurphy.hideAndSeek.game.util.Status;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
import java.util.Optional;
import java.util.Random;
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Config.minPlayers;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
public class Start implements ICommand {
- public void execute(CommandSender sender, String[] args) {
- if(Game.isNotSetup()) {
+ public void execute(Player sender, String[] args) {
+ if (Main.getInstance().getGame().isNotSetup()) {
sender.sendMessage(errorPrefix + message("GAME_SETUP"));
return;
}
- if(Game.status != Status.STANDBY) {
+ if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
sender.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
return;
}
- if(!Board.isPlayer(sender)) {
+ if (!Main.getInstance().getBoard().contains(sender)) {
sender.sendMessage(errorPrefix + message("GAME_NOT_INGAME"));
return;
}
- if(Board.size() < minPlayers) {
+ if (Main.getInstance().getBoard().size() < minPlayers) {
sender.sendMessage(errorPrefix + message("START_MIN_PLAYERS").addAmount(minPlayers));
return;
}
String seekerName;
- if(args.length < 1) {
- Optional rand = Board.getPlayers().stream().skip(new Random().nextInt(Board.size())).findFirst();
- if(!rand.isPresent()){
- Main.plugin.getLogger().warning("Failed to select random seeker.");
+ if (args.length < 1) {
+ Optional rand = Main.getInstance().getBoard().getPlayers().stream().skip(new Random().nextInt(Main.getInstance().getBoard().size())).findFirst();
+ if (!rand.isPresent()) {
+ Main.getInstance().getLogger().warning("Failed to select random seeker.");
return;
}
seekerName = rand.get().getName();
@@ -66,16 +62,16 @@ public class Start implements ICommand {
seekerName = args[0];
}
Player temp = Bukkit.getPlayer(seekerName);
- if(temp == null) {
+ if (temp == null) {
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
return;
}
- Player seeker = Board.getPlayer(temp.getUniqueId());
- if(seeker == null) {
+ Player seeker = Main.getInstance().getBoard().getPlayer(temp.getUniqueId());
+ if (seeker == null) {
sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(seekerName));
return;
}
- Game.start(seeker);
+ Main.getInstance().getGame().start(seeker);
}
public String getLabel() {
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java
index b41277b..9280b53 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java
@@ -19,27 +19,24 @@
package net.tylermurphy.hideAndSeek.command;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.util.Status;
+import org.bukkit.entity.Player;
-import net.tylermurphy.hideAndSeek.game.Game;
-import net.tylermurphy.hideAndSeek.util.Status;
-import net.tylermurphy.hideAndSeek.util.WinType;
-import org.bukkit.Bukkit;
-import org.bukkit.command.CommandSender;
-
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.abortPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Stop implements ICommand {
- public void execute(CommandSender sender, String[] args) {
- if(Game.isNotSetup()) {
+ public void execute(Player sender, String[] args) {
+ if (Main.getInstance().getGame().isNotSetup()) {
sender.sendMessage(errorPrefix + "Game is not setup. Run /hs setup to see what you needed to do");
return;
}
- if(Game.status == Status.STARTING || Game.status == Status.PLAYING) {
- if(announceMessagesToNonPlayers) Bukkit.broadcastMessage(abortPrefix + message("STOP"));
- else Game.broadcastMessage(abortPrefix + message("STOP"));
- Game.stop(WinType.NONE);
+ if (Main.getInstance().getGame().getStatus() == Status.STARTING || Main.getInstance().getGame().getStatus() == Status.PLAYING) {
+ Main.getInstance().getGame().broadcastMessage(abortPrefix + message("STOP"));
+ Main.getInstance().getGame().end();
} else {
sender.sendMessage(errorPrefix + message("GAME_NOT_INPROGRESS"));
}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
index 760bb2c..6125a00 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Top.java
@@ -20,47 +20,52 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.database.Database;
-import net.tylermurphy.hideAndSeek.database.PlayerInfo;
+import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
+import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
-import org.bukkit.command.CommandSender;
+import org.bukkit.OfflinePlayer;
+import org.bukkit.entity.Player;
import java.util.List;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Top implements ICommand {
- public void execute(CommandSender sender, String[] args) {
+ public void execute(Player sender, String[] args) {
int page;
- if(args.length == 0) page = 1;
+ if (args.length == 0) page = 1;
else try{
page = Integer.parseInt(args[0]);
- } catch(Exception e){
+ } catch(Exception e) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(args[0]));
return;
}
- if(page < 1){
+ if (page < 1) {
sender.sendMessage(errorPrefix + message("WORLDBORDER_INVALID_INPUT").addAmount(page));
return;
}
StringBuilder message = new StringBuilder(String.format(
"%s------- %sLEADERBOARD %s(Page %s) %s-------\n",
ChatColor.WHITE, ChatColor.BOLD, ChatColor.GRAY, page, ChatColor.WHITE));
- List infos = Database.playerInfo.getInfoPage(page);
+ List infos = Main.getInstance().getDatabase().getGameData().getInfoPage(page);
int i = 1 + (page-1)*10;
- for(PlayerInfo info : infos){
- String name = Main.plugin.getServer().getOfflinePlayer(info.uuid).getName();
+ if (infos == null) {
+ sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
+ return;
+ }
+ for(PlayerInfo info : infos) {
+ String name = Main.getInstance().getDatabase().getNameData().getName(info.getUniqueId());
ChatColor color;
- switch (i){
+ switch (i) {
case 1: color = ChatColor.YELLOW; break;
case 2: color = ChatColor.GRAY; break;
case 3: color = ChatColor.GOLD; break;
default: color = ChatColor.WHITE; break;
}
message.append(String.format("%s%s. %s%s %s%s\n",
- color, i, ChatColor.RED, info.wins, ChatColor.WHITE, name));
+ color, i, ChatColor.RED, info.getSeekerWins() +info.getHiderWins(), ChatColor.WHITE, name));
i++;
}
sender.sendMessage(message.toString());
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
index dfa5338..e12d2d4 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java
@@ -20,45 +20,36 @@
package net.tylermurphy.hideAndSeek.command;
import net.tylermurphy.hideAndSeek.Main;
-import net.tylermurphy.hideAndSeek.database.Database;
-import net.tylermurphy.hideAndSeek.database.PlayerInfo;
-import net.tylermurphy.hideAndSeek.util.UUIDFetcher;
+import net.tylermurphy.hideAndSeek.database.util.PlayerInfo;
import org.bukkit.ChatColor;
-import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.UUID;
-import static net.tylermurphy.hideAndSeek.configuration.Config.*;
-import static net.tylermurphy.hideAndSeek.configuration.Localization.*;
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
public class Wins implements ICommand {
- public void execute(CommandSender sender, String[] args) {
- Main.plugin.getServer().getScheduler().runTaskAsynchronously(Main.plugin, () -> {
+ public void execute(Player sender, String[] args) {
+ Main.getInstance().getServer().getScheduler().runTaskAsynchronously(Main.getInstance(), () -> {
UUID uuid;
String name;
- if(args.length == 0) {
- Player player = Main.plugin.getServer().getPlayer(sender.getName());
- if(player == null){
- sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(sender.getName()));
- return;
- }
- uuid = player.getUniqueId();
+ if (args.length == 0) {
+ uuid = sender.getUniqueId();
name = sender.getName();
}
else {
- try {
- name = args[0];
- uuid = UUIDFetcher.getUUID(args[0]);
- } catch (Exception e){
- sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0]));
- return;
- }
+ name = args[0];
+ uuid = Main.getInstance().getDatabase().getNameData().getUUID(args[0]);
}
- PlayerInfo info = Database.playerInfo.getInfo(uuid);
- if(info == null){
+ if(uuid == null){
+ sender.sendMessage(errorPrefix + message("START_INVALID_NAME").addPlayer(args[0]));
+ return;
+ }
+ PlayerInfo info = Main.getInstance().getDatabase().getGameData().getInfo(uuid);
+ if (info == null) {
sender.sendMessage(errorPrefix + message("NO_GAME_INFO"));
return;
}
@@ -66,8 +57,8 @@ public class Wins implements ICommand {
message = message + message("INFORMATION_FOR").addPlayer(name) + "\n";
message = message + "==============================\n";
message = message + String.format("%sTOTAL WINS: %s%s\n%sHIDER WINS: %s%s\n%sSEEKER WINS: %s%s\n%sGAMES PLAYED: %s",
- ChatColor.YELLOW, ChatColor.WHITE, info.wins, ChatColor.GOLD, ChatColor.WHITE, info.hider_wins,
- ChatColor.RED, ChatColor.WHITE, info.seeker_wins, ChatColor.WHITE, info.games_played);
+ ChatColor.YELLOW, ChatColor.WHITE, info.getSeekerWins() +info.getHiderWins(), ChatColor.GOLD, ChatColor.WHITE, info.getHiderWins(),
+ ChatColor.RED, ChatColor.WHITE, info.getSeekerWins(), ChatColor.WHITE, info.getSeekerGames() +info.getHiderGames());
message = message + ChatColor.WHITE + "" + ChatColor.BOLD + "\n==============================";
sender.sendMessage(message);
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java
new file mode 100644
index 0000000..93c0d8c
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java
@@ -0,0 +1,49 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2021 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.command.location;
+
+import net.tylermurphy.hideAndSeek.command.ICommand;
+import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils;
+import net.tylermurphy.hideAndSeek.command.location.util.Locations;
+import org.bukkit.entity.Player;
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+
+public class SetExitLocation implements ICommand {
+
+ public void execute(Player sender, String[] args) {
+ LocationUtils.setLocation(sender, Locations.EXIT, vector -> {
+ exitWorld = sender.getLocation().getWorld().getName();
+ exitPosition = vector;
+ });
+ }
+
+ public String getLabel() {
+ return "setexit";
+ }
+
+ public String getUsage() {
+ return "";
+ }
+
+ public String getDescription() {
+ return "Sets hide and seeks exit location to current position and world";
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java
new file mode 100644
index 0000000..eb228f9
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java
@@ -0,0 +1,50 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2021 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.command.location;
+
+import net.tylermurphy.hideAndSeek.command.ICommand;
+import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils;
+import net.tylermurphy.hideAndSeek.command.location.util.Locations;
+import org.bukkit.entity.Player;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+
+public class SetLobbyLocation implements ICommand {
+
+ public void execute(Player sender, String[] args) {
+ LocationUtils.setLocation(sender, Locations.LOBBY, vector -> {
+ lobbyWorld = sender.getLocation().getWorld().getName();
+ lobbyPosition = vector;
+ });
+ }
+
+ public String getLabel() {
+ return "setlobby";
+ }
+
+ public String getUsage() {
+ return "";
+ }
+
+ public String getDescription() {
+ return "Sets hide and seeks lobby location to current position";
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java
new file mode 100644
index 0000000..5ecfb8d
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java
@@ -0,0 +1,62 @@
+/*
+ * This file is part of Kenshins Hide and Seek
+ *
+ * Copyright (c) 2021 Tyler Murphy.
+ *
+ * Kenshins Hide and Seek free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * he Free Software Foundation version 3.
+ *
+ * Kenshins Hide and Seek is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ *
+ */
+
+package net.tylermurphy.hideAndSeek.command.location;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.command.ICommand;
+import net.tylermurphy.hideAndSeek.command.location.util.LocationUtils;
+import net.tylermurphy.hideAndSeek.command.location.util.Locations;
+import org.bukkit.entity.Player;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
+public class SetSpawnLocation implements ICommand {
+
+ public void execute(Player sender, String[] args) {
+ LocationUtils.setLocation(sender, Locations.GAME, vector -> {
+ if (worldBorderEnabled && vector.distance(worldBorderPosition) > 100) {
+ sender.sendMessage(errorPrefix + message("WORLDBORDER_POSITION"));
+ throw new RuntimeException("World border not enabled or not in valid position!");
+ }
+
+ if (!sender.getLocation().getWorld().getName().equals(spawnWorld)) {
+ Main.getInstance().getGame().getWorldLoader().unloadMap();
+ Main.getInstance().getGame().getWorldLoader().setNewMap(sender.getLocation().getWorld().getName());
+ }
+
+ spawnWorld = sender.getLocation().getWorld().getName();
+ spawnPosition = vector;
+ });
+ }
+
+ public String getLabel() {
+ return "setspawn";
+ }
+
+ public String getUsage() {
+ return "";
+ }
+
+ public String getDescription() {
+ return "Sets hide and seeks spawn location to current position";
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java
new file mode 100644
index 0000000..50d1776
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java
@@ -0,0 +1,59 @@
+package net.tylermurphy.hideAndSeek.command.location.util;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.util.Status;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.function.Consumer;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.*;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
+/**
+ * @author bobby29831
+ */
+public class LocationUtils {
+
+ /**
+ * Provides a vector for a player
+ * @param player the player to create the vector for
+ * @return the vector
+ */
+ private static @Nullable Vector vector(Player player) {
+ if (Main.getInstance().getGame().getStatus() != Status.STANDBY) {
+ player.sendMessage(errorPrefix + message("GAME_INPROGRESS"));
+ return null;
+ }
+
+ if (player.getLocation().getBlockX() == 0 || player.getLocation().getBlockZ() == 0 || player.getLocation().getBlockY() == 0){
+ player.sendMessage(errorPrefix + message("NOT_AT_ZERO"));
+ return null;
+ }
+
+ Location loc = player.getLocation();
+ return new Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
+ }
+
+ public static void setLocation(Player player, Locations place, @Nullable Consumer consumer) {
+ Vector vec = vector(player);
+
+ World world = player.getLocation().getWorld();
+ if(world == null) {
+ throw new RuntimeException("Unable to get world: " + spawnWorld);
+ }
+
+ consumer.accept(vec);
+
+ player.sendMessage(messagePrefix + message(place.message()));
+ addToConfig(place.path("x"), vec.getX());
+ addToConfig(place.path("y"), vec.getY());
+ addToConfig(place.path("z"), vec.getZ());
+ addToConfig(place.path("world"), player.getLocation().getWorld().getName());
+ saveConfig();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java
new file mode 100644
index 0000000..137bc69
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java
@@ -0,0 +1,25 @@
+package net.tylermurphy.hideAndSeek.command.location.util;
+
+/**
+ * @author bobby29831
+ */
+public enum Locations {
+
+ GAME("spawns.game"),
+ LOBBY("spawns.lobby"),
+ EXIT("spawns.exit");
+
+ private final String path;
+ Locations(String path) {
+ this.path = path;
+ }
+
+ public String message() {
+ return this + "_SPAWN";
+ }
+
+ public String path(String additive) {
+ return path + "." + additive;
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
index c021fce..4aeac68 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/Config.java
@@ -21,13 +21,16 @@ package net.tylermurphy.hideAndSeek.configuration;
import com.cryptomorin.xseries.XItemStack;
import com.cryptomorin.xseries.XMaterial;
-import net.tylermurphy.hideAndSeek.util.Version;
+import com.cryptomorin.xseries.XSound;
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.util.CountdownDisplay;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
+import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
@@ -36,36 +39,45 @@ import java.util.Optional;
public class Config {
- private static ConfigManager config, leaderboard;
-
+ private static ConfigManager config;
+
public static String
messagePrefix,
errorPrefix,
tauntPrefix,
- worldborderPrefix,
+ worldBorderPrefix,
abortPrefix,
- gameoverPrefix,
+ gameOverPrefix,
warningPrefix,
spawnWorld,
exitWorld,
lobbyWorld,
locale,
- leaveServer;
+ leaveServer,
+ placeholderError,
+ placeholderNoData,
+ databaseType,
+ databaseHost,
+ databasePort,
+ databaseUser,
+ databasePass,
+ databaseName;
public static Vector
spawnPosition,
lobbyPosition,
exitPosition,
- worldborderPosition;
+ worldBorderPosition;
- public static boolean
- nametagsVisible,
+ public static boolean
+ nameTagsVisible,
permissionsRequired,
announceMessagesToNonPlayers,
- worldborderEnabled,
+ worldBorderEnabled,
tauntEnabled,
tauntCountdown,
tauntLast,
+ alwaysGlow,
glowEnabled,
glowStackable,
pvpEnabled,
@@ -74,14 +86,17 @@ public class Config {
lobbyCountdownEnabled,
seekerPing,
bungeeLeave,
- lobbyItemStartAdmin;
+ lobbyItemStartAdmin,
+ leaveOnEnd,
+ mapSaveEnabled,
+ allowNaturalCauses;
public static int
minPlayers,
- worldborderSize,
- worldborderDelay,
+ worldBorderSize,
+ worldBorderDelay,
currentWorldborderSize,
- worldborderChange,
+ worldBorderChange,
gameLength,
saveMinX,
saveMinZ,
@@ -97,7 +112,14 @@ public class Config {
seekerPingLevel2,
seekerPingLevel3,
lobbyItemLeavePosition,
- lobbyItemStartPosition;
+ lobbyItemStartPosition,
+ flightToggleItemPosition,
+ teleportItemPosition;
+
+ public static float
+ seekerPingLeadingVolume,
+ seekerPingVolume,
+ seekerPingPitch;
public static List
blockedCommands,
@@ -123,18 +145,28 @@ public class Config {
public static ItemStack
lobbyLeaveItem,
- lobbyStartItem;
+ lobbyStartItem,
+ glowPowerupItem,
+ flightToggleItem,
+ teleportItem;
+
+ public static XSound
+ ringingSound,
+ heartbeatSound;
+
+ public static CountdownDisplay
+ countdownDisplay;
public static void loadConfig() {
- config = new ConfigManager("config.yml");
+ config = ConfigManager.create("config.yml");
config.saveConfig();
- leaderboard = new ConfigManager("leaderboard.yml");
+ ConfigManager leaderboard = ConfigManager.create("leaderboard.yml");
//Spawn
spawnPosition = new Vector(
config.getDouble("spawns.game.x"),
- Math.max(Version.atLeast("1.18") ? -64 : 0, Math.min(255, config.getDouble("spawns.game.y"))),
+ Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.game.y"))),
config.getDouble("spawns.game.z")
);
spawnWorld = config.getString("spawns.game.world");
@@ -142,7 +174,7 @@ public class Config {
///Lobby
lobbyPosition = new Vector(
config.getDouble("spawns.lobby.x"),
- Math.max(Version.atLeast("1.18") ? -64 : 0, Math.min(255, config.getDouble("spawns.lobby.y"))),
+ Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.lobby.y"))),
config.getDouble("spawns.lobby.z")
);
lobbyWorld = config.getString("spawns.lobby.world");
@@ -151,21 +183,21 @@ public class Config {
exitPosition = new Vector(
config.getDouble("spawns.exit.x"),
- Math.max(Version.atLeast("1.18") ? -64 : 0, Math.min(255, config.getDouble("spawns.exit.y"))),
+ Math.max(Main.getInstance().supports(18) ? -64 : 0, Math.min(255, config.getDouble("spawns.exit.y"))),
config.getDouble("spawns.exit.z")
);
exitWorld = config.getString("spawns.exit.world");
//World border
- worldborderPosition = new Vector(
+ worldBorderPosition = new Vector(
config.getInt("worldBorder.x"),
0,
config.getInt("worldBorder.z")
);
- worldborderSize = Math.max(100, config.getInt("worldBorder.size"));
- worldborderDelay = Math.max(1, config.getInt("worldBorder.delay"));
- worldborderEnabled = config.getBoolean("worldBorder.enabled");
- worldborderChange = config.getInt("worldBorder.moveAmount");
+ worldBorderSize = Math.max(100, config.getInt("worldBorder.size"));
+ worldBorderDelay = Math.max(1, config.getInt("worldBorder.delay"));
+ worldBorderEnabled = config.getBoolean("worldBorder.enabled");
+ worldBorderChange = config.getInt("worldBorder.moveAmount");
//Prefix
char SYMBOLE = '\u00A7';
@@ -174,9 +206,9 @@ public class Config {
messagePrefix = config.getString("prefix.default").replace("&", SYMBOLE_STRING);
errorPrefix = config.getString("prefix.error").replace("&", SYMBOLE_STRING);
tauntPrefix = config.getString("prefix.taunt").replace("&", SYMBOLE_STRING);
- worldborderPrefix = config.getString("prefix.border").replace("&", SYMBOLE_STRING);
+ worldBorderPrefix = config.getString("prefix.border").replace("&", SYMBOLE_STRING);
abortPrefix = config.getString("prefix.abort").replace("&", SYMBOLE_STRING);
- gameoverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING);
+ gameOverPrefix = config.getString("prefix.gameover").replace("&", SYMBOLE_STRING);
warningPrefix = config.getString("prefix.warning").replace("&", SYMBOLE_STRING);
//Map Bounds
@@ -184,6 +216,7 @@ public class Config {
saveMinZ = config.getInt("bounds.min.z");
saveMaxX = config.getInt("bounds.max.x");
saveMaxZ = config.getInt("bounds.max.z");
+ mapSaveEnabled = config.getBoolean("mapSaveEnabled");
//Taunt
tauntEnabled = config.getBoolean("taunt.enabled");
@@ -192,9 +225,13 @@ public class Config {
tauntLast = config.getBoolean("taunt.whenLastPerson");
//Glow
+ alwaysGlow = config.getBoolean("alwaysGlow") && Main.getInstance().supports(9);
glowLength = Math.max(1, config.getInt("glow.time"));
glowStackable = config.getBoolean("glow.stackable");
- glowEnabled = config.getBoolean("glow.enabled") && Version.atLeast("1.9");
+ glowEnabled = config.getBoolean("glow.enabled") && Main.getInstance().supports(9) && !alwaysGlow;
+ if (glowEnabled) {
+ glowPowerupItem = createItemStack("glow");
+ }
//Lobby
minPlayers = Math.max(2, config.getInt("minPlayers"));
@@ -209,23 +246,40 @@ public class Config {
seekerPingLevel1 = config.getInt("seekerPing.distances.level1");
seekerPingLevel2 = config.getInt("seekerPing.distances.level2");
seekerPingLevel3 = config.getInt("seekerPing.distances.level3");
+ seekerPingLeadingVolume = config.getFloat("seekerPing.sounds.leadingVolume");
+ seekerPingVolume = config.getFloat("seekerPing.sounds.volume");
+ seekerPingPitch = config.getFloat("seekerPing.sounds.pitch");
+ Optional heartbeatOptional = XSound.matchXSound(config.getString("seekerPing.sounds.heartbeatNoise"));
+ heartbeatSound = heartbeatOptional.orElse(XSound.BLOCK_NOTE_BLOCK_BASEDRUM);
+ Optional ringingOptional = XSound.matchXSound(config.getString("seekerPing.sounds.ringingNoise"));
+ ringingSound = ringingOptional.orElse(XSound.BLOCK_NOTE_BLOCK_PLING);
//Other
- nametagsVisible = config.getBoolean("nametagsVisible");
+ nameTagsVisible = config.getBoolean("nametagsVisible");
permissionsRequired = config.getBoolean("permissionsRequired");
gameLength = config.getInt("gameLength");
pvpEnabled = config.getBoolean("pvp");
+ allowNaturalCauses = config.getBoolean("allowNaturalCauses");
autoJoin = config.getBoolean("autoJoin");
teleportToExit = config.getBoolean("teleportToExit");
locale = config.getString("locale", "local");
blockedCommands = config.getStringList("blockedCommands");
+ leaveOnEnd = config.getBoolean("leaveOnEnd");
+ placeholderError = config.getString("placeholder.incorrect");
+ placeholderNoData = config.getString("placeholder.noData");
+ try {
+ countdownDisplay = CountdownDisplay.valueOf(config.getString("hideCountdownDisplay"));
+ } catch (IllegalArgumentException e) {
+ countdownDisplay = CountdownDisplay.CHAT;
+ Main.getInstance().getLogger().warning("hideCountdownDisplay: "+config.getString("hideCountdownDisplay")+" is not a valid configuration option!");
+ }
blockedInteracts = new ArrayList<>();
List tempInteracts = config.getStringList("blockedInteracts");
- for(String id : tempInteracts){
+ for(String id : tempInteracts) {
Optional optional_mat = XMaterial.matchXMaterial(id);
- if(optional_mat.isPresent()){
+ if (optional_mat.isPresent()) {
Material mat = optional_mat.get().parseMaterial();
- if(mat != null){
+ if (mat != null) {
blockedInteracts.add(mat.name());
}
}
@@ -252,29 +306,35 @@ public class Config {
BORDER_DECREASING = leaderboard.getString("border.decreasing");
//Lobby Items
- if(config.getBoolean("lobbyItems.leave.enabled")) {
- ConfigurationSection item = new YamlConfiguration().createSection("temp");
- item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.leave.name")));
- item.set("material", config.getString("lobbyItems.leave.material"));
- List lore = config.getStringList("lobbyItems.leave.lore");
- if (lore != null && !lore.isEmpty()) item.set("lore", lore);
- ItemStack temp = null;
- try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){}
- lobbyLeaveItem = temp;
+ if (config.getBoolean("lobbyItems.leave.enabled")) {
+ lobbyLeaveItem = createItemStack("lobbyItems.leave");
lobbyItemLeavePosition = config.getInt("lobbyItems.leave.position");
}
- if(config.getBoolean("lobbyItems.start.enabled")) {
- ConfigurationSection item = new YamlConfiguration().createSection("temp");
- item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString("lobbyItems.start.name")));
- item.set("material", config.getString("lobbyItems.start.material"));
- List lore = config.getStringList("lobbyItems.start.lore");
- if (lore != null && !lore.isEmpty()) item.set("lore", lore);
- ItemStack temp = null;
- try{ temp = XItemStack.deserialize(item); } catch(Exception ignored){}
- lobbyStartItem = temp;
+ if (config.getBoolean("lobbyItems.start.enabled")) {
+ lobbyStartItem = createItemStack("lobbyItems.start");
lobbyItemStartAdmin = config.getBoolean("lobbyItems.start.adminOnly");
lobbyItemStartPosition = config.getInt("lobbyItems.start.position");
}
+
+ //Spectator Items
+ flightToggleItem = createItemStack("spectatorItems.flight");
+ flightToggleItemPosition = config.getInt("spectatorItems.flight.position");
+
+ teleportItem = createItemStack("spectatorItems.teleport");
+ teleportItemPosition = config.getInt("spectatorItems.teleport.position");
+
+ //Database
+ databaseHost = config.getString("databaseHost");
+ databasePort = config.getString("databasePort");
+ databaseUser = config.getString("databaseUser");
+ databasePass = config.getString("databasePass");
+ databaseName = config.getString("databaseName");
+
+ databaseType = config.getString("databaseType").toUpperCase();
+ if(!databaseType.equals("SQLITE") && !databaseType.equals("MYSQL")){
+ Main.getInstance().getLogger().warning("databaseType: "+databaseType+" is not a valid configuration option!");
+ databaseType = "SQLITE";
+ }
}
public static void addToConfig(String path, Object value) {
@@ -284,5 +344,22 @@ public class Config {
public static void saveConfig() {
config.saveConfig();
}
+
+ @Nullable
+ private static ItemStack createItemStack(String path){
+ ConfigurationSection item = new YamlConfiguration().createSection("temp");
+ item.set("name", ChatColor.translateAlternateColorCodes('&',config.getString(path+".name")));
+ item.set("material", config.getString(path+".material"));
+ if (Main.getInstance().supports(14)) {
+ if (config.contains(path+".model-data") && config.getInt(path+".model-data") != 0) {
+ item.set("model-data", config.getInt(path+".model-data"));
+ }
+ }
+ List lore = config.getStringList(path+".lore");
+ if (lore != null && !lore.isEmpty()) item.set("lore", lore);
+ ItemStack temp = null;
+ try{ temp = XItemStack.deserialize(item); } catch(Exception ignored) {}
+ return temp;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
index 1684896..5e28258 100644
--- a/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
+++ b/src/main/java/net/tylermurphy/hideAndSeek/configuration/ConfigManager.java
@@ -21,6 +21,7 @@ package net.tylermurphy.hideAndSeek.configuration;
import net.tylermurphy.hideAndSeek.Main;
import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*;
@@ -35,111 +36,136 @@ public class ConfigManager {
private YamlConfiguration config,defaultConfig;
private String defaultFilename;
- public ConfigManager(String filename){
- this.file = new File(Main.data, filename);
- this.defaultFilename = file.getName();
+ public static ConfigManager create(String filename) {
+ return new ConfigManager(filename, filename);
+ }
- File folder = Main.data;
- if(!folder.exists()){
- if(!folder.mkdirs()){
+ public static ConfigManager create(String filename, String defaultFilename) {
+ return new ConfigManager(filename, defaultFilename);
+ }
+
+ private ConfigManager(String filename, String defaultFilename) {
+
+ File dataFolder = Main.getInstance().getDataFolder();
+ File oldDataFolder = new File(Main.getInstance().getDataFolder().getParent() + File.separator + "HideAndSeek");
+
+ this.defaultFilename = defaultFilename;
+ this.file = new File(dataFolder, filename);
+
+ if(oldDataFolder.exists()){
+ if(!dataFolder.exists()){
+ if(!oldDataFolder.renameTo(dataFolder)){
+ throw new RuntimeException("Could not rename folder: " + oldDataFolder.getPath());
+ }
+ } else {
+ throw new RuntimeException("Plugin folders for HideAndSeek & KenshinsHideAndSeek both exists. There can only be one!");
+ }
+
+ }
+
+ if (!dataFolder.exists()) {
+ if (!dataFolder.mkdirs()) {
throw new RuntimeException("Failed to make directory: " + file.getPath());
}
}
- if(!file.exists()){
- saveDefaultConfiguration();
+ if (!file.exists()) {
+ try{
+ InputStream input = Main.getInstance().getResource(defaultFilename);
+ if (input == null) {
+ throw new RuntimeException("Could not create input stream for "+defaultFilename);
+ }
+ java.nio.file.Files.copy(input, file.toPath());
+ input.close();
+ } catch(IOException e) {
+ e.printStackTrace();
+ }
}
- this.config = YamlConfiguration.loadConfiguration(file);
-
- InputStream input = Main.plugin.getResource(file.getName());
- if(input == null){
+ FileInputStream fileInputStream;
+ try {
+ fileInputStream = new FileInputStream(file);
+ } catch (FileNotFoundException e) {
throw new RuntimeException("Could not create input stream for "+file.getPath());
}
- InputStreamReader reader = new InputStreamReader(input);
- this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
- try{
- input.close();
- reader.close();
- } catch (IOException ignored){}
- }
-
- public ConfigManager(String filename, String defaultFilename){
-
- this.defaultFilename = defaultFilename;
- this.file = new File(Main.data, filename);
-
- if(!file.exists()){
- saveDefaultConfiguration();
+ InputStreamReader reader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
+ this.config = new YamlConfiguration();
+ try {
+ this.config.load(reader);
+ } catch(InvalidConfigurationException e) {
+ throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
+ } catch(IOException e) {
+ throw new RuntimeException("Could not access file: "+file.getPath());
}
- this.config = YamlConfiguration.loadConfiguration(file);
-
- InputStream input = Main.plugin.getResource(defaultFilename);
- if(input == null){
+ InputStream input = this.getClass().getClassLoader().getResourceAsStream(defaultFilename);
+ if (input == null) {
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
- InputStreamReader reader = new InputStreamReader(input);
- this.defaultConfig = YamlConfiguration.loadConfiguration(reader);
+ InputStreamReader default_reader = new InputStreamReader(input, StandardCharsets.UTF_8);
+ this.defaultConfig = new YamlConfiguration();
+ try {
+ this.defaultConfig.load(default_reader);
+ } catch(InvalidConfigurationException e) {
+ throw new RuntimeException("Invalid configuration in config file: "+file.getPath());
+ } catch(IOException e) {
+ throw new RuntimeException("Could not access file: "+file.getPath());
+ }
+
try{
- input.close();
- reader.close();
- } catch (IOException e){
- Main.plugin.getLogger().severe("Couldn't find "+defaultFilename+" internally. Did you set an incorrect local?");
- Main.plugin.getServer().getPluginManager().disablePlugin(Main.plugin);
- throw new RuntimeException();
+ fileInputStream.close();
+ default_reader.close();
+ } catch (IOException e) {
+ throw new RuntimeException("Unable to finalize loading of config files.");
}
}
- private void saveDefaultConfiguration(){
- try{
- InputStream input = Main.plugin.getResource(defaultFilename);
- if(input == null){
- throw new RuntimeException("Could not create input stream for "+defaultFilename);
- }
- java.nio.file.Files.copy(input, file.toPath());
- input.close();
- } catch(IOException e){
- e.printStackTrace();
- }
+ public boolean contains(String path) {
+ return config.contains(path);
}
- public double getDouble(String path){
- double value = config.getDouble(path);
- if(value == 0.0D){
+ public double getDouble(String path) {
+ if (!config.contains(path)) {
return defaultConfig.getDouble(path);
} else {
- return value;
+ return config.getDouble(path);
}
}
- public int getInt(String path){
- int value = config.getInt(path);
- if(value == 0){
+ public int getInt(String path) {
+ if (!config.contains(path)) {
return defaultConfig.getInt(path);
} else {
- return value;
+ return config.getInt(path);
}
}
- public int getDefaultInt(String path){
+ public int getDefaultInt(String path) {
return defaultConfig.getInt(path);
}
- public String getString(String path){
+ public float getFloat(String path) {
+ if (!config.contains(path)) {
+ return (float) defaultConfig.getDouble(path);
+ } else {
+ return (float) config.getDouble(path);
+ }
+ }
+
+ public String getString(String path) {
String value = config.getString(path);
- if(value == null){
+ if (value == null) {
return defaultConfig.getString(path);
} else {
return value;
}
}
- public String getString(String path, String oldPath){
+ public String getString(String path, String oldPath) {
String value = config.getString(path);
- if(value == null){
+ if (value == null) {
String oldValue = config.getString(oldPath);
- if(oldValue == null){
+ if (oldValue == null) {
return defaultConfig.getString(path);
} else {
return oldValue;
@@ -149,24 +175,24 @@ public class ConfigManager {
}
}
- public List getStringList(String path){
+ public List getStringList(String path) {
List value = config.getStringList(path);
- if(value == null){
+ if (value == null) {
return defaultConfig.getStringList(path);
} else {
return value;
}
}
- public void reset(String path){
+ public void reset(String path) {
config.set(path, defaultConfig.get(path));
}
- public void resetFile(String newDefaultFilename){
+ public void resetFile(String newDefaultFilename) {
this.defaultFilename = newDefaultFilename;
- InputStream input = Main.plugin.getResource(defaultFilename);
- if(input == null){
+ InputStream input = Main.getInstance().getResource(defaultFilename);
+ if (input == null) {
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
InputStreamReader reader = new InputStreamReader(input);
@@ -175,85 +201,94 @@ public class ConfigManager {
}
- public boolean getBoolean(String path){
- boolean value = config.getBoolean(path);
- if(!value){
+ public boolean getBoolean(String path) {
+ if (!config.contains(path)) {
return defaultConfig.getBoolean(path);
} else {
- return true;
+ return config.getBoolean(path);
}
}
- public ConfigurationSection getConfigurationSection(String path){
+ public ConfigurationSection getConfigurationSection(String path) {
ConfigurationSection section = config.getConfigurationSection(path);
- if(section == null){
+ if (section == null) {
return defaultConfig.getConfigurationSection(path);
} else {
return section;
}
}
- public void set(String path, Object value){
+ public ConfigurationSection getDefaultConfigurationSection(String path) {
+ return defaultConfig.getConfigurationSection(path);
+ }
+
+ public void set(String path, Object value) {
config.set(path, value);
}
- public void saveConfig(){
+ public void saveConfig() {
try {
- InputStream is = Main.plugin.getResource(defaultFilename);
- if(is == null){
+ InputStream is = Main.getInstance().getResource(defaultFilename);
+ if (is == null) {
throw new RuntimeException("Could not create input stream for "+defaultFilename);
}
- StringBuilder textBuilder = new StringBuilder();
+ StringBuilder textBuilder = new StringBuilder(new String("".getBytes(), StandardCharsets.UTF_8));
Reader reader = new BufferedReader(new InputStreamReader(is, Charset.forName(StandardCharsets.UTF_8.name())));
int c;
- while((c = reader.read()) != -1){
+ while((c = reader.read()) != -1) {
textBuilder.append((char) c);
}
- String yamlString = textBuilder.toString();
+ String yamlString = new String(textBuilder.toString().getBytes(), StandardCharsets.UTF_8);
Map temp = config.getValues(true);
- for(Map.Entry entry: temp.entrySet()){
- if(entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List){
+ for(Map.Entry entry: temp.entrySet()) {
+ if (entry.getValue() instanceof Integer || entry.getValue() instanceof Double || entry.getValue() instanceof String || entry.getValue() instanceof Boolean || entry.getValue() instanceof List) {
String[] parts = entry.getKey().split("\\.");
int index = 0;
int i = 0;
for(String part : parts) {
- if(i == 0) {
+ if (i == 0) {
index = yamlString.indexOf(part+":", index);
} else {
index = yamlString.indexOf(" " + part+":", index);
index++;
}
i++;
- if(index == -1) break;
+ if (index == -1) break;
}
- if(index < 10) continue;
+ if (index < 10) continue;
int start = yamlString.indexOf(' ', index);
int end = yamlString.indexOf('\n', index);
- if(end == -1) end = yamlString.length();
- String replace;
- if(entry.getValue() instanceof List){
- if(((List>) entry.getValue()).isEmpty()) continue;
- replace = "[";
- for(Object o : (List