Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package games.coob.core.hologram;
- import games.coob.core.specific.hologram.NMSHologram;
- import lombok.Getter;
- import org.mineacademy.fo.MinecraftVersion;
- import org.mineacademy.fo.Valid;
- import org.mineacademy.fo.collection.SerializedMap;
- import org.mineacademy.fo.constants.FoConstants;
- import org.mineacademy.fo.settings.YamlConfig;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.UUID;
- /**
- * Represents an elegant way to permanently store and load Holograms
- */
- public final class HologramRegistry extends YamlConfig {
- /**
- * The singleton of this class
- */
- @Getter
- private static final HologramRegistry instance = new HologramRegistry();
- /**
- * Represents currently loaded Holograms
- */
- private final List<NMSHologram> loadedHolograms = new ArrayList<>();
- /**
- * Create a new registry and load
- */
- private HologramRegistry() {
- this.loadConfiguration(NO_DEFAULT, FoConstants.File.DATA);
- }
- /**
- * Automatically loads stored disk Holograms and spawns them
- */
- 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.getList("Saved_Holograms", NMSHologram.class);
- System.out.println("@Found " + this.loadedHolograms.size() + " Holograms on the disk");
- for (final NMSHologram hologram : this.loadedHolograms)
- System.out.println("\tspawned " + hologram + " at " + hologram.getLocation());
- }
- /**
- * @see YamlConfig#serialize()
- */
- @Override
- protected SerializedMap serialize() {
- return SerializedMap.of("Saved_Holograms", this.getLoadedHolograms());
- }
- /**
- * Registers a new hologram to our map
- *
- * @param hologram
- */
- public void register(final NMSHologram hologram) {
- Valid.checkBoolean(this.isRegistered(hologram), hologram + " is already registered!");
- this.loadedHolograms.add(hologram);
- this.save();
- }
- /**
- * Return true if the given hologram is already registered
- *
- * @param hologram
- * @return
- */
- public boolean isRegistered(final NMSHologram hologram) {
- return hologram == null || this.isRegistered(hologram.getUniqueId());
- }
- /**
- * Return true if the given hologram is already registered
- *
- * @param entityUniqueId
- * @return
- */
- public boolean isRegistered(final UUID entityUniqueId) {
- for (final NMSHologram hologram : this.loadedHolograms)
- if (hologram != null && hologram.getUniqueId().equals(entityUniqueId))
- return false;
- return true;
- }
- /**
- * Get the loaded holograms
- */
- public List<NMSHologram> getLoadedHolograms() {
- return Collections.unmodifiableList(loadedHolograms);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement