Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.63 KB | None | 0 0
  1. package ru.meloncode.cristalix.prison.mobs;
  2.  
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import java.util.UUID;
  8.  
  9. import org.bukkit.ChatColor;
  10. import org.bukkit.Location;
  11. import org.bukkit.Material;
  12. import org.bukkit.inventory.ItemStack;
  13.  
  14. import com.gmail.filoghost.holographicdisplays.api.Hologram;
  15. import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
  16.  
  17. import net.minecraft.server.v1_12_R1.Entity;
  18. import ru.meloncode.cristalix.prison.Main;
  19.  
  20. /* public class Spawner
  21. {
  22. public static Map<UUID, Spawner> spawners;
  23. Location location;
  24. EntityTypes type;
  25. Entity current;
  26. long deathtime;
  27. int interval;
  28. UUID uid;
  29.  
  30. static {
  31. Spawner.spawners = new HashMap<UUID, Spawner>();
  32. }
  33.  
  34. public Spawner(final Location location, final EntityTypes type, final int interval) {
  35. this.location = location;
  36. this.current = null;
  37. this.deathtime = -1L;
  38. this.uid = UUID.randomUUID();
  39. this.type = type;
  40. this.interval = interval;
  41. Spawner.spawners.put(this.uid, this);
  42. }
  43.  
  44. public void spawn() {
  45. if (this.location.getChunk().isLoaded()) {
  46. EntityTypes.spawnEntity(this.type, this.location.clone().add(0.0, 1.0, 0.0), this);
  47. }
  48. }
  49.  
  50. public void iDead() {
  51. this.current = null;
  52. this.deathtime = System.currentTimeMillis() / 1000L;
  53. }
  54.  
  55. public Location getSpawnLocation() {
  56. return this.location;
  57. }
  58.  
  59. public void update() {
  60. if (this.current == null) {
  61. if (System.currentTimeMillis() / 1000L - this.deathtime >= this.interval) {
  62. this.spawn();
  63. }
  64. }
  65. else if (this.current.getBukkitEntity().getLocation().distance(this.location) > 64.0) {
  66. this.reset();
  67. }
  68. }
  69.  
  70. public void register(final Entity me) {
  71. this.current = me;
  72. }
  73.  
  74. public void reset() {
  75. if (this.current != null) {
  76. if (this.current.passengers.size() != 0) {
  77. this.current.passengers.get(0).getBukkitEntity().remove();
  78. }
  79. this.current.getBukkitEntity().remove();
  80. }
  81. this.deathtime = -1L;
  82. this.spawn();
  83. }
  84.  
  85. public UUID getUid() {
  86. return this.uid;
  87. }
  88.  
  89. public Entity getCurrent() {
  90. return this.current;
  91. }
  92.  
  93. public EntityTypes getType() {
  94. return this.type;
  95. }
  96. } */
  97.  
  98. public class Spawner
  99. {
  100. public static Map<UUID, Spawner> spawners;
  101. Location location;
  102. EntityTypes type;
  103. Entity current;
  104. long deathtime;
  105. int interval;
  106. UUID uid;
  107. Hologram hologram;
  108.  
  109. static {
  110. Spawner.spawners = new HashMap<UUID, Spawner>();
  111. }
  112.  
  113. public Spawner(final Location location, final EntityTypes type, final int interval) {
  114. this.location = location;
  115. this.current = null;
  116. this.deathtime = -1L;
  117. this.uid = UUID.randomUUID();
  118. this.type = type;
  119. this.interval = interval;
  120. Spawner.spawners.put(this.uid, this);
  121. }
  122.  
  123. public void create(String boss, int rewardMoney, int rewardExp) {
  124. if (this.hologram == null) {
  125. System.out.println("hologram is null. but Why?...");
  126. }
  127. this.hologram.clearLines();
  128. if (System.currentTimeMillis() / 1000L - (this.deathtime + 1) >= this.interval) {
  129. /* this.hologram.appendTextLine(ChatColor.RED + "УЖЕ ЗАРЕСПАУНЕН"); */
  130. } else {
  131. this.hologram.appendTextLine(ChatColor.DARK_GREEN + (getTime((this.deathtime + this.interval) - System.currentTimeMillis() / 1000L)));
  132. }
  133. }
  134.  
  135. public void create() {
  136. this.hologram = HologramsAPI.createHologram(Main.getInstance(), location.clone().add(0, 2, 0));
  137. if (this.hologram == null) {
  138. System.out.println("hologram is null. but Why?...");
  139. }
  140. this.hologram.clearLines();
  141. /* this.hologram.appendTextLine(ChatColor.RED + "УЖЕ ЗАРЕСПАУНЕН"); */
  142. }
  143.  
  144. public void spawn() {
  145. if (this.location.getChunk().isLoaded()) {
  146. if(this.hologram != null)
  147. this.hologram.delete();
  148. create();
  149. EntityTypes.spawnEntity(this.type, this.location.clone().add(0.0, 1.0, 0.0), this);
  150. } else {
  151. location.getWorld().loadChunk(location.getChunk());
  152. if(this.hologram != null)
  153. this.hologram.delete();
  154. create();
  155. EntityTypes.spawnEntity(this.type, this.location.clone().add(0.0, 1.0, 0.0), this);
  156. }
  157. }
  158.  
  159. public void iDead() {
  160. this.current = null;
  161. this.deathtime = System.currentTimeMillis() / 1000L;
  162. }
  163.  
  164. public Location getSpawnLocation() {
  165. return this.location;
  166. }
  167.  
  168. public long getTime() {
  169. return this.interval - (System.currentTimeMillis() / 1000L - this.deathtime);
  170. }
  171.  
  172. public void update() {
  173. if (this.current == null) {
  174. if (System.currentTimeMillis() / 1000L - this.deathtime >= this.interval) {
  175. this.spawn();
  176. }
  177. }
  178. else if (this.current.getBukkitEntity().getLocation().distance(this.location) > 64.0) {
  179. this.reset();
  180. }
  181. }
  182.  
  183. public void update(String boss, int rewardMoney, int rewardExp) {
  184. if (this.current == null) {
  185. if (System.currentTimeMillis() / 1000L - this.deathtime >= this.interval) {
  186. this.spawn();
  187. } else {
  188. this.create(boss, rewardMoney, rewardExp);
  189. }
  190. }
  191. else if (this.current.getBukkitEntity().getLocation().distance(this.location) > 64.0) {
  192. this.reset();
  193. }
  194. }
  195.  
  196. public void register(final Entity me) {
  197. this.current = me;
  198. }
  199.  
  200. public String getTimeUntil(long epoch)
  201. {
  202. epoch -= System.currentTimeMillis() / 1000L;
  203. return getTime(epoch);
  204. }
  205.  
  206. public String getDataString(long time)
  207. {
  208. return new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date(time));
  209. }
  210.  
  211. public String getTime(long ms)
  212. {
  213. StringBuilder builder = new StringBuilder();
  214.  
  215. if(ms / 31536000 > 0L)
  216. {
  217. long years = ms / 31536000;
  218. builder.append(ChatColor.DARK_GREEN + ((years + Case("", " §aгод ", " §aгода ", " §aлет ", years))));
  219. ms -= years * 31536000;
  220. }
  221. if(ms / 2592000 > 0L)
  222. {
  223. long months = ms / 2592000;
  224. builder.append(ChatColor.DARK_GREEN + ((months + Case(" §aмес.", "", "", "", months))));
  225. ms -= months * 2592000;
  226. }
  227. if(ms / 604800L > 0L)
  228. {
  229. long weeks = ms / 604800L;
  230. builder.append(ChatColor.DARK_GREEN + ((weeks + Case(" §aнедел", "§aю ", "§aи ", "§aь ", weeks))));
  231. ms -= weeks * 604800L;
  232. }
  233. if(ms / 86400L > 0L)
  234. {
  235. long days = ms / 86400L;
  236. builder.append(ChatColor.DARK_GREEN + ((days + Case("", " §aд.", "", "", days))));
  237. ms -= days * 86400L;
  238. }
  239. if(ms / 3600L > 0L)
  240. {
  241. long hours = ms / 3600L;
  242. builder.append(ChatColor.DARK_GREEN + ((hours + Case(" §aчас.", "", "", "", hours))));
  243. ms -= hours * 3600L;
  244. }
  245. if(ms / 60L > 0L)
  246. {
  247. long minutes = ms / 60L;
  248. builder.append(ChatColor.DARK_GREEN + ((minutes + Case(" §aмиyн.", "", "", "", minutes))));
  249. ms -= minutes * 60L;
  250. }
  251. if(ms > 0L)
  252. {
  253. builder.append(ChatColor.DARK_GREEN + ((ms + Case(" §aсекун", "§aду§2 ", "§aды§2 ", "§aд§2 ", ms))));
  254. }
  255. if(builder.length() > 1)
  256. {
  257. builder.replace(builder.length() - 1, builder.length(), "");
  258. }
  259. return builder.toString();
  260. }
  261.  
  262. public static String Case(String ed, String a, String b, String c, long years) {
  263. if (years < 0) years = -years;
  264. long last = years % 100;
  265. if (last > 10 && last < 21) return ed + c;
  266. last = years % 10;
  267. if (last == 0 || last > 4) return ed + c;
  268. if (last == 1) return ed + a;
  269. if (last < 5) return ed + b;
  270. return ed + c;
  271. }
  272.  
  273. public void reset() {
  274. if (this.current != null) {
  275. if (this.current.passengers.size() != 0) {
  276. this.current.passengers.get(0).getBukkitEntity().remove();
  277. }
  278. this.current.getBukkitEntity().remove();
  279. }
  280. this.hologram.delete();
  281. this.deathtime = -1L;
  282. this.spawn();
  283. }
  284.  
  285. public UUID getUid() {
  286. return this.uid;
  287. }
  288.  
  289. public Entity getCurrent() {
  290. return this.current;
  291. }
  292.  
  293. public EntityTypes getType() {
  294. return this.type;
  295. }
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement