Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. package me.fatal;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.util.ArrayList;
  6. import java.util.List;
  7. import java.util.Set;
  8.  
  9. import org.bukkit.Bukkit;
  10. import org.bukkit.Location;
  11. import org.bukkit.Material;
  12. import org.bukkit.World;
  13. import org.bukkit.block.Block;
  14. import org.bukkit.command.Command;
  15. import org.bukkit.command.CommandSender;
  16. import org.bukkit.configuration.file.YamlConfiguration;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.plugin.PluginManager;
  19. import org.bukkit.plugin.java.JavaPlugin;
  20.  
  21. import net.md_5.bungee.api.ChatColor;
  22.  
  23. public class JumpPad extends JavaPlugin {
  24.  
  25. public File file = new File(getDataFolder() + "/padlocations.yml");
  26.  
  27. public static List<Location> blockLocs = new ArrayList<Location>();
  28. public static Location Location;
  29. String createPerm = "jumppad.create";
  30. String removePerm = "jumppad.remove";
  31.  
  32. String noPerms = (ChatColor.RED + "You do not have access to this command.");
  33.  
  34.  
  35. public JumpPad() {
  36.  
  37. }
  38.  
  39. @Override
  40. public void onEnable() {
  41. registerConfig();
  42. PluginManager pm = getServer().getPluginManager();
  43. ListenerClass list = new ListenerClass(this);
  44. JumpPadManager jpm = new JumpPadManager();
  45. pm.registerEvents(list, this);
  46.  
  47. World world = (World)getConfig().get("world");
  48. Location locc = new Location(world, getConfig().getDouble(".x"), getConfig().getDouble(".y"), getConfig().getDouble(".y"));
  49.  
  50.  
  51.  
  52.  
  53. blockLocs.add(locc);
  54.  
  55. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
  56. public void run() {
  57.  
  58. //Bukkit.broadcastMessage("" + locc);
  59. blockLocs.add(locc);
  60.  
  61.  
  62. }
  63. }, 20, 1);
  64.  
  65. }
  66.  
  67.  
  68.  
  69.  
  70. @Override
  71. public void onDisable() {
  72.  
  73. }
  74.  
  75. private void registerConfig(){
  76. getConfig().options().copyDefaults(true);
  77. saveConfig();
  78. }
  79.  
  80. public boolean onCommand(CommandSender pl, Command cmd, String label, String[] args) {
  81. Player p = (Player) pl;
  82. @SuppressWarnings("deprecation")
  83. Block block = p.getTargetBlock((Set<Material>) null, 5);
  84.  
  85. Location bLoc = block.getLocation();
  86.  
  87.  
  88.  
  89. if (cmd.getName().equalsIgnoreCase("jumppad")) {
  90.  
  91. if (p instanceof Player) {
  92. if (args.length == 0) {
  93. pl.sendMessage(ChatColor.RED + "Usage : /jumppad <Create/Remove> <Multiplier(Number)> <BlockName>");
  94. pl.sendMessage(ChatColor.RED+ "[WARNING] :" + ChatColor.GREEN + " Keep this number under 100, otherwise the sever might crash!");
  95.  
  96. } else if (args.length >= 1) {
  97. if (args[0].equalsIgnoreCase("create")) {
  98. if (args.length == 3) {
  99.  
  100. if (pl.hasPermission(createPerm)) {
  101. if (!block.getType().isSolid()) {
  102.  
  103. p.sendMessage(ChatColor.RED + "You must be looking at a block, 5 blocks away or closer.");
  104. return false;
  105. } else {
  106. if (isFloat(args[1])) {
  107. //Location = bLoc;
  108. JumpPadManager.CreatePad(bLoc, p, Float.parseFloat(args[1]));
  109.  
  110.  
  111.  
  112.  
  113. String name = args[2].toString();
  114. getConfig().set("block." + name + ".location", bLoc);
  115.  
  116. saveConfig();
  117. //blockLocs.add((bLoc));
  118. } else if (args[1] == null || !isFloat(args[1])){
  119. p.sendMessage(ChatColor.RED + "You must specify a multiplier to the jumppad");
  120. p.sendMessage(ChatColor.RED+ "[WARNING] :" + ChatColor.GREEN + " Keep this number under 100, otherwise the sever might crash!");
  121. }
  122. }
  123. }
  124. } else {
  125. pl.sendMessage(ChatColor.RED + "Usage : /jumppad <Create/Remove> <Multiplier(Number)> <BlockName>");
  126. pl.sendMessage(ChatColor.RED+ "[WARNING] :" + ChatColor.GREEN + " Keep this number under 100, otherwise the sever might crash!");
  127. }
  128. } else if (args[0].equalsIgnoreCase("remove")) {
  129. if (pl.hasPermission(removePerm)) {
  130. if (!block.getType().isSolid()) {
  131. pl.sendMessage(ChatColor.RED + "You must be looking at a block, 5 blocks away or closer.");
  132. return false;
  133. } else {
  134.  
  135. // String location = bLoc.getWorld().getName() + "," + bLoc.getX() + "," + bLoc.getY() + "," + bLoc.getZ() + "," + bLoc.getYaw() + "," + bLoc.getPitch();
  136. // List<String> locations = this.getConfig().getStringList("locations");
  137. // locations.remove(location);
  138. // this.getConfig().set("locations", null);
  139. // this.saveConfig();
  140. JumpPadManager.RemovePad(bLoc, p);
  141. }
  142. }
  143.  
  144. } else if (args[0].equalsIgnoreCase("list")) {
  145. p.sendMessage(blockLocs + " <");
  146. }
  147. }
  148. } else {
  149. pl.sendMessage(ChatColor.RED + "You must be in game to access this command!");
  150.  
  151. return false;
  152. }
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166. return false;
  167. }
  168. return false;
  169.  
  170.  
  171. }
  172.  
  173. private boolean isFloat(String text) {
  174. try {
  175. Float.parseFloat(text);
  176. return true;
  177.  
  178. } catch (Exception e) {
  179. return false;
  180. }
  181. }
  182. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement