mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
Fix help not showing for invalid commands
This commit is contained in:
parent
8cb421b27a
commit
3651972901
@ -9,6 +9,7 @@ import java.util.Set;
|
|||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.World.Environment;
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
@ -524,4 +525,29 @@ public class MultiverseCore extends JavaPlugin {
|
|||||||
public String getTag() {
|
public String getTag() {
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* This code should get moved somewhere more appropriate, but for now, it's here.
|
||||||
|
* @param env
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Environment getEnvFromString(String env, CommandSender sender) {
|
||||||
|
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
|
||||||
|
if (env.equalsIgnoreCase("HELL") || env.equalsIgnoreCase("NETHER"))
|
||||||
|
env = "NETHER";
|
||||||
|
|
||||||
|
if (env.equalsIgnoreCase("SKYLANDS") || env.equalsIgnoreCase("SKYLAND") || env.equalsIgnoreCase("STARWARS"))
|
||||||
|
env = "SKYLANDS";
|
||||||
|
|
||||||
|
if (env.equalsIgnoreCase("NORMAL") || env.equalsIgnoreCase("WORLD"))
|
||||||
|
env = "NORMAL";
|
||||||
|
|
||||||
|
try {
|
||||||
|
environment = Environment.valueOf(env);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Environment type " + env + " does not exist!");
|
||||||
|
// TODO: Show the player the mvenvironments command.
|
||||||
|
}
|
||||||
|
return environment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,12 @@ import org.bukkit.command.CommandSender;
|
|||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
protected List<BaseCommand> commands;
|
protected List<BaseCommand> commands;
|
||||||
private CommandSender sender;
|
|
||||||
|
|
||||||
public CommandManager() {
|
public CommandManager() {
|
||||||
commands = new ArrayList<BaseCommand>();
|
commands = new ArrayList<BaseCommand>();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
BaseCommand match = null;
|
BaseCommand match = null;
|
||||||
String[] trimmedArgs = null;
|
String[] trimmedArgs = null;
|
||||||
@ -34,9 +32,12 @@ public class CommandManager {
|
|||||||
for (BaseCommand cmd : commands) {
|
for (BaseCommand cmd : commands) {
|
||||||
StringBuilder tmpIdentifier = new StringBuilder();
|
StringBuilder tmpIdentifier = new StringBuilder();
|
||||||
String[] tmpArgs = parseAllQuotedStrings(args);
|
String[] tmpArgs = parseAllQuotedStrings(args);
|
||||||
if(cmd.validate(label, tmpArgs, tmpIdentifier) && tmpIdentifier.length() > identifier.length()) {
|
if (match == null) {
|
||||||
|
match = cmd.matchIdentifier(label) == null ? null : cmd;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match != null && cmd.validate(label, tmpArgs, tmpIdentifier) && tmpIdentifier.length() > identifier.length()) {
|
||||||
identifier = tmpIdentifier;
|
identifier = tmpIdentifier;
|
||||||
match = cmd;
|
|
||||||
trimmedArgs = tmpArgs;
|
trimmedArgs = tmpArgs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,8 +66,10 @@ public class CommandManager {
|
|||||||
public List<BaseCommand> getCommands() {
|
public List<BaseCommand> getCommands() {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Combines all quoted strings
|
* Combines all quoted strings
|
||||||
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -94,8 +97,8 @@ public class CommandManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the string was ended but had an open quote...
|
// If the string was ended but had an open quote...
|
||||||
if(start != -1) {
|
if (start != -1) {
|
||||||
//... then we want to close that quote and make that one arg.
|
// ... then we want to close that quote and make that one arg.
|
||||||
newArgs.add(parseQuotedString(args, start, args.length));
|
newArgs.add(parseQuotedString(args, start, args.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,19 +40,6 @@ public class CreateCommand extends BaseCommand {
|
|||||||
seed = args[2];
|
seed = args[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage("Stuff I found:");
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "worldName" + ChatColor.WHITE + worldName);
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "env " + ChatColor.WHITE + env);
|
|
||||||
sender.sendMessage(ChatColor.GREEN + "seed " + ChatColor.WHITE + seed);
|
|
||||||
// This is unreachable code, will remove next commit
|
|
||||||
// if (args.length < 2) {
|
|
||||||
// sender.sendMessage("Not enough parameters to create a new world");
|
|
||||||
// sender.sendMessage(ChatColor.RED + "/mvcreate {WORLDNAME} {ENVIRONMENT} - Create a new World.");
|
|
||||||
// sender.sendMessage(ChatColor.RED + "Example - /mvcreate world NORMAL");
|
|
||||||
// sender.sendMessage(ChatColor.RED + "Example - /mvcreate airworld SKYLANDS");
|
|
||||||
// sender.sendMessage(ChatColor.RED + "Example - /mvcreate hellworld NETHER");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
if (new File(worldName).exists() || this.plugin.worlds.containsKey(worldName)) {
|
if (new File(worldName).exists() || this.plugin.worlds.containsKey(worldName)) {
|
||||||
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
|
sender.sendMessage(ChatColor.RED + "A Folder/World already exists with this name!");
|
||||||
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
|
sender.sendMessage(ChatColor.RED + "If you are confident it is a world you can import with /mvimport");
|
||||||
@ -85,19 +72,5 @@ public class CreateCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Takes a string array and returns a combined string, excluding the stop position, including the start
|
|
||||||
*
|
|
||||||
* @param args
|
|
||||||
* @param start
|
|
||||||
* @param stop
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private String parseQuotedString(String[] args, int start, int stop) {
|
|
||||||
String returnVal = args[start];
|
|
||||||
for (int i = start + 1; i < stop; i++) {
|
|
||||||
returnVal += " " + args[i];
|
|
||||||
}
|
|
||||||
return returnVal.replace("\"", "");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package com.onarandombox.MultiverseCore.command.commands;
|
package com.onarandombox.MultiverseCore.command.commands;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.World.Environment;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
import com.onarandombox.MultiverseCore.MVCommandHandler;
|
|
||||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||||
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
import com.onarandombox.MultiverseCore.command.BaseCommand;
|
||||||
|
|
||||||
@ -21,8 +23,22 @@ public class ImportCommand extends BaseCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender sender, String[] args) {
|
public void execute(CommandSender sender, String[] args) {
|
||||||
// TODO Auto-generated method stub
|
String worldName = args[0];
|
||||||
|
if (this.plugin.worlds.containsKey(worldName) && new File(worldName).exists()) {
|
||||||
|
sender.sendMessage(ChatColor.RED + "Multiverse already knows about this world!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Environment env = plugin.getEnvFromString(args[1], sender);
|
||||||
|
|
||||||
|
// TODO: What if the folder does not exist but MV knows about the world?
|
||||||
|
|
||||||
|
if (new File(worldName).exists() && env != null) {
|
||||||
|
sender.sendMessage(ChatColor.AQUA + "Starting world import...");
|
||||||
|
plugin.addWorld(worldName, env);
|
||||||
|
sender.sendMessage(ChatColor.GREEN + "Complete!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user