feat: add error messages for the destination commands

This commit is contained in:
sekwah 2023-12-03 18:31:53 +00:00
parent 013d41d65d
commit c3e60fa02e
4 changed files with 20 additions and 12 deletions

View File

@ -44,9 +44,14 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
destinationTags.add(nameTag); destinationTags.add(nameTag);
} }
if (nameTag == null) {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
return;
}
Destination destination = destinationServices.createDesti(player, player.getLoc(), destinationTags); Destination destination = destinationServices.createDesti(player, player.getLoc(), destinationTags);
if(destination != null) { if(destination != null) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.createdesti.complete")); sender.sendMessage("");
sender.sendMessage(Lang.translate("command.create.tags")); sender.sendMessage(Lang.translate("command.create.tags"));
ArrayList<DataTag> destiArgs = destination.getArgs(); ArrayList<DataTag> destiArgs = destination.getArgs();
@ -57,19 +62,21 @@ public class CreateDestiSubCommand extends CreateTaggedSubCommand {
else { else {
for (DataTag tag : destiArgs) { for (DataTag tag : destiArgs) {
if(tag.VALUES.length == 1) { if(tag.VALUES.length == 1) {
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]); sender.sendMessage(" \u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]);
} else { } else {
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]); sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]);
} }
} }
} }
sender.sendMessage("");
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.createdesti.complete"));
} }
else { else {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.error")); sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.error"));
} }
} }
else { else {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.error.noname")); sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
} }
} }

View File

@ -33,7 +33,7 @@ public class Destination implements TagTarget {
private PlayerLocation loc; private PlayerLocation loc;
@SerializedName("a") @SerializedName("a")
private HashMap<String, String[]> args = new HashMap<>(); transient private HashMap<String, String[]> args = new HashMap<>();
private transient Set<String> argsCol; private transient Set<String> argsCol;

View File

@ -66,16 +66,16 @@ public class DestinationServices {
// If the name is null, send an error saying that the name is required. // If the name is null, send an error saying that the name is required.
if(nameTag == null) { if(nameTag == null) {
player.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("desti.error.noname")); player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.noname"));
return null; return null;
} }
if(name == null || name.equals("")) { if(name == null || name.equals("")) {
player.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("desti.error.noname")); player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
return null; return null;
} }
else if(this.destinationRepository.containsKey(name)) { else if(this.destinationRepository.containsKey(name)) {
player.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("desti.error.takenname")); player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translateInsertVariables("command.error.nametaken", name));
return null; return null;
} }
@ -92,8 +92,9 @@ public class DestinationServices {
} }
try { try {
this.destinationRepository.addDestination(name, desti); this.destinationRepository.addDestination(name, desti);
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save"));
} }
this.saveDestinations(); this.saveDestinations();
return desti; return desti;

View File

@ -67,7 +67,7 @@ command.createdesti.console= You cannot create a destination using the console.
command.createdesti.detailedhelp=Format is /desti create (name) [tag:tagvalue] List tags after create in the format tag:value, if your value needs spaces use the format tag:"value with spaces" command.createdesti.detailedhelp=Format is /desti create (name) [tag:tagvalue] List tags after create in the format tag:value, if your value needs spaces use the format tag:"value with spaces"
command.createdesti.complete= The destination has been successfully created. command.createdesti.complete= The destination has been successfully created.
command.create.tags=&aTags: command.create.tags=&aTags&e:
command.playeronly= Sorry but that command can only be run by a player. command.playeronly= Sorry but that command can only be run by a player.
@ -97,11 +97,11 @@ portal.error.selection.differentworlds=Both the selected points need to be in th
desti.info.noargs=&cNo tags were given desti.info.noargs=&cNo tags were given
command.error.noname= No name has been given. command.error.noname= You must specify a name. (name:someNameHere)
command.error.notags= No tags have been given. You need to include at least &ename:(name)&c. command.error.notags= No tags have been given. You need to include at least &ename:(name)&c.
command.error.nametaken= The name &e%1$s &cis already taken.
desti.error.takenname=The name given for the portal is already taken. desti.error.save= There was a problem saving the destination:
desti.error.noname=You must specify a name for the destination. (name:destinationname)
error.notplayer=Only players can do that. error.notplayer=Only players can do that.