Skip to content

Commit

Permalink
add config option to prioritize one hologram plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
ryderbelserion committed Aug 25, 2024
1 parent 2084db0 commit 4eaa13a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 21 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
### Fixed:
- Fixed a class cast exception with the ItemBuilder when using `Data:` or `DisplayData:`
### 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.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,6 +117,16 @@ public void registerComments(CommentsConfiguration conf) {
})
public static final Property<State> 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<String> 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,",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -217,31 +217,63 @@ 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",
"Please make sure you enabled the hologram module in modules.yml",
"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());
}

/**
Expand Down

0 comments on commit 4eaa13a

Please sign in to comment.