From 856215ab979829de6657945df67f0308505d414f Mon Sep 17 00:00:00 2001 From: OmerBenGera Date: Mon, 14 Sep 2020 18:44:27 +0300 Subject: [PATCH] Added list command to the loaders --- .../com/bgsoftware/wildloaders/Locale.java | 7 ++ .../wildloaders/command/CommandsHandler.java | 2 + .../wildloaders/command/commands/CmdList.java | 74 +++++++++++++++++++ src/main/resources/lang.yml | 5 ++ src/main/resources/plugin.yml | 5 +- 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/bgsoftware/wildloaders/command/commands/CmdList.java diff --git a/src/main/java/com/bgsoftware/wildloaders/Locale.java b/src/main/java/com/bgsoftware/wildloaders/Locale.java index 2bab5f7..b3cd344 100644 --- a/src/main/java/com/bgsoftware/wildloaders/Locale.java +++ b/src/main/java/com/bgsoftware/wildloaders/Locale.java @@ -24,6 +24,9 @@ public final class Locale { public static Locale INVALID_AMOUNT = new Locale("INVALID_AMOUNT"); public static Locale INVALID_LOADER = new Locale("INVALID_LOADER"); public static Locale INVALID_PLAYER = new Locale("INVALID_PLAYER"); + public static Locale LIST_LOADERS_HEADER = new Locale("LIST_LOADERS_HEADER"); + public static Locale LIST_LOADERS_LINE = new Locale("LIST_LOADERS_LINE"); + public static Locale LIST_LOADERS_FOOTER = new Locale("LIST_LOADERS_FOOTER"); public static Locale NO_PERMISSION = new Locale("NO_PERMISSION"); public static Locale NO_PLACE_PERMISSION = new Locale("NO_PLACE_PERMISSION"); public static Locale PLACED_LOADER = new Locale("PLACED_LOADER"); @@ -48,6 +51,10 @@ public final class Locale { return null; } + public boolean isEmpty(){ + return message == null || message.equals(""); + } + public void send(CommandSender sender, Object... objects){ String message = getMessage(objects); if(message != null && sender != null) diff --git a/src/main/java/com/bgsoftware/wildloaders/command/CommandsHandler.java b/src/main/java/com/bgsoftware/wildloaders/command/CommandsHandler.java index b3919a0..4cd611c 100644 --- a/src/main/java/com/bgsoftware/wildloaders/command/CommandsHandler.java +++ b/src/main/java/com/bgsoftware/wildloaders/command/CommandsHandler.java @@ -3,6 +3,7 @@ package com.bgsoftware.wildloaders.command; import com.bgsoftware.wildloaders.Locale; import com.bgsoftware.wildloaders.WildLoadersPlugin; import com.bgsoftware.wildloaders.command.commands.CmdGive; +import com.bgsoftware.wildloaders.command.commands.CmdList; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; @@ -18,6 +19,7 @@ public final class CommandsHandler implements CommandExecutor, TabCompleter { public CommandsHandler(WildLoadersPlugin plugin){ this.plugin = plugin; subCommands.add(new CmdGive()); + subCommands.add(new CmdList()); } @Override diff --git a/src/main/java/com/bgsoftware/wildloaders/command/commands/CmdList.java b/src/main/java/com/bgsoftware/wildloaders/command/commands/CmdList.java new file mode 100644 index 0000000..ea0772d --- /dev/null +++ b/src/main/java/com/bgsoftware/wildloaders/command/commands/CmdList.java @@ -0,0 +1,74 @@ +package com.bgsoftware.wildloaders.command.commands; + +import com.bgsoftware.wildloaders.Locale; +import com.bgsoftware.wildloaders.WildLoadersPlugin; +import com.bgsoftware.wildloaders.api.loaders.LoaderData; +import com.bgsoftware.wildloaders.command.ICommand; +import org.bukkit.command.CommandSender; + +import java.util.ArrayList; +import java.util.List; + +public final class CmdList implements ICommand { + + @Override + public String getLabel() { + return "list"; + } + + @Override + public String getUsage() { + return "loader list"; + } + + @Override + public String getPermission() { + return "wildloaders.list"; + } + + @Override + public String getDescription() { + return "Show all the available chunk loaders on the server."; + } + + @Override + public int getMinArgs() { + return 1; + } + + @Override + public int getMaxArgs() { + return 1; + } + + @Override + public void perform(WildLoadersPlugin plugin, CommandSender sender, String[] args) { + StringBuilder message = new StringBuilder(); + + if(!Locale.LIST_LOADERS_HEADER.isEmpty()) + message.append(Locale.LIST_LOADERS_HEADER.getMessage()).append("\n"); + + if(!Locale.LIST_LOADERS_LINE.isEmpty()) { + for (LoaderData loaderData : plugin.getLoaders().getLoaderDatas()) { + message.append(Locale.LIST_LOADERS_LINE.getMessage(loaderData.getName(), loaderData.getTimeLeft())).append("\n"); + } + } + + String parsedMessage; + + if(!Locale.LIST_LOADERS_FOOTER.isEmpty()) { + message.append(Locale.LIST_LOADERS_FOOTER.getMessage()); + parsedMessage = message.toString(); + } + else{ + parsedMessage = message.substring(0, message.length() - 1); + } + + sender.sendMessage(parsedMessage); + } + + @Override + public List tabComplete(WildLoadersPlugin plugin, CommandSender sender, String[] args) { + return new ArrayList<>(); + } +} diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index a33a7a3..80da34e 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -15,6 +15,11 @@ HELP_COMMAND_FOOTER: '' INVALID_AMOUNT: '&a&lWildLoaders &7Invalid amount {0}.' INVALID_LOADER: '&a&lWildLoaders &7Couldn''t find a valid chunk-loader with the name {0}.' INVALID_PLAYER: '&a&lWildLoaders &7Couldn''t find a player with the name {0}.' +LIST_LOADERS_HEADER: '&a&lWildLoaders &7Available loaders:' +LIST_LOADERS_LINE: | + &a {0}: + &7 - &aDefault Time Left&7: &f{1} +LIST_LOADERS_FOOTER: '' NO_PERMISSION: '&fUnknown command. Type "/help" for help.' NO_PLACE_PERMISSION: '&a&lWildLoaders &7You are lacking the permission to place chunk loaders.' PLACED_LOADER: '&a&lWildLoaders &7Successfully placed a new chunk-loader at {0}.' diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 9ddb128..7ce08b1 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -15,7 +15,10 @@ permissions: children: wildloaders.use: true wildloaders.give: true + wildloaders.list: true wildloaders.use: description: Gives access to place a chunkloader. wildloaders.give: - description: Gives access to give chunkloaders to other players. \ No newline at end of file + description: Gives access to give chunkloaders to other players. + wildloaders.list: + description: Gives access to see all the available chunk loaders. \ No newline at end of file