Skip to content

Commit

Permalink
Split out individual boolean conditions with custom errors; closes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyekl committed Dec 19, 2011
1 parent d621051 commit aa33177
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,40 +25,47 @@ public MVLinkChecker(MultiverseNetherPortals plugin) {

public Location findNewTeleportLocation(Location fromLocation, String worldstring, Player p) {
MultiverseWorld tpto = this.worldManager.getMVWorld(worldstring);
if (tpto != null && this.plugin.getCore().getMVPerms().canEnterWorld(p, tpto) && this.worldManager.isMVWorld(fromLocation.getWorld().getName())) {

if (tpto == null) {
this.plugin.log(Level.WARNING, "Can't find world " + worldstring);
} else if (!this.plugin.getCore().getMVPerms().canEnterWorld(p, tpto)) {
this.plugin.log(Level.WARNING, "Player " + p.getName() + " can't enter world " + worldstring);
} else if (!this.worldManager.isMVWorld(fromLocation.getWorld().getName())) {
this.plugin.log(Level.WARNING, "World " + fromLocation.getWorld().getName() + " is not a Multiverse world");
} else {
this.plugin.log(Level.FINE, "Finding new teleport location for player " + p.getName() + " to world " + worldstring);

// Set the output location to the same XYZ coords but different world
double toScaling = this.worldManager.getMVWorld(tpto.getName()).getScaling();
double fromScaling = this.worldManager.getMVWorld(fromLocation.getWorld().getName()).getScaling();

fromLocation = this.getScaledLocation(fromLocation, fromScaling, toScaling);
fromLocation.setWorld(tpto.getCBWorld());
return fromLocation;
} else {
this.plugin.log(Level.WARNING, "Looks like " + worldstring + " does not exist. Whoops on your part!");
this.plugin.log(Level.WARNING, "You should check your Multiverse-NetherPortals configs!!");
// Set the event to redirect back to the same portal
// otherwise they sit in the jelly stuff forever!
return null;
}
return null;
}

public void getNewTeleportLocation(PlayerPortalEvent event, Location fromLocation, String worldstring) {
MultiverseWorld tpto = this.worldManager.getMVWorld(worldstring);
if (tpto != null && this.plugin.getCore().getMVPerms().canEnterWorld(event.getPlayer(), tpto) && this.worldManager.isMVWorld(fromLocation.getWorld().getName())) {

if (tpto == null) {
this.plugin.log(Level.WARNING, "Can't find world " + worldstring);
} else if (!this.plugin.getCore().getMVPerms().canEnterWorld(event.getPlayer(), tpto)) {
this.plugin.log(Level.WARNING, "Player " + event.getPlayer().getName() + " can't enter world " + worldstring);
} else if (!this.worldManager.isMVWorld(fromLocation.getWorld().getName())) {
this.plugin.log(Level.WARNING, "World " + fromLocation.getWorld().getName() + " is not a Multiverse world");
} else {
this.plugin.log(Level.FINE, "Getting new teleport location for player " + event.getPlayer().getName() + " to world " + worldstring);

// Set the output location to the same XYZ coords but different world
double toScaling = this.worldManager.getMVWorld(tpto.getName()).getScaling();
double fromScaling = this.worldManager.getMVWorld(event.getFrom().getWorld().getName()).getScaling();

fromLocation = this.getScaledLocation(fromLocation, fromScaling, toScaling);
fromLocation.setWorld(tpto.getCBWorld());
event.setTo(fromLocation);
} else {
this.plugin.log(Level.WARNING, "Looks like " + worldstring + " does not exist. Whoops on your part!");
this.plugin.log(Level.WARNING, "You should check your Multiverse-NetherPortals configs!!");
// Set the event to redirect back to the same portal
// otherwise they sit in the jelly stuff forever!
event.setTo(fromLocation);
}
event.setTo(fromLocation);
}

private Location getScaledLocation(Location fromLocation, double fromScaling, double toScaling) {
Expand Down

0 comments on commit aa33177

Please sign in to comment.