Advertisement
Guest User

commands.class

a guest
Nov 21st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. package site.joshinator117.Checkpoints.commands;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandExecutor;
  7. import org.bukkit.command.CommandSender;
  8. import org.bukkit.configuration.file.FileConfiguration;
  9. import org.bukkit.entity.Player;
  10.  
  11. import site.joshinator117.Checkpoints.utils.CPlayer;
  12. import site.joshinator117.Checkpoints.utils.Config;
  13.  
  14. public class Commands implements CommandExecutor {
  15.  
  16. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  17.  
  18. if ((sender instanceof Player)) {
  19.  
  20. } else {
  21.  
  22. sender.sendMessage("This command is not supported by the console/commandblock!");
  23. sender.sendMessage("It can only be executed as a player cause it's a help menu!");
  24. return false;
  25.  
  26. }
  27.  
  28. Player p = (Player) sender;
  29.  
  30. if (cmd.getName().equalsIgnoreCase("checkpoints")) {
  31.  
  32. if (p.hasPermission("checkpoints.admin")) {
  33.  
  34. p.sendMessage(Config.c("&8&m*]-----------[*&r &9&lCheckPoints &8&m*]-----------[*&r"));
  35. p.sendMessage(Config.c("&b/checkpoints &8» &7Laat het help bericht zien"));
  36. p.sendMessage(Config.c("&b/checkpoint &8» &7Ga terug naar je laatste checkpoint"));
  37. p.sendMessage(Config.c("&b/cp &8» &7Ga terug naar je laatste checkpoint"));
  38. p.sendMessage(Config.c("&b/checkpoint reset &9<&bplayer&9> &8» &7Reset iemand z'n checkpoint"));
  39. p.sendMessage(Config.c("&b/cpreset &9<&bplayer&9> &8» &7Reset iemand z'n checkpoint"));
  40. p.sendMessage(Config.c("&b/cpsetspawn &8» &7Zet het default respawn punt"));
  41. p.sendMessage(Config.c("&b/checkpoint reload &8» &7Reload de config"));
  42. p.sendMessage(Config.c("&b/checkpoint sendback &8» &7Stuurt een speler terug naar de default spawn"));
  43. p.sendMessage(Config.c("&8&m*]---------------------------------------[*&r"));
  44. return true;
  45.  
  46. } else {
  47.  
  48. p.sendMessage(Config.c("&8&m*]-----------[*&r &9&lCheckPoints &8&m*]-----------[*&r"));
  49. p.sendMessage(Config.c("&b/checkpoints &8» &7Laat het help bericht zien"));
  50. p.sendMessage(Config.c("&b/checkpoint &8» &7Ga terug naar je laatste checkpoint"));
  51. p.sendMessage(Config.c("&b/cp &8» &7Ga terug naar je laatste checkpoint"));
  52. p.sendMessage(Config.c("&8&m*]---------------------------------------[*&r"));
  53. return true;
  54.  
  55. }
  56.  
  57. } else if (cmd.getName().equalsIgnoreCase("checkpoint") || cmd.getName().equalsIgnoreCase("cp")) {
  58. if (args.length == 0) {
  59.  
  60. if (!(CPlayer.getCPlayer(p).getCheckpoint() == null)) {
  61.  
  62. Location loc = CPlayer.getCPlayer(p).getCheckpoint();
  63. p.teleport(loc);
  64.  
  65. } else {
  66.  
  67. return false;
  68.  
  69. }
  70. } else if (args.length == 2) {
  71.  
  72. if (args[0].equalsIgnoreCase("sendback")) {
  73.  
  74. if (p.hasPermission("checkpoint.admin")) {
  75.  
  76. if (!(args[1] == null)) {
  77.  
  78. Player p2;
  79.  
  80. try {
  81. p2 = Bukkit.getPlayer(args[1]);
  82. } catch (NullPointerException e) {
  83. p.sendMessage(Config.c(Config.getInstance().prefix + " "
  84. + Config.getInstance().getConfig().getString("Messages.Player is not online")));
  85. return false;
  86. }
  87.  
  88. p2.sendMessage(Config.c(Config.getInstance().prefix + " "
  89. + Config.getInstance().getConfig().getString("Messages.Player is sent back")));
  90.  
  91. FileConfiguration c = Config.getInstance().getConfig();
  92.  
  93. double x = c.getDouble("Default Checkpoint.x");
  94. double y = c.getDouble("Default Checkpoint.y");
  95. double z = c.getDouble("Default Checkpoint.z");
  96.  
  97. float yaw = (float) c.getDouble("Default Checkpoint.yaw");
  98. float pitch = (float) c.getDouble("Default Checkpoint.pitch");
  99.  
  100. Location l = new Location(Bukkit.getWorld(c.getString("Default Checkpoint.World")), x, y, z, yaw, pitch);
  101.  
  102. CPlayer.getCPlayer(p2).setCheckpoint(l);
  103. p2.teleport(l);
  104. p2.sendMessage(Config.c("&f&l[&a&lParkour&f&l] &aYou completed a course!"));
  105.  
  106. } else {
  107.  
  108. return false;
  109.  
  110. }
  111. }
  112.  
  113. }
  114.  
  115. if (args[0].equalsIgnoreCase("reset")) {
  116.  
  117. if (p.hasPermission("checkpoint.admin")) {
  118.  
  119. if (!(args[1] == null)) {
  120.  
  121. Player p2;
  122.  
  123. try {
  124. p2 = Bukkit.getPlayer(args[1]);
  125. } catch (NullPointerException e) {
  126. p.sendMessage(Config.c(Config.getInstance().prefix + " "
  127. + Config.getInstance().getConfig().getString("Messages.Player is not online")));
  128. return false;
  129. }
  130.  
  131. FileConfiguration c = Config.getInstance().getConfig();
  132.  
  133. double x = c.getDouble("Default Checkpoint.x");
  134. double y = c.getDouble("Default Checkpoint.y");
  135. double z = c.getDouble("Default Checkpoint.z");
  136.  
  137. float yaw = (float) c.getDouble("Default Checkpoint.yaw");
  138. float pitch = (float) c.getDouble("Default Checkpoint.pitch");
  139.  
  140. Location l = new Location(Bukkit.getWorld(c.getString("Default Checkpoint.World")), x, y, z, yaw, pitch);
  141.  
  142. CPlayer.getCPlayer(p2).setCheckpoint(l);
  143.  
  144. p.sendMessage(Config.c("&cYou reset the checkpoint of " + p2.getName()));
  145.  
  146. } else {
  147.  
  148. return false;
  149.  
  150. }
  151.  
  152. } else {
  153.  
  154. p.sendMessage(Config.c(Config.getInstance().prefix + " "
  155. + Config.getInstance().getConfig().getString("Messages.Permissions Denied")));
  156. return false;
  157.  
  158. }
  159.  
  160. }
  161.  
  162. } else if (args.length == 1) {
  163.  
  164. if (p.hasPermission("checkpoint.admin")) {
  165.  
  166. if (args[0].equalsIgnoreCase("setspawn")) {
  167.  
  168. FileConfiguration c = Config.getInstance().getConfig();
  169.  
  170. Location l = p.getLocation().getBlock().getLocation();
  171.  
  172. double x = l.getX();
  173. double y = l.getY();
  174. double z = l.getZ();
  175.  
  176. float yaw = (float) l.getYaw();
  177. float pitch = (float) l.getPitch();
  178.  
  179. c.set("Default Checkpoint.World", l.getWorld().getName());
  180. c.set("Default Checkpoint.x", x);
  181. c.set("Default Checkpoint.y", y);
  182. c.set("Default Checkpoint.z", z);
  183. c.set("Default Checkpoint.pitch", pitch);
  184. c.set("Default Checkpoint.yaw", yaw);
  185.  
  186. Config.getInstance().saveConfig();
  187. Config.getInstance().reloadConfig();
  188. p.sendMessage(Config.c("&aSuccesfully setted default-spawn"));
  189.  
  190. }
  191.  
  192. if (args[0].equalsIgnoreCase("reload")) {
  193.  
  194. Config.getInstance().reloadConfig();
  195. p.sendMessage(Config.c("&aSuccessfully reloaded the config!"));
  196. }
  197.  
  198. } else {
  199.  
  200. p.sendMessage(Config.c(Config.getInstance().prefix + " "
  201. + Config.getInstance().getConfig().getString("Messages.Permissions Denied")));
  202. return false;
  203.  
  204. }
  205.  
  206. }
  207.  
  208. }
  209. return false;
  210. }
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement