fancyholograms v3: Use config for feature flags

This commit is contained in:
Oliver
2025-07-19 19:27:45 +02:00
parent 5f047bbf70
commit ff959bab4b
7 changed files with 54 additions and 28 deletions

View File

@@ -50,4 +50,18 @@ public interface HologramConfiguration {
* @return The log level for the plugin.
*/
String getLogLevel();
/**
* Returns whether holograms should be shown to bedrock players.
*
* @return {@code true} if holograms should be shown to bedrock players, {@code false} otherwise.
*/
boolean isHologramsForBedrockPlayersEnabled();
/**
* Returns whether holograms should be shown to players with an old client version.
*
* @return {@code true} if holograms should be shown to players with an old client version, {@code false} otherwise.
*/
boolean isHologramsForOldClientsEnabled();
}

View File

@@ -15,6 +15,8 @@ public final class FHConfiguration implements HologramConfiguration {
private static final String VISIBILITY_DISTANCE_PATH = "visibility_distance";
private static final String REGISTER_COMMANDS_PATH = "register_commands";
private static final String LOG_LEVEL_PATH = "log_level";
private static final String DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS_PATH = "disable_holograms_for_bedrock_players";
private static final String DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS = "disable_holograms_for_old_clients";
private Config config;
@@ -84,6 +86,28 @@ public final class FHConfiguration implements HologramConfiguration {
String.class
));
/*
FEATURE FLAGS
*/
config.addField(new ConfigField<>(
DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS_PATH,
"Do not show holograms to bedrock players",
false,
false,
false,
Boolean.class
));
config.addField(new ConfigField<>(
DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS,
"Do not show holograms to clients with a version older than 1.19.4",
false,
false,
false,
Boolean.class
));
config.reload();
}
@@ -125,4 +149,14 @@ public final class FHConfiguration implements HologramConfiguration {
public String getLogLevel() {
return config.get(LOG_LEVEL_PATH);
}
@Override
public boolean isHologramsForBedrockPlayersEnabled() {
return !(boolean) config.get(DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS_PATH);
}
@Override
public boolean isHologramsForOldClientsEnabled() {
return !(boolean) config.get(DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS);
}
}

View File

@@ -1,19 +0,0 @@
package de.oliver.fancyholograms.config;
import com.fancyinnovations.config.featureflags.FeatureFlag;
import com.fancyinnovations.config.featureflags.FeatureFlagConfig;
import de.oliver.fancyholograms.main.FancyHologramsPlugin;
public class FHFeatureFlags {
public static final FeatureFlag DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS = new FeatureFlag("disable-holograms-for-bedrock-players", "Do not show holograms to bedrock players", false);
public static final FeatureFlag DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS = new FeatureFlag("disable-holograms-for-old-clients", "Do not show holograms to clients with a version older than 1.19.4", false);
public static void load() {
FeatureFlagConfig config = new FeatureFlagConfig(FancyHologramsPlugin.get());
config.addFeatureFlag(DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS);
config.addFeatureFlag(DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS);
config.load();
}
}

View File

@@ -6,7 +6,7 @@ import de.oliver.fancyholograms.api.data.*;
import de.oliver.fancyholograms.api.events.HologramDespawnEvent;
import de.oliver.fancyholograms.api.events.HologramSpawnEvent;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.config.FHFeatureFlags;
import de.oliver.fancyholograms.main.FancyHologramsPlugin;
import de.oliver.fancyholograms.util.PluginUtils;
import de.oliver.fancysitula.api.entities.*;
import de.oliver.fancysitula.factories.FancySitula;
@@ -49,7 +49,7 @@ public final class HologramImpl extends Hologram {
return;
}
if (FHFeatureFlags.DISABLE_HOLOGRAMS_FOR_OLD_CLIENTS.isEnabled()) {
if (FancyHologramsPlugin.get().getFHConfiguration().isHologramsForOldClientsEnabled()) {
final var protocolVersion = PluginUtils.isViaVersionEnabled() ? Via.getAPI().getPlayerVersion(player.getUniqueId()) : MINIMUM_PROTOCOL_VERSION;
if (protocolVersion < MINIMUM_PROTOCOL_VERSION) {
FancyHolograms.get().getFancyLogger().debug("Player " + player.getName() + " is using an outdated protocol version (" + protocolVersion + "). Hologram will not be shown.");

View File

@@ -1,7 +1,7 @@
package de.oliver.fancyholograms.listeners;
import de.oliver.fancyholograms.api.events.HologramSpawnEvent;
import de.oliver.fancyholograms.config.FHFeatureFlags;
import de.oliver.fancyholograms.main.FancyHologramsPlugin;
import de.oliver.fancyholograms.util.PluginUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
@@ -11,7 +11,7 @@ public class BedrockPlayerListener implements Listener {
@EventHandler
public void onHologramShow(final HologramSpawnEvent event) {
if (FHFeatureFlags.DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS.isEnabled() && PluginUtils.isFloodgateEnabled()) {
if (FancyHologramsPlugin.get().getFHConfiguration().isHologramsForBedrockPlayersEnabled() && PluginUtils.isFloodgateEnabled()) {
boolean isBedrockPlayer = FloodgateApi.getInstance().isFloodgatePlayer(event.getPlayer().getUniqueId());
if (isBedrockPlayer) {
event.setCancelled(true);

View File

@@ -16,7 +16,6 @@ import de.oliver.fancyholograms.commands.FancyHologramsCMD;
import de.oliver.fancyholograms.commands.FancyHologramsTestCMD;
import de.oliver.fancyholograms.commands.HologramCMD;
import de.oliver.fancyholograms.config.FHConfiguration;
import de.oliver.fancyholograms.config.FHFeatureFlags;
import de.oliver.fancyholograms.controller.HologramControllerImpl;
import de.oliver.fancyholograms.converter.FHConversionRegistry;
import de.oliver.fancyholograms.hologram.version.*;
@@ -131,7 +130,6 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
@Override
public void onLoad() {
FHFeatureFlags.load();
configuration.init();
LogLevel logLevel;
@@ -276,7 +274,7 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog
getServer().getPluginManager().registerEvents(new NpcListener(this), this);
}
if (FHFeatureFlags.DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS.isEnabled() && PluginUtils.isFloodgateEnabled()) {
if (configuration.isHologramsForBedrockPlayersEnabled() && PluginUtils.isFloodgateEnabled()) {
getServer().getPluginManager().registerEvents(new BedrockPlayerListener(), this);
}
}

View File

@@ -4,7 +4,6 @@ import de.oliver.fancyanalytics.api.FancyAnalyticsAPI;
import de.oliver.fancyanalytics.api.metrics.MetricSupplier;
import de.oliver.fancyanalytics.logger.ExtendedFancyLogger;
import de.oliver.fancyholograms.api.HologramRegistry;
import de.oliver.fancyholograms.config.FHFeatureFlags;
import de.oliver.fancyholograms.main.FancyHologramsPlugin;
import de.oliver.fancylib.Metrics;
import org.bukkit.Bukkit;
@@ -55,7 +54,7 @@ public class FHMetrics {
fancyAnalytics.registerNumberMetric(new MetricSupplier<>("amount_holograms", () -> (double) registry.getAll().size()));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_update_notifications", () -> FancyHologramsPlugin.get().getFHConfiguration().areVersionNotificationsMuted() ? "false" : "true"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("fflag_disable_holograms_for_bedrock_players", () -> FHFeatureFlags.DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS.isEnabled() ? "true" : "false"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("fflag_disable_holograms_for_bedrock_players", () -> FancyHologramsPlugin.get().getFHConfiguration().isHologramsForBedrockPlayersEnabled() ? "false" : "true"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("using_development_build", () -> FancyHologramsPlugin.get().getVersionConfig().isDevelopmentBuild() ? "true" : "false"));
fancyAnalytics.registerStringArrayMetric(new MetricSupplier<>("hologram_type", () -> {