| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package me.lethunderhawk.custom.entity;
- import me.lethunderhawk.fluxapi.FluxService;
- import me.lethunderhawk.main.BazaarFlux;
- import org.bukkit.entity.Entity;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.jetbrains.annotations.NotNull;
- import java.util.*;
- public class CustomEntityRegistry {
- private static Map<Entity, CustomEntity> entities = new HashMap<>();
- private static Map<Entity, Integer> indicators = new HashMap<>();
- static {
- new BukkitRunnable() {
- Set<Entity> armorStands = indicators.keySet();
- List<Entity> removals = new ArrayList<>();
- @Override
- public void run() {
- for(Entity stand : armorStands) {
- int ticksLeft = indicators.get(stand);
- if(ticksLeft == 0) {
- stand.remove();
- removals.add(stand);
- continue;
- }
- ticksLeft--;
- indicators.put(stand, ticksLeft);
- }
- armorStands.removeAll(removals);
- }
- }.runTaskTimer(FluxService.get(BazaarFlux.class), 0L, 1L);
- }
- public static CustomEntity remove(@NotNull Entity entity) {
- return entities.remove(entity);
- }
- public static void add(@NotNull Entity entity, @NotNull CustomEntity customEntity) {
- entities.put(entity, customEntity);
- }
- public static boolean contains(@NotNull Entity entity) {
- return entities.containsKey(entity);
- }
- public static CustomEntity get(Entity entity) {
- return entities.get(entity);
- }
- public static Map<Entity, Integer> getIndicators() {
- return indicators;
- }
- }
|