summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/command
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2022-06-01 20:03:01 -0400
committerGitHub <noreply@github.com>2022-06-01 20:03:01 -0400
commitc506030cbabe938f0afccbf3489ab72e7463e1e7 (patch)
tree0cafe99d4b314c761d2621457c4a4a824e53350e /src/main/java/net/tylermurphy/hideAndSeek/command
parentmove code of conduct and contributing guidelines (diff)
parentUpdate CONTRIBUTING.md (diff)
downloadkenshinshideandseek-c506030cbabe938f0afccbf3489ab72e7463e1e7.tar.gz
kenshinshideandseek-c506030cbabe938f0afccbf3489ab72e7463e1e7.tar.bz2
kenshinshideandseek-c506030cbabe938f0afccbf3489ab72e7463e1e7.zip
Merge pull request #68 from tylermurphy534/1.5.0
1.5.0
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/About.java6
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Debug.java112
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Help.java7
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/ICommand.java4
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Join.java19
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Leave.java21
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Reload.java19
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/SaveMap.java28
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/SetBorder.java58
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/SetBounds.java30
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/SetExitLocation.java75
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/SetLobbyLocation.java75
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/SetSpawnLocation.java85
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Setup.java31
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Start.java42
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Stop.java25
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Top.java33
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Wins.java43
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/SetExitLocation.java49
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/SetLobbyLocation.java50
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/SetSpawnLocation.java62
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/util/LocationUtils.java59
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/location/util/Locations.java25
23 files changed, 529 insertions, 429 deletions
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<Integer, Consumer<Player>> 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<Player> 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<Player> 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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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 <http://www.gnu.org/licenses/>.
- *
- */
-
-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 net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.game.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 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<Player> 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<Player> 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<PlayerInfo> infos = Database.playerInfo.getInfoPage(page);
+ List<PlayerInfo> 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+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<Vector> 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