mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-10-05 11:07:28 +02:00
Teleports work with spaces, still needs refactor before merge
This commit is contained in:
parent
80fd19c0f8
commit
4556b0d4c6
@ -26,22 +26,20 @@ public abstract class BaseCommand {
|
|||||||
|
|
||||||
public abstract void execute(CommandSender sender, String[] args);
|
public abstract void execute(CommandSender sender, String[] args);
|
||||||
|
|
||||||
public String[] validate(String input, StringBuilder identifier) {
|
public boolean validate(String name, String[] parsedArgs, StringBuilder identifier) {
|
||||||
String match = matchIdentifier(input);
|
String match = matchIdentifier(name);
|
||||||
|
|
||||||
if (match != null) {
|
if (match != null) {
|
||||||
identifier = identifier.append(match);
|
identifier = identifier.append(match);
|
||||||
int i = identifier.length();
|
int i = identifier.length();
|
||||||
String[] args = input.substring(i).trim().split(" ");
|
if (parsedArgs == null) {
|
||||||
if (args[0].isEmpty()) {
|
parsedArgs = new String[0];
|
||||||
args = new String[0];
|
|
||||||
}
|
}
|
||||||
int l = args.length;
|
int l = parsedArgs.length;
|
||||||
if (l >= minArgs && (maxArgs == -1 ||l <= maxArgs)) {
|
if (l >= minArgs && (maxArgs == -1 ||l <= maxArgs)) {
|
||||||
return args;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String matchIdentifier(String input) {
|
public String matchIdentifier(String input) {
|
||||||
|
@ -26,10 +26,6 @@ public class CommandManager {
|
|||||||
|
|
||||||
public boolean dispatch(CommandSender sender, Command command, String label, String[] args) {
|
public boolean dispatch(CommandSender sender, Command command, String label, String[] args) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
String input = label + " ";
|
|
||||||
for (String s : args) {
|
|
||||||
input += s + " ";
|
|
||||||
}
|
|
||||||
|
|
||||||
BaseCommand match = null;
|
BaseCommand match = null;
|
||||||
String[] trimmedArgs = null;
|
String[] trimmedArgs = null;
|
||||||
@ -37,10 +33,8 @@ public class CommandManager {
|
|||||||
|
|
||||||
for (BaseCommand cmd : commands) {
|
for (BaseCommand cmd : commands) {
|
||||||
StringBuilder tmpIdentifier = new StringBuilder();
|
StringBuilder tmpIdentifier = new StringBuilder();
|
||||||
String[] tmpArgs = cmd.validate(input, tmpIdentifier);
|
String[] tmpArgs = parseAllQuotedStrings(args);
|
||||||
// If temp args is not null, then we'll parse the quoted strings out of it
|
if(cmd.validate(label, tmpArgs, tmpIdentifier) && tmpIdentifier.length() > identifier.length()) {
|
||||||
tmpArgs = tmpArgs == null ? null : parseAllQuotedStrings(tmpArgs);
|
|
||||||
if (tmpIdentifier.length() > identifier.length()) {
|
|
||||||
identifier = tmpIdentifier;
|
identifier = tmpIdentifier;
|
||||||
match = cmd;
|
match = cmd;
|
||||||
trimmedArgs = tmpArgs;
|
trimmedArgs = tmpArgs;
|
||||||
@ -113,7 +107,7 @@ public class CommandManager {
|
|||||||
this.sender.sendMessage(msg);
|
this.sender.sendMessage(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
return args;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,59 +20,26 @@ public class CreateCommand extends BaseCommand {
|
|||||||
super(plugin);
|
super(plugin);
|
||||||
name = "Create World";
|
name = "Create World";
|
||||||
description = "Creates a new world of the specified type";
|
description = "Creates a new world of the specified type";
|
||||||
// Syntax is s:SEED so we can see this variable seperately when spaces are allowed in worldnames
|
usage = "/mvcreate" + ChatColor.GREEN + " {NAME} {TYPE}" + ChatColor.GOLD + " [SEED]";
|
||||||
usage = "/mvcreate" + ChatColor.GREEN + " {NAME} {TYPE}" + ChatColor.GOLD + " [s:SEED]";
|
|
||||||
minArgs = 2;
|
minArgs = 2;
|
||||||
maxArgs = -1;
|
maxArgs = 3;
|
||||||
identifiers.add("mvcreate");
|
identifiers.add("mvcreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
// TODO: Permissions, check
|
// TODO: Permissions, check
|
||||||
// TODO: Allow spaces in world names, currently this will catch it --FF
|
|
||||||
|
|
||||||
int numOfParams = args.length;
|
int numOfParams = args.length;
|
||||||
// We'll search for this in a minute, if it's still -1 after the search, a user did this:
|
|
||||||
// /mvcreate "My Awesome world NETHER
|
boolean hasSeed = numOfParams == 3;
|
||||||
// ie. they forgot to close the "
|
String worldName = args[0];
|
||||||
int envPosition = -1;
|
String env = args[1];
|
||||||
boolean hasSeed = false;
|
String seed = "";
|
||||||
|
if(hasSeed) {
|
||||||
// Did the user input "s?
|
seed = args[2];
|
||||||
if (args[0].substring(0, 1).equals("\"")) {
|
|
||||||
// Find the magical keyword,
|
|
||||||
for (int i = 0; i < numOfParams; i++) {
|
|
||||||
if (args[i].substring(args[i].length() - 1, args[i].length()).equals("\"") && envPosition == -1) {
|
|
||||||
// We found a word that ended with a quote, the next one MUST be the environment keyword
|
|
||||||
envPosition = i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// There can only be one word, envPosition must be 1
|
|
||||||
envPosition = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (envPosition == -1) {
|
|
||||||
sender.sendMessage("Why are you such a failure...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the environment position is not the last in the list, we have a seed after it:
|
|
||||||
if (envPosition != numOfParams - 1) {
|
|
||||||
hasSeed = true;
|
|
||||||
}
|
|
||||||
String worldName = parseQuotedString(args, 0, envPosition);
|
|
||||||
String env = args[envPosition];
|
|
||||||
// If we have a seed, parse the quotes out of it, if not, it's == ""
|
|
||||||
String seed = hasSeed ? parseQuotedString(args, envPosition + 1, numOfParams) : "";
|
|
||||||
|
|
||||||
if (args[numOfParams - 1].substring(0, 2).equalsIgnoreCase("s:")) {
|
|
||||||
envPosition--;
|
|
||||||
hasSeed = true;
|
|
||||||
// Pull out the seed name, drop the "s:"
|
|
||||||
seed = args[numOfParams - 1].split(":")[1];
|
|
||||||
}
|
|
||||||
sender.sendMessage("Stuff I found:");
|
sender.sendMessage("Stuff I found:");
|
||||||
sender.sendMessage(ChatColor.GREEN + "worldName" + ChatColor.WHITE + worldName);
|
sender.sendMessage(ChatColor.GREEN + "worldName" + ChatColor.WHITE + worldName);
|
||||||
sender.sendMessage(ChatColor.GREEN + "env " + ChatColor.WHITE + env);
|
sender.sendMessage(ChatColor.GREEN + "env " + ChatColor.WHITE + env);
|
||||||
@ -94,29 +61,26 @@ public class CreateCommand extends BaseCommand {
|
|||||||
|
|
||||||
Environment environment = null;
|
Environment environment = null;
|
||||||
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
|
// Don't reference the enum directly as there aren't that many, and we can be more forgiving to users this way
|
||||||
if (env.equalsIgnoreCase("NETHER") || env.equalsIgnoreCase("HELL"))
|
if (env.equalsIgnoreCase("HELL"))
|
||||||
environment = Environment.NETHER;
|
env = "NETHER";;
|
||||||
|
|
||||||
if (env.equalsIgnoreCase("NORMAL"))
|
if (env.equalsIgnoreCase("SKYLAND") || env.equalsIgnoreCase("STARWARS"))
|
||||||
environment = Environment.NORMAL;
|
env = "SKYLAND";
|
||||||
|
try {
|
||||||
if (env.equalsIgnoreCase("SKYLANDS") || env.equalsIgnoreCase("SKYLAND"))
|
environment = Environment.valueOf(env);
|
||||||
environment = Environment.SKYLANDS;
|
} catch (IllegalArgumentException e) {
|
||||||
|
|
||||||
if (environment == null) {
|
|
||||||
sender.sendMessage(ChatColor.RED + "Environment type " + env + " does not exist!");
|
sender.sendMessage(ChatColor.RED + "Environment type " + env + " does not exist!");
|
||||||
|
// TODO: Show the player the mvenvironments command.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasSeed) {
|
if (hasSeed) {
|
||||||
// plugin.getServer().createWorld(worldName, environment, Long.parseLong(seed));
|
|
||||||
try {
|
try {
|
||||||
plugin.addWorld(worldName, environment, Long.parseLong(seed));
|
plugin.addWorld(worldName, environment, Long.parseLong(seed));
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
plugin.addWorld(worldName, environment, (long) seed.hashCode());
|
plugin.addWorld(worldName, environment, (long) seed.hashCode());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// plugin.getServer().createWorld(worldName, environment);
|
|
||||||
plugin.addWorld(worldName, environment);
|
plugin.addWorld(worldName, environment);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -38,7 +38,7 @@ public class TeleportCommand extends BaseCommand {
|
|||||||
Destination d = Destination.parseDestination(args[0]);
|
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
|
// TODO: I'd like to find a way to do these next bits inside Destination, so we're always valid --FF
|
||||||
// TODO: Support portals, but I didn't see the portals list --FF
|
// TODO: Support portals, but I didn't see the portals list --FF
|
||||||
if (this.plugin.worlds.containsKey(d.getName().toLowerCase())) {
|
if (this.plugin.worlds.containsKey(d.getName())) {
|
||||||
if (d.getType() == DestinationType.World) {
|
if (d.getType() == DestinationType.World) {
|
||||||
Location l = playerTeleporter.getSafeDestination(plugin.getServer().getWorld(d.getName()).getSpawnLocation());
|
Location l = playerTeleporter.getSafeDestination(plugin.getServer().getWorld(d.getName()).getSpawnLocation());
|
||||||
p.teleport(l);
|
p.teleport(l);
|
||||||
|
Loading…
Reference in New Issue
Block a user