SkyeDarkhawk

PlayerCommands.java

May 10th, 2011
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 53.94 KB | None | 0 0
  1. import java.util.LinkedHashMap;
  2. import java.util.logging.Logger;
  3. import java.util.Map;
  4. import java.util.Map.Entry;
  5. import java.util.ArrayList;
  6. import java.util.Date;
  7. import java.util.List;
  8.  
  9. public class PlayerCommands {
  10.     private static final Logger                      log      = Logger.getLogger("Minecraft");
  11.     private static PlayerCommands             instance;
  12.     private final LinkedHashMap<String, BaseCommand> commands = new LinkedHashMap<String, BaseCommand>();
  13.     private static List<String>        onlyOneUseKits     = new ArrayList<String>();
  14.  
  15.     public PlayerCommands() {
  16.         add("/help", help);
  17.         add("/playerlist", playerlist);
  18.         add("/who", playerlist);
  19.         add("/banlist", banList);
  20.         add("/banip", banip);
  21.         add("/unbanip", unbanip);
  22.         add("/ban", ban);
  23.         add("/unban", unban);
  24.         add("/mute", mute);
  25.         add("/tp", tp);
  26.         add("/tphere", tphere);
  27.         add("/s", tphere);
  28.         add("/kick", kick);
  29.         add("/item", item);
  30.         add("/i", item);
  31.         add("/give", item);
  32.         add("/cloth", cloth);
  33.         add("/dye", cloth);
  34.         add("/kit", kit);
  35.         add("/listwarps", listwarps);
  36.         add("/home", home);
  37.         add("/sethome", sethome);
  38.         add("/setspawn", setspawn);
  39.         add("/me", me);
  40.         add("/msg", msg);
  41.         add("/tell", msg);
  42.         add("/m", msg);
  43.         add("/spawn", spawn);
  44.         add("/warp", warp);
  45.         add("/setwarp", setwarp);
  46.         add("/removewarp", removewarp);
  47.         add("/getpos", getpos);
  48.         add("/compass", compass);
  49.         add("/time", time);
  50.         add("/lighter", lighter);
  51.         add("/motd", motd);
  52.         add("/clearinventory", clearInventory);
  53.         add("/update", update);
  54.         add("/#", serverCommand);
  55.         add("/spawnmob", spawnmob);
  56.         add("/mspawn", mobSpawner);
  57.        
  58.     }
  59.  
  60.     /**
  61.      * Add a command to the player list.
  62.      *
  63.      * @param name
  64.      * @param cmd
  65.      */
  66.     public void add(String name, BaseCommand cmd) {
  67.         if (name != null && cmd != null)
  68.             add(name, cmd);
  69.     }
  70.  
  71.     /**
  72.      * Remove a command from the server list.
  73.      *
  74.      * @param name
  75.      */
  76.     public void remove(String name) {
  77.         if (name != null) {
  78.             etc.getInstance().removeCommand(name);
  79.             commands.remove(name);
  80.         }
  81.     }
  82.  
  83.     /**
  84.      * Performs a lookup for a command of the given name and executes it if
  85.      * found. Returns false if command not found.
  86.      *
  87.      * @param command
  88.      * @param player
  89.      * @param parameters
  90.      * @return
  91.      */
  92.     public static boolean parseCommand(MessageReceiver caller, String command, String[] args) {
  93.         if (instance == null)
  94.             instance = new PlayerCommands();
  95.  
  96.         BaseCommand cmd = instance.getCommand(command);
  97.         if (cmd != null) {
  98.             cmd.parseCommand(caller, args);
  99.             // Inform caller a matching command was found.
  100.             return true;
  101.         }
  102.         return false;
  103.     }
  104.  
  105.     public LinkedHashMap<String, BaseCommand> getCommands(String command) {
  106.         return commands.get(command);
  107.     }
  108.  
  109.     public static final BaseCommand help         = new BaseCommand("[Page] - Shows a list of commands. 7 per page.") {
  110.                                                      @Override
  111.                                                      void execute (MessageReceiver caller, String[] parameters) {
  112.                                                          List<String> availableCommands = new ArrayList<String>();
  113.                                                          for (Entry<String, String> entry : PlayerCommands.getCommands().entrySet())
  114.                                                              if (etc.getServer().getPlayer(caller.getName()).canUseCommand(entry.getKey())) {
  115.                                                                  if (entry.getKey().equals("/kit") && !etc.getDataSource().hasKits())
  116.                                                                     continue;
  117.                                                                  if (entry.getKey().equals("/listwarps") && !etc.getDataSource().hasWarps())
  118.                                                                     continue;
  119.  
  120.                                                                  availableCommands.add(entry.getKey() + " " + entry.getValue());
  121.                                                              }
  122.  
  123.                                                          caller.notify(Colors.Blue + "Available commands (Page " + (parameters.length == 2 ? parameters[1] : "1") + " of " + (int) Math.ceil((double) availableCommands.size() / (double) 7) + ") [] = required <> = optional:");
  124.                                                          if (parameters.length == 2)
  125.                                                              try {
  126.                                                                  int amount = Integer.parseInt(parameters[1]);
  127.  
  128.                                                                  if (amount > 0)
  129.                                                                      amount = (amount - 1) * 7;
  130.                                                                  else
  131.                                                                      amount = 0;
  132.  
  133.                                                                  for (int i = amount; i < amount + 7; i++)
  134.                                                                      if (availableCommands.size() > i)
  135.                                                                          caller.notify(Colors.Rose + availableCommands.get(i));
  136.                                                              } catch (NumberFormatException ex) {
  137.                                                                  caller.notify(Colors.Rose + "Not a valid page number.");
  138.                                                              }
  139.                                                          else
  140.                                                              for (int i = 0; i < 7; i++)
  141.                                                                  if (availableCommands.size() > i)
  142.                                                                      caller.notify(Colors.Rose + availableCommands.get(i));
  143.                                                      }
  144.                                                  };
  145.     public static final BaseCommand mute         = new BaseCommand("[Player] - Toggles mute on player.") {
  146.                                                      @Override
  147.                                                      void execute(MessageReceiver caller, String[] parameters){
  148.                                                          if (parameters.length != 2) {
  149.                                                              caller.notify(Colors.Rose + "Correct usage is: /mute [player]");
  150.                                                              return;
  151.                                                          }
  152.  
  153.                                                      Player player = etc.getServer().matchPlayer(parameters[1]);
  154.  
  155.                                                      if (player != null) {
  156.                                                         if (player.toggleMute())
  157.                                                             caller.notify(Colors.Rose + "player was muted");
  158.                                                         else
  159.                                                             caller.notify(Colors.Rose + "player was unmuted");
  160.                                                     } else
  161.                                                         caller.notify(Colors.Rose + "Can't find player " + parameters[1]);
  162.                                                     }
  163.                                                  };
  164.     public static final BaseCommand msg          = new BaseCommand("[Player] [Message] - Sends a message to player") {
  165.                                                      @Override
  166.                                                      void execute(MessageReceiver caller, String[] parameters) {
  167.                                                          if (parameters.length < 3) {
  168.                                                              caller.notify(Colors.Rose + "Correct usage is: /msg [player] [message]");
  169.                                                              return;
  170.                                                          }
  171.                                                          if (etc.getServer().getPlayer(caller.getName()).isMuted()) {
  172.                                                              caller.notify(Colors.Rose + "You are currently muted.");
  173.                                                              return;
  174.                                                          }
  175.                                                          
  176.                                                          Player player = etc.getServer().matchPlayer(parameters[1]);
  177.  
  178.                                                          if (player != null) {
  179.                                                              if (player.getName().equals(caller.getName())) {
  180.                                                                  caller.notify(Colors.Rose + "You can't message yourself!");
  181.                                                                  return;
  182.                                                              }
  183.  
  184.                                                              player.sendMessage("(MSG) " + etc.getServer().getPlayer(caller.getName()).getColor() + "<" + etc.getServer().getPlayer(caller.getName()) + "> " + Colors.White + etc.combineSplit(2, parameters, " "));
  185.                                                              caller.notify("(MSG) " + etc.getServer().getPlayer(caller.getName()).getColor() + "<" + etc.getServer().getPlayer(caller.getName()) + "> " + Colors.White + etc.combineSplit(2, parameters, " "));
  186.                                                          } else
  187.                                                              caller.notify(Colors.Rose + "Couldn't find player " + parameters[1]);
  188.                                                      }
  189.                                                  };
  190.  
  191.     public static final BaseCommand kit              = new BaseCommand ("[Kit] - Gives a kit. To get a list of kits type /kit") {
  192.                                                        @Override
  193.                                                        void execute(MessageReceiver caller, String[] parameters) {
  194.                                                             if (etc.getDataSource().hasKits()) {
  195.                                                                 if (parameters.length != 2 && parameters.length != 3) {
  196.                                                                  caller.notify(Colors.Rose + "Available kits" + Colors.White + ": " + etc.getDataSource().getKitNames(etc.getServer().getPlayer(caller.getName())));
  197.                                                                   return;
  198.                                                                 }
  199.                                                                
  200.                                                             Player toGive = etc.getServer().getPlayer(caller.getName());
  201.                                                             if (parameters.length > 2 && etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  202.                                                                 toGive = etc.getServer().matchPlayer(parameters[2]);
  203.  
  204.                                                              Kit kit = etc.getDataSource().getKit(parameters[1]);
  205.                                                              if (toGive != null) {
  206.                                                                 if (kit != null) {
  207.                                                                    if (!etc.getServer().getPlayer(caller.getName()).isInGroup(kit.Group) && !kit.Group.equals(""))
  208.                                                                       caller.notify(Colors.Rose + "That kit does not exist.");
  209.                                                                    else if (onlyOneUseKits.contains(kit.Name))
  210.                                                                        caller.notify(Colors.Rose + "You can only get this kit once per login.");
  211.                                                                    else if (etc.getMCServer().b.containsKey(etc.getServer().getPlayer(caller.getName()).getName() + " " + kit.Name))
  212.                                                                            caller.notify(Colors.Rose + "You can't get this kit again for a while.");
  213.                                                                    else {
  214.                                                                         if (!etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  215.                                                                            if (kit.Delay >= 0)
  216.                                                                               etc.getMCServer().b.put(etc.getServer().getPlayer(caller.getName()).getName() + " " + kit.Name, kit.Delay);
  217.                                                                            else
  218.                                                                               onlyOneUseKits.add(kit.Name);
  219.                                                                        
  220.                                                                 log.info(etc.getServer().getPlayer(caller.getName()).getName() + " got a kit!");
  221.                                                                 toGive.notify(Colors.Rose + "Enjoy this kit!");
  222.                                                                 for (Map.Entry<String, Integer> entry : kit.IDs.entrySet())
  223.                                                                    try {
  224.                                                                        int itemId = 0;
  225.                                                                        try {
  226.                                                                            itemId = Integer.parseInt(entry.getKey());
  227.                                                                        } catch (NumberFormatException n) {
  228.                                                                                itemId = etc.getDataSource().getItem(entry.getKey());
  229.                                                                        }
  230.  
  231.                                                                        toGive.giveItem(itemId, kit.IDs.get(entry.getKey()));
  232.                                                                        } catch (Exception e1) {
  233.                                                                                log.info("Got an exception while giving out a kit (Kit name \"" + kit.Name + "\"). Are you sure all the Ids are numbers?");
  234.                                                                                caller.notify(Colors.Rose + "The server encountered a problem while giving the kit :(");
  235.                                                                        }
  236.                                                                     }
  237.                                                                 } else
  238.                                                             caller.notify(Colors.Rose + "That kit does not exist.");
  239.                                                          } else
  240.                                                          caller.notify(Colors.Rose + "That user does not exist.");
  241.                                                        }
  242.                                                      }
  243.                                                  };
  244.  
  245.     public static final BaseCommand tp           = new BaseCommand("Correct usage is: /tp [player]") {
  246.                                                      @Override
  247.                                                      void execute(MessageReceiver caller, String[] parameters){
  248.                                                          if (parameters.length < 2) {
  249.                                                              caller.notify(Colors.Rose + "Correct usage is: /tp [player]");
  250.                                                              return;
  251.                                                              }
  252.  
  253.                                                          Player player = etc.getServer().matchPlayer(parameters[1]);
  254.  
  255.                                                          if (player != null) {
  256.                                                              if (caller.getName().equalsIgnoreCase(player.getName())) {
  257.                                                                  caller.notify(Colors.Rose + "You're already here!");
  258.                                                                  return;
  259.                                                              }
  260.  
  261.                                                          log.info(caller.getName() + " teleported to " + player.getName());
  262.                                                          etc.getServer().getPlayer(caller.getName()).teleportTo(player);
  263.                                                          } else
  264.                                                          caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
  265.                                                      }
  266.                                                  };
  267.  
  268.     public static final BaseCommand tphere       = new BaseCommand("Correct usage is: /tphere [player]") {
  269.                                                      @Override
  270.                                                      void execute (MessageReceiver caller, String[] parameters){
  271.                                                          if (parameters.length < 2) {
  272.                                                              caller.notify(Colors.Rose + "Correct usage is: /tphere [player]");
  273.                                                              return;
  274.                                                          }
  275.  
  276.                                                          Player player = etc.getServer().matchPlayer(parameters[1]);
  277.  
  278.                                                          if (player != null) {
  279.                                                              if (caller.getName().equalsIgnoreCase(player.getName())) {
  280.                                                                  caller.notify(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
  281.                                                                  return;
  282.                                                                  }
  283.  
  284.                                                              log.info(caller.getName() + " teleported " + player.getName() + " to their self.");
  285.                                                              player.teleportTo(etc.getServer().getPlayer(caller.getName()));
  286.                                                          } else
  287.                                                              caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
  288.                                                      }
  289.                                                  };
  290.    
  291.     public static final BaseCommand playerlist  = new BaseCommand("- Shows a list of players"){
  292.                                                     @Override
  293.                                                     void execute (MessageReceiver caller, String[] parameters){
  294.                                                         caller.notify(Colors.Rose + "Player list (" + etc.getMCServer().f.b.size() + "/" + etc.getInstance().getPlayerLimit() + "): " + Colors.White + etc.getMCServer().f.c());
  295.                                                     }
  296.                                                 };
  297.    
  298.     public static final BaseCommand item = new BaseCommand("[ID] <Amount> <Damage> <Player> - Gives items") {
  299.         @Override
  300.                 public void execute (MessageReceiver caller, String[] parameters){
  301.             if (parameters.length < 2) {
  302.                     if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  303.                         caller.notify(Colors.Rose + "Correct usage is: /item [itemid] <amount> <damage> <player> (optional)");
  304.                     else
  305.                         caller.notify(Colors.Rose + "Correct usage is: /item [itemid] <amount> <damage>");
  306.                     return;
  307.                 }
  308.  
  309.                 Player toGive = etc.getServer().getPlayer(caller.getName());
  310.                 int itemId = 0, amount = 1, damage = 0;
  311.                 try {
  312.                     if (parameters.length > 1)
  313.                         try {
  314.                             itemId = Integer.parseInt(parameters[1]);
  315.                         } catch (NumberFormatException n) {
  316.                             itemId = etc.getDataSource().getItem(parameters[1]);
  317.                         }
  318.                     if (parameters.length > 2) {
  319.                         amount = Integer.parseInt(parameters[2]);
  320.                         if (amount <= 0 && !etc.getServer().getPlayer(caller.getName()).isAdmin())
  321.                             amount = 1;
  322.  
  323.                         if (amount > 64 && !etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  324.                             amount = 64;
  325.                         if (amount > 1024)
  326.                             amount = 1024; // 16 stacks worth. More than enough.
  327.                     }
  328.                     if (parameters.length == 4) {
  329.                         int temp = -1;
  330.                         try {
  331.                             temp = Integer.parseInt(parameters[3]);
  332.                         } catch (NumberFormatException n) {
  333.                             if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  334.                                 toGive = etc.getServer().matchPlayer(parameters[3]);
  335.                         }
  336.                         if (temp > -1 && temp < 50)
  337.                             damage = temp;
  338.                     } else if (parameters.length == 5) {
  339.                         damage = Integer.parseInt(parameters[3]);
  340.                         if (damage < 0 && damage > 49)
  341.                             damage = 0;
  342.                         if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  343.                             toGive = etc.getServer().matchPlayer(parameters[4]);
  344.                     }
  345.  
  346.                 } catch (NumberFormatException localNumberFormatException) {
  347.                     caller.notify(Colors.Rose + "Improper ID and/or amount.");
  348.                     return;
  349.                 }
  350.  
  351.                 if (toGive != null) {
  352.  
  353.                     boolean allowedItem = etc.getInstance().getAllowedItems().isEmpty() || etc.getInstance().getAllowedItems().contains(itemId);
  354.  
  355.                     if (!etc.getInstance().getDisallowedItems().isEmpty() && etc.getInstance().getDisallowedItems().contains(itemId))
  356.                         allowedItem = false;
  357.  
  358.                     if (Item.isValidItem(itemId)) {
  359.                         if (allowedItem || etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions()) {
  360.                             Item i = new Item(itemId, amount, -1, damage);
  361.                             log.info("Giving " + toGive.getName() + " some " + i.toString());
  362.                             // toGive.giveItem(itemId, amount);
  363.                             Inventory inv = toGive.getInventory();
  364.                             ArrayList<Item> list = new ArrayList<Item>();
  365.                             for (Item it : inv.getContents())
  366.                                 if (it != null && it.getItemId() == i.getItemId() && it.getDamage() == i.getDamage())
  367.                                     list.add(it);
  368.  
  369.                             for (Item it : list) {
  370.                                 if (it.getAmount() < 64) {
  371.                                     if (amount >= 64 - it.getAmount()) {
  372.                                         amount -= 64 - it.getAmount();
  373.                                         it.setAmount(64);
  374.                                         toGive.giveItem(it);
  375.                                     } else {
  376.                                         it.setAmount(it.getAmount() + amount);
  377.                                         amount = 0;
  378.                                         toGive.giveItem(it);
  379.                                     }
  380.                                 }
  381.                             }
  382.                             if (amount != 0) {
  383.                                 i.setAmount(64);
  384.                                 while (amount > 64) {
  385.                                     amount -= 64;
  386.                                     toGive.giveItem(i);
  387.                                     i.setSlot(-1);
  388.                                 }
  389.                                 i.setAmount(amount);
  390.                                 toGive.giveItem(i);
  391.                             }
  392.                             if (toGive.getName().equalsIgnoreCase(caller.getName()))
  393.                                 caller.notify(Colors.Rose + "There you go " + caller.getName() + ".");
  394.                             else {
  395.                                 caller.notify(Colors.Rose + "Gift given! :D");
  396.                                 toGive.sendMessage(Colors.Rose + "Enjoy your gift! :D");
  397.                             }
  398.                         } else if (!allowedItem && !etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  399.                             caller.notify(Colors.Rose + "You are not allowed to spawn that item.");
  400.                     } else
  401.                         caller.notify(Colors.Rose + "No item with ID " + parameters[1]);
  402.  
  403.                 } else
  404.                     caller.notify(Colors.Rose + "Can't find user " + parameters[3]);
  405.         }
  406.     };
  407.    
  408.     public final static BaseCommand cloth = new BaseCommand("[Amount] [Color] - Gives cloth"){
  409.         @Override
  410.                 public void execute(MessageReceiver caller, String[] parameters){
  411.       if (parameters.length < 3) {
  412.                     caller.notify(Colors.Rose + "Correct usage is: " + parameters[0] + " [amount] [color]");
  413.                     return;
  414.                 }
  415.                 try {
  416.                     int amount = Integer.parseInt(parameters[1]);
  417.                     if (amount <= 0 && !etc.getServer().getPlayer(caller.getName()).isAdmin())
  418.                         amount = 1;
  419.  
  420.                     if (amount > 64 && !etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  421.                         amount = 64;
  422.                     if (amount > 1024)
  423.                         amount = 1024; // 16 stacks worth. More than enough.
  424.  
  425.                     String color = parameters[2];
  426.                     if (parameters.length > 3)
  427.                         color += " " + parameters[3];
  428.                     Cloth.Color c = Cloth.Color.getColor(color.toLowerCase());
  429.                     if (c == null) {
  430.                         caller.notify(Colors.Rose + "Invalid color name!");
  431.                         return;
  432.                     }
  433.                     Item i = c.getItem();
  434.  
  435.                     if (parameters[0].equalsIgnoreCase("/dye")) {
  436.                         i.setType(Item.Type.InkSack);
  437.                         // some1 had fun inverting this i guess .....
  438.                         i.setDamage(15 - i.getDamage());
  439.                     }
  440.                     i.setAmount(amount);
  441.                     log.info("Giving " + caller.getName() + " some " + i.toString());
  442.  
  443.                     Inventory inv = etc.getServer().getPlayer(caller.getName()).getInventory();
  444.                     ArrayList<Item> list = new ArrayList<Item>();
  445.                     for (Item it : inv.getContents())
  446.                         if (it != null && it.getItemId() == i.getItemId() && it.getDamage() == i.getDamage())
  447.                             list.add(it);
  448.  
  449.                     for (Item it : list) {
  450.                         if (it.getAmount() < 64) {
  451.                             if (amount >= 64 - it.getAmount()) {
  452.                                 amount -= 64 - it.getAmount();
  453.                                 it.setAmount(64);
  454.                                 etc.getServer().getPlayer(caller.getName()).giveItem(it);
  455.                             } else {
  456.                                 it.setAmount(it.getAmount() + amount);
  457.                                 amount = 0;
  458.                                 etc.getServer().getPlayer(caller.getName()).giveItem(it);
  459.                             }
  460.                         }
  461.                     }
  462.                     if (amount != 0) {
  463.                         i.setAmount(64);
  464.                         while (amount > 64) {
  465.                             amount -= 64;
  466.                             etc.getServer().getPlayer(caller.getName()).giveItem(i);
  467.                             i.setSlot(-1);
  468.                         }
  469.                         i.setAmount(amount);
  470.                         etc.getServer().getPlayer(caller.getName()).giveItem(i);
  471.                     }
  472.                     caller.notify(Colors.Rose + "There you go " + caller.getName() + ".");
  473.                 } catch (NumberFormatException localNumberFormatException) {
  474.                     caller.notify(Colors.Rose + "Improper ID and/or amount.");
  475.                 }      
  476.         }
  477.     };
  478.    
  479.     public static final BaseCommand banList = new BaseCommand ("<IP or bans> - Gives a list of bans"){
  480.       @Override
  481.              void execute (MessageReceiver caller, String[] parameters){
  482.            byte type = 0;
  483.                 if (parameters.length == 2)
  484.                     if (parameters[1].equalsIgnoreCase("ips"))
  485.                         type = 1;
  486.                 if (type == 0)
  487.                     caller.notify(Colors.Blue + "Ban list:" + Colors.White + " " + etc.getMCServer().f.getBans());
  488.                 else
  489.                     caller.notify(Colors.Blue + "IP Ban list:" + Colors.White + " " + etc.getMCServer().f.getIpBans());
  490.       }
  491.     };
  492.    
  493.     public static final BaseCommand banip = new BaseCommand("[Player] <Reason> - Bans the player's IP"){
  494.       @Override
  495.               void execute (MessageReceiver caller, String[] parameters){
  496.           if (parameters.length < 2) {
  497.                     caller.notify(Colors.Rose + "Correct usage is: /banip [player] <reason> (optional) NOTE: this permabans IPs.");
  498.                     return;
  499.                 }
  500.  
  501.                 Player player = etc.getServer().matchPlayer(parameters[1]);
  502.  
  503.                 if (player != null) {
  504.                     if (!etc.getServer().getPlayer(caller.getName()).hasControlOver(player)) {
  505.                         caller.notify(Colors.Rose + "You can't ban that user.");
  506.                         return;
  507.                     }
  508.  
  509.                     // adds player to ban list
  510.                     etc.getMCServer().f.c(player.getIP());
  511.                     etc.getLoader().callHook(PluginLoader.Hook.IPBAN, new Object[] { etc.getServer().getPlayer(caller.getName()), player, parameters.length >= 3 ? etc.combineSplit(2, parameters, " ") : "" });
  512.  
  513.                     log.info("IP Banning " + player.getName() + " (IP: " + player.getIP() + ")");
  514.                     caller.notify(Colors.Rose + "IP Banning " + player.getName() + " (IP: " + player.getIP() + ")");
  515.  
  516.                     if (parameters.length > 2)
  517.                         player.kick("IP Banned by " + caller.getName() + ": " + etc.combineSplit(2, parameters, " "));
  518.                     else
  519.                         player.kick("IP Banned by " + caller.getName() + ".");
  520.                 } else
  521.                     caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
  522.       }
  523.     };
  524.    
  525.     public static final BaseCommand ban = new BaseCommand("[Player] <Reason> - Bans the player"){
  526.       @Override
  527.               void execute (MessageReceiver caller, String[] parameters){
  528.           if (parameters.length < 2) {
  529.                     caller.notify(Colors.Rose + "Correct usage is: /ban [player] <reason> (optional)");
  530.                     return;
  531.                 }
  532.  
  533.                 Player player = etc.getServer().matchPlayer(parameters[1]);
  534.  
  535.                 if (player != null) {
  536.                     if (!etc.getServer().getPlayer(caller.getName()).hasControlOver(player)) {
  537.                         caller.notify(Colors.Rose + "You can't ban that user.");
  538.                         return;
  539.                     }
  540.  
  541.                     // adds player to ban list
  542.                     etc.getServer().ban(player.getName());
  543.  
  544.                     etc.getLoader().callHook(PluginLoader.Hook.BAN, new Object[] { this, player, parameters.length >= 3 ? etc.combineSplit(2, parameters, " ") : "" });
  545.  
  546.                     if (parameters.length > 2)
  547.                         player.kick("Banned by " + caller.getName() + ": " + etc.combineSplit(2, parameters, " "));
  548.                     else
  549.                         player.kick("Banned by " + caller.getName() + ".");
  550.                     log.info("Banning " + player.getName());
  551.                     caller.notify(Colors.Rose + "Banning " + player.getName());
  552.                 } else {
  553.                     // sendMessage(Colors.Rose + "Can't find user " + parameters[1] +
  554.                     // ".");
  555.                     etc.getServer().ban(parameters[1]);
  556.                     log.info("Banning " + parameters[1]);
  557.                     caller.notify(Colors.Rose + "Banning " + parameters[1]);
  558.                 }
  559.       }
  560.     };
  561.    
  562.     public static final BaseCommand unban = new BaseCommand ("[Player] - Unbans the player"){
  563.       @Override
  564.               void execute (MessageReceiver caller, String[] parameters){
  565.           if (parameters.length != 2) {
  566.                     caller.notify(Colors.Rose + "Correct usage is: /unban [player]");
  567.                     return;
  568.                 }
  569.                 etc.getServer().unban(parameters[1]);
  570.                 caller.notify(Colors.Rose + "Unbanned " + parameters[1]);
  571.       }
  572.     };
  573.    
  574.     public static final BaseCommand unbanip = new BaseCommand("[IP] - Unbans the IP"){
  575.       @Override
  576.               void execute (MessageReceiver caller, String[] parameters){
  577.        if (parameters.length != 2) {
  578.                    caller.notify(Colors.Rose + "Correct usage is: /unbanip [ip]");
  579.                     return;
  580.                 }
  581.                 etc.getMCServer().f.d(parameters[1]);
  582.                 caller.notify(Colors.Rose + "Unbanned " + parameters[1]);  
  583.       }    
  584.     };
  585.    
  586.     public static final BaseCommand kick = new BaseCommand("[Player] <Reason> - Kicks player"){
  587.       @Override
  588.               void execute (MessageReceiver caller, String[] parameters){
  589.           if (parameters.length < 2) {
  590.                     caller.notify(Colors.Rose + "Correct usage is: /kick [player] <reason> (optional)");
  591.                     return;
  592.                 }
  593.  
  594.                 Player player = etc.getServer().matchPlayer(parameters[1]);
  595.  
  596.                 if (player != null) {
  597.                     if (!etc.getServer().getPlayer(caller.getName()).hasControlOver(player)){
  598.                         caller.notify(Colors.Rose + "You can't kick that user.");
  599.                         return;
  600.                     }
  601.  
  602.                     etc.getLoader().callHook(PluginLoader.Hook.KICK, new Object[] { this, player, parameters.length >= 3 ? etc.combineSplit(2, parameters, " ") : "" });
  603.  
  604.                     if (parameters.length > 2)
  605.                         player.kick("Kicked by " + caller.getName() + ": " + etc.combineSplit(2, parameters, " "));
  606.                     else
  607.                         player.kick("Kicked by " + caller.getName() + ".");
  608.                     log.info("Kicking " + player.getName());
  609.                     caller.notify(Colors.Rose + "Kicking " + player.getName());
  610.                 } else
  611.                     caller.notify(Colors.Rose + "Can't find user " + parameters[1] + ".");
  612.       }
  613.     };
  614.    
  615.     public static final BaseCommand me = new BaseCommand("[Message] - * CanaryMod says hi!"){
  616.       @Override
  617.               void execute (MessageReceiver caller, String[] parameters){
  618.           if (etc.getServer().getPlayer(caller.getName()).isMuted()) {
  619.                     caller.notify(Colors.Rose + "You are currently muted.");
  620.                     return;
  621.                 }
  622.           String command="";
  623.           for (int i = 1; i < parameters.length; i++)
  624.               command = command + parameters[i]+ " ";
  625.              
  626.          
  627.                 if (parameters.length == 1)
  628.                     return;
  629.                 String paramString2 = "* " + etc.getServer().getPlayer(caller.getName()).getColor() + caller.getName() + Colors.White + " " + command.substring(command.indexOf(" ")).trim();
  630.                 log.info("* " + caller.getName() + " " + command.substring(command.indexOf(" ")).trim());
  631.                 etc.getServer().messageAll(paramString2);
  632.       }
  633.     };
  634.    
  635.     public final static BaseCommand sethome = new BaseCommand ("- Sets your home"){
  636.       @Override
  637.               void execute (MessageReceiver caller, String[] parameters){
  638.           // player.k, player.l, player.m
  639.                 // x, y, z
  640.                 Warp home = new Warp();
  641.                 home.Location = etc.getServer().getPlayer(caller.getName()).getLocation();
  642.                 home.Group = ""; // no group neccessary, lol.
  643.                 home.Name = etc.getServer().getPlayer(caller.getName()).getName();
  644.                 etc.getInstance().changeHome(home);
  645.                 caller.notify(Colors.Rose + "Your home has been set.");
  646.       }
  647.     };
  648.    
  649.     public final static BaseCommand spawn = new BaseCommand ("- Teleports you to spawn"){
  650.       @Override
  651.               void execute (MessageReceiver caller, String[] parameters){
  652.           etc.getServer().getPlayer(caller.getName()).teleportTo(etc.getServer().getSpawnLocation());
  653.       }
  654.     };
  655.    
  656.     public final static BaseCommand setspawn = new BaseCommand ("- Sets the spawn point to your position."){
  657.       @Override
  658.               void execute (MessageReceiver caller, String[] parameters){
  659.           // New system in beta 1.3: WorldInfo.
  660.                 OWorldInfo info = etc.getMCServer().e.s;
  661.                 info.a((int) etc.getServer().getPlayer(caller.getName()).getX(), info.d(), (int) etc.getServer().getPlayer(caller.getName()).getZ());
  662.  
  663.                 log.info("Spawn position changed.");
  664.                 caller.notify(Colors.Rose + "You have set the spawn to your current position.");
  665.       }
  666.     };
  667.    
  668.     public final static BaseCommand home = new BaseCommand ("- Teleports you home"){
  669.       @Override
  670.               void execute (MessageReceiver caller, String[] parameters){
  671.           Warp home = null;
  672.                 if (parameters.length > 1 && etc.getServer().getPlayer(caller.getName()).isAdmin())
  673.                     home = etc.getDataSource().getHome(parameters[1]);
  674.                 else
  675.                     home = etc.getDataSource().getHome(caller.getName());
  676.  
  677.                 if (home != null)
  678.                     etc.getServer().getPlayer(caller.getName()).teleportTo(home.Location);
  679.                 else if (parameters.length > 1 && etc.getServer().getPlayer(caller.getName()).isAdmin())
  680.                     caller.notify(Colors.Rose + "That player home does not exist");
  681.                 else
  682.                     etc.getServer().getPlayer(caller.getName()).teleportTo(etc.getServer().getSpawnLocation());
  683.          
  684.       }
  685.     };
  686.    
  687.     public static final BaseCommand warp = new BaseCommand ("[Warp] - Warps to the specified warp."){
  688.       @Override
  689.               void execute (MessageReceiver caller, String[] parameters){
  690.           if (parameters.length < 2) {
  691.                     caller.notify(Colors.Rose + "Correct usage is: /warp [warpname]");
  692.                     return;
  693.                 }
  694.                 Player toWarp = etc.getServer().getPlayer(caller.getName());
  695.                 Warp warp = null;
  696.                 if (parameters.length == 3 && toWarp.canIgnoreRestrictions()) {
  697.                     warp = etc.getDataSource().getWarp(parameters[1]);
  698.                     toWarp = etc.getServer().matchPlayer(parameters[2]);
  699.                 } else
  700.                     warp = etc.getDataSource().getWarp(parameters[1]);
  701.                 if (toWarp != null) {
  702.                     if (warp != null) {
  703.                         if (!toWarp.isInGroup(warp.Group) && !warp.Group.equals(""))
  704.                             caller.notify(Colors.Rose + "Warp not found.");
  705.                         else {
  706.                             toWarp.teleportTo(warp.Location);
  707.                             toWarp.sendMessage(Colors.Rose + "Woosh!");
  708.                         }
  709.                     } else
  710.                         caller.notify(Colors.Rose + "Warp not found");
  711.                 } else
  712.                     caller.notify(Colors.Rose + "Player not found.");
  713.       }
  714.     };
  715.    
  716.     public static final BaseCommand listwarps = new BaseCommand ("- Gives a list of available warps"){
  717.       @Override
  718.               void execute (MessageReceiver caller, String[] parameters){
  719.           if (parameters.length != 2 && parameters.length != 3) {
  720.                     caller.notify(Colors.Rose + "Available warps: " + Colors.White + etc.getDataSource().getWarpNames(etc.getServer().getPlayer(caller.getName())));
  721.                     return;
  722.                 }
  723.       }
  724.     };
  725.    
  726.     public static final BaseCommand setwarp = new BaseCommand ("[Warp] - Sets the warp to your current position."){
  727.       @Override
  728.               void execute (MessageReceiver caller, String[] parameters){
  729.           if (parameters.length < 2) {
  730.                     if (etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  731.                         caller.notify(Colors.Rose + "Correct usage is: /setwarp [warpname] [group]");
  732.                     else
  733.                         caller.notify(Colors.Rose + "Correct usage is: /setwarp [warpname]");
  734.                     return;
  735.                 }
  736.                 if (parameters[1].contains(":")) {
  737.                     caller.notify("You can't set a warp with \":\" in its name");
  738.                     return;
  739.                 }
  740.                 Warp warp = new Warp();
  741.                 warp.Name = parameters[1];
  742.                 warp.Location = etc.getServer().getPlayer(caller.getName()).getLocation();
  743.                 if (parameters.length == 3)
  744.                     warp.Group = parameters[2];
  745.                 else
  746.                     warp.Group = "";
  747.                 etc.getInstance().setWarp(warp);
  748.                 caller.notify(Colors.Rose + "Created warp point " + parameters[1] + ".");
  749.       }
  750.     };
  751.    
  752.     public static final BaseCommand removewarp = new BaseCommand ("[Warp] - Removes the specified warp."){
  753.       @Override
  754.               void execute (MessageReceiver caller, String[] parameters){
  755.           if (parameters.length < 2) {
  756.                     caller.notify(Colors.Rose + "Correct usage is: /removewarp [warpname]");
  757.                     return;
  758.                 }
  759.                 Warp warp = etc.getDataSource().getWarp(parameters[1]);
  760.                 if (warp != null) {
  761.                     etc.getDataSource().removeWarp(warp);
  762.                     caller.notify(Colors.Blue + "Warp removed.");
  763.                 } else
  764.                     caller.notify(Colors.Rose + "That warp does not exist");
  765.       }
  766.              
  767.     };
  768.    
  769.     public static final BaseCommand lighter = new BaseCommand("- Gives you a lighter for lighting furnaces"){
  770.       @Override
  771.               void execute (MessageReceiver caller, String[] paramaters){
  772.            if (etc.getInstance().getMCServer().b.containsKey(caller.getName() + " lighter")) {
  773.                     log.info(caller.getName() + " failed to iron!");
  774.                     caller.notify(Colors.Rose + "You can't create another lighter again so soon");
  775.                 } else {
  776.                     if (!etc.getServer().getPlayer(caller.getName()).canIgnoreRestrictions())
  777.                         etc.getInstance().getMCServer().b.put(caller.getName() + " lighter", Integer.valueOf(6000));
  778.                     log.info(caller.getName() + " created a lighter!");
  779.                     etc.getServer().getPlayer(caller.getName()).giveItem(259, 1);
  780.                 }
  781.       }
  782.     };
  783.    
  784.     public static final BaseCommand serverCommand = new BaseCommand ("- Performs command as Server"){
  785.       @Override
  786.               void execute (MessageReceiver caller, String[] parameters){
  787.           String command = "";
  788.           for (int i = 1; i < parameters.length; i++)
  789.               command = command + parameters[i] + " ";
  790.           String str = command.substring(2);
  791.                 log.info(caller.getName() + " issued server command: " + str);
  792.       }
  793.     };
  794.    
  795.     public static final BaseCommand time = new BaseCommand ("[time|'day|night|check|raw'] (rawtime) - Changes or checks the time"){
  796.       @Override
  797.               void execute (MessageReceiver caller, String[] parameters){
  798.           if (parameters.length == 2) {
  799.                     if (parameters[1].equalsIgnoreCase("day"))
  800.                         etc.getServer().setRelativeTime(0);
  801.                     else if (parameters[1].equalsIgnoreCase("night"))
  802.                         etc.getServer().setRelativeTime(13000);
  803.                     else if (parameters[1].equalsIgnoreCase("check"))
  804.                         caller.notify(Colors.Rose + "The time is " + etc.getServer().getRelativeTime() + "! (RAW: " + etc.getServer().getTime() + ")");
  805.                     else
  806.                         try {
  807.                             etc.getServer().setRelativeTime(Long.parseLong(parameters[1]));
  808.                         } catch (NumberFormatException ex) {
  809.                             caller.notify(Colors.Rose + "Please enter numbers, not letters.");
  810.                         }
  811.                 } else if (parameters.length == 3) {
  812.                     if (parameters[1].equalsIgnoreCase("raw"))
  813.                         try {
  814.                             etc.getServer().setTime(Long.parseLong(parameters[2]));
  815.                         } catch (NumberFormatException ex) {
  816.                             caller.notify(Colors.Rose + "Please enter numbers, not letters.");
  817.                         }
  818.                 } else {
  819.                     caller.notify(Colors.Rose + "Correct usage is: /time [time|'day|night|check|raw'] (rawtime)");
  820.                     return;
  821.                 }
  822.       }
  823.     };
  824.    
  825.     public static final BaseCommand getpos = new BaseCommand ("- Displays your current position."){
  826.       @Override
  827.               void execute (MessageReceiver caller, String[] parameters){
  828.                 caller.notify("Pos X: " + etc.getServer().getPlayer(caller.getName()).getX() + " Y: " + etc.getServer().getPlayer(caller.getName()).getY() + " Z: " + etc.getServer().getPlayer(caller.getName()).getZ());
  829.                 caller.notify("Rotation: " + etc.getServer().getPlayer(caller.getName()).getRotation() + " Pitch: " + etc.getServer().getPlayer(caller.getName()).getPitch());
  830.  
  831.                 double degreeRotation = ((etc.getServer().getPlayer(caller.getName()).getRotation() - 90) % 360);
  832.                 if (degreeRotation < 0)
  833.                     degreeRotation += 360.0;
  834.                 caller.notify("Compass: " + etc.getCompassPointForDirection(degreeRotation) + " (" + (Math.round(degreeRotation * 10) / 10.0) + ")");
  835.       }
  836.     };
  837.    
  838.     public static final BaseCommand compass = new BaseCommand ("- Gives you a compass reading."){
  839.       @Override
  840.               void execute (MessageReceiver caller, String[] parameters){
  841.           double degreeRotation = ((etc.getServer().getPlayer(caller.getName()).getRotation() - 90) % 360);
  842.                 if (degreeRotation < 0)
  843.                     degreeRotation += 360.0;
  844.  
  845.                 caller.notify(Colors.Rose + "Compass: " + etc.getCompassPointForDirection(degreeRotation));
  846.       }
  847.     };
  848.    
  849.     public static final BaseCommand spawnmob = new BaseCommand ("- Spawns the number of specified Mpb"){
  850.       @Override
  851.               void execute (MessageReceiver caller, String[] parameters){
  852.           if (parameters.length == 1) {
  853.                     caller.notify(Colors.Rose + "Correct usage is: /spawnmob [name] <amount>");
  854.                     return;
  855.                 }
  856.                 if (!Mob.isValid(parameters[1])) {
  857.                     caller.notify(Colors.Rose + "Invalid mob. Name has to start with a capital like so: Pig");
  858.                     return;
  859.                 }
  860.  
  861.                 if (parameters.length == 2) {
  862.                     Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
  863.                     mob.spawn();
  864.                 } else if (parameters.length == 3)
  865.                     try {
  866.                         int mobnumber = Integer.parseInt(parameters[2]);
  867.                         for (int i = 0; i < mobnumber; i++) {
  868.                             Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
  869.                             mob.spawn();
  870.                         }
  871.                     } catch (NumberFormatException nfe) {
  872.                         if (!Mob.isValid(parameters[2])) {
  873.                             caller.notify(Colors.Rose + "Invalid mob name or number of mobs.");
  874.                             caller.notify(Colors.Rose + "Mob names have to start with a capital like so: Pig");
  875.                         } else {
  876.                             Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
  877.                             mob.spawn(new Mob(parameters[2]));
  878.                         }
  879.                     }
  880.                 else if (parameters.length == 4)
  881.                     try {
  882.                         int mobnumber = Integer.parseInt(parameters[3]);
  883.                         if (!Mob.isValid(parameters[2]))
  884.                             caller.notify(Colors.Rose + "Invalid rider. Name has to start with a capital like so: Pig");
  885.                         else
  886.                             for (int i = 0; i < mobnumber; i++) {
  887.                                 Mob mob = new Mob(parameters[1], etc.getServer().getPlayer(caller.getName()).getLocation());
  888.                                 mob.spawn(new Mob(parameters[2]));
  889.                             }
  890.                     } catch (NumberFormatException nfe) {
  891.                         caller.notify(Colors.Rose + "Invalid number of mobs.");
  892.                     }
  893.       }
  894.     };
  895.    
  896.     public static final BaseCommand clearInventory = new BaseCommand("- Clears your inventory"){
  897.       @Override
  898.               void execute(MessageReceiver caller, String[] parameters){
  899.           Player target = etc.getServer().getPlayer(caller.getName());
  900.                 if (parameters.length >= 2 && target.isAdmin())
  901.                     target = etc.getServer().matchPlayer(parameters[1]);
  902.                 if (target != null) {
  903.                     Inventory inv = target.getInventory();
  904.                     inv.clearContents();
  905.                     inv.update();
  906.                     if (!target.getName().equals(caller.getName()))
  907.                         caller.notify(Colors.Rose + "Cleared " + target.getName() + "'s inventory.");
  908.                 } else
  909.                     caller.notify(Colors.Rose + "Target not found");
  910.       }
  911.     };
  912.    
  913.     public static final BaseCommand mobSpawner = new BaseCommand ("- Changes what mob spawns from a created spawner."){
  914.       @Override
  915.               void execute (MessageReceiver caller, String[] parameters){
  916.           if (parameters.length != 2) {
  917.                     caller.notify(Colors.Rose + "You must specify what to change the mob spawner to.");
  918.                     return;
  919.                 }
  920.                 if (!Mob.isValid(parameters[1])) {
  921.                     caller.notify(Colors.Rose + "Invalid mob specified.");
  922.                     return;
  923.                 }
  924.  
  925.                 HitBlox hb = new HitBlox(etc.getServer().getPlayer(caller.getName()));
  926.                 Block block = hb.getTargetBlock();
  927.                 if (block.getType() == 52) { // mob spawner
  928.                     MobSpawner ms = (MobSpawner) etc.getServer().getComplexBlock(block.getX(), block.getY(), block.getZ());
  929.                     if (ms != null)
  930.                         ms.setSpawn(parameters[1]);
  931.                 } else
  932.                     caller.notify(Colors.Rose + "You are not targeting a mob spawner.");
  933.       }
  934.     };
  935.    
  936.     public static final BaseCommand update = new BaseCommand ("- Checks your Canary version versus available online version."){
  937.       @Override
  938.               void execute (MessageReceiver caller, String[] parameters){
  939.           if (Main.onlineVersion == etc.getInstance().getVersion())
  940.                     caller.notify(Colors.Rose + "You have the latest version of Canary.");
  941.                 else
  942.                     caller.notify(Colors.Rose + "You need to update your version of Canary.");
  943.       }
  944.     };
  945.    
  946.     public static final BaseCommand motd = new BaseCommand ("- Displays the Message of the Day"){
  947.       @Override
  948.               void execute (MessageReceiver caller, String[] parameters){
  949.           for (String str : etc.getInstance().getMotd())
  950.                     caller.notify(str);
  951.       }
  952.     };
  953.    
  954.     public static final BaseCommand tempban = new BaseCommand ("Placeholder for Tempory banning"){
  955.       @Override
  956.               void execute (MessageReceiver caller, String[] parameters){
  957.           if (parameters.length == 1)
  958.                     return;
  959.                 int minutes = 0, hours = 0, days = 0;
  960.                 if (parameters.length >= 2)
  961.                     minutes = Integer.parseInt(parameters[1]);
  962.                 if (parameters.length >= 3)
  963.                     hours = Integer.parseInt(parameters[2]);
  964.                 if (parameters.length >= 4)
  965.                     days = Integer.parseInt(parameters[3]);
  966.                 Date date = new Date();
  967.       }
  968.     };
  969.    
  970. }
Advertisement
Add Comment
Please, Sign In to add comment