Skip to content

Commit

Permalink
feat: add error messages for the destination commands
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Dec 3, 2023
1 parent 013d41d commit c3e60fa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
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);
if(destination != null) {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.createdesti.complete"));
sender.sendMessage("");
sender.sendMessage(Lang.translate("command.create.tags"));

ArrayList<DataTag> destiArgs = destination.getArgs();
Expand All @@ -57,19 +62,21 @@ public void onCommand(CommandSenderContainer sender, String[] args) {
else {
for (DataTag tag : destiArgs) {
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 {
sender.sendMessage("\u00A7a" + tag.NAME + "\u00A77:\u00A7e" + tag.VALUES[0]);
}
}
}
sender.sendMessage("");
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.createdesti.complete"));
}
else {
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.createdesti.error"));
}
}
else {
sender.sendMessage(Lang.translate("messageprefix.positive") + Lang.translate("command.error.noname"));
sender.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("command.error.noname"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Destination implements TagTarget {
private PlayerLocation loc;

@SerializedName("a")
private HashMap<String, String[]> args = new HashMap<>();
transient private HashMap<String, String[]> args = new HashMap<>();

private transient Set<String> argsCol;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ public Destination createDesti(PlayerContainer player, PlayerLocation playerLoca

// If the name is null, send an error saying that the name is required.
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;
}

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;
}
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;
}

Expand All @@ -92,8 +92,9 @@ else if(this.destinationRepository.containsKey(name)) {
}
try {
this.destinationRepository.addDestination(name, desti);
} catch (IOException e) {
} catch (Exception e) {
e.printStackTrace();
player.sendMessage(Lang.translate("messageprefix.negative") + Lang.translate("desti.error.save"));
}
this.saveDestinations();
return desti;
Expand Down
8 changes: 4 additions & 4 deletions lang/src/main/resources/lang/en_GB.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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.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.

Expand Down Expand Up @@ -97,11 +97,11 @@ portal.error.selection.differentworlds=Both the selected points need to be in th

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.nametaken= The name &e%1$s &cis already taken.

desti.error.takenname=The name given for the portal is already taken.
desti.error.noname=You must specify a name for the destination. (name:destinationname)
desti.error.save= There was a problem saving the destination:

error.notplayer=Only players can do that.

Expand Down

0 comments on commit c3e60fa

Please sign in to comment.