Advertisement
JackOUT

Untitled

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