Advertisement
JackOUT

Untitled

Jul 3rd, 2023 (edited)
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. package games.coob.nmsinterface;
  2.  
  3. import lombok.Getter;
  4. import lombok.NonNull;
  5. import org.bukkit.Location;
  6. import org.mineacademy.fo.settings.ConfigItems;
  7. import org.mineacademy.fo.settings.YamlConfig;
  8.  
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import java.util.Set;
  12.  
  13. public abstract class HologramRegistry extends YamlConfig {
  14.  
  15.     private static final String FOLDER = "holograms";
  16.  
  17.     private static final ConfigItems<HologramRegistry> loadedFiles = ConfigItems.fromFolder(FOLDER, HologramRegistry.class);
  18.  
  19.     @Getter
  20.     private NMSHologramI hologram;
  21.  
  22.     protected HologramRegistry(final String id) {
  23.         this(id, null);
  24.     }
  25.  
  26.     protected HologramRegistry(final String id, final NMSHologramI hologram) {
  27.         System.out.println("Hologram constructor: " + hologram);
  28.  
  29.         if (hologram != null)
  30.             this.hologram = hologram;
  31.  
  32.         this.loadConfiguration(NO_DEFAULT, FOLDER + "/" + id + ".yml");
  33.     }
  34.  
  35.     @Override
  36.     protected void onLoad() {
  37.         if (this.hologram == null)
  38.             this.hologram = this.get("Hologram", NMSHologramI.class); // todo can't deserialize this
  39.  
  40.         System.out.println("hologram: " + this.hologram);
  41.         this.save();
  42.     }
  43.  
  44.     @Override
  45.     protected void onSave() {
  46.         System.out.println("saved hologram: " + this.hologram);
  47.         this.set("Hologram", this.hologram);
  48.     }
  49.  
  50.     // -----------------------------------------------------------------
  51.     // Static
  52.     // -----------------------------------------------------------------
  53.  
  54.     public static void createHologram(@NonNull final String id, @NonNull final NMSHologramI hologram) {
  55.         loadedFiles.loadOrCreateItem(id, () -> new HologramRegistry(id, hologram) {
  56.         });
  57.     }
  58.  
  59.     public static List<Location> getHologramLocations() {
  60.         final List<Location> locations = new ArrayList<>();
  61.  
  62.         for (final HologramRegistry registry : getHolograms())
  63.             locations.add(((NMSHologramI) registry.getHologram()).getLocation());
  64.  
  65.         return locations;
  66.     }
  67.  
  68.     public static List<? extends HologramRegistry> getHolograms() {
  69.         return loadedFiles.getItems();
  70.     }
  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.     public static void loadHolograms() {
  81.         loadedFiles.loadItems();
  82.     }
  83.  
  84.     public static void removeHologram(final String id) {
  85.         loadedFiles.removeItemByName(id);
  86.     }
  87.  
  88.     public static void removeHologram(final NMSHologramI hologram) {
  89.         for (final HologramRegistry registry : getHolograms())
  90.             if (registry.getHologram().equals(hologram))
  91.                 loadedFiles.removeItem(registry);
  92.     }
  93.  
  94.  
  95.     public static boolean isHologramLoaded(final String id) {
  96.         return loadedFiles.isItemLoaded(id);
  97.     }
  98.  
  99.     public static HologramRegistry findById(@NonNull final String id) {
  100.         return loadedFiles.findItem(id);
  101.     }
  102. }
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement