Advertisement
Guest User

Untitled

a guest
Aug 16th, 2020
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. package com.wakils.Launch;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.command.Command;
  6. import org.bukkit.command.CommandSender;
  7. import org.bukkit.entity.Player;
  8. // import org.bukkit.event.Listener;
  9. import org.bukkit.plugin.java.JavaPlugin;
  10.  
  11. public class Main extends JavaPlugin { // remember to 'implements Listener' when bringing a listener into the code
  12.  
  13. @Override
  14. public void onEnable() {
  15. // this.getServer().getPluginManager().registerEvents(this, this);
  16. }
  17.  
  18. @Override
  19. public void onDisable() {
  20.  
  21. }
  22.  
  23. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  24. if (label.equalsIgnoreCase("launch") || label.equalsIgnoreCase("lch") ) {
  25. if (!(sender instanceof Player)) {
  26. sender.sendMessage("Console can't use /launch");
  27. return true;
  28. }
  29. Player player = (Player) sender;
  30. // /launch
  31. if (!(player.hasPermission("launch.use"))) {
  32. player.sendMessage(ChatColor.RED + "" + "You don't have permission to do this!");
  33. return true;
  34. }
  35. if (args.length == 0) {
  36. player.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
  37. player.setVelocity(player.getLocation().getDirection().multiply(2).setY(2));
  38. return true;
  39.  
  40. }
  41. // /launch NUMBER/PLAYER
  42. if (args.length == 1) {
  43. // help
  44. if (args[0].equalsIgnoreCase("help")) {
  45. fail(player);
  46. return true;
  47. }
  48. //launch NUMBER
  49. if (isNum(args[0])) {
  50. player.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
  51. player.setVelocity(player.getLocation().getDirection().multiply(Integer.parseInt(args[0])).setY(2));
  52. return true;
  53. }
  54. //launch PLAYER
  55. if (!isNum(args[0])) {
  56. Player target = Bukkit.getServer().getPlayer(args[0]);
  57. if (!(player.hasPermission("launch.use.others"))) {
  58. player.sendMessage(ChatColor.RED + "" + "You don't have permission to do this!");
  59. return true;
  60. }
  61. if(target == null) {
  62. player.sendMessage(ChatColor.AQUA + args[0] + ChatColor.DARK_GREEN + " is either offline or doesn't exist.");
  63. return true;
  64. }
  65. if (!(target == player)) {
  66. player.sendMessage(ChatColor.DARK_GREEN + "You made " + ChatColor.YELLOW + ChatColor.BOLD + target.getName() +
  67. ChatColor.RESET + ChatColor.GREEN + " launch up into the sky!");
  68. }
  69. target.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
  70. target.setVelocity(target.getLocation().getDirection().multiply(2).setY(2));
  71. return true;
  72. }
  73.  
  74. }
  75.  
  76. // /launch PLAYER NUMBER
  77. Player target = Bukkit.getServer().getPlayer(args[0]);
  78. if (args.length == 2) {
  79. if (!(player.hasPermission("launch.use.others"))) {
  80. player.sendMessage(ChatColor.RED + "" + "You don't have permission to do this!");
  81. return true;
  82. }
  83. if(target == null) {
  84. player.sendMessage(ChatColor.AQUA + args[0] + ChatColor.DARK_GREEN + " is either offline or doesn't exist.");
  85. return true;
  86. }
  87. if(args[1] == null) {
  88. if (!(target == player)) {
  89. player.sendMessage(ChatColor.DARK_GREEN + "You made " + ChatColor.YELLOW + ChatColor.BOLD + target.getName() +
  90. ChatColor.RESET + ChatColor.GREEN + " launch up into the sky.");
  91. }
  92. target.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
  93. target.setVelocity(target.getLocation().getDirection().multiply(2).setY(2));
  94. return true;
  95. }
  96. if (!(target == player)) {
  97. player.sendMessage(ChatColor.DARK_GREEN + "You made " + ChatColor.YELLOW + ChatColor.BOLD + target.getName() +
  98. ChatColor.RESET + ChatColor.GREEN + " launch up into the sky.");
  99. }
  100. target.sendMessage(ChatColor.DARK_GREEN + "" + "You just got launched!");
  101. target.setVelocity(target.getLocation().getDirection().multiply(Integer.parseInt(args[1])).setY(2));
  102. return true;
  103.  
  104. }
  105.  
  106. fail(player);
  107. }
  108. return false;
  109. }
  110.  
  111. public boolean isNum(String num) {
  112. try {
  113. Integer.parseInt(num);
  114. } catch (Exception e) {
  115. return false;
  116. }
  117. return true;
  118. }
  119.  
  120. public void fail(final Player player) {
  121. player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4=== &6&lLAUNCH &4==="));
  122. player.sendMessage(ChatColor.BLUE + "Usage:");
  123. player.sendMessage(ChatColor.GRAY + "/lch " + ChatColor.WHITE + "- launches yourself");
  124. player.sendMessage(ChatColor.GRAY + "/lch <integer> " + ChatColor.WHITE + "- launches yourself at increased velocity");
  125. player.sendMessage(ChatColor.GRAY + "/lch <player>" + ChatColor.WHITE + " - launches player");
  126. player.sendMessage(ChatColor.GRAY + "/lch <player> <integer>" + ChatColor.WHITE + " - launches player at increased velocity");
  127. player.sendMessage(ChatColor.GRAY + "/lch help");
  128. player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4=== &6&lLAUNCH &4==="));
  129. }
  130.  
  131.  
  132.  
  133. // @EventHandler
  134. // public void onFall(EntityDamageEvent event) {
  135. // if (event.getEntity() instanceof Player) {
  136. // Player player = (Player) event.getEntity();
  137. // if (event.getCause() == DamageCause.FALL) {
  138. // this is where i need to check if the damage is caused by /launch
  139. // event.setCancelled(true);
  140. // }
  141. // }
  142. // }
  143. // }
  144.  
  145. }
  146.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement