diff options
Diffstat (limited to 'src/main/java/cat/freya/khs/command/world')
4 files changed, 257 insertions, 0 deletions
diff --git a/src/main/java/cat/freya/khs/command/world/Create.java b/src/main/java/cat/freya/khs/command/world/Create.java new file mode 100644 index 0000000..8b429b3 --- /dev/null +++ b/src/main/java/cat/freya/khs/command/world/Create.java @@ -0,0 +1,80 @@ +package cat.freya.khs.command.world; + +import cat.freya.khs.Main; +import cat.freya.khs.configuration.Config; +import cat.freya.khs.configuration.Localization; +import cat.freya.khs.util.Location; +import cat.freya.khs.command.util.ICommand; +import org.bukkit.World; +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; + +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(Config.errorPrefix + Localization.message("WORLD_EXISTS").addAmount(args[0])); + return; + } + WorldType type; + World.Environment environment; + switch (args[1]) { + case "normal": + type = WorldType.NORMAL; + environment = World.Environment.NORMAL; + break; + case "flat": + type = WorldType.FLAT; + environment = World.Environment.NORMAL; + break; + case "nether": + type = WorldType.NORMAL; + environment = World.Environment.NETHER; + break; + case "end": + type = WorldType.NORMAL; + environment = World.Environment.THE_END; + break; + default: + sender.sendMessage(Config.errorPrefix + Localization.message("INVALID_WORLD_TYPE").addAmount(args[1])); + return; + } + + Location temp = new Location(args[0], 0, 0, 0); + + if (temp.load(type, environment) == null) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLD_ADDED_FAILED")); + } else { + sender.sendMessage(Config.messagePrefix + Localization.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", "nether", "end"); + } + return null; + } +}
\ No newline at end of file diff --git a/src/main/java/cat/freya/khs/command/world/Delete.java b/src/main/java/cat/freya/khs/command/world/Delete.java new file mode 100644 index 0000000..629eef4 --- /dev/null +++ b/src/main/java/cat/freya/khs/command/world/Delete.java @@ -0,0 +1,74 @@ +package cat.freya.khs.command.world; + +import cat.freya.khs.Main; +import cat.freya.khs.command.Confirm; +import cat.freya.khs.command.util.ICommand; +import cat.freya.khs.configuration.Config; +import cat.freya.khs.configuration.Localization; +import cat.freya.khs.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; + +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(Config.errorPrefix + Localization.message("WORLD_DOESNT_EXIST").addAmount(args[0])); + return; + } + + 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(Config.errorPrefix + Localization.message("WORLD_DOESNT_EXIST").addAmount(world)); + return; + } + World bukkit_world = Bukkit.getWorld(world); + if(bukkit_world != null && bukkit_world.getPlayers().size() > 0) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLD_NOT_EMPTY")); + return; + } + String path = Main.getInstance().getWorldContainer().getPath() + File.separator + world; + if (!Bukkit.getServer().unloadWorld(world, false)) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLD_REMOVED_FAILED")); + return; + } + try { + WorldLoader.deleteDirectory(new File(path)); + } catch (Exception e) { + sender.sendMessage(Config.errorPrefix + Localization.message("WORLD_REMOVED_FAILED")); + return; + } + sender.sendMessage(Config.messagePrefix + Localization.message("WORLD_REMOVED").addAmount(world)); + }); + + Confirm.confirmations.put(sender.getUniqueId(), confirmation); + sender.sendMessage(Config.messagePrefix + Localization.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/cat/freya/khs/command/world/List.java b/src/main/java/cat/freya/khs/command/world/List.java new file mode 100644 index 0000000..a65930e --- /dev/null +++ b/src/main/java/cat/freya/khs/command/world/List.java @@ -0,0 +1,55 @@ +package cat.freya.khs.command.world; + +import cat.freya.khs.Main; +import cat.freya.khs.configuration.Config; +import cat.freya.khs.configuration.Localization; +import cat.freya.khs.command.util.ICommand; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +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(Config.errorPrefix + Localization.message("NO_WORLDS")); + } else { + StringBuilder response = new StringBuilder(Config.messagePrefix + Localization.message("LIST_WORLDS")); + for (String world : worlds) { + String status = ChatColor.GRAY + "NOT LOADED"; + World bukkit_world = Bukkit.getWorld(world); + if(bukkit_world != null) { + if(bukkit_world.getEnvironment() == World.Environment.NETHER) { + status = ChatColor.RED + "NETHER"; + } else if(bukkit_world.getEnvironment() == World.Environment.THE_END) { + status = ChatColor.YELLOW + "THE END"; + } else { + status = ChatColor.GREEN + bukkit_world.getWorldType().toString(); + } + } + response.append("\n ").append(world).append(": ").append(status).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/cat/freya/khs/command/world/Tp.java b/src/main/java/cat/freya/khs/command/world/Tp.java new file mode 100644 index 0000000..ff6190a --- /dev/null +++ b/src/main/java/cat/freya/khs/command/world/Tp.java @@ -0,0 +1,48 @@ +package cat.freya.khs.command.world; + +import cat.freya.khs.Main; +import cat.freya.khs.command.util.ICommand; +import cat.freya.khs.configuration.Config; +import cat.freya.khs.configuration.Localization; +import cat.freya.khs.util.Location; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +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(Config.errorPrefix + Localization.message("WORLD_DOESNT_EXIT")); + return; + } + World world = test.load(); + if(world == null) { + sender.sendMessage(Config.errorPrefix + Localization.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; + } +} |