CustomEntityRegistry.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package me.lethunderhawk.custom.entity;
  2. import me.lethunderhawk.fluxapi.FluxService;
  3. import me.lethunderhawk.main.BazaarFlux;
  4. import org.bukkit.entity.Entity;
  5. import org.bukkit.scheduler.BukkitRunnable;
  6. import org.jetbrains.annotations.NotNull;
  7. import java.util.*;
  8. public class CustomEntityRegistry {
  9. private static Map<Entity, CustomEntity> entities = new HashMap<>();
  10. private static Map<Entity, Integer> indicators = new HashMap<>();
  11. static {
  12. new BukkitRunnable() {
  13. Set<Entity> armorStands = indicators.keySet();
  14. List<Entity> removals = new ArrayList<>();
  15. @Override
  16. public void run() {
  17. for(Entity stand : armorStands) {
  18. int ticksLeft = indicators.get(stand);
  19. if(ticksLeft == 0) {
  20. stand.remove();
  21. removals.add(stand);
  22. continue;
  23. }
  24. ticksLeft--;
  25. indicators.put(stand, ticksLeft);
  26. }
  27. armorStands.removeAll(removals);
  28. }
  29. }.runTaskTimer(FluxService.get(BazaarFlux.class), 0L, 1L);
  30. }
  31. public static CustomEntity remove(@NotNull Entity entity) {
  32. return entities.remove(entity);
  33. }
  34. public static void add(@NotNull Entity entity, @NotNull CustomEntity customEntity) {
  35. entities.put(entity, customEntity);
  36. }
  37. public static boolean contains(@NotNull Entity entity) {
  38. return entities.containsKey(entity);
  39. }
  40. public static CustomEntity get(Entity entity) {
  41. return entities.get(entity);
  42. }
  43. public static Map<Entity, Integer> getIndicators() {
  44. return indicators;
  45. }
  46. }