Move MVTP and MVList to proper command style

Add Destination which allows easier parsing of World/Portals. This currently has NO regex check, but it can be added here for easy control over portal/world naming conventions
This commit is contained in:
Eric Stokes 2011-06-02 09:45:42 -04:00
parent 2a991a3e7d
commit 116b661b84
11 changed files with 155 additions and 72 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
.project
bin/
.DS_Store
.settings

View File

@ -1,6 +1,7 @@
package com.onarandombox.MultiverseCore;
import java.util.ArrayList;
import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.Material;
@ -15,7 +16,7 @@ public class MVTeleport {
MultiverseCore plugin;
BlockSafety bs = new BlockSafety();
private static final Logger log = Logger.getLogger("Minecraft");
public MVTeleport(MultiverseCore plugin) {
this.plugin = plugin;
}
@ -105,11 +106,11 @@ public class MVTeleport {
}
if (aux == -1) {
// MultiverseCore.debugMsg("Uh oh, no safe location.");
log.warning("Uh oh, no safe location.");
return null;
}
// MultiverseCore.debugMsg("Target location (safe): " + x + ", " + aux + ", " + z);
log.info("Target location (safe): " + x + ", " + aux + ", " + z);
return new Location(w, x, aux, z);
}

View File

@ -44,17 +44,17 @@ import com.nijikokun.bukkit.Permissions.Permissions;
import com.onarandombox.MultiverseCore.command.CommandManager;
import com.onarandombox.MultiverseCore.command.commands.CoordCommand;
import com.onarandombox.MultiverseCore.command.commands.HelpCommand;
import com.onarandombox.MultiverseCore.command.commands.ListCommand;
import com.onarandombox.MultiverseCore.command.commands.WhoCommand;
import com.onarandombox.MultiverseCore.command.commands.TeleportCommand;
import com.onarandombox.MultiverseCore.commands.MVCoord;
import com.onarandombox.MultiverseCore.commands.MVCreate;
import com.onarandombox.MultiverseCore.commands.MVImport;
import com.onarandombox.MultiverseCore.commands.MVList;
import com.onarandombox.MultiverseCore.commands.MVModify;
import com.onarandombox.MultiverseCore.commands.MVReload;
import com.onarandombox.MultiverseCore.commands.MVRemove;
import com.onarandombox.MultiverseCore.commands.MVSetSpawn;
import com.onarandombox.MultiverseCore.commands.MVSpawn;
import com.onarandombox.MultiverseCore.commands.MVTP;
import com.onarandombox.MultiverseCore.commands.MVWho;
import com.onarandombox.MultiverseCore.configuration.DefaultConfiguration;
import com.onarandombox.utils.DebugLog;
import com.onarandombox.utils.Messaging;
@ -292,6 +292,9 @@ public class MultiverseCore extends JavaPlugin {
// Page 1
commandManager.addCommand(new HelpCommand(this));
commandManager.addCommand(new CoordCommand(this));
commandManager.addCommand(new TeleportCommand(this));
commandManager.addCommand(new ListCommand(this));
commandManager.addCommand(new WhoCommand(this));
}
/**
@ -302,12 +305,12 @@ public class MultiverseCore extends JavaPlugin {
commands.put("mvimport", new MVImport(this));
commands.put("mvremove", new MVRemove(this));
commands.put("mvmodify", new MVModify(this));
commands.put("mvtp", new MVTP(this));
commands.put("mvlist", new MVList(this));
// commands.put("mvtp", new TeleportCommand(this));
// commands.put("mvlist", new ListCommand(this));
commands.put("mvsetspawn", new MVSetSpawn(this));
commands.put("mvspawn", new MVSpawn(this));
commands.put("mvcoord", new MVCoord(this));
commands.put("mvwho", new MVWho(this));
// commands.put("mvwho", new WhoCommand(this));
commands.put("mvreload", new MVReload(this));
}

View File

@ -48,9 +48,9 @@ public class CommandManager {
match.execute(sender, trimmedArgs);
return true;
} else {
sender.sendMessage("§cCommand: " + ChatColor.WHITE + match.getName());
sender.sendMessage("§cDescription: " + ChatColor.WHITE + match.getDescription());
sender.sendMessage("§cUsage: " + ChatColor.WHITE + match.getUsage());
sender.sendMessage(ChatColor.AQUA + "Command: " + ChatColor.WHITE + match.getName());
sender.sendMessage(ChatColor.AQUA + "Description: " + ChatColor.WHITE + match.getDescription());
sender.sendMessage(ChatColor.AQUA + "Usage: " + ChatColor.WHITE + match.getUsage());
}
}
return true;

View File

@ -27,12 +27,13 @@ public class CoordCommand extends BaseCommand {
public void execute(CommandSender sender, String[] args) {
// Check if the command was sent from a Player.
if (sender instanceof Player) {
Player p = (Player) sender;
// If this command was sent from a Player then we need to check Permissions
if (!(plugin.ph.has(((Player) sender), "multiverse.coord"))) {
if (!(plugin.ph.has((p), "multiverse.coord"))) {
sender.sendMessage("You do not have access to this command.");
return;
}
Player p = (Player) sender;
p.sendMessage(ChatColor.RED + "World: " + ChatColor.WHITE + p.getWorld().getName());
p.sendMessage(ChatColor.RED + "Compression: " + ChatColor.WHITE + plugin.worlds.get(p.getWorld().getName()).compression);

View File

@ -10,6 +10,7 @@ package com.onarandombox.MultiverseCore.command.commands;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import com.onarandombox.MultiverseCore.MultiverseCore;
@ -22,7 +23,7 @@ public class HelpCommand extends BaseCommand {
super(plugin);
name = "Help";
description = "Displays the help menu";
usage = "§e/mv help §8[page#]";
usage = ChatColor.AQUA + "/mv help " + ChatColor.GOLD + "[page#]";
minArgs = 0;
maxArgs = 1;
identifiers.add("mv help");
@ -49,7 +50,7 @@ public class HelpCommand extends BaseCommand {
if (page >= numPages || page < 0) {
page = 0;
}
sender.sendMessage("§c-----[ " + "§f" + plugin.getTag().replace("[", "").replace("]", "") + " Help <" + (page + 1) + "/" + numPages + ">§c ]-----");
sender.sendMessage(ChatColor.GREEN + "-----[ " + ChatColor.WHITE + plugin.getTag().replace("[", "").replace("]", "") + " Help <" + (page + 1) + "/" + numPages + ">" + ChatColor.GREEN + " ]-----");
int start = page * CMDS_PER_PAGE;
int end = start + CMDS_PER_PAGE;
if (end > commands.size()) {
@ -57,10 +58,10 @@ public class HelpCommand extends BaseCommand {
}
for (int c = start; c < end; c++) {
BaseCommand cmd = commands.get(c);
sender.sendMessage(" §a" + cmd.getUsage());
sender.sendMessage(ChatColor.AQUA + " " + cmd.getUsage());
}
sender.sendMessage("§cFor more info on a particular command, type '/<command> ?'");
sender.sendMessage(ChatColor.GREEN + "For more info on a particular command, type '/<command> ?'");
}
}

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.command.commands;
import org.bukkit.ChatColor;
import org.bukkit.World;
@ -6,23 +6,29 @@ import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.onarandombox.MultiverseCore.MVCommandHandler;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.command.BaseCommand;
public class MVList extends MVCommandHandler {
public class ListCommand extends BaseCommand {
public MVList(MultiverseCore plugin) {
public ListCommand(MultiverseCore plugin) {
super(plugin);
name = "World Listing";
description = "Returns all valid worlds";
usage = "/mvlist";
minArgs = 0;
maxArgs = 0;
identifiers.add("mvlist");
}
@Override
public boolean perform(CommandSender sender, String[] args) {
public void execute(CommandSender sender, String[] args) {
Player p = null;
if (sender instanceof Player) {
p = (Player) sender;
if (!(plugin.ph.has(p, "multiverse.world.list"))) {
sender.sendMessage("You do not have access to this command.");
return true;
return;
}
}
@ -40,10 +46,13 @@ public class MVList extends MVCommandHandler {
ChatColor color;
if (world.getEnvironment() == Environment.NETHER)
if (world.getEnvironment() == Environment.NETHER) {
color = ChatColor.RED;
else
} else if(world.getEnvironment() == Environment.SKYLANDS) {
color = ChatColor.AQUA;
} else {
color = ChatColor.GREEN;
}
output += color + world.getName() + " - " + world.getEnvironment().toString() + " \n";
@ -52,6 +61,5 @@ public class MVList extends MVCommandHandler {
for (String msg : response) {
sender.sendMessage(msg);
}
return true;
}
}

View File

@ -0,0 +1,39 @@
package com.onarandombox.MultiverseCore.command.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.command.BaseCommand;
public class TeleportCommand extends BaseCommand {
public TeleportCommand(MultiverseCore plugin) {
super(plugin);
name = "Teleport";
description = "Teleports you to a different world.";
usage = "/mvcoord" + ChatColor.RED + "{WORLD}";
minArgs = 1;
maxArgs = 1;
identifiers.add("mvtp");
}
@Override
public void execute(CommandSender sender, String[] args) {
// Check if the command was sent from a Player.
if(sender instanceof Player) {
Player p = (Player) sender;
// If this command was sent from a Player then we need to check Permissions
if (!(plugin.ph.has((p), "multiverse.tp"))) {
sender.sendMessage("You do not have access to this command.");
return;
}
} else {
sender.sendMessage("This command needs to be used from a Player.");
}
}
}

View File

@ -1,4 +1,4 @@
package com.onarandombox.MultiverseCore.commands;
package com.onarandombox.MultiverseCore.command.commands;
import java.util.ArrayList;
import java.util.List;
@ -9,30 +9,36 @@ import org.bukkit.World.Environment;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.onarandombox.MultiverseCore.MVCommandHandler;
import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.command.BaseCommand;
public class MVWho extends MVCommandHandler {
public class WhoCommand extends BaseCommand {
public MVWho(MultiverseCore plugin) {
public WhoCommand(MultiverseCore plugin) {
super(plugin);
name = "Who";
description = "States who is in what world";
usage = "/mvwho [WORLD]";
minArgs = 0;
maxArgs = 1;
identifiers.add("mvwho");
}
@Override
public boolean perform(CommandSender sender, String[] args) {
public void execute(CommandSender sender, String[] args) {
// If this command was sent from a Player then we need to check Permissions
if (sender instanceof Player) {
if (!(plugin.ph.has(((Player) sender), "multiverse.who"))) {
sender.sendMessage("You do not have access to this command.");
return true;
return;
}
}
List<World> worlds = new ArrayList<World>();
if (args.length > 1) {
return false;
}
// No longer needed
// if (args.length > 1) {
// return false;
// }
if (args.length > 0) {
World world = plugin.getServer().getWorld(args[0].toString());
@ -40,7 +46,7 @@ public class MVWho extends MVCommandHandler {
worlds.add(world);
} else {
sender.sendMessage(ChatColor.RED + "World does not exist");
return true;
return;
}
} else {
worlds = plugin.getServer().getWorlds();
@ -65,7 +71,7 @@ public class MVWho extends MVCommandHandler {
}
sender.sendMessage(color + world.getName() + ChatColor.WHITE + " - " + result);
}
return true;
return;
}
}

View File

@ -1,21 +0,0 @@
package com.onarandombox.MultiverseCore.commands;
import org.bukkit.command.CommandSender;
import com.onarandombox.MultiverseCore.MVCommandHandler;
import com.onarandombox.MultiverseCore.MultiverseCore;
public class MVTP extends MVCommandHandler {
public MVTP(MultiverseCore plugin) {
super(plugin);
// TODO Auto-generated constructor stub
}
@Override
public boolean perform(CommandSender sender, String[] args) {
// TODO Auto-generated method stub
return false;
}
}

View File

@ -0,0 +1,44 @@
package com.onarandombox.utils;
enum DestinationType {
World, Portal, Invalid
}
public class Destination {
private String name;
private DestinationType type;
public Destination(String name, DestinationType type) {
this.name = name;
this.type = type;
}
public String getName() {
return name;
}
public DestinationType getType() {
return type;
}
private static Destination getBadDestination() {
return new Destination("", DestinationType.Invalid);
}
public static Destination parseDestination(String dest) {
if (dest == null) {
return getBadDestination();
}
String[] items = dest.split(":");
if (items.length != 2) {
return getBadDestination();
}
if (items[0].equalsIgnoreCase("w")) {
return new Destination(items[1], DestinationType.World);
} else if (items[0].equalsIgnoreCase("p")) {
return new Destination(items[1], DestinationType.Portal);
}
return getBadDestination();
}
}