entities support wip
This commit is contained in:
parent
aeb5d23c6c
commit
2cbaae4300
2 changed files with 67 additions and 0 deletions
|
@ -0,0 +1,50 @@
|
||||||
|
package me.unurled.sacredrealms.sr.components.entity;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
import me.unurled.sacredrealms.sr.managers.Manager;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.bukkit.entity.Mob;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
public class EntityManager extends Manager {
|
||||||
|
|
||||||
|
@NotNull private final HashMap<UUID, SREntity> entities;
|
||||||
|
|
||||||
|
public EntityManager() {
|
||||||
|
super();
|
||||||
|
entities = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public SREntity getEntity(@NotNull UUID uuid) {
|
||||||
|
return entities.get(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEntity(@NotNull SREntity entity) {
|
||||||
|
entities.put(entity.getUuid(), entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addEntity(@NotNull Entity e) {
|
||||||
|
entities.put(e.getUniqueId(), new SREntity(e));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSREntity(@NotNull UUID uuid) {
|
||||||
|
return entities.containsKey(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onEntitySpawn(EntitySpawnEvent e) {
|
||||||
|
if (e.getEntity() instanceof Player) return;
|
||||||
|
|
||||||
|
if (isSREntity(e.getEntity().getUniqueId())) return;
|
||||||
|
|
||||||
|
if (!(e.getEntity() instanceof Mob)) return;
|
||||||
|
|
||||||
|
e.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package me.unurled.sacredrealms.sr.components.entity;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class SREntity {
|
||||||
|
private final UUID uuid;
|
||||||
|
|
||||||
|
public SREntity(@NotNull Entity e) {
|
||||||
|
uuid = e.getUniqueId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue