Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.LinkedHashMap;
- import java.util.logging.Logger;
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- public class PlayerCommands {
- private static final Logger log = Logger.getLogger("Minecraft");
- private static PlayerCommands instance;
- private final LinkedHashMap<String, BaseCommand> commands = new LinkedHashMap<String, BaseCommand>();
- private static List<String> onlyOneUseKits = new ArrayList<String>();
- public PlayerCommands() {
- add("/help", help);
- add("/playerlist", playerlist);
- add("/who", playerlist);
- add("/banlist", banList);
- add("/banip", banip);
- add("/unbanip", unbanip);
- add("/ban", ban);
- add("/unban", unban);
- add("/mute", mute);
- add("/tp", tp);
- add("/tphere", tphere);
- add("/s", tphere);
- add("/kick", kick);
- add("/item", item);
- add("/i", item);
- add("/give", item);
- add("/cloth", cloth);
- add("/dye", cloth);
- add("/kit", kit);
- add("/listwarps", listwarps);
- add("/home", home);
- add("/sethome", sethome);
- add("/setspawn", setspawn);
- add("/me", me);
- add("/msg", msg);
- add("/tell", msg);
- add("/m", msg);
- add("/spawn", spawn);
- add("/warp", warp);
- add("/setwarp", setwarp);
- add("/removewarp", removewarp);
- add("/getpos", getpos);
- add("/compass", compass);
- add("/time", time);
- add("/lighter", lighter);
- add("/motd", motd);
- add("/clearinventory", clearInventory);
- add("/update", update);
- add("/#", serverCommand);
- add("/spawnmob", spawnmob);
- add("/mspawn", mobSpawner);
- }
- /**
- * Add a command to the player list.
- *
- * @param name
- * @param cmd
- */
- public void add(String name, BaseCommand cmd) {
- if (name != null && cmd != null)
- add(name, cmd);
- }
- /**
- * Remove a command from the server list.
- *
- * @param name
- */
- public void remove(String name) {
- if (name != null) {
- etc.getInstance().removeCommand(name);
- commands.remove(name);
- }
- }
- /**
- * Performs a lookup for a command of the given name and executes it if
- * found. Returns false if command not found.
- *
- * @param command
- * @param player
- * @param parameters
- * @return
- */
- public static boolean parseCommand(MessageReceiver caller, String command, String[] args) {
- if (instance == null)
- instance = new PlayerCommands();
- BaseCommand cmd = instance.getCommand(command);
- if (cmd != null) {
- cmd.parseCommand(caller, args);
- // Inform caller a matching command was found.
- return true;
- }
- return false;
- }
- public LinkedHashMap<String, BaseCommand> getCommands(String command) {
- return commands.get(command);
- }
- public static final BaseCommand help = new BaseCommand("[Page] - Shows a list of commands. 7 per page.") {
- @Override
- void execute (MessageReceiver caller, String[] parameters) {
- List<String> availableCommands = new ArrayList<String>();
- for (Entry<String, String> entry : PlayerCommands.getCommands().entrySet())
- if (etc.getServer().getPlayer(caller.getName()).canUseCommand(entry.getKey())) {
- if (entry.getKey().equals("/kit") && !etc.getDataSource().hasKits())
- continue;
- if (entry.getKey().equals("/listwarps") && !etc.getDataSource().hasWarps())
- continue;
- availableCommands.add(entry.getKey() + " " + entry.getValue());
- }
- caller.notify(Colors.Blue + "Available commands (Page " + (parameters.length == 2 ? parameters[1] : "1") + " of " + (int) Math.ceil((double) availableCommands.size() / (double) 7) + ") [] = required <> = optional:");
- if (parameters.length == 2)
- try {
- int amount = Integer.parseInt(parameters[1]);
- if (amount > 0)
- amount = (amount - 1) * 7;
- else
- amount = 0;
- for (int i = amount; i < amount + 7; i++)
- if (availableCommands.size() > i)
- caller.notify(Colors.Rose + availableCommands.get(i));
- } catch (NumberFormatException ex) {
- caller.notify(Colors.Rose + "Not a valid page number.");
- }
- else
- for (int i = 0; i < 7; i++)
- if (availableCommands.size() > i)
- caller.notify(Colors.Rose + availableCommands.get(i));
- }
- };
- public static final BaseCommand mute = new BaseCommand("[Player] - Toggles mute on player.") {
- @Override
- void execute(MessageReceiver caller, String[] parameters){
- if (parameters.length != 2) {
- caller.notify(Colors.Rose + "Correct usage is: /mute [player]");
- return;
- }
- Player player = etc.getServer().matchPlayer(parameters[1]);
- if (player != null) {
- if (player.toggleMute())
- caller.notify(Colors.Rose + "player was muted");
- else
- caller.notify(Colors.Rose + "player was unmuted");
- } else
- caller.notify(Colors.Rose + "Can't find player " + parameters[1]);
- }
- };
- public static final BaseCommand msg = new BaseCommand("[Player] [Message] - Sends a message to player") {
- @Override
- void execute(MessageReceiver caller, String[] parameters) {
- if (parameters.length < 3) {
- caller.notify(Colors.Rose + "Correct usage is: /msg [player] [message]");
- return;
- }
- if (etc.getServer().getPlayer(caller.getName()).isMuted()) {
- caller.notify(Colors.Rose + "You are currently muted.");
- return;
- }
- Player player = etc.getServer().matchPlayer(parameters[1]);
- if (player != null) {
- if (player.getName().equals(caller.getName())) {
- caller.notify(Colors.Rose + "You can't message yourself!");
- return;
- }
- player.sendMessage("(MSG) " + etc.getServer().getPlayer(caller.getName()).getColor() + "<" + etc.getServer().getPlayer(caller.getName()) + "> " + Colors.White + etc.combineSplit(2, parameters, " "));
- caller.notify("(MSG) " + etc.getServer().getPlayer(caller.getName()).getColor() + "<" + etc.getServer().getPlayer(caller.getName()) + "> " + Colors.White + etc.combineSplit(2, parameters, " "));
- } else
- caller.notify(Colors.Rose + "Couldn't find player " + parameters[1]);
- }
- };
- public static final BaseCommand kit = new BaseCommand ("[Kit] - Gives a kit. To get a list of kits type /kit") {
- @Override
- void execute(MessageReceiver caller, String[] parameters) {
- if (etc.getDataSource().hasKits()) {
- if (parameters.length != 2 && parameters.length != 3) {
- caller.notify(Colors.Rose + "Available kits" + Colors.White + ": " + etc.getDataSource().getKitNames(etc.getServer().getPlayer(caller.getName())));
- return;
- }
- Player toGive = etc.getServer().getPlayer(caller.getName());
- if (parameters.length > 2 && etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- toGive = etc.getServer().matchPlayer(parameters[2]);
- Kit kit = etc.getDataSource().getKit(parameters[1]);
- if (toGive != null) {
- if (kit != null) {
- if (!etc.getServer().getPlayer(caller.getName()).isInGroup(kit.Group) && !kit.Group.equals(""))
- caller.notify(Colors.Rose + "That kit does not exist.");
- else if (onlyOneUseKits.contains(kit.Name))
- caller.notify(Colors.Rose + "You can only get this kit once per login.");
- else if (etc.getMCServer().b.containsKey(etc.getServer().getPlayer(caller.getName()).getName() + " " + kit.Name))
- caller.notify(Colors.Rose + "You can't get this kit again for a while.");
- else {
- if (!etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- if (kit.Delay >= 0)
- etc.getMCServer().b.put(etc.getServer().getPlayer(caller.getName()).getName() + " " + kit.Name, kit.Delay);
- else
- onlyOneUseKits.add(kit.Name);
- log.info(etc.getServer().getPlayer(caller.getName()).getName() + " got a kit!");
- toGive.notify(Colors.Rose + "Enjoy this kit!");
- for (Map.Entry<String, Integer> entry : kit.IDs.entrySet())
- try {
- int itemId = 0;
- try {
- itemId = Integer.parseInt(entry.getKey());
- } catch (NumberFormatException n) {
- itemId = etc.getDataSource().getItem(entry.getKey());
- }
- toGive.giveItem(itemId, kit.IDs.get(entry.getKey()));
- } catch (Exception e1) {
- log.info("Got an exception while giving out a kit (Kit name \"" + kit.Name + "\"). Are you sure all the Ids are numbers?");
- caller.notify(Colors.Rose + "The server encountered a problem while giving the kit :(");
- }
- }
- } else
- caller.notify(Colors.Rose + "That kit does not exist.");
- } else
- caller.notify(Colors.Rose + "That user does not exist.");
- }
- }
- };
- public static final BaseCommand tp = new BaseCommand("Correct usage is: /tp [player]") {
- @Override
- void execute(MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- caller.notify(Colors.Rose + "Correct usage is: /tp [player]");
- return;
- }
- Player player = etc.getServer().matchPlayer(parameters[1]);
- if (player != null) {
- if (caller.getName().equalsIgnoreCase(player.getName())) {
- caller.notify(Colors.Rose + "You're already here!");
- return;
- }
- log.info(caller.getName() + " teleported to " + player.getName());
- etc.getServer().getPlayer(caller.getName()).teleportTo(player);
- } else
- caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
- }
- };
- public static final BaseCommand tphere = new BaseCommand("Correct usage is: /tphere [player]") {
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- caller.notify(Colors.Rose + "Correct usage is: /tphere [player]");
- return;
- }
- Player player = etc.getServer().matchPlayer(parameters[1]);
- if (player != null) {
- if (caller.getName().equalsIgnoreCase(player.getName())) {
- caller.notify(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
- return;
- }
- log.info(caller.getName() + " teleported " + player.getName() + " to their self.");
- player.teleportTo(etc.getServer().getPlayer(caller.getName()));
- } else
- caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
- }
- };
- public static final BaseCommand playerlist = new BaseCommand("- Shows a list of players"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- caller.notify(Colors.Rose + "Player list (" + etc.getMCServer().f.b.size() + "/" + etc.getInstance().getPlayerLimit() + "): " + Colors.White + etc.getMCServer().f.c());
- }
- };
- public static final BaseCommand item = new BaseCommand("[ID] <Amount> <Damage> <Player> - Gives items") {
- @Override
- public void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- caller.notify(Colors.Rose + "Correct usage is: /item [itemid] <amount> <damage> <player> (optional)");
- else
- caller.notify(Colors.Rose + "Correct usage is: /item [itemid] <amount> <damage>");
- return;
- }
- Player toGive = etc.getServer().getPlayer(caller.getName());
- int itemId = 0, amount = 1, damage = 0;
- try {
- if (parameters.length > 1)
- try {
- itemId = Integer.parseInt(parameters[1]);
- } catch (NumberFormatException n) {
- itemId = etc.getDataSource().getItem(parameters[1]);
- }
- if (parameters.length > 2) {
- amount = Integer.parseInt(parameters[2]);
- if (amount <= 0 && !etc.getServer().getPlayer(caller.getName()).isAdmin())
- amount = 1;
- if (amount > 64 && !etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- amount = 64;
- if (amount > 1024)
- amount = 1024; // 16 stacks worth. More than enough.
- }
- if (parameters.length == 4) {
- int temp = -1;
- try {
- temp = Integer.parseInt(parameters[3]);
- } catch (NumberFormatException n) {
- if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- toGive = etc.getServer().matchPlayer(parameters[3]);
- }
- if (temp > -1 && temp < 50)
- damage = temp;
- } else if (parameters.length == 5) {
- damage = Integer.parseInt(parameters[3]);
- if (damage < 0 && damage > 49)
- damage = 0;
- if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- toGive = etc.getServer().matchPlayer(parameters[4]);
- }
- } catch (NumberFormatException localNumberFormatException) {
- caller.notify(Colors.Rose + "Improper ID and/or amount.");
- return;
- }
- if (toGive != null) {
- boolean allowedItem = etc.getInstance().getAllowedItems().isEmpty() || etc.getInstance().getAllowedItems().contains(itemId);
- if (!etc.getInstance().getDisallowedItems().isEmpty() && etc.getInstance().getDisallowedItems().contains(itemId))
- allowedItem = false;
- if (Item.isValidItem(itemId)) {
- if (allowedItem || etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions()) {
- Item i = new Item(itemId, amount, -1, damage);
- log.info("Giving " + toGive.getName() + " some " + i.toString());
- // toGive.giveItem(itemId, amount);
- Inventory inv = toGive.getInventory();
- ArrayList<Item> list = new ArrayList<Item>();
- for (Item it : inv.getContents())
- if (it != null && it.getItemId() == i.getItemId() && it.getDamage() == i.getDamage())
- list.add(it);
- for (Item it : list) {
- if (it.getAmount() < 64) {
- if (amount >= 64 - it.getAmount()) {
- amount -= 64 - it.getAmount();
- it.setAmount(64);
- toGive.giveItem(it);
- } else {
- it.setAmount(it.getAmount() + amount);
- amount = 0;
- toGive.giveItem(it);
- }
- }
- }
- if (amount != 0) {
- i.setAmount(64);
- while (amount > 64) {
- amount -= 64;
- toGive.giveItem(i);
- i.setSlot(-1);
- }
- i.setAmount(amount);
- toGive.giveItem(i);
- }
- if (toGive.getName().equalsIgnoreCase(caller.getName()))
- caller.notify(Colors.Rose + "There you go " + caller.getName() + ".");
- else {
- caller.notify(Colors.Rose + "Gift given! :D");
- toGive.sendMessage(Colors.Rose + "Enjoy your gift! :D");
- }
- } else if (!allowedItem && !etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- caller.notify(Colors.Rose + "You are not allowed to spawn that item.");
- } else
- caller.notify(Colors.Rose + "No item with ID " + parameters[1]);
- } else
- caller.notify(Colors.Rose + "Can't find user " + parameters[3]);
- }
- };
- public final static BaseCommand cloth = new BaseCommand("[Amount] [Color] - Gives cloth"){
- @Override
- public void execute(MessageReceiver caller, String[] parameters){
- if (parameters.length < 3) {
- caller.notify(Colors.Rose + "Correct usage is: " + parameters[0] + " [amount] [color]");
- return;
- }
- try {
- int amount = Integer.parseInt(parameters[1]);
- if (amount <= 0 && !etc.getServer().getPlayer(caller.getName()).isAdmin())
- amount = 1;
- if (amount > 64 && !etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- amount = 64;
- if (amount > 1024)
- amount = 1024; // 16 stacks worth. More than enough.
- String color = parameters[2];
- if (parameters.length > 3)
- color += " " + parameters[3];
- Cloth.Color c = Cloth.Color.getColor(color.toLowerCase());
- if (c == null) {
- caller.notify(Colors.Rose + "Invalid color name!");
- return;
- }
- Item i = c.getItem();
- if (parameters[0].equalsIgnoreCase("/dye")) {
- i.setType(Item.Type.InkSack);
- // some1 had fun inverting this i guess .....
- i.setDamage(15 - i.getDamage());
- }
- i.setAmount(amount);
- log.info("Giving " + caller.getName() + " some " + i.toString());
- Inventory inv = etc.getServer().getPlayer(caller.getName()).getInventory();
- ArrayList<Item> list = new ArrayList<Item>();
- for (Item it : inv.getContents())
- if (it != null && it.getItemId() == i.getItemId() && it.getDamage() == i.getDamage())
- list.add(it);
- for (Item it : list) {
- if (it.getAmount() < 64) {
- if (amount >= 64 - it.getAmount()) {
- amount -= 64 - it.getAmount();
- it.setAmount(64);
- etc.getServer().getPlayer(caller.getName()).giveItem(it);
- } else {
- it.setAmount(it.getAmount() + amount);
- amount = 0;
- etc.getServer().getPlayer(caller.getName()).giveItem(it);
- }
- }
- }
- if (amount != 0) {
- i.setAmount(64);
- while (amount > 64) {
- amount -= 64;
- etc.getServer().getPlayer(caller.getName()).giveItem(i);
- i.setSlot(-1);
- }
- i.setAmount(amount);
- etc.getServer().getPlayer(caller.getName()).giveItem(i);
- }
- caller.notify(Colors.Rose + "There you go " + caller.getName() + ".");
- } catch (NumberFormatException localNumberFormatException) {
- caller.notify(Colors.Rose + "Improper ID and/or amount.");
- }
- }
- };
- public static final BaseCommand banList = new BaseCommand ("<IP or bans> - Gives a list of bans"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- byte type = 0;
- if (parameters.length == 2)
- if (parameters[1].equalsIgnoreCase("ips"))
- type = 1;
- if (type == 0)
- caller.notify(Colors.Blue + "Ban list:" + Colors.White + " " + etc.getMCServer().f.getBans());
- else
- caller.notify(Colors.Blue + "IP Ban list:" + Colors.White + " " + etc.getMCServer().f.getIpBans());
- }
- };
- public static final BaseCommand banip = new BaseCommand("[Player] <Reason> - Bans the player's IP"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- caller.notify(Colors.Rose + "Correct usage is: /banip [player] <reason> (optional) NOTE: this permabans IPs.");
- return;
- }
- Player player = etc.getServer().matchPlayer(parameters[1]);
- if (player != null) {
- if (!etc.getServer().getPlayer(caller.getName()).hasControlOver(player)) {
- caller.notify(Colors.Rose + "You can't ban that user.");
- return;
- }
- // adds player to ban list
- etc.getMCServer().f.c(player.getIP());
- etc.getLoader().callHook(PluginLoader.Hook.IPBAN, new Object[] { etc.getServer().getPlayer(caller.getName()), player, parameters.length >= 3 ? etc.combineSplit(2, parameters, " ") : "" });
- log.info("IP Banning " + player.getName() + " (IP: " + player.getIP() + ")");
- caller.notify(Colors.Rose + "IP Banning " + player.getName() + " (IP: " + player.getIP() + ")");
- if (parameters.length > 2)
- player.kick("IP Banned by " + caller.getName() + ": " + etc.combineSplit(2, parameters, " "));
- else
- player.kick("IP Banned by " + caller.getName() + ".");
- } else
- caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
- }
- };
- public static final BaseCommand ban = new BaseCommand("[Player] <Reason> - Bans the player"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- caller.notify(Colors.Rose + "Correct usage is: /ban [player] <reason> (optional)");
- return;
- }
- Player player = etc.getServer().matchPlayer(parameters[1]);
- if (player != null) {
- if (!etc.getServer().getPlayer(caller.getName()).hasControlOver(player)) {
- caller.notify(Colors.Rose + "You can't ban that user.");
- return;
- }
- // adds player to ban list
- etc.getServer().ban(player.getName());
- etc.getLoader().callHook(PluginLoader.Hook.BAN, new Object[] { this, player, parameters.length >= 3 ? etc.combineSplit(2, parameters, " ") : "" });
- if (parameters.length > 2)
- player.kick("Banned by " + caller.getName() + ": " + etc.combineSplit(2, parameters, " "));
- else
- player.kick("Banned by " + caller.getName() + ".");
- log.info("Banning " + player.getName());
- caller.notify(Colors.Rose + "Banning " + player.getName());
- } else {
- // sendMessage(Colors.Rose + "Can't find user " + parameters[1] +
- // ".");
- etc.getServer().ban(parameters[1]);
- log.info("Banning " + parameters[1]);
- caller.notify(Colors.Rose + "Banning " + parameters[1]);
- }
- }
- };
- public static final BaseCommand unban = new BaseCommand ("[Player] - Unbans the player"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length != 2) {
- caller.notify(Colors.Rose + "Correct usage is: /unban [player]");
- return;
- }
- etc.getServer().unban(parameters[1]);
- caller.notify(Colors.Rose + "Unbanned " + parameters[1]);
- }
- };
- public static final BaseCommand unbanip = new BaseCommand("[IP] - Unbans the IP"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length != 2) {
- caller.notify(Colors.Rose + "Correct usage is: /unbanip [ip]");
- return;
- }
- etc.getMCServer().f.d(parameters[1]);
- caller.notify(Colors.Rose + "Unbanned " + parameters[1]);
- }
- };
- public static final BaseCommand kick = new BaseCommand("[Player] <Reason> - Kicks player"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- caller.notify(Colors.Rose + "Correct usage is: /kick [player] <reason> (optional)");
- return;
- }
- Player player = etc.getServer().matchPlayer(parameters[1]);
- if (player != null) {
- if (!etc.getServer().getPlayer(caller.getName()).hasControlOver(player)){
- caller.notify(Colors.Rose + "You can't kick that user.");
- return;
- }
- etc.getLoader().callHook(PluginLoader.Hook.KICK, new Object[] { this, player, parameters.length >= 3 ? etc.combineSplit(2, parameters, " ") : "" });
- if (parameters.length > 2)
- player.kick("Kicked by " + caller.getName() + ": " + etc.combineSplit(2, parameters, " "));
- else
- player.kick("Kicked by " + caller.getName() + ".");
- log.info("Kicking " + player.getName());
- caller.notify(Colors.Rose + "Kicking " + player.getName());
- } else
- caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
- }
- };
- public static final BaseCommand me = new BaseCommand("[Message] - * CanaryMod says hi!"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (etc.getServer().getPlayer(caller.getName()).isMuted()) {
- caller.notify(Colors.Rose + "You are currently muted.");
- return;
- }
- String command="";
- for (int i = 1; i < parameters.length; i++)
- command = command + parameters[i]+ " ";
- if (parameters.length == 1)
- return;
- String paramString2 = "* " + etc.getServer().getPlayer(caller.getName()).getColor() + caller.getName() + Colors.White + " " + command.substring(command.indexOf(" ")).trim();
- log.info("* " + caller.getName() + " " + command.substring(command.indexOf(" ")).trim());
- etc.getServer().messageAll(paramString2);
- }
- };
- public final static BaseCommand sethome = new BaseCommand ("- Sets your home"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- // player.k, player.l, player.m
- // x, y, z
- Warp home = new Warp();
- home.Location = etc.getServer().getPlayer(caller.getName()).getLocation();
- home.Group = ""; // no group neccessary, lol.
- home.Name = etc.getServer().getPlayer(caller.getName()).getName();
- etc.getInstance().changeHome(home);
- caller.notify(Colors.Rose + "Your home has been set.");
- }
- };
- public final static BaseCommand spawn = new BaseCommand ("- Teleports you to spawn"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- etc.getServer().getPlayer(caller.getName()).teleportTo(etc.getServer().getSpawnLocation());
- }
- };
- public final static BaseCommand setspawn = new BaseCommand ("- Sets the spawn point to your position."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- // New system in beta 1.3: WorldInfo.
- OWorldInfo info = etc.getMCServer().e.s;
- info.a((int) etc.getServer().getPlayer(caller.getName()).getX(), info.d(), (int) etc.getServer().getPlayer(caller.getName()).getZ());
- log.info("Spawn position changed.");
- caller.notify(Colors.Rose + "You have set the spawn to your current position.");
- }
- };
- public final static BaseCommand home = new BaseCommand ("- Teleports you home"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- Warp home = null;
- if (parameters.length > 1 && etc.getServer().getPlayer(caller.getName()).isAdmin())
- home = etc.getDataSource().getHome(parameters[1]);
- else
- home = etc.getDataSource().getHome(caller.getName());
- if (home != null)
- etc.getServer().getPlayer(caller.getName()).teleportTo(home.Location);
- else if (parameters.length > 1 && etc.getServer().getPlayer(caller.getName()).isAdmin())
- caller.notify(Colors.Rose + "That player home does not exist");
- else
- etc.getServer().getPlayer(caller.getName()).teleportTo(etc.getServer().getSpawnLocation());
- }
- };
- public static final BaseCommand warp = new BaseCommand ("[Warp] - Warps to the specified warp."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- caller.notify(Colors.Rose + "Correct usage is: /warp [warpname]");
- return;
- }
- Player toWarp = etc.getServer().getPlayer(caller.getName());
- Warp warp = null;
- if (parameters.length == 3 && toWarp.canIgnoreRestrictions()) {
- warp = etc.getDataSource().getWarp(parameters[1]);
- toWarp = etc.getServer().matchPlayer(parameters[2]);
- } else
- warp = etc.getDataSource().getWarp(parameters[1]);
- if (toWarp != null) {
- if (warp != null) {
- if (!toWarp.isInGroup(warp.Group) && !warp.Group.equals(""))
- caller.notify(Colors.Rose + "Warp not found.");
- else {
- toWarp.teleportTo(warp.Location);
- toWarp.sendMessage(Colors.Rose + "Woosh!");
- }
- } else
- caller.notify(Colors.Rose + "Warp not found");
- } else
- caller.notify(Colors.Rose + "Player not found.");
- }
- };
- public static final BaseCommand listwarps = new BaseCommand ("- Gives a list of available warps"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length != 2 && parameters.length != 3) {
- caller.notify(Colors.Rose + "Available warps: " + Colors.White + etc.getDataSource().getWarpNames(etc.getServer().getPlayer(caller.getName())));
- return;
- }
- }
- };
- public static final BaseCommand setwarp = new BaseCommand ("[Warp] - Sets the warp to your current position."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- caller.notify(Colors.Rose + "Correct usage is: /setwarp [warpname] [group]");
- else
- caller.notify(Colors.Rose + "Correct usage is: /setwarp [warpname]");
- return;
- }
- if (parameters[1].contains(":")) {
- caller.notify("You can't set a warp with \":\" in its name");
- return;
- }
- Warp warp = new Warp();
- warp.Name = parameters[1];
- warp.Location = etc.getServer().getPlayer(caller.getName()).getLocation();
- if (parameters.length == 3)
- warp.Group = parameters[2];
- else
- warp.Group = "";
- etc.getInstance().setWarp(warp);
- caller.notify(Colors.Rose + "Created warp point " + parameters[1] + ".");
- }
- };
- public static final BaseCommand removewarp = new BaseCommand ("[Warp] - Removes the specified warp."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length < 2) {
- caller.notify(Colors.Rose + "Correct usage is: /removewarp [warpname]");
- return;
- }
- Warp warp = etc.getDataSource().getWarp(parameters[1]);
- if (warp != null) {
- etc.getDataSource().removeWarp(warp);
- caller.notify(Colors.Blue + "Warp removed.");
- } else
- caller.notify(Colors.Rose + "That warp does not exist");
- }
- };
- public static final BaseCommand lighter = new BaseCommand("- Gives you a lighter for lighting furnaces"){
- @Override
- void execute (MessageReceiver caller, String[] paramaters){
- if (etc.getInstance().getMCServer().b.containsKey(caller.getName() + " lighter")) {
- log.info(caller.getName() + " failed to iron!");
- caller.notify(Colors.Rose + "You can't create another lighter again so soon");
- } else {
- if (!etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
- etc.getInstance().getMCServer().b.put(caller.getName() + " lighter", Integer.valueOf(6000));
- log.info(caller.getName() + " created a lighter!");
- etc.getServer().getPlayer(caller.getName()).giveItem(259, 1);
- }
- }
- };
- public static final BaseCommand serverCommand = new BaseCommand ("- Performs command as Server"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- String command = "";
- for (int i = 1; i < parameters.length; i++)
- command = command + parameters[i] + " ";
- String str = command.substring(2);
- log.info(caller.getName() + " issued server command: " + str);
- }
- };
- public static final BaseCommand time = new BaseCommand ("[time|'day|night|check|raw'] (rawtime) - Changes or checks the time"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length == 2) {
- if (parameters[1].equalsIgnoreCase("day"))
- etc.getServer().setRelativeTime(0);
- else if (parameters[1].equalsIgnoreCase("night"))
- etc.getServer().setRelativeTime(13000);
- else if (parameters[1].equalsIgnoreCase("check"))
- caller.notify(Colors.Rose + "The time is " + etc.getServer().getRelativeTime() + "! (RAW: " + etc.getServer().getTime() + ")");
- else
- try {
- etc.getServer().setRelativeTime(Long.parseLong(parameters[1]));
- } catch (NumberFormatException ex) {
- caller.notify(Colors.Rose + "Please enter numbers, not letters.");
- }
- } else if (parameters.length == 3) {
- if (parameters[1].equalsIgnoreCase("raw"))
- try {
- etc.getServer().setTime(Long.parseLong(parameters[2]));
- } catch (NumberFormatException ex) {
- caller.notify(Colors.Rose + "Please enter numbers, not letters.");
- }
- } else {
- caller.notify(Colors.Rose + "Correct usage is: /time [time|'day|night|check|raw'] (rawtime)");
- return;
- }
- }
- };
- public static final BaseCommand getpos = new BaseCommand ("- Displays your current position."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- caller.notify("Pos X: " + etc.getServer().getPlayer(caller.getName()).getX() + " Y: " + etc.getServer().getPlayer(caller.getName()).getY() + " Z: " + etc.getServer().getPlayer(caller.getName()).getZ());
- caller.notify("Rotation: " + etc.getServer().getPlayer(caller.getName()).getRotation() + " Pitch: " + etc.getServer().getPlayer(caller.getName()).getPitch());
- double degreeRotation = ((etc.getServer().getPlayer(caller.getName()).getRotation() - 90) % 360);
- if (degreeRotation < 0)
- degreeRotation += 360.0;
- caller.notify("Compass: " + etc.getCompassPointForDirection(degreeRotation) + " (" + (Math.round(degreeRotation * 10) / 10.0) + ")");
- }
- };
- public static final BaseCommand compass = new BaseCommand ("- Gives you a compass reading."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- double degreeRotation = ((etc.getServer().getPlayer(caller.getName()).getRotation() - 90) % 360);
- if (degreeRotation < 0)
- degreeRotation += 360.0;
- caller.notify(Colors.Rose + "Compass: " + etc.getCompassPointForDirection(degreeRotation));
- }
- };
- public static final BaseCommand spawnmob = new BaseCommand ("- Spawns the number of specified Mpb"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length == 1) {
- caller.notify(Colors.Rose + "Correct usage is: /spawnmob [name] <amount>");
- return;
- }
- if (!Mob.isValid(parameters[1])) {
- caller.notify(Colors.Rose + "Invalid mob. Name has to start with a capital like so: Pig");
- return;
- }
- if (parameters.length == 2) {
- Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
- mob.spawn();
- } else if (parameters.length == 3)
- try {
- int mobnumber = Integer.parseInt(parameters[2]);
- for (int i = 0; i < mobnumber; i++) {
- Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
- mob.spawn();
- }
- } catch (NumberFormatException nfe) {
- if (!Mob.isValid(parameters[2])) {
- caller.notify(Colors.Rose + "Invalid mob name or number of mobs.");
- caller.notify(Colors.Rose + "Mob names have to start with a capital like so: Pig");
- } else {
- Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
- mob.spawn(new Mob(parameters[2]));
- }
- }
- else if (parameters.length == 4)
- try {
- int mobnumber = Integer.parseInt(parameters[3]);
- if (!Mob.isValid(parameters[2]))
- caller.notify(Colors.Rose + "Invalid rider. Name has to start with a capital like so: Pig");
- else
- for (int i = 0; i < mobnumber; i++) {
- Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
- mob.spawn(new Mob(parameters[2]));
- }
- } catch (NumberFormatException nfe) {
- caller.notify(Colors.Rose + "Invalid number of mobs.");
- }
- }
- };
- public static final BaseCommand clearInventory = new BaseCommand("- Clears your inventory"){
- @Override
- void execute(MessageReceiver caller, String[] parameters){
- Player target = etc.getServer().getPlayer(caller.getName());
- if (parameters.length >= 2 && target.isAdmin())
- target = etc.getServer().matchPlayer(parameters[1]);
- if (target != null) {
- Inventory inv = target.getInventory();
- inv.clearContents();
- inv.update();
- if (!target.getName().equals(caller.getName()))
- caller.notify(Colors.Rose + "Cleared " + target.getName() + "'s inventory.");
- } else
- caller.notify(Colors.Rose + "Target not found");
- }
- };
- public static final BaseCommand mobSpawner = new BaseCommand ("- Changes what mob spawns from a created spawner."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length != 2) {
- caller.notify(Colors.Rose + "You must specify what to change the mob spawner to.");
- return;
- }
- if (!Mob.isValid(parameters[1])) {
- caller.notify(Colors.Rose + "Invalid mob specified.");
- return;
- }
- HitBlox hb = new HitBlox(etc.getServer().getPlayer(caller.getName()));
- Block block = hb.getTargetBlock();
- if (block.getType() == 52) { // mob spawner
- MobSpawner ms = (MobSpawner) etc.getServer().getComplexBlock(block.getX(), block.getY(), block.getZ());
- if (ms != null)
- ms.setSpawn(parameters[1]);
- } else
- caller.notify(Colors.Rose + "You are not targeting a mob spawner.");
- }
- };
- public static final BaseCommand update = new BaseCommand ("- Checks your Canary version versus available online version."){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (Main.onlineVersion == etc.getInstance().getVersion())
- caller.notify(Colors.Rose + "You have the latest version of Canary.");
- else
- caller.notify(Colors.Rose + "You need to update your version of Canary.");
- }
- };
- public static final BaseCommand motd = new BaseCommand ("- Displays the Message of the Day"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- for (String str : etc.getInstance().getMotd())
- caller.notify(str);
- }
- };
- public static final BaseCommand tempban = new BaseCommand ("Placeholder for Tempory banning"){
- @Override
- void execute (MessageReceiver caller, String[] parameters){
- if (parameters.length == 1)
- return;
- int minutes = 0, hours = 0, days = 0;
- if (parameters.length >= 2)
- minutes = Integer.parseInt(parameters[1]);
- if (parameters.length >= 3)
- hours = Integer.parseInt(parameters[2]);
- if (parameters.length >= 4)
- days = Integer.parseInt(parameters[3]);
- Date date = new Date();
- }
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment