Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.24 KB | None | 0 0
  1. package me.customboss.Entity;
  2.  
  3. import org.bukkit.*;
  4. import net.minecraft.server.v1_8_R3.*;
  5. import java.util.*;
  6.  
  7. public class Spawner
  8. {
  9.     public static Map<UUID, Spawner> spawners;
  10.     Location location;
  11.     EntityTypes type;
  12.     Entity current;
  13.     long deathtime;
  14.     int interval;
  15.     UUID uid;
  16.    
  17.     static {
  18.         Spawner.spawners = new HashMap<UUID, Spawner>();
  19.     }
  20.    
  21.     public Spawner(final Location location, final EntityTypes type, final int interval) {
  22.         this.location = location;
  23.         this.current = null;
  24.         this.deathtime = -1L;
  25.         this.uid = UUID.randomUUID();
  26.         this.type = type;
  27.         this.interval = interval;
  28.         Spawner.spawners.put(this.uid, this);
  29.     }
  30.    
  31.     public void spawn() {
  32.         if (this.location.getChunk().isLoaded()) {
  33.             EntityTypes.spawnEntity(this.type, this.location.clone().add(0.0, 1.0, 0.0), this);
  34.         }
  35.     }
  36.    
  37.     public void iDead() {
  38.         this.current = null;
  39.         this.deathtime = System.currentTimeMillis() / 1000L;
  40.     }
  41.    
  42.     public Location getSpawnLocation() {
  43.         return this.location;
  44.     }
  45.    
  46.     public long getTime() {
  47.         return this.interval - (System.currentTimeMillis() / 1000L - this.deathtime);
  48.     }
  49.    
  50.     public void update() {
  51.         if (this.current == null) {
  52.             if (System.currentTimeMillis() / 1000L - this.deathtime >= this.interval) {
  53.                 this.spawn();
  54.             }
  55.         }
  56.         else if (this.current.getBukkitEntity().getLocation().distance(this.location) > 64.0) {
  57.             this.reset();
  58.         }
  59.     }
  60.    
  61.     public void register(final Entity me) {
  62.         this.current = me;
  63.     }
  64.    
  65.     public void reset() {
  66.         if (this.current != null) {
  67.             if (this.current.passenger != null) {
  68.                 this.current.passenger.getBukkitEntity().remove();
  69.             }
  70.             this.current.getBukkitEntity().remove();
  71.         }
  72.         this.deathtime = -1L;
  73.         this.spawn();
  74.     }
  75.    
  76.     public UUID getUid() {
  77.         return this.uid;
  78.     }
  79.    
  80.     public Entity getCurrent() {
  81.         return this.current;
  82.     }
  83.    
  84.     public EntityTypes getType() {
  85.         return this.type;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement