SkyeDarkhawk

Player.java

May 10th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 36.80 KB | None | 0 0
  1. public void command(String command) {
  2.         try {
  3.             if (etc.getInstance().isLogging())
  4.                 log.info("Command used by " + getName() + " " + command);
  5.  
  6.             String[] split = command.split(" ");
  7.             String cmd = split[0];
  8.  
  9.             if ((Boolean) etc.getLoader().callHook(PluginLoader.Hook.COMMAND, new Object[] { this, split }))
  10.                 return; // No need to go on, commands were parsed.
  11.             if (!canUseCommand(cmd) && !cmd.startsWith("/#")) {
  12.                 if (etc.getInstance().showUnknownCommand())
  13.                     sendMessage(Colors.Rose + "Unknown command.");
  14.                 return;
  15.             }
  16.  
  17.             // Remove '/' before checking.
  18.             if (ServerConsoleCommands.parseServerConsoleCommand(this, cmd.substring(1), split)) {
  19.                 // Command parsed successfully...
  20.             } else if (PlayerCommands.parseCommand(this, cmd, split)){/*else if (cmd.equalsIgnoreCase("/help")) {
  21.                 // Meh, not the greatest way, but not the worst either.
  22.                 List<String> availableCommands = new ArrayList<String>();
  23.                 for (Entry<String, String> entry : etc.getInstance().getCommands().entrySet())
  24.                     if (canUseCommand(entry.getKey())) {
  25.                         if (entry.getKey().equals("/kit") && !etc.getDataSource().hasKits())
  26.                             continue;
  27.                         if (entry.getKey().equals("/listwarps") && !etc.getDataSource().hasWarps())
  28.                             continue;
  29.  
  30.                         availableCommands.add(entry.getKey() + " " + entry.getValue());
  31.                     }
  32.  
  33.                 sendMessage(Colors.Blue + "Available commands (Page " + (split.length == 2 ? split[1] : "1") + " of " + (int) Math.ceil((double) availableCommands.size() / (double) 7) + ") [] = required <> = optional:");
  34.                 if (split.length == 2)
  35.                     try {
  36.                         int amount = Integer.parseInt(split[1]);
  37.  
  38.                         if (amount > 0)
  39.                             amount = (amount - 1) * 7;
  40.                         else
  41.                             amount = 0;
  42.  
  43.                         for (int i = amount; i < amount + 7; i++)
  44.                             if (availableCommands.size() > i)
  45.                                 sendMessage(Colors.Rose + availableCommands.get(i));
  46.                     } catch (NumberFormatException ex) {
  47.                         sendMessage(Colors.Rose + "Not a valid page number.");
  48.                     }
  49.                 else
  50.                     for (int i = 0; i < 7; i++)
  51.                         if (availableCommands.size() > i)
  52.                             sendMessage(Colors.Rose + availableCommands.get(i));
  53.             } else if (cmd.equalsIgnoreCase("/mute")) {
  54.                 if (split.length != 2) {
  55.                     sendMessage(Colors.Rose + "Correct usage is: /mute [player]");
  56.                     return;
  57.                 }
  58.  
  59.                 Player player = etc.getServer().matchPlayer(split[1]);
  60.  
  61.                 if (player != null) {
  62.                     if (player.toggleMute())
  63.                         sendMessage(Colors.Rose + "player was muted");
  64.                     else
  65.                         sendMessage(Colors.Rose + "player was unmuted");
  66.                 } else
  67.                     sendMessage(Colors.Rose + "Can't find player " + split[1]);
  68.             } else if ((cmd.equalsIgnoreCase("/msg") || cmd.equalsIgnoreCase("/tell")) || cmd.equalsIgnoreCase("/m")) {
  69.                 if (split.length < 3) {
  70.                     sendMessage(Colors.Rose + "Correct usage is: /msg [player] [message]");
  71.                     return;
  72.                 }
  73.                 if (isMuted()) {
  74.                     sendMessage(Colors.Rose + "You are currently muted.");
  75.                     return;
  76.                 }
  77.  
  78.                 Player player = etc.getServer().matchPlayer(split[1]);
  79.  
  80.                 if (player != null) {
  81.                     if (player.getName().equals(getName())) {
  82.                         sendMessage(Colors.Rose + "You can't message yourself!");
  83.                         return;
  84.                     }
  85.  
  86.                     player.sendMessage("(MSG) " + getColor() + "<" + getName() + "> " + Colors.White + etc.combineSplit(2, split, " "));
  87.                     sendMessage("(MSG) " + getColor() + "<" + getName() + "> " + Colors.White + etc.combineSplit(2, split, " "));
  88.                 } else
  89.                     sendMessage(Colors.Rose + "Couldn't find player " + split[1]);
  90.             } else if (cmd.equalsIgnoreCase("/kit") && etc.getDataSource().hasKits()) {
  91.                 if (split.length != 2 && split.length != 3) {
  92.                     sendMessage(Colors.Rose + "Available kits" + Colors.White + ": " + etc.getDataSource().getKitNames(this));
  93.                     return;
  94.                 }
  95.  
  96.                 Player toGive = this;
  97.                 if (split.length > 2 && canIgnoreRestrictions())
  98.                     toGive = etc.getServer().matchPlayer(split[2]);
  99.  
  100.                 Kit kit = etc.getDataSource().getKit(split[1]);
  101.                 if (toGive != null) {
  102.                     if (kit != null) {
  103.                         if (!isInGroup(kit.Group) && !kit.Group.equals(""))
  104.                             sendMessage(Colors.Rose + "That kit does not exist.");
  105.                         else if (onlyOneUseKits.contains(kit.Name))
  106.                             sendMessage(Colors.Rose + "You can only get this kit once per login.");
  107.                         else if (MinecraftServer.b.containsKey(getName() + " " + kit.Name))
  108.                             sendMessage(Colors.Rose + "You can't get this kit again for a while.");
  109.                         else {
  110.                             if (!canIgnoreRestrictions())
  111.                                 if (kit.Delay >= 0)
  112.                                     MinecraftServer.b.put(getName() + " " + kit.Name, kit.Delay);
  113.                                 else
  114.                                     onlyOneUseKits.add(kit.Name);
  115.  
  116.                             log.info(getName() + " got a kit!");
  117.                             toGive.sendMessage(Colors.Rose + "Enjoy this kit!");
  118.                             for (Map.Entry<String, Integer> entry : kit.IDs.entrySet())
  119.                                 try {
  120.                                     int itemId = 0;
  121.                                     try {
  122.                                         itemId = Integer.parseInt(entry.getKey());
  123.                                     } catch (NumberFormatException n) {
  124.                                         itemId = etc.getDataSource().getItem(entry.getKey());
  125.                                     }
  126.  
  127.                                     toGive.giveItem(itemId, kit.IDs.get(entry.getKey()));
  128.                                 } catch (Exception e1) {
  129.                                     log.info("Got an exception while giving out a kit (Kit name \"" + kit.Name + "\"). Are you sure all the Ids are numbers?");
  130.                                     sendMessage(Colors.Rose + "The server encountered a problem while giving the kit :(");
  131.                                 }
  132.                         }
  133.                     } else
  134.                         sendMessage(Colors.Rose + "That kit does not exist.");
  135.                 } else
  136.                     sendMessage(Colors.Rose + "That user does not exist.");
  137.             } else if (cmd.equalsIgnoreCase("/tp")) {
  138.                 if (split.length < 2) {
  139.                     sendMessage(Colors.Rose + "Correct usage is: /tp [player]");
  140.                     return;
  141.                 }
  142.  
  143.                 Player player = etc.getServer().matchPlayer(split[1]);
  144.  
  145.                 if (player != null) {
  146.                     if (getName().equalsIgnoreCase(player.getName())) {
  147.                         sendMessage(Colors.Rose + "You're already here!");
  148.                         return;
  149.                     }
  150.  
  151.                     log.info(getName() + " teleported to " + player.getName());
  152.                     teleportTo(player);
  153.                 } else
  154.                     sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  155.             } else if ((cmd.equalsIgnoreCase("/tphere") || cmd.equalsIgnoreCase("/s"))) {
  156.                 if (split.length < 2) {
  157.                     sendMessage(Colors.Rose + "Correct usage is: /tphere [player]");
  158.                     return;
  159.                 }
  160.  
  161.                 Player player = etc.getServer().matchPlayer(split[1]);
  162.  
  163.                 if (player != null) {
  164.                     if (getName().equalsIgnoreCase(player.getName())) {
  165.                         sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
  166.                         return;
  167.                     }
  168.  
  169.                     log.info(getName() + " teleported " + player.getName() + " to their self.");
  170.                     player.teleportTo(this);
  171.                 } else
  172.                     sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  173.             } else if (cmd.equalsIgnoreCase("/playerlist") || cmd.equalsIgnoreCase("/who"))
  174.                 sendMessage(Colors.Rose + "Player list (" + etc.getMCServer().f.b.size() + "/" + etc.getInstance().getPlayerLimit() + "): " + Colors.White + etc.getMCServer().f.c());
  175.             else if (cmd.equalsIgnoreCase("/item") || cmd.equalsIgnoreCase("/i") || cmd.equalsIgnoreCase("/give")) {
  176.                 if (split.length < 2) {
  177.                     if (canIgnoreRestrictions())
  178.                         sendMessage(Colors.Rose + "Correct usage is: /item [itemid] <amount> <damage> <player> (optional)");
  179.                     else
  180.                         sendMessage(Colors.Rose + "Correct usage is: /item [itemid] <amount> <damage>");
  181.                     return;
  182.                 }
  183.  
  184.                 Player toGive = this;
  185.                 int itemId = 0, amount = 1, damage = 0;
  186.                 try {
  187.                     if (split.length > 1)
  188.                         try {
  189.                             itemId = Integer.parseInt(split[1]);
  190.                         } catch (NumberFormatException n) {
  191.                             itemId = etc.getDataSource().getItem(split[1]);
  192.                         }
  193.                     if (split.length > 2) {
  194.                         amount = Integer.parseInt(split[2]);
  195.                         if (amount <= 0 && !isAdmin())
  196.                             amount = 1;
  197.  
  198.                         if (amount > 64 && !canIgnoreRestrictions())
  199.                             amount = 64;
  200.                         if (amount > 1024)
  201.                             amount = 1024; // 16 stacks worth. More than enough.
  202.                     }
  203.                     if (split.length == 4) {
  204.                         int temp = -1;
  205.                         try {
  206.                             temp = Integer.parseInt(split[3]);
  207.                         } catch (NumberFormatException n) {
  208.                             if (canIgnoreRestrictions())
  209.                                 toGive = etc.getServer().matchPlayer(split[3]);
  210.                         }
  211.                         if (temp > -1 && temp < 50)
  212.                             damage = temp;
  213.                     } else if (split.length == 5) {
  214.                         damage = Integer.parseInt(split[3]);
  215.                         if (damage < 0 && damage > 49)
  216.                             damage = 0;
  217.                         if (canIgnoreRestrictions())
  218.                             toGive = etc.getServer().matchPlayer(split[4]);
  219.                     }
  220.  
  221.                 } catch (NumberFormatException localNumberFormatException) {
  222.                     sendMessage(Colors.Rose + "Improper ID and/or amount.");
  223.                     return;
  224.                 }
  225.  
  226.                 if (toGive != null) {
  227.  
  228.                     boolean allowedItem = etc.getInstance().getAllowedItems().isEmpty() || etc.getInstance().getAllowedItems().contains(itemId);
  229.  
  230.                     if (!etc.getInstance().getDisallowedItems().isEmpty() && etc.getInstance().getDisallowedItems().contains(itemId))
  231.                         allowedItem = false;
  232.  
  233.                     if (Item.isValidItem(itemId)) {
  234.                         if (allowedItem || canIgnoreRestrictions()) {
  235.                             Item i = new Item(itemId, amount, -1, damage);
  236.                             log.log(Level.INFO, "Giving " + toGive.getName() + " some " + i.toString());
  237.                             // toGive.giveItem(itemId, amount);
  238.                             Inventory inv = toGive.getInventory();
  239.                             ArrayList<Item> list = new ArrayList<Item>();
  240.                             for (Item it : inv.getContents())
  241.                                 if (it != null && it.getItemId() == i.getItemId() && it.getDamage() == i.getDamage())
  242.                                     list.add(it);
  243.  
  244.                             for (Item it : list) {
  245.                                 if (it.getAmount() < 64) {
  246.                                     if (amount >= 64 - it.getAmount()) {
  247.                                         amount -= 64 - it.getAmount();
  248.                                         it.setAmount(64);
  249.                                         toGive.giveItem(it);
  250.                                     } else {
  251.                                         it.setAmount(it.getAmount() + amount);
  252.                                         amount = 0;
  253.                                         toGive.giveItem(it);
  254.                                     }
  255.                                 }
  256.                             }
  257.                             if (amount != 0) {
  258.                                 i.setAmount(64);
  259.                                 while (amount > 64) {
  260.                                     amount -= 64;
  261.                                     toGive.giveItem(i);
  262.                                     i.setSlot(-1);
  263.                                 }
  264.                                 i.setAmount(amount);
  265.                                 toGive.giveItem(i);
  266.                             }
  267.                             if (toGive.getName().equalsIgnoreCase(getName()))
  268.                                 sendMessage(Colors.Rose + "There you go " + getName() + ".");
  269.                             else {
  270.                                 sendMessage(Colors.Rose + "Gift given! :D");
  271.                                 toGive.sendMessage(Colors.Rose + "Enjoy your gift! :D");
  272.                             }
  273.                         } else if (!allowedItem && !canIgnoreRestrictions())
  274.                             sendMessage(Colors.Rose + "You are not allowed to spawn that item.");
  275.                     } else
  276.                         sendMessage(Colors.Rose + "No item with ID " + split[1]);
  277.  
  278.                 } else
  279.                     sendMessage(Colors.Rose + "Can't find user " + split[3]);
  280.             } else if (cmd.equalsIgnoreCase("/cloth") || cmd.equalsIgnoreCase("/dye")) {
  281.                 if (split.length < 3) {
  282.                     sendMessage(Colors.Rose + "Correct usage is: " + cmd + " [amount] [color]");
  283.                     return;
  284.                 }
  285.                 try {
  286.                     int amount = Integer.parseInt(split[1]);
  287.                     if (amount <= 0 && !isAdmin())
  288.                         amount = 1;
  289.  
  290.                     if (amount > 64 && !canIgnoreRestrictions())
  291.                         amount = 64;
  292.                     if (amount > 1024)
  293.                         amount = 1024; // 16 stacks worth. More than enough.
  294.  
  295.                     String color = split[2];
  296.                     if (split.length > 3)
  297.                         color += " " + split[3];
  298.                     Cloth.Color c = Cloth.Color.getColor(color.toLowerCase());
  299.                     if (c == null) {
  300.                         sendMessage(Colors.Rose + "Invalid color name!");
  301.                         return;
  302.                     }
  303.                     Item i = c.getItem();
  304.  
  305.                     if (cmd.equalsIgnoreCase("/dye")) {
  306.                         i.setType(Item.Type.InkSack);
  307.                         // some1 had fun inverting this i guess .....
  308.                         i.setDamage(15 - i.getDamage());
  309.                     }
  310.                     i.setAmount(amount);
  311.                     log.log(Level.INFO, "Giving " + getName() + " some " + i.toString());
  312.  
  313.                     Inventory inv = getInventory();
  314.                     ArrayList<Item> list = new ArrayList<Item>();
  315.                     for (Item it : inv.getContents())
  316.                         if (it != null && it.getItemId() == i.getItemId() && it.getDamage() == i.getDamage())
  317.                             list.add(it);
  318.  
  319.                     for (Item it : list) {
  320.                         if (it.getAmount() < 64) {
  321.                             if (amount >= 64 - it.getAmount()) {
  322.                                 amount -= 64 - it.getAmount();
  323.                                 it.setAmount(64);
  324.                                 giveItem(it);
  325.                             } else {
  326.                                 it.setAmount(it.getAmount() + amount);
  327.                                 amount = 0;
  328.                                 giveItem(it);
  329.                             }
  330.                         }
  331.                     }
  332.                     if (amount != 0) {
  333.                         i.setAmount(64);
  334.                         while (amount > 64) {
  335.                             amount -= 64;
  336.                             giveItem(i);
  337.                             i.setSlot(-1);
  338.                         }
  339.                         i.setAmount(amount);
  340.                         giveItem(i);
  341.                     }
  342.                     sendMessage(Colors.Rose + "There you go " + getName() + ".");
  343.                 } catch (NumberFormatException localNumberFormatException) {
  344.                     sendMessage(Colors.Rose + "Improper ID and/or amount.");
  345.                 }
  346.  
  347.             } else if (cmd.equalsIgnoreCase("/tempban")) {
  348.                 // /tempban MINUTES HOURS DAYS
  349.                 if (split.length == 1)
  350.                     return;
  351.                 int minutes = 0, hours = 0, days = 0;
  352.                 if (split.length >= 2)
  353.                     minutes = Integer.parseInt(split[1]);
  354.                 if (split.length >= 3)
  355.                     hours = Integer.parseInt(split[2]);
  356.                 if (split.length >= 4)
  357.                     days = Integer.parseInt(split[3]);
  358.                 Date date = new Date();
  359.                 // date.
  360.             } else if (cmd.equalsIgnoreCase("/banlist")) {
  361.                 byte type = 0;
  362.                 if (split.length == 2)
  363.                     if (split[1].equalsIgnoreCase("ips"))
  364.                         type = 1;
  365.                 if (type == 0)
  366.                     sendMessage(Colors.Blue + "Ban list:" + Colors.White + " " + etc.getMCServer().f.getBans());
  367.                 else
  368.                     sendMessage(Colors.Blue + "IP Ban list:" + Colors.White + " " + etc.getMCServer().f.getIpBans());
  369.             } else if (cmd.equalsIgnoreCase("/banip")) {
  370.                 if (split.length < 2) {
  371.                     sendMessage(Colors.Rose + "Correct usage is: /banip [player] <reason> (optional) NOTE: this permabans IPs.");
  372.                     return;
  373.                 }
  374.  
  375.                 Player player = etc.getServer().matchPlayer(split[1]);
  376.  
  377.                 if (player != null) {
  378.                     if (!hasControlOver(player)) {
  379.                         sendMessage(Colors.Rose + "You can't ban that user.");
  380.                         return;
  381.                     }
  382.  
  383.                     // adds player to ban list
  384.                     etc.getMCServer().f.c(player.getIP());
  385.                     etc.getLoader().callHook(PluginLoader.Hook.IPBAN, new Object[] { this, player, split.length >= 3 ? etc.combineSplit(2, split, " ") : "" });
  386.  
  387.                     log.log(Level.INFO, "IP Banning " + player.getName() + " (IP: " + player.getIP() + ")");
  388.                     sendMessage(Colors.Rose + "IP Banning " + player.getName() + " (IP: " + player.getIP() + ")");
  389.  
  390.                     if (split.length > 2)
  391.                         player.kick("IP Banned by " + getName() + ": " + etc.combineSplit(2, split, " "));
  392.                     else
  393.                         player.kick("IP Banned by " + getName() + ".");
  394.                 } else
  395.                     sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  396.             } else if (cmd.equalsIgnoreCase("/ban")) {
  397.                 if (split.length < 2) {
  398.                     sendMessage(Colors.Rose + "Correct usage is: /ban [player] <reason> (optional)");
  399.                     return;
  400.                 }
  401.  
  402.                 Player player = etc.getServer().matchPlayer(split[1]);
  403.  
  404.                 if (player != null) {
  405.                     if (!hasControlOver(player)) {
  406.                         sendMessage(Colors.Rose + "You can't ban that user.");
  407.                         return;
  408.                     }
  409.  
  410.                     // adds player to ban list
  411.                     etc.getServer().ban(player.getName());
  412.  
  413.                     etc.getLoader().callHook(PluginLoader.Hook.BAN, new Object[] { this, player, split.length >= 3 ? etc.combineSplit(2, split, " ") : "" });
  414.  
  415.                     if (split.length > 2)
  416.                         player.kick("Banned by " + getName() + ": " + etc.combineSplit(2, split, " "));
  417.                     else
  418.                         player.kick("Banned by " + getName() + ".");
  419.                     log.log(Level.INFO, "Banning " + player.getName());
  420.                     sendMessage(Colors.Rose + "Banning " + player.getName());
  421.                 } else {
  422.                     // sendMessage(Colors.Rose + "Can't find user " + split[1] +
  423.                     // ".");
  424.                     etc.getServer().ban(split[1]);
  425.                     log.log(Level.INFO, "Banning " + split[1]);
  426.                     sendMessage(Colors.Rose + "Banning " + split[1]);
  427.                 }
  428.             } else if (cmd.equalsIgnoreCase("/unban")) {
  429.                 if (split.length != 2) {
  430.                     sendMessage(Colors.Rose + "Correct usage is: /unban [player]");
  431.                     return;
  432.                 }
  433.                 etc.getServer().unban(split[1]);
  434.                 sendMessage(Colors.Rose + "Unbanned " + split[1]);
  435.             } else if (cmd.equalsIgnoreCase("/unbanip")) {
  436.                 if (split.length != 2) {
  437.                     sendMessage(Colors.Rose + "Correct usage is: /unbanip [ip]");
  438.                     return;
  439.                 }
  440.                 etc.getMCServer().f.d(split[1]);
  441.                 sendMessage(Colors.Rose + "Unbanned " + split[1]);
  442.             } else if (cmd.equalsIgnoreCase("/kick")) {
  443.                 if (split.length < 2) {
  444.                     sendMessage(Colors.Rose + "Correct usage is: /kick [player] <reason> (optional)");
  445.                     return;
  446.                 }
  447.  
  448.                 Player player = etc.getServer().matchPlayer(split[1]);
  449.  
  450.                 if (player != null) {
  451.                     if (!hasControlOver(player)) {
  452.                         sendMessage(Colors.Rose + "You can't kick that user.");
  453.                         return;
  454.                     }
  455.  
  456.                     etc.getLoader().callHook(PluginLoader.Hook.KICK, new Object[] { this, player, split.length >= 3 ? etc.combineSplit(2, split, " ") : "" });
  457.  
  458.                     if (split.length > 2)
  459.                         player.kick("Kicked by " + getName() + ": " + etc.combineSplit(2, split, " "));
  460.                     else
  461.                         player.kick("Kicked by " + getName() + ".");
  462.                     log.log(Level.INFO, "Kicking " + player.getName());
  463.                     sendMessage(Colors.Rose + "Kicking " + player.getName());
  464.                 } else
  465.                     sendMessage(Colors.Rose + "Can't find user " + split[1] + ".");
  466.             } else if (cmd.equalsIgnoreCase("/me")) {
  467.                 if (isMuted()) {
  468.                     sendMessage(Colors.Rose + "You are currently muted.");
  469.                     return;
  470.                 }
  471.                 if (split.length == 1)
  472.                     return;
  473.                 String paramString2 = "* " + getColor() + getName() + Colors.White + " " + command.substring(command.indexOf(" ")).trim();
  474.                 log.info("* " + getName() + " " + command.substring(command.indexOf(" ")).trim());
  475.                 etc.getServer().messageAll(paramString2);
  476.             } else if (cmd.equalsIgnoreCase("/sethome")) {
  477.                 // player.k, player.l, player.m
  478.                 // x, y, z
  479.                 Warp home = new Warp();
  480.                 home.Location = getLocation();
  481.                 home.Group = ""; // no group neccessary, lol.
  482.                 home.Name = getName();
  483.                 etc.getInstance().changeHome(home);
  484.                 sendMessage(Colors.Rose + "Your home has been set.");
  485.             } else if (cmd.equalsIgnoreCase("/spawn"))
  486.                 teleportTo(etc.getServer().getSpawnLocation());
  487.             else if (cmd.equalsIgnoreCase("/setspawn")) {
  488.                 // New system in beta 1.3: WorldInfo.
  489.                 OWorldInfo info = etc.getMCServer().e.s;
  490.                 info.a((int) getX(), info.d(), (int) getZ());
  491.  
  492.                 log.info("Spawn position changed.");
  493.                 sendMessage(Colors.Rose + "You have set the spawn to your current position.");
  494.             } else if (cmd.equalsIgnoreCase("/home")) {
  495.                 Warp home = null;
  496.                 if (split.length > 1 && isAdmin())
  497.                     home = etc.getDataSource().getHome(split[1]);
  498.                 else
  499.                     home = etc.getDataSource().getHome(getName());
  500.  
  501.                 if (home != null)
  502.                     teleportTo(home.Location);
  503.                 else if (split.length > 1 && isAdmin())
  504.                     sendMessage(Colors.Rose + "That player home does not exist");
  505.                 else
  506.                     teleportTo(etc.getServer().getSpawnLocation());
  507.             } else if (cmd.equalsIgnoreCase("/warp")) {
  508.                 if (split.length < 2) {
  509.                     sendMessage(Colors.Rose + "Correct usage is: /warp [warpname]");
  510.                     return;
  511.                 }
  512.                 Player toWarp = this;
  513.                 Warp warp = null;
  514.                 if (split.length == 3 && canIgnoreRestrictions()) {
  515.                     warp = etc.getDataSource().getWarp(split[1]);
  516.                     toWarp = etc.getServer().matchPlayer(split[2]);
  517.                 } else
  518.                     warp = etc.getDataSource().getWarp(split[1]);
  519.                 if (toWarp != null) {
  520.                     if (warp != null) {
  521.                         if (!isInGroup(warp.Group) && !warp.Group.equals(""))
  522.                             sendMessage(Colors.Rose + "Warp not found.");
  523.                         else {
  524.                             toWarp.teleportTo(warp.Location);
  525.                             toWarp.sendMessage(Colors.Rose + "Woosh!");
  526.                         }
  527.                     } else
  528.                         sendMessage(Colors.Rose + "Warp not found");
  529.                 } else
  530.                     sendMessage(Colors.Rose + "Player not found.");
  531.             } else if (cmd.equalsIgnoreCase("/listwarps") && etc.getDataSource().hasWarps()) {
  532.                 if (split.length != 2 && split.length != 3) {
  533.                     sendMessage(Colors.Rose + "Available warps: " + Colors.White + etc.getDataSource().getWarpNames(this));
  534.                     return;
  535.                 }
  536.             } else if (cmd.equalsIgnoreCase("/setwarp")) {
  537.                 if (split.length < 2) {
  538.                     if (canIgnoreRestrictions())
  539.                         sendMessage(Colors.Rose + "Correct usage is: /setwarp [warpname] [group]");
  540.                     else
  541.                         sendMessage(Colors.Rose + "Correct usage is: /setwarp [warpname]");
  542.                     return;
  543.                 }
  544.                 if (split[1].contains(":")) {
  545.                     sendMessage("You can't set a warp with \":\" in its name");
  546.                     return;
  547.                 }
  548.                 Warp warp = new Warp();
  549.                 warp.Name = split[1];
  550.                 warp.Location = getLocation();
  551.                 if (split.length == 3)
  552.                     warp.Group = split[2];
  553.                 else
  554.                     warp.Group = "";
  555.                 etc.getInstance().setWarp(warp);
  556.                 sendMessage(Colors.Rose + "Created warp point " + split[1] + ".");
  557.             } else if (cmd.equalsIgnoreCase("/removewarp")) {
  558.                 if (split.length < 2) {
  559.                     sendMessage(Colors.Rose + "Correct usage is: /removewarp [warpname]");
  560.                     return;
  561.                 }
  562.                 Warp warp = etc.getDataSource().getWarp(split[1]);
  563.                 if (warp != null) {
  564.                     etc.getDataSource().removeWarp(warp);
  565.                     sendMessage(Colors.Blue + "Warp removed.");
  566.                 } else
  567.                     sendMessage(Colors.Rose + "That warp does not exist");
  568.             } else if (cmd.equalsIgnoreCase("/lighter")) {
  569.                 if (MinecraftServer.b.containsKey(getName() + " lighter")) {
  570.                     log.info(getName() + " failed to iron!");
  571.                     sendMessage(Colors.Rose + "You can't create another lighter again so soon");
  572.                 } else {
  573.                     if (!canIgnoreRestrictions())
  574.                         MinecraftServer.b.put(getName() + " lighter", Integer.valueOf(6000));
  575.                     log.info(getName() + " created a lighter!");
  576.                     giveItem(259, 1);
  577.                 }
  578.             } else if ((command.startsWith("/#")) && (etc.getMCServer().f.h(getName()))) {
  579.                 String str = command.substring(2);
  580.                 log.info(getName() + " issued server command: " + str);
  581.                 etc.getMCServer().a(str, getEntity().a);
  582.             } else if (cmd.equalsIgnoreCase("/time")) {
  583.                 if (split.length == 2) {
  584.                     if (split[1].equalsIgnoreCase("day"))
  585.                         etc.getServer().setRelativeTime(0);
  586.                     else if (split[1].equalsIgnoreCase("night"))
  587.                         etc.getServer().setRelativeTime(13000);
  588.                     else if (split[1].equalsIgnoreCase("check"))
  589.                         sendMessage(Colors.Rose + "The time is " + etc.getServer().getRelativeTime() + "! (RAW: " + etc.getServer().getTime() + ")");
  590.                     else
  591.                         try {
  592.                             etc.getServer().setRelativeTime(Long.parseLong(split[1]));
  593.                         } catch (NumberFormatException ex) {
  594.                             sendMessage(Colors.Rose + "Please enter numbers, not letters.");
  595.                         }
  596.                 } else if (split.length == 3) {
  597.                     if (split[1].equalsIgnoreCase("raw"))
  598.                         try {
  599.                             etc.getServer().setTime(Long.parseLong(split[2]));
  600.                         } catch (NumberFormatException ex) {
  601.                             sendMessage(Colors.Rose + "Please enter numbers, not letters.");
  602.                         }
  603.                 } else {
  604.                     sendMessage(Colors.Rose + "Correct usage is: /time [time|'day|night|check|raw'] (rawtime)");
  605.                     return;
  606.                 }
  607.             } else if (cmd.equalsIgnoreCase("/getpos")) {
  608.                 sendMessage("Pos X: " + getX() + " Y: " + getY() + " Z: " + getZ());
  609.                 sendMessage("Rotation: " + getRotation() + " Pitch: " + getPitch());
  610.  
  611.                 double degreeRotation = ((getRotation() - 90) % 360);
  612.                 if (degreeRotation < 0)
  613.                     degreeRotation += 360.0;
  614.                 sendMessage("Compass: " + etc.getCompassPointForDirection(degreeRotation) + " (" + (Math.round(degreeRotation * 10) / 10.0) + ")");
  615.             } else if (cmd.equalsIgnoreCase("/compass")) {
  616.                 double degreeRotation = ((getRotation() - 90) % 360);
  617.                 if (degreeRotation < 0)
  618.                     degreeRotation += 360.0;
  619.  
  620.                 sendMessage(Colors.Rose + "Compass: " + etc.getCompassPointForDirection(degreeRotation));
  621.             } else if (cmd.equalsIgnoreCase("/motd"))
  622.                 for (String str : etc.getInstance().getMotd())
  623.                     sendMessage(str);
  624.             else if (cmd.equalsIgnoreCase("/spawnmob")) {
  625.                 if (split.length == 1) {
  626.                     sendMessage(Colors.Rose + "Correct usage is: /spawnmob [name] <amount>");
  627.                     return;
  628.                 }
  629.                 if (!Mob.isValid(split[1])) {
  630.                     sendMessage(Colors.Rose + "Invalid mob. Name has to start with a capital like so: Pig");
  631.                     return;
  632.                 }
  633.  
  634.                 if (split.length == 2) {
  635.                     Mob mob = new Mob(split[1], getLocation());
  636.                     mob.spawn();
  637.                 } else if (split.length == 3)
  638.                     try {
  639.                         int mobnumber = Integer.parseInt(split[2]);
  640.                         for (int i = 0; i < mobnumber; i++) {
  641.                             Mob mob = new Mob(split[1], getLocation());
  642.                             mob.spawn();
  643.                         }
  644.                     } catch (NumberFormatException nfe) {
  645.                         if (!Mob.isValid(split[2])) {
  646.                             sendMessage(Colors.Rose + "Invalid mob name or number of mobs.");
  647.                             sendMessage(Colors.Rose + "Mob names have to start with a capital like so: Pig");
  648.                         } else {
  649.                             Mob mob = new Mob(split[1], getLocation());
  650.                             mob.spawn(new Mob(split[2]));
  651.                         }
  652.                     }
  653.                 else if (split.length == 4)
  654.                     try {
  655.                         int mobnumber = Integer.parseInt(split[3]);
  656.                         if (!Mob.isValid(split[2]))
  657.                             sendMessage(Colors.Rose + "Invalid rider. Name has to start with a capital like so: Pig");
  658.                         else
  659.                             for (int i = 0; i < mobnumber; i++) {
  660.                                 Mob mob = new Mob(split[1], getLocation());
  661.                                 mob.spawn(new Mob(split[2]));
  662.                             }
  663.                     } catch (NumberFormatException nfe) {
  664.                         sendMessage(Colors.Rose + "Invalid number of mobs.");
  665.                     }
  666.             } else if (cmd.equalsIgnoreCase("/clearinventory")) {
  667.                 Player target = this;
  668.                 if (split.length >= 2 && isAdmin())
  669.                     target = etc.getServer().matchPlayer(split[1]);
  670.                 if (target != null) {
  671.                     Inventory inv = target.getInventory();
  672.                     inv.clearContents();
  673.                     inv.update();
  674.                     if (!target.getName().equals(getName()))
  675.                         sendMessage(Colors.Rose + "Cleared " + target.getName() + "'s inventory.");
  676.                 } else
  677.                     sendMessage(Colors.Rose + "Target not found");
  678.             } else if (cmd.equals("/mspawn")) {
  679.                 if (split.length != 2) {
  680.                     sendMessage(Colors.Rose + "You must specify what to change the mob spawner to.");
  681.                     return;
  682.                 }
  683.                 if (!Mob.isValid(split[1])) {
  684.                     sendMessage(Colors.Rose + "Invalid mob specified.");
  685.                     return;
  686.                 }
  687.  
  688.                 HitBlox hb = new HitBlox(this);
  689.                 Block block = hb.getTargetBlock();
  690.                 if (block.getType() == 52) { // mob spawner
  691.                     MobSpawner ms = (MobSpawner) etc.getServer().getComplexBlock(block.getX(), block.getY(), block.getZ());
  692.                     if (ms != null)
  693.                         ms.setSpawn(split[1]);
  694.                 } else
  695.                     sendMessage(Colors.Rose + "You are not targeting a mob spawner.");
  696.             } else if (cmd.equals("/update")){
  697.                 if (Main.onlineVersion == etc.getInstance().getVersion())
  698.                     sendMessage(Colors.Rose + "You have the latest version of Canary.");
  699.                 else
  700.                     sendMessage(Colors.Rose + "You need to update your version of Canary.");
  701.         } else {
  702.                 log.info(getName() + " tried command " + command);
  703.                 if (etc.getInstance().showUnknownCommand())
  704.                     sendMessage(Colors.Rose + "Unknown command");*/
  705.         }          
  706.         } catch (Throwable ex) { // Might as well try and catch big exceptions
  707.             // before the server crashes from a stack
  708.             // overflow or something
  709.             log.log(Level.SEVERE, "Exception in command handler (Report this on github unless you did something dumb like enter letters as numbers):", ex);
  710.             if (isAdmin())
  711.                 sendMessage(Colors.Rose + "Exception occured. Check the server for more info.");
  712.         }
  713.     }
Advertisement
Add Comment
Please, Sign In to add comment