Skip to content

Commit

Permalink
Incorporate suggestions by samolego
Browse files Browse the repository at this point in the history
  • Loading branch information
Zacrain committed May 25, 2022
1 parent 72a5e01 commit 0a46f20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -252,18 +252,19 @@ private static int selectTaterzenByName(CommandContext<CommandSourceStack> conte
if (npcIt.getName().getString().equals(name)) {
taterzen = npcIt;
count++;

if (count > 1) {
source.sendFailure(errorText("taterzens.error.multiple.name", name));
return 0;
}
}
}

if (count == 0) { // equivalent to taterzen == null
source.sendFailure(errorText("taterzens.error.404.name", name));
return -1;
}
else if (count > 1) {
source.sendFailure(errorText("taterzens.error.multiple.name", name));
return -1;
return 0;
}
else if (count == 1) {
else { // if count == 1

ServerPlayer player = source.getPlayerOrException();
TaterzenNPC npc = ((ITaterzenEditor) player).getNpc();
Expand All @@ -281,16 +282,9 @@ else if (count == 1) {
source.sendFailure(
errorText("taterzens.command.error.locked", taterzen.getName().getString())
);
return -1;
return 0;
}
}
else {
// in theory there could be more than 2^32-1 NPCs.
// More than that will result in an overflow, i.e. a negative int.
// In practise, this is highly improbable.

return -1;
}
}

private static String[] getAvailableTaterzenUUIDs() {
Expand All @@ -309,8 +303,8 @@ private static int selectTaterzenByUUID(CommandContext<CommandSourceStack> conte
try {
uuid = UUID.fromString(StringArgumentType.getString(context, "uuid"));
} catch (IllegalArgumentException ex) {
source.sendFailure(errorText("taterzens.error.invalid.uuid"));
return -1;
source.sendFailure(errorText("argument.uuid.invalid"));
return 0;
}

TaterzenNPC taterzen = null;
Expand All @@ -324,7 +318,7 @@ private static int selectTaterzenByUUID(CommandContext<CommandSourceStack> conte
}
if (taterzen == null) {
source.sendFailure(errorText("taterzens.error.404.uuid", uuid.toString()));
return -1;
return 0;
} else {
ServerPlayer player = source.getPlayerOrException();
TaterzenNPC npc = ((ITaterzenEditor) player).getNpc();
Expand All @@ -342,7 +336,7 @@ private static int selectTaterzenByUUID(CommandContext<CommandSourceStack> conte
source.sendFailure(
errorText("taterzens.command.error.locked", taterzen.getName().getString())
);
return -1;
return 0;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion common/src/main/resources/data/taterzens/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@
"taterzens.tooltip.exit": "Exit",
"taterzens.error.invalid.url": "URL %s is malformed.",
"taterzens.error.invalid.text": "The text nbt you entered is invalid.",
"taterzens.error.invalid.uuid": "The uuid you entered is invalid.",
"taterzens.error.404.detected": "No Taterzen was detected in front of you.",
"taterzens.error.404.id": "No Taterzen with id %s was found.",
"taterzens.error.404.name": "No Taterzen with name %s was found.",
Expand Down

0 comments on commit 0a46f20

Please sign in to comment.