patison234

Untitled

Jul 31st, 2015
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.29 KB | None | 0 0
  1. package com.gmail.filoghost.touchscreen.command.subs;
  2.  
  3. import com.gmail.filoghost.holographicdisplays.api.line.TextLine;
  4. import com.gmail.filoghost.holographicdisplays.object.NamedHologram;
  5. import com.gmail.filoghost.holographicdisplays.object.NamedHologramManager;
  6. import com.gmail.filoghost.touchscreen.Command;
  7. import com.gmail.filoghost.touchscreen.Database;
  8. import com.gmail.filoghost.touchscreen.TouchHologram;
  9. import com.gmail.filoghost.touchscreen.TouchManager;
  10. import com.gmail.filoghost.touchscreen.command.CommandValidator;
  11. import com.gmail.filoghost.touchscreen.command.TouchSubCommand;
  12. import com.gmail.filoghost.touchscreen.command.TouchSubCommand.SubCommandType;
  13. import com.gmail.filoghost.touchscreen.exception.CommandException;
  14. import com.gmail.filoghost.touchscreen.utils.Format;
  15. import com.gmail.filoghost.touchscreen.utils.StringUtils;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. import org.bukkit.ChatColor;
  19. import org.bukkit.command.CommandSender;
  20.  
  21. public class AddCommand
  22. extends TouchSubCommand
  23. {
  24. public AddCommand()
  25. {
  26. super("add", new String[] { "addcmd", "addcommand" });
  27. setPermission("touchscreenholograms.admin");
  28. }
  29.  
  30. public String getPossibleArguments()
  31. {
  32. return "<hologram> <command>";
  33. }
  34.  
  35. public int getMinimumArguments()
  36. {
  37. return 2;
  38. }
  39.  
  40. public void execute(CommandSender sender, String[] args)
  41. throws CommandException
  42. {
  43. TouchHologram touch = TouchManager.getByName(args[0].toLowerCase());
  44. if (touch == null)
  45. {
  46. NamedHologram hologram = NamedHologramManager.getHologram(args[0]);
  47. CommandValidator.notNull(hologram, "There's no hologram with that name. The name is case sensitive.");
  48.  
  49. touch = new TouchHologram(hologram.getName());
  50. TouchManager.add(touch);
  51. TouchManager.refreshAll();
  52. if (hologram.size() == 0)
  53. {
  54. Format.sendWarning(sender, "The hologram has no lines!");
  55. }
  56. else
  57. {
  58. if (hologram.size() > 1) {
  59. Format.sendWarning(sender, "You selected a hologram that contains more than one line: it's recommanded to use holograms with a single line, because the click wouldn't be detected correctly in the other lines.");
  60. }
  61. if (((hologram.getLine(0) instanceof TextLine)) && (((TextLine)hologram.getLine(0)).getText().length() > 6)) {
  62. Format.sendWarning(sender, "You selected a hologram with the first line longer than 6 chars. Since the holograms rotate (client side), you should reduce the length, because the click wouldn't be detected correctly.");
  63. }
  64. }
  65. }
  66. String command = StringUtils.join(args, " ", 1, args.length);
  67. if (command.startsWith("/")) {
  68. Format.sendWarning(sender, "You used a slash before the command, is that an error? For normal commands, do not include the slash.");
  69. }
  70. touch.getCommands().add(Command.fromString(command));
  71.  
  72. Database.saveTouchHologram(touch);
  73. Database.trySaveToDisk();
  74. sender.sendMessage(ChatColor.GREEN + "Command added to the hologram!");
  75. }
  76.  
  77. public List<String> getTutorial()
  78. {
  79. return Arrays.asList(new String[] { "Adds a command to a hologram." });
  80. }
  81.  
  82. public TouchSubCommand.SubCommandType getType()
  83. {
  84. return TouchSubCommand.SubCommandType.NORMAL;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment