mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-02 13:41:22 +01:00
Verify worlds and portals at the time of Destination creation
This commit is contained in:
parent
7061c7a9c2
commit
1f3a325bc9
@ -30,7 +30,6 @@ public abstract class BaseCommand {
|
||||
String match = matchIdentifier(name);
|
||||
if (match != null) {
|
||||
identifier = identifier.append(match);
|
||||
int i = identifier.length();
|
||||
if (parsedArgs == null) {
|
||||
parsedArgs = new String[0];
|
||||
}
|
||||
|
@ -35,14 +35,11 @@ public class TeleportCommand extends BaseCommand {
|
||||
p.sendMessage("You do not have access to this command.");
|
||||
return;
|
||||
}
|
||||
Destination d = Destination.parseDestination(args[0]);
|
||||
// TODO: I'd like to find a way to do these next bits inside Destination, so we're always valid --FF
|
||||
Destination d = Destination.parseDestination(args[0], this.plugin);
|
||||
// TODO: Support portals, but I didn't see the portals list --FF
|
||||
if (this.plugin.worlds.containsKey(d.getName())) {
|
||||
if (d.getType() == DestinationType.World) {
|
||||
Location l = playerTeleporter.getSafeDestination(plugin.getServer().getWorld(d.getName()).getSpawnLocation());
|
||||
p.teleport(l);
|
||||
}
|
||||
if (d.getType() == DestinationType.World) {
|
||||
Location l = playerTeleporter.getSafeDestination(this.plugin.getServer().getWorld(d.getName()).getSpawnLocation());
|
||||
p.teleport(l);
|
||||
} else {
|
||||
p.sendMessage("That was not a valid world (portals aren't yet supported)");
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.onarandombox.utils;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
|
||||
public class Destination {
|
||||
private String name;
|
||||
private DestinationType type;
|
||||
@ -20,26 +22,31 @@ public class Destination {
|
||||
private static Destination getBadDestination() {
|
||||
return new Destination("", DestinationType.Invalid);
|
||||
}
|
||||
|
||||
public static Destination parseDestination(String dest) {
|
||||
/**
|
||||
* Takes the given string and returns a Destination. This will NEVER be NULL. It will return a destination of type Invalid if the destination is bad.
|
||||
* @param dest The parceable string, ex: w:My World
|
||||
* @param plugin The MultiverseCore plugin used to find valid worlds/portals
|
||||
* @return A new Destination from the parsed string.
|
||||
*/
|
||||
public static Destination parseDestination(String dest, MultiverseCore plugin) {
|
||||
if (dest == null) {
|
||||
return getBadDestination();
|
||||
}
|
||||
|
||||
String[] items = dest.split(":");
|
||||
if (items.length > 1) {
|
||||
if (items.length > 2) {
|
||||
return getBadDestination();
|
||||
}
|
||||
|
||||
// If we only found one param, assume world
|
||||
// TODO: Check for a valid world
|
||||
if (items.length == 1) {
|
||||
// If we only found one param, assume world, but still check for validity
|
||||
if (items.length == 1 && plugin.worlds.containsKey(items[0])) {
|
||||
return new Destination(items[0], DestinationType.World);
|
||||
}
|
||||
|
||||
if (items[0].equalsIgnoreCase("w")) {
|
||||
if (items[0].equalsIgnoreCase("w") && plugin.worlds.containsKey(items[0])) {
|
||||
return new Destination(items[1], DestinationType.World);
|
||||
} else if (items[0].equalsIgnoreCase("p")) {
|
||||
// TODO: Check for a valid portal, we can't right now, as portals aren't really in yet.
|
||||
return new Destination(items[1], DestinationType.Portal);
|
||||
}
|
||||
return getBadDestination();
|
||||
|
Loading…
Reference in New Issue
Block a user