diff --git a/src/main/java/net/coreprotect/command/CommandHandler.java b/src/main/java/net/coreprotect/command/CommandHandler.java index d379e48..a90c33b 100755 --- a/src/main/java/net/coreprotect/command/CommandHandler.java +++ b/src/main/java/net/coreprotect/command/CommandHandler.java @@ -1122,6 +1122,9 @@ public class CommandHandler implements CommandExecutor { else if (user.hasPermission("coreprotect.status") && (corecommand.equals("status") || corecommand.equals("stats") || corecommand.equals("version"))) { permission = true; } + else if (user.hasPermission("coreprotect.consumer") && corecommand.equals("consumer")) { + permission = true; + } } if (corecommand.equals("rollback") || corecommand.equals("restore") || corecommand.equals("rb") || corecommand.equals("rs") || corecommand.equals("ro") || corecommand.equals("re")) { @@ -1160,6 +1163,9 @@ public class CommandHandler implements CommandExecutor { else if (corecommand.equals("reload")) { ReloadCommand.runCommand(user, permission, argumentArray); } + else if (corecommand.equals("consumer")) { + ConsumerCommand.runCommand(user, permission, argumentArray); + } else { Chat.sendMessage(user, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.COMMAND_NOT_FOUND, Color.WHITE, "/co " + corecommand)); } diff --git a/src/main/java/net/coreprotect/command/ConsumerCommand.java b/src/main/java/net/coreprotect/command/ConsumerCommand.java new file mode 100644 index 0000000..299c905 --- /dev/null +++ b/src/main/java/net/coreprotect/command/ConsumerCommand.java @@ -0,0 +1,69 @@ +package net.coreprotect.command; + +import java.util.Locale; + +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; + +import net.coreprotect.config.ConfigHandler; +import net.coreprotect.language.Phrase; +import net.coreprotect.language.Selector; +import net.coreprotect.utility.Chat; +import net.coreprotect.utility.Color; + +public class ConsumerCommand { + + private ConsumerCommand() { + throw new IllegalStateException("Command class"); + } + + protected static void runCommand(final CommandSender player, boolean permission, String[] args) { + if (!permission) { + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.NO_PERMISSION)); + return; + } + if (!(player instanceof ConsoleCommandSender)) { + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.COMMAND_CONSOLE)); + return; + } + if (ConfigHandler.converterRunning) { + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.UPGRADE_IN_PROGRESS)); + return; + } + if (ConfigHandler.purgeRunning) { + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.PURGE_IN_PROGRESS)); + return; + } + + if (args.length == 2) { + String action = args[1].toLowerCase(Locale.ROOT); + boolean pauseCommand = (action.equals("pause") || action.equals("disable") || action.equals("stop")); + boolean resumeCommand = (action.equals("resume") || action.equals("enable") || action.equals("start")); + + if (pauseCommand || resumeCommand) { + if (ConfigHandler.pauseConsumer) { + if (pauseCommand) { + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.CONSUMER_ERROR, Selector.FIRST)); // already paused + } + else { + ConfigHandler.pauseConsumer = false; + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.CONSUMER_TOGGLED, Selector.SECOND)); // now started + } + } + else { + if (resumeCommand) { + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.CONSUMER_ERROR, Selector.SECOND)); // already running + } + else { + ConfigHandler.pauseConsumer = true; + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.CONSUMER_TOGGLED, Selector.FIRST)); // now paused + } + } + return; + } + } + + Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, Color.WHITE, "/co consumer ")); + } + +} diff --git a/src/main/java/net/coreprotect/config/ConfigHandler.java b/src/main/java/net/coreprotect/config/ConfigHandler.java index 89706e5..c8275d0 100644 --- a/src/main/java/net/coreprotect/config/ConfigHandler.java +++ b/src/main/java/net/coreprotect/config/ConfigHandler.java @@ -58,6 +58,7 @@ public class ConfigHandler extends Queue { public static volatile boolean serverRunning = false; public static volatile boolean converterRunning = false; public static volatile boolean purgeRunning = false; + public static volatile boolean pauseConsumer = false; public static volatile boolean worldeditEnabled = false; public static volatile boolean databaseReachable = true; public static volatile int worldId = 0; diff --git a/src/main/java/net/coreprotect/consumer/Consumer.java b/src/main/java/net/coreprotect/consumer/Consumer.java index a11aa73..f5a1693 100755 --- a/src/main/java/net/coreprotect/consumer/Consumer.java +++ b/src/main/java/net/coreprotect/consumer/Consumer.java @@ -100,7 +100,7 @@ public class Consumer extends Process implements Runnable, Thread.UncaughtExcept private static void pauseConsumer(int process_id) { try { - while ((ConfigHandler.serverRunning || ConfigHandler.converterRunning) && (Consumer.isPaused || ConfigHandler.purgeRunning || Consumer.consumer_id.get(process_id)[1] == 1)) { + while ((ConfigHandler.serverRunning || ConfigHandler.converterRunning) && (Consumer.isPaused || ConfigHandler.pauseConsumer || ConfigHandler.purgeRunning || Consumer.consumer_id.get(process_id)[1] == 1)) { pausedSuccess = true; Thread.sleep(100); } diff --git a/src/main/java/net/coreprotect/language/Language.java b/src/main/java/net/coreprotect/language/Language.java index 1690ed4..df818dc 100644 --- a/src/main/java/net/coreprotect/language/Language.java +++ b/src/main/java/net/coreprotect/language/Language.java @@ -38,8 +38,11 @@ public class Language { phrases.put(Phrase.CACHE_ERROR, "WARNING: Error while validating {0} cache."); phrases.put(Phrase.CACHE_RELOAD, "Forcing reload of {mapping|world} caches from database."); phrases.put(Phrase.CHECK_CONFIG, "Please check config.yml"); + phrases.put(Phrase.COMMAND_CONSOLE, "Please run the command from the console."); phrases.put(Phrase.COMMAND_NOT_FOUND, "Command \"{0}\" not found."); phrases.put(Phrase.COMMAND_THROTTLED, "Please wait a moment and try again."); + phrases.put(Phrase.CONSUMER_ERROR, "Consumer queue processing already {paused|resumed}."); + phrases.put(Phrase.CONSUMER_TOGGLED, "Consumer queue processing has been {paused|resumed}."); phrases.put(Phrase.CONTAINER_HEADER, "Container Transactions"); phrases.put(Phrase.DATABASE_BUSY, "Database busy. Please try again later."); phrases.put(Phrase.DATABASE_INDEX_ERROR, "Unable to validate database indexes."); diff --git a/src/main/java/net/coreprotect/language/Phrase.java b/src/main/java/net/coreprotect/language/Phrase.java index 32f78cf..1c12353 100644 --- a/src/main/java/net/coreprotect/language/Phrase.java +++ b/src/main/java/net/coreprotect/language/Phrase.java @@ -19,8 +19,11 @@ public enum Phrase { CACHE_ERROR, CACHE_RELOAD, CHECK_CONFIG, + COMMAND_CONSOLE, COMMAND_NOT_FOUND, COMMAND_THROTTLED, + CONSUMER_ERROR, + CONSUMER_TOGGLED, CONTAINER_HEADER, DATABASE_BUSY, DATABASE_INDEX_ERROR, diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index b8ea535..5ef1269 100755 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -134,4 +134,7 @@ permissions: default: op coreprotect.status: description: Has permission to use the status command + default: op + coreprotect.consumer: + description: Has permission to use the consumer command default: op \ No newline at end of file