Added list command to the loaders

This commit is contained in:
OmerBenGera 2020-09-14 18:44:27 +03:00
parent 4e9be10fb4
commit 856215ab97
5 changed files with 92 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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<String> tabComplete(WildLoadersPlugin plugin, CommandSender sender, String[] args) {
return new ArrayList<>();
}
}

View File

@ -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}.'

View File

@ -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.
description: Gives access to give chunkloaders to other players.
wildloaders.list:
description: Gives access to see all the available chunk loaders.