Advertisement
Guest User

Untitled

a guest
May 24th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. package net.plaria.system.utils.manager;
  2.  
  3. import com.google.common.collect.Lists;
  4. import de.dytanic.cloudnet.common.collection.Maps;
  5. import net.plaria.system.SystemPlugin;
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.Location;
  8. import org.bukkit.World;
  9.  
  10. import java.util.List;
  11. import java.util.Map;
  12.  
  13. public class WarpManager {
  14.  
  15. private final SystemPlugin systemPlugin;
  16. private final Map<String, Location> warps;
  17. private final Map<String, Integer> warpProtection;
  18.  
  19. /**
  20. *
  21. * @param systemPlugin
  22. */
  23.  
  24. public WarpManager(final SystemPlugin systemPlugin) {
  25. this.systemPlugin = systemPlugin;
  26. this.warps = Maps.newConcurrentHashMap();
  27. this.warpProtection = Maps.newConcurrentHashMap();
  28. loadWarps();
  29. }
  30.  
  31. /**
  32. * Warps:
  33. * - NAME;WORLD;X;Y;Z;Yaw;Pitch;Protection-Radius
  34. *
  35. * Example:
  36. * - Qetz;world;0;100;0;0;010
  37. */
  38.  
  39. private void loadWarps() {
  40. Bukkit.getScheduler().runTaskLaterAsynchronously(this.systemPlugin, () -> {
  41. for(String warp : this.systemPlugin.getConfigFileHandler().getCfg().getStringList("Warps")) {
  42. String warpName = warp.split(";")[0].toUpperCase();
  43. World world = Bukkit.getWorld(warp.split(";")[1]);
  44. double x = Double.parseDouble(warp.split(";")[2]);
  45. double y = Double.parseDouble(warp.split(";")[3]);
  46. double z = Double.parseDouble(warp.split(";")[4]);
  47. float yaw = Float.parseFloat(warp.split(";")[5]);
  48. float pitch = Float.parseFloat(warp.split(";")[6]);
  49. int protection = Integer.parseInt(warp.split(";")[7]);
  50.  
  51. addWarp(warpName, new Location(world, x, y, z, yaw, pitch), protection);
  52. }
  53. }, 20 * 3);
  54.  
  55. }
  56.  
  57. public void saveWarps() {
  58. List<String> warps = Lists.newArrayList();
  59. for(String warpName : this.warps.keySet()) {
  60. Location warpLocation = this.warps.get(warpName.toUpperCase());
  61. int protection = this.warpProtection.get(warpName.toUpperCase());
  62.  
  63. warps.add(warpName + ";" + warpLocation.getWorld() + ";" + warpLocation.getX() + ";" + warpLocation.getY() +
  64. ";" + warpLocation.getZ() + warpLocation.getYaw() + warpLocation.getPitch() + ";" + protection);
  65. }
  66. this.systemPlugin.getConfigFileHandler().getCfg().set("Warps", warps);
  67. this.systemPlugin.getConfigFileHandler().save();
  68. }
  69.  
  70. public boolean existWarp(String warpName) {
  71. return this.warps.containsKey(warpName.toUpperCase());
  72. }
  73.  
  74. public boolean addWarp(String warpName, Location warpLocation, int protection) {
  75. if (!existWarp(warpName.toUpperCase())) {
  76. this.warps.put(warpName.toUpperCase(), warpLocation);
  77. this.warpProtection.put(warpName.toUpperCase(), protection);
  78. return true;
  79. }
  80. return false;
  81. }
  82.  
  83. public boolean addWarp(String warpName, Location warpLocation) {
  84. return addWarp(warpName, warpLocation, 0);
  85. }
  86.  
  87. public boolean removeWarp(String warpName) {
  88. if(existWarp(warpName.toUpperCase())) {
  89. this.warps.remove(warpName.toUpperCase());
  90. this.warpProtection.remove(warpName.toUpperCase());
  91. return true;
  92. }
  93. return false;
  94. }
  95.  
  96. public Location getLocation(String warpName) {
  97. return this.warps.get(warpName.toUpperCase());
  98. }
  99.  
  100. public int getProtection(String warpName) {
  101. return this.warpProtection.get(warpName.toUpperCase());
  102. }
  103.  
  104. public String[] getNames() {
  105. return this.warps.keySet().toArray(new String[warps.keySet().size()]);
  106. }
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement