Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.meloncode.cristalix.prison.mobs;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.UUID;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.inventory.ItemStack;
- import com.gmail.filoghost.holographicdisplays.api.Hologram;
- import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
- import net.minecraft.server.v1_12_R1.Entity;
- import ru.meloncode.cristalix.prison.Main;
- /* public class Spawner
- {
- public static Map<UUID, Spawner> spawners;
- Location location;
- EntityTypes type;
- Entity current;
- long deathtime;
- int interval;
- UUID uid;
- static {
- Spawner.spawners = new HashMap<UUID, Spawner>();
- }
- public Spawner(final Location location, final EntityTypes type, final int interval) {
- this.location = location;
- this.current = null;
- this.deathtime = -1L;
- this.uid = UUID.randomUUID();
- this.type = type;
- this.interval = interval;
- Spawner.spawners.put(this.uid, this);
- }
- public void spawn() {
- if (this.location.getChunk().isLoaded()) {
- EntityTypes.spawnEntity(this.type, this.location.clone().add(0.0, 1.0, 0.0), this);
- }
- }
- public void iDead() {
- this.current = null;
- this.deathtime = System.currentTimeMillis() / 1000L;
- }
- public Location getSpawnLocation() {
- return this.location;
- }
- public void update() {
- if (this.current == null) {
- if (System.currentTimeMillis() / 1000L - this.deathtime >= this.interval) {
- this.spawn();
- }
- }
- else if (this.current.getBukkitEntity().getLocation().distance(this.location) > 64.0) {
- this.reset();
- }
- }
- public void register(final Entity me) {
- this.current = me;
- }
- public void reset() {
- if (this.current != null) {
- if (this.current.passengers.size() != 0) {
- this.current.passengers.get(0).getBukkitEntity().remove();
- }
- this.current.getBukkitEntity().remove();
- }
- this.deathtime = -1L;
- this.spawn();
- }
- public UUID getUid() {
- return this.uid;
- }
- public Entity getCurrent() {
- return this.current;
- }
- public EntityTypes getType() {
- return this.type;
- }
- } */
- public class Spawner
- {
- public static Map<UUID, Spawner> spawners;
- Location location;
- EntityTypes type;
- Entity current;
- long deathtime;
- int interval;
- UUID uid;
- Hologram hologram;
- static {
- Spawner.spawners = new HashMap<UUID, Spawner>();
- }
- public Spawner(final Location location, final EntityTypes type, final int interval) {
- this.location = location;
- this.current = null;
- this.deathtime = -1L;
- this.uid = UUID.randomUUID();
- this.type = type;
- this.interval = interval;
- Spawner.spawners.put(this.uid, this);
- }
- public void create(String boss, int rewardMoney, int rewardExp) {
- if (this.hologram == null) {
- System.out.println("hologram is null. but Why?...");
- }
- this.hologram.clearLines();
- if (System.currentTimeMillis() / 1000L - (this.deathtime + 1) >= this.interval) {
- /* this.hologram.appendTextLine(ChatColor.RED + "УЖЕ ЗАРЕСПАУНЕН"); */
- } else {
- this.hologram.appendTextLine(ChatColor.DARK_GREEN + (getTime((this.deathtime + this.interval) - System.currentTimeMillis() / 1000L)));
- }
- }
- public void create() {
- this.hologram = HologramsAPI.createHologram(Main.getInstance(), location.clone().add(0, 2, 0));
- if (this.hologram == null) {
- System.out.println("hologram is null. but Why?...");
- }
- this.hologram.clearLines();
- /* this.hologram.appendTextLine(ChatColor.RED + "УЖЕ ЗАРЕСПАУНЕН"); */
- }
- public void spawn() {
- if (this.location.getChunk().isLoaded()) {
- if(this.hologram != null)
- this.hologram.delete();
- create();
- EntityTypes.spawnEntity(this.type, this.location.clone().add(0.0, 1.0, 0.0), this);
- } else {
- location.getWorld().loadChunk(location.getChunk());
- if(this.hologram != null)
- this.hologram.delete();
- create();
- EntityTypes.spawnEntity(this.type, this.location.clone().add(0.0, 1.0, 0.0), this);
- }
- }
- public void iDead() {
- this.current = null;
- this.deathtime = System.currentTimeMillis() / 1000L;
- }
- public Location getSpawnLocation() {
- return this.location;
- }
- public long getTime() {
- return this.interval - (System.currentTimeMillis() / 1000L - this.deathtime);
- }
- public void update() {
- if (this.current == null) {
- if (System.currentTimeMillis() / 1000L - this.deathtime >= this.interval) {
- this.spawn();
- }
- }
- else if (this.current.getBukkitEntity().getLocation().distance(this.location) > 64.0) {
- this.reset();
- }
- }
- public void update(String boss, int rewardMoney, int rewardExp) {
- if (this.current == null) {
- if (System.currentTimeMillis() / 1000L - this.deathtime >= this.interval) {
- this.spawn();
- } else {
- this.create(boss, rewardMoney, rewardExp);
- }
- }
- else if (this.current.getBukkitEntity().getLocation().distance(this.location) > 64.0) {
- this.reset();
- }
- }
- public void register(final Entity me) {
- this.current = me;
- }
- public String getTimeUntil(long epoch)
- {
- epoch -= System.currentTimeMillis() / 1000L;
- return getTime(epoch);
- }
- public String getDataString(long time)
- {
- return new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date(time));
- }
- public String getTime(long ms)
- {
- StringBuilder builder = new StringBuilder();
- if(ms / 31536000 > 0L)
- {
- long years = ms / 31536000;
- builder.append(ChatColor.DARK_GREEN + ((years + Case("", " §aгод ", " §aгода ", " §aлет ", years))));
- ms -= years * 31536000;
- }
- if(ms / 2592000 > 0L)
- {
- long months = ms / 2592000;
- builder.append(ChatColor.DARK_GREEN + ((months + Case(" §aмес.", "", "", "", months))));
- ms -= months * 2592000;
- }
- if(ms / 604800L > 0L)
- {
- long weeks = ms / 604800L;
- builder.append(ChatColor.DARK_GREEN + ((weeks + Case(" §aнедел", "§aю ", "§aи ", "§aь ", weeks))));
- ms -= weeks * 604800L;
- }
- if(ms / 86400L > 0L)
- {
- long days = ms / 86400L;
- builder.append(ChatColor.DARK_GREEN + ((days + Case("", " §aд.", "", "", days))));
- ms -= days * 86400L;
- }
- if(ms / 3600L > 0L)
- {
- long hours = ms / 3600L;
- builder.append(ChatColor.DARK_GREEN + ((hours + Case(" §aчас.", "", "", "", hours))));
- ms -= hours * 3600L;
- }
- if(ms / 60L > 0L)
- {
- long minutes = ms / 60L;
- builder.append(ChatColor.DARK_GREEN + ((minutes + Case(" §aмиyн.", "", "", "", minutes))));
- ms -= minutes * 60L;
- }
- if(ms > 0L)
- {
- builder.append(ChatColor.DARK_GREEN + ((ms + Case(" §aсекун", "§aду§2 ", "§aды§2 ", "§aд§2 ", ms))));
- }
- if(builder.length() > 1)
- {
- builder.replace(builder.length() - 1, builder.length(), "");
- }
- return builder.toString();
- }
- public static String Case(String ed, String a, String b, String c, long years) {
- if (years < 0) years = -years;
- long last = years % 100;
- if (last > 10 && last < 21) return ed + c;
- last = years % 10;
- if (last == 0 || last > 4) return ed + c;
- if (last == 1) return ed + a;
- if (last < 5) return ed + b;
- return ed + c;
- }
- public void reset() {
- if (this.current != null) {
- if (this.current.passengers.size() != 0) {
- this.current.passengers.get(0).getBukkitEntity().remove();
- }
- this.current.getBukkitEntity().remove();
- }
- this.hologram.delete();
- this.deathtime = -1L;
- this.spawn();
- }
- public UUID getUid() {
- return this.uid;
- }
- public Entity getCurrent() {
- return this.current;
- }
- public EntityTypes getType() {
- return this.type;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement