forked from github-mirror/CoreProtect
Added argument validation to purge command (fixes #848)
This commit is contained in:
1 parent
7c7013f49f
commit
7caa617a34
5 files changed
+66
-2
No files matched your search
@@ -66,6 +66,9 @@ HELP_PARAMS_6: "Include specific blocks/entities in the {lookup|rollback|restore
|
||||
HELP_PARAMS_7: "Exclude blocks/users from the {lookup|rollback|restore}."
|
||||
HELP_PURGE_1: "Delete data older than specified time."
|
||||
HELP_PURGE_2: "For example, \"{0}\" will delete all data older than one month, and only keep the last 30 days of data."
|
||||
HELP_PURGE_3: "Specify the amount of time to purge."
|
||||
HELP_PURGE_4: "Specify a world to limit the purge to."
|
||||
HELP_PURGE_5: "Include specific blocks in the purge."
|
||||
HELP_PURGE_COMMAND: "Delete old block data."
|
||||
HELP_RADIUS_1: "Specify a radius area."
|
||||
HELP_RADIUS_2: "Examples: [r:10] (Only make changes within 10 blocks of you)"
|
||||
@@ -94,6 +97,7 @@ INVALID_CONTAINER: "Please inspect a valid container first."
|
||||
INVALID_DONATION_KEY: "Invalid donation key."
|
||||
INVALID_INCLUDE: "\"{0}\" is an invalid block/entity name."
|
||||
INVALID_INCLUDE_COMBO: "That is an invalid block/entity combination."
|
||||
INVALID_PARAMETER: "\"{0}\" is not a supported parameter."
|
||||
INVALID_RADIUS: "Please enter a valid radius."
|
||||
INVALID_SELECTION: "{0} selection not found."
|
||||
INVALID_USERNAME: "\"{0}\" is an invalid username."
|
||||
|
||||
@@ -67,8 +67,11 @@ public class HelpCommand {
|
||||
Chat.sendMessage(player, Color.GREY + Color.ITALIC + Phrase.build(Phrase.HELP_PARAMETER, "/co help params"));
|
||||
}
|
||||
else if (helpcommand.equals("purge") || helpcommand.equals("purges")) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "/co purge t:<time> " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_PURGE_1));
|
||||
Chat.sendMessage(player, Color.GREY + Color.ITALIC + "" + Phrase.build(Phrase.HELP_PURGE_2, "/co purge t:30d"));
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "/co purge " + Color.GREY + "<params> " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_PURGE_1));
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "| " + Color.GREY + "t:<time> " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_PURGE_3));
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "| " + Color.GREY + "r:<world> " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_PURGE_4));
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "| " + Color.GREY + "i:<include> " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_PURGE_5));
|
||||
Chat.sendMessage(player, Color.GREY + Color.ITALIC + Phrase.build(Phrase.HELP_PURGE_2, "/co purge t:30d"));
|
||||
}
|
||||
else if (helpcommand.equals("reload")) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "/co reload " + Color.WHITE + "- " + Phrase.build(Phrase.HELP_RELOAD_COMMAND));
|
||||
|
||||
@@ -34,6 +34,49 @@ import net.coreprotect.utility.VersionUtils;
|
||||
|
||||
public class PurgeCommand extends Consumer {
|
||||
|
||||
private static String findUnsupportedPurgeArgument(String[] args) {
|
||||
boolean includeContinuation = false;
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String token = args[i].trim();
|
||||
if (token.length() == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String argument = token.toLowerCase(Locale.ROOT);
|
||||
argument = argument.replaceAll("\\\\", "");
|
||||
argument = argument.replaceAll("'", "");
|
||||
|
||||
if (includeContinuation) {
|
||||
includeContinuation = argument.endsWith(",");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argument.equals("#optimize")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argument.startsWith("i:") || argument.startsWith("include:") || argument.startsWith("item:") || argument.startsWith("items:") || argument.startsWith("b:") || argument.startsWith("block:") || argument.startsWith("blocks:")) {
|
||||
String includeValues = argument.replaceAll("include:", "").replaceAll("i:", "").replaceAll("items:", "").replaceAll("item:", "").replaceAll("blocks:", "").replaceAll("block:", "").replaceAll("b:", "");
|
||||
includeContinuation = includeValues.length() == 0 || includeValues.endsWith(",");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argument.startsWith("t:") || argument.startsWith("time:")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argument.startsWith("r:") || argument.startsWith("radius:")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (argument.contains(":")) {
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static void runCommand(final CommandSender player, boolean permission, String[] args) {
|
||||
int resultc = args.length;
|
||||
Location location = CommandParser.parseLocation(player, args);
|
||||
@@ -68,6 +111,12 @@ public class PurgeCommand extends Consumer {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co purge t:<time>"));
|
||||
return;
|
||||
}
|
||||
String unsupportedArgument = findUnsupportedPurgeArgument(args);
|
||||
if (unsupportedArgument != null) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.INVALID_PARAMETER, unsupportedArgument));
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co help purge"));
|
||||
return;
|
||||
}
|
||||
if (endTime <= 0) {
|
||||
Chat.sendMessage(player, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.MISSING_PARAMETERS, "/co purge t:<time>"));
|
||||
return;
|
||||
|
||||
@@ -95,6 +95,9 @@ public class Language {
|
||||
phrases.put(Phrase.HELP_PARAMS_7, "Exclude blocks/users from the {lookup|rollback|restore}.");
|
||||
phrases.put(Phrase.HELP_PURGE_1, "Delete data older than specified time.");
|
||||
phrases.put(Phrase.HELP_PURGE_2, "For example, \"{0}\" will delete all data older than one month, and only keep the last 30 days of data.");
|
||||
phrases.put(Phrase.HELP_PURGE_3, "Specify the amount of time to purge.");
|
||||
phrases.put(Phrase.HELP_PURGE_4, "Specify a world to limit the purge to.");
|
||||
phrases.put(Phrase.HELP_PURGE_5, "Include specific blocks in the purge.");
|
||||
phrases.put(Phrase.HELP_PURGE_COMMAND, "Delete old block data.");
|
||||
phrases.put(Phrase.HELP_RADIUS_1, "Specify a radius area.");
|
||||
phrases.put(Phrase.HELP_RADIUS_2, "Examples: [r:10] (Only make changes within 10 blocks of you)");
|
||||
@@ -123,6 +126,7 @@ public class Language {
|
||||
phrases.put(Phrase.INVALID_DONATION_KEY, "Invalid donation key.");
|
||||
phrases.put(Phrase.INVALID_INCLUDE, "\"{0}\" is an invalid block/entity name.");
|
||||
phrases.put(Phrase.INVALID_INCLUDE_COMBO, "That is an invalid block/entity combination.");
|
||||
phrases.put(Phrase.INVALID_PARAMETER, "\"{0}\" is not a supported parameter.");
|
||||
phrases.put(Phrase.INVALID_RADIUS, "Please enter a valid radius.");
|
||||
phrases.put(Phrase.INVALID_SELECTION, "{0} selection not found.");
|
||||
phrases.put(Phrase.INVALID_USERNAME, "\"{0}\" is an invalid username.");
|
||||
|
||||
@@ -78,6 +78,9 @@ public enum Phrase {
|
||||
HELP_PARAMS_7,
|
||||
HELP_PURGE_1,
|
||||
HELP_PURGE_2,
|
||||
HELP_PURGE_3,
|
||||
HELP_PURGE_4,
|
||||
HELP_PURGE_5,
|
||||
HELP_PURGE_COMMAND,
|
||||
HELP_RADIUS_1,
|
||||
HELP_RADIUS_2,
|
||||
@@ -106,6 +109,7 @@ public enum Phrase {
|
||||
INVALID_DONATION_KEY,
|
||||
INVALID_INCLUDE,
|
||||
INVALID_INCLUDE_COMBO,
|
||||
INVALID_PARAMETER,
|
||||
INVALID_RADIUS,
|
||||
INVALID_SELECTION,
|
||||
INVALID_USERNAME,
|
||||
|
||||
Reference in new issue
Block a user