From 3cc2e9f9857e66ac3b46bafbdf9e1b16a7cd3ab1 Mon Sep 17 00:00:00 2001 From: Kris Date: Thu, 21 Dec 2017 23:18:44 +0000 Subject: [PATCH] Prevent accidentally resetting all quests by default If no username is specified for the reset command, don't assume it's to reset everybody, this could lead to some very bad cases. Instead, detect if the username is "all", to reset all, otherwise throw a SyntaxErrorException to remind the username what to use. --- .../commands/admin/QuestCommandReset.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/betterquesting/commands/admin/QuestCommandReset.java b/src/main/java/betterquesting/commands/admin/QuestCommandReset.java index 3476eab45..35a109cc5 100644 --- a/src/main/java/betterquesting/commands/admin/QuestCommandReset.java +++ b/src/main/java/betterquesting/commands/admin/QuestCommandReset.java @@ -6,6 +6,7 @@ import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; +import net.minecraft.command.SyntaxErrorException import net.minecraft.server.MinecraftServer; import net.minecraft.util.text.TextComponentTranslation; import betterquesting.api.questing.IQuest; @@ -19,7 +20,7 @@ public class QuestCommandReset extends QuestCommandBase @Override public String getUsageSuffix() { - return "[all|] [username|uuid]"; + return "[all|] [all||]"; } @Override @@ -81,7 +82,7 @@ public void runCommand(MinecraftServer server, CommandBase command, ICommandSend if(uuid != null) { quest.resetUser(uuid, true); // Clear progress and state - } else + } else if(args[2].equalsIgnoreCase("all")) { quest.resetAll(true); } @@ -90,9 +91,12 @@ public void runCommand(MinecraftServer server, CommandBase command, ICommandSend if(uuid != null) { sender.addChatMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_all", pName)); - } else + } else if(args[2].equalsIgnoreCase("all")) { sender.addChatMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_all")); + } else + { + throw new SyntaxErrorException(); } } else { @@ -105,10 +109,13 @@ public void runCommand(MinecraftServer server, CommandBase command, ICommandSend { quest.resetUser(uuid, true); // Clear progress and state sender.addChatMessage(new TextComponentTranslation("betterquesting.cmd.reset.player_single", new TextComponentTranslation(quest.getUnlocalisedName()), pName)); - } else + } else if(args[2].equalsIgnoreCase("all")) { quest.resetAll(true); sender.addChatMessage(new TextComponentTranslation("betterquesting.cmd.reset.all_single", new TextComponentTranslation(quest.getUnlocalisedName()))); + } else + { + throw new SyntaxErrorException(); } } catch(Exception e) {