Advertisement
JackOUT

Untitled

Jul 4th, 2023
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.00 KB | None | 0 0
  1. package games.coob.v1_19;
  2.  
  3. import games.coob.nmsinterface.HologramRegistry;
  4. import games.coob.nmsinterface.NMSHologramI;
  5. import lombok.Getter;
  6. import lombok.NonNull;
  7. import org.bukkit.Location;
  8. import org.mineacademy.fo.settings.ConfigItems;
  9.  
  10. import java.util.ArrayList;
  11. import java.util.List;
  12. import java.util.Set;
  13.  
  14. public abstract class HologramRegistry_v1_19 extends HologramRegistry {
  15.  
  16.     private static final String FOLDER = "holograms";
  17.  
  18.     private static final ConfigItems<HologramRegistry_v1_19> loadedFiles = ConfigItems.fromFolder(FOLDER, HologramRegistry_v1_19.class);
  19.  
  20.     @Getter
  21.     private NMSHologram_v1_19 hologram;
  22.  
  23.     protected HologramRegistry_v1_19(String id) {
  24.         super(id);
  25.     }
  26.  
  27.     protected HologramRegistry_v1_19(String id, NMSHologramI hologram) {
  28.         super(id, hologram);
  29.     }
  30.  
  31.     @Override
  32.     protected void onLoad() {
  33.         if (this.hologram == null)
  34.             this.hologram = this.get("Hologram", NMSHologram_v1_19.class); // todo find out why this is causing issues
  35.  
  36.         System.out.println("hologram: " + this.hologram);
  37.         this.save();
  38.     }
  39.  
  40.     @Override
  41.     protected void onSave() {
  42.         System.out.println("saved hologram: " + this.hologram);
  43.         this.set("Hologram", this.hologram);
  44.     }
  45.  
  46.     // -----------------------------------------------------------------
  47.     // Static
  48.     // -----------------------------------------------------------------
  49.  
  50.     public static void createHologram(@NonNull final String id, @NonNull final NMSHologram_v1_19 hologram) {
  51.         loadedFiles.loadOrCreateItem(id, () -> new HologramRegistry_v1_19(id, hologram) {
  52.         });
  53.     }
  54.  
  55.     public static List<Location> getHologramLocations() {
  56.         final List<Location> locations = new ArrayList<>();
  57.  
  58.         for (final HologramRegistry_v1_19 registry : getHolograms())
  59.             locations.add(((NMSHologramI) registry.getHologram()).getLocation());
  60.  
  61.         return locations;
  62.     }
  63.  
  64.     /**
  65.      * @return
  66.      * @see ConfigItems#getItems()
  67.      */
  68.     public static List<? extends HologramRegistry_v1_19> getHolograms() {
  69.         return loadedFiles.getItems();
  70.     }
  71.  
  72.     /**
  73.      * @return
  74.      * @see ConfigItems#getItemNames()
  75.      */
  76.     public static Set<String> getHologramIDs() {
  77.         return loadedFiles.getItemNames();
  78.     }
  79.  
  80.     //System.out.println("create holo param: " + hologram);
  81.     //System.out.println("createmethod");
  82.  
  83.     /**
  84.      * @see ConfigItems#loadItems()
  85.      */
  86.     public static void loadHolograms() {
  87.         loadedFiles.loadItems();
  88.     }
  89.  
  90.     public static void removeHologram(final String id) {
  91.         loadedFiles.removeItemByName(id);
  92.     }
  93.  
  94.     public static void removeHologram(final NMSHologramI hologram) {
  95.         for (final HologramRegistry_v1_19 registry : getHolograms())
  96.             if (registry.getHologram().equals(hologram))
  97.                 loadedFiles.removeItem(registry);
  98.     }
  99.  
  100.     /**
  101.      * @see ConfigItems#isItemLoaded(String)
  102.      */
  103.     public static boolean isHologramLoaded(final String id) {
  104.         return loadedFiles.isItemLoaded(id);
  105.     }
  106.  
  107.     /**
  108.      * @return
  109.      * @see ConfigItems#findItem(String)
  110.      */
  111.     public static HologramRegistry_v1_19 findById(@NonNull final String id) {
  112.         return loadedFiles.findItem(id);
  113.     }
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement