summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/command
diff options
context:
space:
mode:
authorTyler Murphy <tylermurphy534@gmail.com>2022-11-21 13:33:55 -0500
committerTyler Murphy <tylermurphy534@gmail.com>2022-11-21 13:33:55 -0500
commit1815b63bc94382a36b610be8082a423364e51b21 (patch)
tree574ebf7d505b6f1b438765aff6e743c5e972d661 /src/main/java/net/tylermurphy/hideAndSeek/command
parent1.7.0 beta 5 (diff)
downloadkenshinshideandseek-1815b63bc94382a36b610be8082a423364e51b21.tar.gz
kenshinshideandseek-1815b63bc94382a36b610be8082a423364e51b21.tar.bz2
kenshinshideandseek-1815b63bc94382a36b610be8082a423364e51b21.zip
1.7.0 beta 6
Diffstat (limited to 'src/main/java/net/tylermurphy/hideAndSeek/command')
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java62
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java66
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java74
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java46
-rw-r--r--src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java49
5 files changed, 297 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java b/src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java
new file mode 100644
index 0000000..a25185d
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/Confirm.java
@@ -0,0 +1,62 @@
+package net.tylermurphy.hideAndSeek.command;
+
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.*;
+import java.util.function.Consumer;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
+public class Confirm implements ICommand {
+
+ public static final Map<UUID, Confirmation> confirmations = new HashMap<>();
+
+ public void execute(Player sender, String[] args) {
+ Confirmation confirmation = confirmations.get(sender.getUniqueId());
+ confirmations.remove(sender.getUniqueId());
+ if(confirmation == null) {
+ sender.sendMessage(errorPrefix + message("NO_CONFIRMATION"));
+ } else {
+ long now = System.currentTimeMillis();
+ float secs = (now - confirmation.start) / 1000F;
+ if(secs > 10) {
+ sender.sendMessage(errorPrefix + message("CONFIRMATION_TIMED_OUT"));
+ return;
+ }
+ confirmation.callback.accept(confirmation.data);
+ }
+ }
+
+ public String getLabel() {
+ return "confirm";
+ }
+
+ public String getUsage() {
+ return "";
+ }
+
+ public String getDescription() {
+ return "Confirm another command if required";
+ }
+
+ public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
+ return null;
+ }
+
+ public static class Confirmation {
+ public final Consumer<String> callback;
+ public final String data;
+ public final long start;
+
+ public Confirmation(String data, Consumer<String> callback) {
+ this.callback = callback;
+ this.data = data;
+ this.start = System.currentTimeMillis();
+ }
+
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java
new file mode 100644
index 0000000..5ab9039
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Create.java
@@ -0,0 +1,66 @@
+package net.tylermurphy.hideAndSeek.command.world;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.util.Location;
+import org.bukkit.WorldType;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+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 Create implements ICommand {
+
+ public void execute(Player sender, String[] args) {
+ List<String> worlds = Main.getInstance().getWorlds();
+ if(worlds.contains(args[0])) {
+ sender.sendMessage(errorPrefix + message("WORLD_EXISTS").addAmount(args[0]));
+ }
+ WorldType type;
+ if(args[1].equals("normal")) {
+ type = WorldType.NORMAL;
+ } else if(args[1].equals("flat")) {
+ type = WorldType.FLAT;
+ } else {
+ sender.sendMessage(errorPrefix + message("INVALID_WORLD_TYPE").addAmount(args[1]));
+ return;
+ }
+
+ Location temp = new Location(args[0], 0, 0, 0);
+
+ if (temp.load(type) == null) {
+ sender.sendMessage(errorPrefix + message("WORLD_ADDED_FAILED"));
+ } else {
+ sender.sendMessage(messagePrefix + message("WORLD_ADDED").addAmount(args[0]));
+ }
+
+ }
+
+ public String getLabel() {
+ return "create";
+ }
+
+ public String getUsage() {
+ return "<name> <type>";
+ }
+
+ public String getDescription() {
+ return "Create a new world";
+ }
+
+ public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
+ if(parameter.equals("name")) {
+ return Collections.singletonList("name");
+ }
+ if(parameter.equals("type")) {
+ return Arrays.asList("normal", "flat");
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java
new file mode 100644
index 0000000..4800e08
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Delete.java
@@ -0,0 +1,74 @@
+package net.tylermurphy.hideAndSeek.command.world;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.command.Confirm;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.world.WorldLoader;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.io.File;
+import java.util.List;
+
+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 Delete implements ICommand {
+
+ public void execute(Player sender, String[] args) {
+ java.util.List<String> worlds = Main.getInstance().getWorlds();
+ if(!worlds.contains(args[0])) {
+ sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(args[0]));
+ }
+
+ Confirm.Confirmation confirmation = new Confirm.Confirmation(args[0], world -> {
+ java.util.List<String> worlds_now = Main.getInstance().getWorlds();
+ if(!worlds_now.contains(world)) {
+ sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIST").addAmount(world));
+ }
+ World bukkit_world = Bukkit.getWorld(world);
+ if(bukkit_world != null && bukkit_world.getPlayers().size() > 0) {
+ sender.sendMessage(errorPrefix + message("WORLD_NOT_EMPTY"));
+ return;
+ }
+ String path = Main.getInstance().getWorldContainer().getPath() + File.separator + world;
+ if (!Bukkit.getServer().unloadWorld(world, false)) {
+ sender.sendMessage(errorPrefix + message("WORLD_REMOVED_FAILED"));
+ return;
+ }
+ try {
+ WorldLoader.deleteDirectory(new File(path));
+ } catch (Exception e) {
+ sender.sendMessage(errorPrefix + message("WORLD_REMOVED_FAILED"));
+ return;
+ }
+ sender.sendMessage(messagePrefix + message("WORLD_REMOVED").addAmount(world));
+ });
+
+ Confirm.confirmations.put(sender.getUniqueId(), confirmation);
+ sender.sendMessage(messagePrefix + message("CONFIRMATION"));
+
+ }
+
+ public String getLabel() {
+ return "delete";
+ }
+
+ public String getUsage() {
+ return "<name>";
+ }
+
+ public String getDescription() {
+ return "Delete a world";
+ }
+
+ public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
+ if(parameter.equals("name")) {
+ return Main.getInstance().getWorlds();
+ }
+ return null;
+ }
+} \ No newline at end of file
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java
new file mode 100644
index 0000000..2c0f745
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/List.java
@@ -0,0 +1,46 @@
+package net.tylermurphy.hideAndSeek.command.world;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+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 List implements ICommand {
+
+ public void execute(Player sender, String[] args) {
+ java.util.List<String> worlds = Main.getInstance().getWorlds();
+ if(worlds.isEmpty()) {
+ sender.sendMessage(errorPrefix + message("NO_WORLDS"));
+ } else {
+ StringBuilder response = new StringBuilder(messagePrefix + message("LIST_WORLDS"));
+ for (String world : worlds) {
+ boolean loaded = Bukkit.getWorld(world) != null;
+ response.append("\n ").append(world).append(": ").append(loaded ? ChatColor.GREEN + "LOADED" : ChatColor.YELLOW + "NOT LOADED").append(ChatColor.WHITE);
+ }
+ sender.sendMessage(response.toString());
+ }
+ }
+
+ public String getLabel() {
+ return "list";
+ }
+
+ public String getUsage() {
+ return "";
+ }
+
+ public String getDescription() {
+ return "List all worlds in the server";
+ }
+
+ public java.util.List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
+ return null;
+ }
+
+}
diff --git a/src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java
new file mode 100644
index 0000000..b166297
--- /dev/null
+++ b/src/main/java/net/tylermurphy/hideAndSeek/command/world/Tp.java
@@ -0,0 +1,49 @@
+package net.tylermurphy.hideAndSeek.command.world;
+
+import net.tylermurphy.hideAndSeek.Main;
+import net.tylermurphy.hideAndSeek.command.util.ICommand;
+import net.tylermurphy.hideAndSeek.util.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+import static net.tylermurphy.hideAndSeek.configuration.Config.errorPrefix;
+import static net.tylermurphy.hideAndSeek.configuration.Localization.message;
+
+public class Tp implements ICommand {
+ public void execute(Player sender, String[] args) {
+ Location test = new Location(args[0], 0, 0,0);
+ if(!test.exists()) {
+ sender.sendMessage(errorPrefix + message("WORLD_DOESNT_EXIT"));
+ return;
+ }
+ World world = test.load();
+ if(world == null) {
+ sender.sendMessage(errorPrefix + message("WORLD_LOAD_FAILED"));
+ return;
+ }
+ Location loc = new Location(world.getName(), world.getSpawnLocation());
+ loc.teleport(sender);
+ }
+
+ public String getLabel() {
+ return "tp";
+ }
+
+ public String getUsage() {
+ return "<world>";
+ }
+
+ public String getDescription() {
+ return "Teleport to another world";
+ }
+
+ public List<String> autoComplete(@NotNull String parameter, @NotNull String typed) {
+ if(parameter.equals("world")) {
+ return Main.getInstance().getWorlds();
+ }
+ return null;
+ }
+}