Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.19 KB | None | 0 0
  1. package me.anticheater.syrix.managers.koth;
  2.  
  3. import org.bukkit.configuration.file.*;
  4. import org.bukkit.entity.*;
  5. import me.anticheater.syrix.*;
  6. import java.io.*;
  7. import org.bukkit.*;
  8. import me.anticheater.syrix.utils.*;
  9. import org.bukkit.plugin.*;
  10. import java.util.*;
  11.  
  12. public class KothManager
  13. {
  14. private static File file;
  15. private static YamlConfiguration configuration;
  16. public static String kothprefix;
  17. public static ArrayList<Player> capturer;
  18. public static boolean active;
  19. public static String activekoth;
  20. public static double kothtime;
  21. public static int kothtimer;
  22. public static int kingchecktimer;
  23. public static int kothbroadcasttimer;
  24.  
  25. static {
  26. KothManager.file = new File(Main.getInstance().getDataFolder(), "koths.yml");
  27. KothManager.configuration = YamlConfiguration.loadConfiguration(KothManager.file);
  28. KothManager.kothprefix = "&8[&6KoTh&8] ";
  29. KothManager.capturer = new ArrayList<Player>();
  30. KothManager.active = false;
  31. KothManager.activekoth = null;
  32. KothManager.kothtime = 120.0;
  33. }
  34.  
  35. public static YamlConfiguration getConfiguration() {
  36. return KothManager.configuration;
  37. }
  38.  
  39. public static void saveFile() {
  40. try {
  41. KothManager.configuration.save(KothManager.file);
  42. }
  43. catch (IOException e) {
  44. e.printStackTrace();
  45. }
  46. }
  47.  
  48. public static void startKoth(final String name) {
  49. KothManager.active = true;
  50. KothManager.activekoth = name;
  51. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
  52. Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588"));
  53. Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588\u2588\u2588\u2588\u2588&7\u2588"));
  54. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
  55. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
  56. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
  57. Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
  58. Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&9" + KothManager.activekoth + " &ekoth has been started!"));
  59. Bukkit.broadcastMessage(Main.translate("&cCoords: &7Under developing..."));
  60. Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
  61. KothManager.kothtime = 120.0;
  62. new LocationUtils(getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".max.x"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".min.x"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".max.y"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".min.y"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".max.z"), getConfiguration().getInt(String.valueOf(KothManager.activekoth.toLowerCase()) + ".min.z"), getConfiguration().getString(String.valueOf(KothManager.activekoth.toLowerCase()) + ".world"));
  63. KothManager.kothtimer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
  64. @Override
  65. public void run() {
  66. if (!KothManager.active) {
  67. KothManager.activekoth = null;
  68. KothManager.kothtime = 120.0;
  69. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
  70. Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
  71. KothManager.capturer.clear();
  72. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
  73. }
  74. if (!KothManager.capturer.isEmpty()) {
  75. if (KothManager.kothtime > 0.0) {
  76. KothManager.kothtime -= 0.1;
  77. }
  78. }
  79. else if (KothManager.kothtime != 120.0) {
  80. KothManager.kothtime = 120.0;
  81. }
  82. }
  83. }, 2L, 2L);
  84. KothManager.kingchecktimer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
  85. @Override
  86. public void run() {
  87. if (!KothManager.active) {
  88. KothManager.activekoth = null;
  89. KothManager.kothtime = 120.0;
  90. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
  91. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
  92. KothManager.capturer.clear();
  93. Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
  94. }
  95. for (final Player online : Bukkit.getServer().getOnlinePlayers()) {
  96. if (KothManager.capturer.isEmpty() && LocationUtils.hasPlayerInside(online)) {
  97. KothManager.capturer.add(online);
  98. online.sendMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eNow you are capturing..."));
  99. }
  100. else if (KothManager.capturer.contains(online) && !LocationUtils.hasPlayerInside(online)) {
  101. KothManager.capturer.remove(online);
  102. KothManager.kothtime = 120.0;
  103. online.sendMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eKnocked..."));
  104. }
  105. else {
  106. if (KothManager.kothtime > 0.0) {
  107. continue;
  108. }
  109. Player winner = null;
  110. if (KothManager.capturer.contains(online)) {
  111. winner = Bukkit.getServer().getPlayer(online.getName());
  112. }
  113. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
  114. Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588&6\u2588&7\u2588"));
  115. Bukkit.broadcastMessage(Main.translate("&7\u2588&6\u2588\u2588\u2588\u2588\u2588&7\u2588"));
  116. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
  117. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588&6\u2588&7\u2588\u2588\u2588"));
  118. Bukkit.broadcastMessage(Main.translate("&7\u2588\u2588\u2588\u2588\u2588\u2588\u2588"));
  119. Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
  120. Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&9" + KothManager.activekoth + " &ekoth captured by &c" + winner.getName() + "&e."));
  121. Bukkit.broadcastMessage(Main.translate("&8&m-------------------------------"));
  122. KothManager.active = false;
  123. KothManager.activekoth = null;
  124. KothManager.kothtime = 120.0;
  125. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
  126. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
  127. Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
  128. KothManager.capturer.clear();
  129. }
  130. }
  131. }
  132. }, 1L, 1L);
  133. KothManager.kothbroadcasttimer = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask((Plugin)Main.getInstance(), (Runnable)new Runnable() {
  134. @Override
  135. public void run() {
  136. if (!KothManager.active) {
  137. KothManager.activekoth = null;
  138. KothManager.kothtime = 120.0;
  139. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
  140. Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
  141. KothManager.capturer.clear();
  142. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
  143. }
  144. if (!KothManager.capturer.isEmpty()) {
  145. Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eSomebody capturing &c" + name + " &ekoth."));
  146. }
  147. else {
  148. Bukkit.broadcastMessage(Main.translate(String.valueOf(KothManager.kothprefix) + "&eNobody capturing &c" + name + " &ekoth."));
  149. }
  150. }
  151. }, 500L, 500L);
  152. }
  153.  
  154. public static void stopKoth() {
  155. KothManager.active = false;
  156. KothManager.activekoth = null;
  157. KothManager.kothtime = 120.0;
  158. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothbroadcasttimer);
  159. Bukkit.getServer().getScheduler().cancelTask(KothManager.kothtimer);
  160. Bukkit.getServer().getScheduler().cancelTask(KothManager.kingchecktimer);
  161. }
  162.  
  163. public static boolean isActive() {
  164. return KothManager.active;
  165. }
  166.  
  167. public static String formatMillisecondsToMinutes(final Double d) {
  168. final int m1 = (int)(d % 60.0);
  169. final int m2 = (int)(d / 60.0);
  170. final String string = String.format("%02d:%02d", m2, m1);
  171. return string;
  172. }
  173.  
  174. public static String formatMillisecondsToSeconds(final Double d) {
  175. final String timer = String.format("%1$.1f", d);
  176. final String string = String.valueOf(timer.replace(",", "."));
  177. return string;
  178. }
  179.  
  180. public static String getTime() {
  181. if (KothManager.kothtime > 60.0) {
  182. return formatMillisecondsToMinutes(KothManager.kothtime);
  183. }
  184. return String.valueOf(formatMillisecondsToSeconds(KothManager.kothtime)) + "s";
  185. }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement