diff --git a/CHANGELOG.md b/CHANGELOG.md index 04c3f0b83..8181ad326 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ -### Fixed: -- Fixed a class cast exception with the ItemBuilder when using `Data:` or `DisplayData:` \ No newline at end of file +### Changes: +- Added a new config option, `hologram-plugin` which lets you pick a hologram plugin to prioritize + - If you leave it empty, it'll automatically pick one. \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java index 3170f5658..a318592fc 100644 --- a/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java +++ b/src/main/java/com/badbones69/crazycrates/config/impl/ConfigKeys.java @@ -5,6 +5,8 @@ import ch.jalu.configme.configurationdata.CommentsConfiguration; import ch.jalu.configme.properties.Property; import com.badbones69.crazycrates.api.enums.State; +import com.ryderbelserion.vital.paper.api.enums.Support; + import java.util.Collections; import java.util.List; import static ch.jalu.configme.properties.PropertyInitializer.newBeanProperty; @@ -115,6 +117,16 @@ public void registerComments(CommentsConfiguration conf) { }) public static final Property message_state = newBeanProperty(State.class, "root.message-state", State.send_message); + @Comment({ + "A list of available hologram plugins:", + " -> DecentHolograms", + " -> FancyHolograms", + " -> CMI", + "", + "If the option is set to blank, it'll pick whatever plugin it feels like picking." + }) + public static final Property hologram_plugin = newProperty("root.hologram-plugin", ""); + //@Comment({ // "Sends anonymous statistics about how the plugin is used to bstats.org.", // "bstats is a service for plugin developers to find out how the plugin being used,", diff --git a/src/main/java/com/badbones69/crazycrates/support/holograms/HologramManager.java b/src/main/java/com/badbones69/crazycrates/support/holograms/HologramManager.java index e6a661c07..65819a8df 100644 --- a/src/main/java/com/badbones69/crazycrates/support/holograms/HologramManager.java +++ b/src/main/java/com/badbones69/crazycrates/support/holograms/HologramManager.java @@ -28,6 +28,8 @@ public abstract class HologramManager { public abstract void purge(final boolean isShutdown); + public abstract String getName(); + protected @NotNull final String name() { return this.plugin.getName().toLowerCase() + "-" + UUID.randomUUID(); } diff --git a/src/main/java/com/badbones69/crazycrates/support/holograms/types/CMIHologramsSupport.java b/src/main/java/com/badbones69/crazycrates/support/holograms/types/CMIHologramsSupport.java index 52e8d2a9f..4866e4bc8 100644 --- a/src/main/java/com/badbones69/crazycrates/support/holograms/types/CMIHologramsSupport.java +++ b/src/main/java/com/badbones69/crazycrates/support/holograms/types/CMIHologramsSupport.java @@ -74,14 +74,21 @@ public boolean exists(final String id) { @Override public void purge(final boolean isShutdown) { + final String name = this.plugin.getName().toLowerCase(); + final List holograms = new ArrayList<>() {{ hologramManager.getHolograms().forEach((id, hologram) -> { - if (id.startsWith(plugin.getName().toLowerCase() + "-")) { - add(id.replace(plugin.getName().toLowerCase() + "-", "")); + if (id.startsWith(name + "-")) { + add(id.replace(name + "-", "")); } }); }}; holograms.forEach(this::removeHologram); } + + @Override + public final String getName() { + return "CMI"; + } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/support/holograms/types/DecentHologramsSupport.java b/src/main/java/com/badbones69/crazycrates/support/holograms/types/DecentHologramsSupport.java index 0f8bee0dc..1e13005e4 100644 --- a/src/main/java/com/badbones69/crazycrates/support/holograms/types/DecentHologramsSupport.java +++ b/src/main/java/com/badbones69/crazycrates/support/holograms/types/DecentHologramsSupport.java @@ -62,7 +62,17 @@ public boolean exists(final String id) { @Override public void purge(final boolean isShutdown) { - this.holograms.forEach((key, value) -> value.delete()); + this.holograms.forEach((key, value) -> { + removeHologram(key); + + value.delete(); + }); + this.holograms.clear(); } + + @Override + public final String getName() { + return "DecentHolograms"; + } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/support/holograms/types/FancyHologramsSupport.java b/src/main/java/com/badbones69/crazycrates/support/holograms/types/FancyHologramsSupport.java index 8fb08e7b0..907ff78db 100644 --- a/src/main/java/com/badbones69/crazycrates/support/holograms/types/FancyHologramsSupport.java +++ b/src/main/java/com/badbones69/crazycrates/support/holograms/types/FancyHologramsSupport.java @@ -89,16 +89,23 @@ public boolean exists(final String id) { @Override public void purge(final boolean isShutdown) { + final String name = this.plugin.getName().toLowerCase(); + final List holograms = new ArrayList<>() {{ manager.getHolograms().forEach(hologram -> { final String id = hologram.getName(); - if (id.startsWith(plugin.getName().toLowerCase() + "-")) { - add(id.replace(plugin.getName().toLowerCase() + "-", "")); + if (id.startsWith(name + "-")) { + add(id.replace(name + "-", "")); } }); }}; holograms.forEach(this::removeHologram); } + + @Override + public final String getName() { + return "FancyHolograms"; + } } \ No newline at end of file diff --git a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java index b27bab974..4e9b97042 100644 --- a/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java +++ b/src/main/java/com/badbones69/crazycrates/tasks/crates/CrateManager.java @@ -128,7 +128,7 @@ public void reloadCrate(@Nullable final Crate crate) { // If crate null, return. if (crate == null) return; - final String fileName = crate.getFileName(); + //final String fileName = crate.getFileName(); // Grab the new file. FileConfiguration file = crate.getFile(); @@ -217,23 +217,51 @@ public void reloadCrate(@Nullable final Crate crate) { * Load the holograms. */ public void loadHolograms() { - if (this.holograms != null) { - return; + final String pluginName = this.config.getProperty(ConfigKeys.hologram_plugin); + + if (this.holograms != null && !pluginName.isEmpty()) { + this.holograms.purge(false); } - - if (Support.decent_holograms.isEnabled()) { - this.holograms = new DecentHologramsSupport(); - if (MiscUtils.isLogging()) this.plugin.getComponentLogger().info("DecentHolograms support has been enabled."); - } else if (Support.cmi.isEnabled() && CMIModule.holograms.isEnabled()) { - this.holograms = new CMIHologramsSupport(); + switch (pluginName) { + case "DecentHolograms" -> { + if (!Support.decent_holograms.isEnabled()) return; + + this.holograms = new DecentHologramsSupport(); + } + + case "FancyHolograms" -> { + if (!Support.fancy_holograms.isEnabled()) return; - if (MiscUtils.isLogging()) this.plugin.getComponentLogger().info("CMI Hologram support has been enabled."); - } else if (Support.fancy_holograms.isEnabled()) { - this.holograms = new FancyHologramsSupport(); + this.holograms = new FancyHologramsSupport(); + } + + case "CMI" -> { + if (!Support.cmi.isEnabled() && !CMIModule.holograms.isEnabled()) return; + + this.holograms = new CMIHologramsSupport(); + } + + default -> { + if (Support.decent_holograms.isEnabled()) { + this.holograms = new DecentHologramsSupport(); - if (MiscUtils.isLogging()) this.plugin.getComponentLogger().info("FancyHolograms support has been enabled."); - } else { + break; + } + + if (Support.fancy_holograms.isEnabled()) { + this.holograms = new FancyHologramsSupport(); + + break; + } + + if (Support.cmi.isEnabled() && CMIModule.holograms.isEnabled()) { + this.holograms = new CMIHologramsSupport(); + } + } + } + + if (this.holograms == null) { if (MiscUtils.isLogging()) { List.of( "There was no hologram plugin found on the server. If you are using CMI", @@ -241,7 +269,11 @@ public void loadHolograms() { "You can run /crazycrates reload if using CMI otherwise restart your server." ).forEach(this.plugin.getComponentLogger()::warn); } + + return; } + + if (MiscUtils.isLogging()) this.plugin.getComponentLogger().info("{} support has been enabled.", this.holograms.getName()); } /**