Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.coob.nmsinterface;
- import lombok.Getter;
- import lombok.NonNull;
- import org.bukkit.Location;
- import org.jetbrains.annotations.Nullable;
- import org.mineacademy.fo.settings.ConfigItems;
- import org.mineacademy.fo.settings.YamlConfig;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Set;
- public class HologramRegistry extends YamlConfig /*implements HologramRegistryI*/ {
- private static final String FOLDER = "holograms";
- private static final ConfigItems<HologramRegistry> loadedFiles = ConfigItems.fromFolder(FOLDER, HologramRegistry.class);
- @Getter
- private NMSHologramI hologram;
- private HologramRegistry(final String id) {
- this(id, null);
- }
- private HologramRegistry(final String id, @Nullable final NMSHologramI hologram) {
- if (hologram != null)
- this.hologram = hologram;
- this.loadConfiguration(NO_DEFAULT, FOLDER + "/" + id + ".yml");
- }
- @Override
- protected void onLoad() {
- this.hologram = this.get("Hologram", NMSHologramI.class);
- this.save();
- }
- @Override
- protected void onSave() {
- this.set("Hologram", this.hologram);
- }
- /**
- * Automatically loads stored disk Holograms and spawns them
- */
- /*@Override
- public void spawnFromDisk() {
- if (!MinecraftVersion.atLeast(MinecraftVersion.V.v1_16))
- return;
- // Tricky: This automatically calls the spawn method which puts the hologram to our loadedHolograms list
- this.loadedHolograms = loadHolograms();
- Common.log("@Found " + this.loadedHolograms.size() + " Holograms on the disk");
- for (final NMSHologramI hologram : this.loadedHolograms)
- Common.log("\tspawned " + hologram + " at " + hologram.getLocation());
- }*/
- /*@Override
- public List<NMSHologramI> loadHolograms() {
- final List<NMSHologramI> loadedHologram = new ArrayList<>();
- for (final SerializedMap map : getMapList("Saved_Holograms")) {
- final NMSHologramI hologram = NMSHologramProvider.deserialize(map);
- loadedHologram.add(hologram);
- }
- return loadedHologram;
- }*/
- /**
- * Registers a new hologram to our map
- *
- * @param hologram
- */
- /*@Override
- public void register(final NMSHologramI hologram) {
- Valid.checkBoolean(!this.isRegistered(hologram), hologram + " is already registered!");
- this.loadedHolograms.add(hologram);
- this.save();
- }*/
- /*@Override
- public void unregister(final NMSHologramI hologram) {
- this.loadedHolograms.remove(hologram);
- this.save();
- }*/
- /**
- * Return true if the given hologram is already registered
- *
- * @param hologram
- * @return
- */
- /*@Override
- public boolean isRegistered(final NMSHologramI hologram) {
- return this.isRegistered(hologram.getUniqueId());
- }*/
- /**
- * Return true if the given hologram is already registered
- *
- * @param entityUniqueId
- * @return
- */
- /*@Override
- public boolean isRegistered(final UUID entityUniqueId) {
- for (final NMSHologramI hologram : this.loadedHolograms)
- if (hologram != null && hologram.getUniqueId().equals(entityUniqueId))
- return true;
- return false;
- }*/
- /**
- * Get the loaded holograms
- */
- /*@Override
- public List<NMSHologramI> getLoadedHolograms() {
- return Collections.unmodifiableList(this.loadedHolograms);
- }*/
- // -----------------------------------------------------------------
- // Static
- // -----------------------------------------------------------------
- public static List<Location> getHologramLocations() {
- final List<Location> locations = new ArrayList<>();
- for (final HologramRegistry registry : getHolograms())
- locations.add(registry.getHologram().getLocation());
- return locations;
- }
- /**
- * @return
- * @see ConfigItems#getItems()
- */
- public static List<? extends HologramRegistry> getHolograms() {
- return loadedFiles.getItems();
- }
- /**
- * @return
- * @see ConfigItems#getItemNames()
- */
- public static Set<String> getHologramIDs() {
- return loadedFiles.getItemNames();
- }
- public static HologramRegistry createHologram(@NonNull final String id, final NMSHologramI hologram) {
- return loadedFiles.loadOrCreateItem(id, () -> new HologramRegistry(id, hologram));
- }
- /**
- * @see ConfigItems#loadItems()
- */
- public static void loadHolograms() {
- loadedFiles.loadItems();
- }
- public static void removeHologram(final String id) {
- loadedFiles.removeItemByName(id);
- }
- public static void removeHologram(final NMSHologramI hologram) {
- for (final HologramRegistry registry : getHolograms())
- if (registry.getHologram().equals(hologram))
- loadedFiles.removeItem(registry);
- }
- /**
- * @see ConfigItems#isItemLoaded(String)
- */
- public static boolean isHologramLoaded(final String id) {
- return loadedFiles.isItemLoaded(id);
- }
- /**
- * @return
- * @see ConfigItems#findItem(String)
- */
- public static HologramRegistry findById(@NonNull final String id) {
- return loadedFiles.findItem(id);
- }
- }
Add Comment
Please, Sign In to add comment