Skip to content

Commit

Permalink
Better error checking for link and unlink commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
benwoo1110 committed Jan 18, 2021
1 parent 7d19a53 commit b3d1169
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,21 +262,20 @@ public boolean addWorldLink(String from, String to, PortalType type) {
}

this.MVNPConfiguration.set("worlds." + from + ".portalgoesto." + type, to);
this.saveMVNPConfig();
return true;
return this.saveMVNPConfig();
}

public void removeWorldLink(String from, String to, PortalType type) {
public boolean removeWorldLink(String from, String to, PortalType type) {
if (type == PortalType.NETHER) {
this.linkMap.remove(from);
} else if (type == PortalType.ENDER) {
this.endLinkMap.remove(from);
} else {
return;
return false;
}

this.MVNPConfiguration.set("worlds." + from + ".portalgoesto." + type, null);
this.saveMVNPConfig();
return this.saveMVNPConfig();
}

public boolean saveMVNPConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ public void runCommand(CommandSender sender, List<String> args) {
return;
}

this.plugin.addWorldLink(fromWorld.getName(), toWorld.getName(), type);
if (!this.plugin.addWorldLink(fromWorld.getName(), toWorld.getName(), type)) {
sender.sendMessage(ChatColor.RED + "There was an error linking the portals! Please check console for errors.");
return;
}

String coloredFrom = fromWorld.getColoredWorldString();
String coloredTo = toWorld.getColoredWorldString();
if (fromWorld.getName().equals(toWorld.getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ public void runCommand(CommandSender sender, List<String> args) {
}

fromWorld = this.worldManager.getMVWorld(fromWorldString);
if (fromWorld == null) {
sender.sendMessage(ChatColor.RED + "Whoops!" + ChatColor.WHITE + " Doesn't look like Multiverse knows about '" + fromWorldString + "'");
String coloredFrom = (fromWorld == null) ? fromWorldString : fromWorld.getColoredWorldString();

toWorldString = this.plugin.getWorldLink(fromWorldString, type);
if (toWorldString == null) {
sender.sendMessage(ChatColor.RED + "Whoops!" + ChatColor.WHITE + " The world " + coloredFrom + ChatColor.WHITE + " was never linked.");
return;
}

toWorldString = this.plugin.getWorldLink(fromWorld.getName(), type);
if (toWorldString == null) {
sender.sendMessage(ChatColor.RED + "Whoops!" + ChatColor.WHITE + " The world " + fromWorld.getColoredWorldString() + ChatColor.WHITE + " was never linked.");
if (!this.plugin.removeWorldLink(fromWorldString, toWorldString, type)) {
sender.sendMessage(ChatColor.RED + "There was an error unlinking the portals! Please check console for errors.");
return;
}

toWorld = this.worldManager.getMVWorld(toWorldString);
String coloredTo = (toWorld == null) ? toWorldString : toWorld.getColoredWorldString();

String coloredFrom = fromWorld.getColoredWorldString();
String coloredTo = toWorld.getColoredWorldString();
sender.sendMessage("The " + type + " portals in " + coloredFrom + ChatColor.WHITE + " are now " + ChatColor.RED + "unlinked" + ChatColor.WHITE + " from " + coloredTo + ChatColor.WHITE + ".");
this.plugin.removeWorldLink(fromWorld.getName(), toWorld.getName(), type);
}

}

0 comments on commit b3d1169

Please sign in to comment.