mirror of
https://github.com/filoghost/ChestCommands.git
synced 2025-02-19 04:51:23 +01:00
Small refactoring
This commit is contained in:
parent
01a04d19ff
commit
98e768a1f9
@ -141,7 +141,7 @@ public class ChestCommands extends JavaPlugin {
|
||||
errorCollector.logToConsole();
|
||||
Bukkit.getScheduler().runTaskLater(this, () -> {
|
||||
Bukkit.getConsoleSender().sendMessage(
|
||||
ChatColor.RED + "[ChestCommands] Encountered " + errorCollector.getErrorsCount() + " on load. "
|
||||
ChestCommands.CHAT_PREFIX + ChatColor.RED + "Encountered " + errorCollector.getErrorsCount() + " error(s) on load. "
|
||||
+ "Check previous console logs or run \"/chestcommands errors\" to see them again.");
|
||||
}, 10L);
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import me.filoghost.chestcommands.command.framework.CommandFramework;
|
||||
import me.filoghost.chestcommands.command.framework.CommandValidate;
|
||||
import me.filoghost.chestcommands.menu.InternalIconMenu;
|
||||
import me.filoghost.chestcommands.menu.MenuManager;
|
||||
import me.filoghost.chestcommands.util.Utils;
|
||||
import me.filoghost.chestcommands.util.logging.ErrorCollector;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -50,7 +51,7 @@ public class CommandHandler extends CommandFramework {
|
||||
|
||||
|
||||
if (args[0].equalsIgnoreCase("help")) {
|
||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "help"), "You don't have permission.");
|
||||
checkCommandPermission(sender, "help");
|
||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + "Commands:");
|
||||
sender.sendMessage(ChatColor.WHITE + "/" + label + " reload" + ChatColor.GRAY + " - Reloads the plugin.");
|
||||
sender.sendMessage(ChatColor.WHITE + "/" + label + " errors" + ChatColor.GRAY + " - Displays the last load errors on the console.");
|
||||
@ -61,7 +62,7 @@ public class CommandHandler extends CommandFramework {
|
||||
|
||||
|
||||
if (args[0].equalsIgnoreCase("errors")) {
|
||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "errors"), "You don't have permission.");
|
||||
checkCommandPermission(sender, "errors");
|
||||
ErrorCollector errorCollector = ChestCommands.getLastLoadErrors();
|
||||
|
||||
if (errorCollector.hasErrors()) {
|
||||
@ -78,7 +79,7 @@ public class CommandHandler extends CommandFramework {
|
||||
|
||||
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "reload"), "You don't have permission.");
|
||||
checkCommandPermission(sender, "reload");
|
||||
|
||||
ChestCommands.closeAllMenus();
|
||||
|
||||
@ -98,14 +99,14 @@ public class CommandHandler extends CommandFramework {
|
||||
|
||||
|
||||
if (args[0].equalsIgnoreCase("open")) {
|
||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "open"), "You don't have permission.");
|
||||
checkCommandPermission(sender, "open");
|
||||
CommandValidate.minLength(args, 2, "Usage: /" + label + " open <menu> [player]");
|
||||
|
||||
Player target;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
if (args.length > 2) {
|
||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "open.others"), "You don't have permission to open menus for others.");
|
||||
checkCommandPermission(sender, "open.others");
|
||||
target = Bukkit.getPlayerExact(args[2]);
|
||||
} else {
|
||||
target = (Player) sender;
|
||||
@ -117,7 +118,7 @@ public class CommandHandler extends CommandFramework {
|
||||
|
||||
CommandValidate.notNull(target, "That player is not online.");
|
||||
|
||||
String menuName = args[1].toLowerCase().endsWith(".yml") ? args[1] : args[1] + ".yml";
|
||||
String menuName = Utils.addYamlExtension(args[1]);
|
||||
InternalIconMenu menu = menuManager.getMenuByFileName(menuName);
|
||||
CommandValidate.notNull(menu, "The menu \"" + menuName + "\" was not found.");
|
||||
|
||||
@ -142,7 +143,7 @@ public class CommandHandler extends CommandFramework {
|
||||
|
||||
|
||||
if (args[0].equalsIgnoreCase("list")) {
|
||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + "list"), "You don't have permission.");
|
||||
checkCommandPermission(sender, "list");
|
||||
sender.sendMessage(ChestCommands.CHAT_PREFIX + "Loaded menus:");
|
||||
for (String file : menuManager.getMenuFileNames()) {
|
||||
sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.WHITE + file);
|
||||
@ -154,4 +155,8 @@ public class CommandHandler extends CommandFramework {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown sub-command \"" + args[0] + "\".");
|
||||
}
|
||||
|
||||
private void checkCommandPermission(CommandSender sender, String commandPermission) {
|
||||
CommandValidate.isTrue(sender.hasPermission(Permissions.COMMAND_PREFIX + commandPermission), "You don't have permission.");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import me.filoghost.chestcommands.ChestCommands;
|
||||
import me.filoghost.chestcommands.Permissions;
|
||||
import me.filoghost.chestcommands.menu.InternalIconMenu;
|
||||
import me.filoghost.chestcommands.menu.MenuManager;
|
||||
import me.filoghost.chestcommands.util.Utils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Sign;
|
||||
@ -63,7 +64,7 @@ public class SignListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
String menuFileName = addYamlExtension(sign.getLine(FILENAME_LINE).trim());
|
||||
String menuFileName = Utils.addYamlExtension(sign.getLine(FILENAME_LINE).trim());
|
||||
InternalIconMenu menu = menuManager.getMenuByFileName(menuFileName);
|
||||
|
||||
if (menu == null) {
|
||||
@ -85,7 +86,7 @@ public class SignListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
menuFileName = addYamlExtension(menuFileName);
|
||||
menuFileName = Utils.addYamlExtension(menuFileName);
|
||||
|
||||
InternalIconMenu iconMenu = menuManager.getMenuByFileName(menuFileName);
|
||||
if (iconMenu == null) {
|
||||
@ -120,16 +121,5 @@ public class SignListener implements Listener {
|
||||
private boolean canCreateMenuSign(Player player) {
|
||||
return player.hasPermission(Permissions.SIGN_CREATE);
|
||||
}
|
||||
|
||||
private String addYamlExtension(String fileName) {
|
||||
if (fileName == null) {
|
||||
return null;
|
||||
}
|
||||
if (fileName.toLowerCase().endsWith(".yml")) {
|
||||
return fileName;
|
||||
} else {
|
||||
return fileName + ".yml";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.filoghost.chestcommands.logging;
|
||||
|
||||
import me.filoghost.chestcommands.ChestCommands;
|
||||
import me.filoghost.chestcommands.config.framework.exception.ConfigException;
|
||||
import me.filoghost.chestcommands.config.framework.exception.ConfigSyntaxException;
|
||||
import me.filoghost.chestcommands.legacy.UpgradeExecutorException;
|
||||
@ -22,7 +23,7 @@ public class PrintableErrorCollector extends ErrorCollector {
|
||||
StringBuilder output = new StringBuilder();
|
||||
|
||||
if (errors.size() > 0) {
|
||||
output.append(ChatColor.RED).append("[ChestCommands] Encountered ").append(errors.size()).append(" error(s) on load:\n");
|
||||
output.append(ChestCommands.CHAT_PREFIX).append(ChatColor.RED).append("Encountered ").append(errors.size()).append(" error(s) on load:\n");
|
||||
output.append(" \n");
|
||||
|
||||
int index = 1;
|
||||
|
@ -15,4 +15,15 @@ public class Utils {
|
||||
return Strings.capitalizeFully(enumValue.name().replace("_", " "));
|
||||
}
|
||||
|
||||
public static String addYamlExtension(String fileName) {
|
||||
if (fileName == null) {
|
||||
return null;
|
||||
}
|
||||
if (fileName.toLowerCase().endsWith(".yml")) {
|
||||
return fileName;
|
||||
} else {
|
||||
return fileName + ".yml";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user