Advertisement
JackOUT

Untitled

Jul 3rd, 2023
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.94 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(final String id, final NMSHologramI hologram) {
  24.         super(id, hologram);
  25.     }
  26.  
  27.     @Override
  28.     protected void onLoad() {
  29.         if (this.hologram == null)
  30.             this.hologram = this.get("Hologram", NMSHologram_v1_19.class); // todo find out why this is causing issues
  31.  
  32.         System.out.println("hologram: " + this.hologram);
  33.         this.save();
  34.     }
  35.  
  36.     @Override
  37.     protected void onSave() {
  38.         System.out.println("saved hologram: " + this.hologram);
  39.         this.set("Hologram", this.hologram);
  40.     }
  41.  
  42.     // -----------------------------------------------------------------
  43.     // Static
  44.     // -----------------------------------------------------------------
  45.  
  46.     public static void createHologram(@NonNull final String id, @NonNull final NMSHologram_v1_19 hologram) {
  47.         loadedFiles.loadOrCreateItem(id, () -> new HologramRegistry_v1_19(id, hologram) {
  48.         });
  49.     }
  50.  
  51.     public static List<Location> getHologramLocations() {
  52.         final List<Location> locations = new ArrayList<>();
  53.  
  54.         for (final HologramRegistry_v1_19 registry : getHolograms())
  55.             locations.add(((NMSHologramI) registry.getHologram()).getLocation());
  56.  
  57.         return locations;
  58.     }
  59.  
  60.     /**
  61.      * @return
  62.      * @see ConfigItems#getItems()
  63.      */
  64.     public static List<? extends HologramRegistry_v1_19> getHolograms() {
  65.         return loadedFiles.getItems();
  66.     }
  67.  
  68.     /**
  69.      * @return
  70.      * @see ConfigItems#getItemNames()
  71.      */
  72.     public static Set<String> getHologramIDs() {
  73.         return loadedFiles.getItemNames();
  74.     }
  75.  
  76.     //System.out.println("create holo param: " + hologram);
  77.     //System.out.println("createmethod");
  78.  
  79.     /**
  80.      * @see ConfigItems#loadItems()
  81.      */
  82.     public static void loadHolograms() {
  83.         loadedFiles.loadItems();
  84.     }
  85.  
  86.     public static void removeHologram(final String id) {
  87.         loadedFiles.removeItemByName(id);
  88.     }
  89.  
  90.     public static void removeHologram(final NMSHologramI hologram) {
  91.         for (final HologramRegistry_v1_19 registry : getHolograms())
  92.             if (registry.getHologram().equals(hologram))
  93.                 loadedFiles.removeItem(registry);
  94.     }
  95.  
  96.     /**
  97.      * @see ConfigItems#isItemLoaded(String)
  98.      */
  99.     public static boolean isHologramLoaded(final String id) {
  100.         return loadedFiles.isItemLoaded(id);
  101.     }
  102.  
  103.     /**
  104.      * @return
  105.      * @see ConfigItems#findItem(String)
  106.      */
  107.     public static HologramRegistry_v1_19 findById(@NonNull final String id) {
  108.         return loadedFiles.findItem(id);
  109.     }
  110. }
  111.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement