mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-12-28 17:47:41 +01:00
Added "/co consumer <pause|resume>" console command
This commit is contained in:
parent
eb5b3b5bcc
commit
7398f7dfe6
@ -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));
|
||||
}
|
||||
|
69
src/main/java/net/coreprotect/command/ConsumerCommand.java
Normal file
69
src/main/java/net/coreprotect/command/ConsumerCommand.java
Normal file
@ -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 <pause|resume>"));
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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.");
|
||||
|
@ -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,
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user