fancyholograms-v2: Config refactor

Co-authored-by: danny <76127109+dxnnv@users.noreply.github.com>
This commit is contained in:
Oliver
2025-03-30 14:17:00 +02:00
parent c98b1b0c46
commit c233e69184
18 changed files with 239 additions and 143 deletions

View File

@@ -11,13 +11,6 @@ public interface HologramConfiguration {
*/
void reload(@NotNull FancyHologramsPlugin plugin);
/**
* Returns whether version notifications are muted.
*
* @return {@code true} if version notifications are muted, {@code false} otherwise.
*/
boolean areVersionNotificationsMuted();
/**
* Returns whether autosave is enabled.
*
@@ -39,6 +32,27 @@ public interface HologramConfiguration {
*/
boolean isSaveOnChangedEnabled();
/**
* Returns the log level for the plugin.
*
* @return The log level for the plugin.
*/
String getLogLevel();
/**
* Returns whether hologram load logging on world loading is enabled or disabled.
*
* @return {@code true} if hologram loading should be logged on world loading, {@code false} otherwise.
*/
boolean isHologramLoadLogging();
/**
* Returns whether version notifications are enabled or disabled.
*
* @return {@code true} if version notifications are enabled, {@code false} otherwise.
*/
boolean areVersionNotificationsEnabled();
/**
* Returns the default visibility distance for holograms.
*
@@ -53,13 +67,6 @@ public interface HologramConfiguration {
*/
boolean isRegisterCommands();
/**
* Returns the log level for the plugin.
*
* @return The log level for the plugin.
*/
String getLogLevel();
/**
* Returns the interval at which hologram visibility is updated.
*

View File

@@ -1,7 +1,6 @@
package de.oliver.fancyholograms.api.events;
import de.oliver.fancyholograms.api.hologram.Hologram;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;

View File

@@ -1,7 +1,7 @@
package de.oliver.fancyholograms.api.events;
import de.oliver.fancyholograms.api.data.HologramData;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.api.data.*;
import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull;
@@ -82,7 +82,7 @@ public final class HologramUpdateEvent extends HologramEvent {
SHADOW_RADIUS,
SHADOW_STRENGTH,
UPDATE_TEXT_INTERVAL,
UPDATE_VISIBILITY_DISTANCE;
UPDATE_VISIBILITY_DISTANCE
}
}

View File

@@ -157,7 +157,7 @@ public final class FancyHolograms extends JavaPlugin implements FancyHologramsPl
registerListeners();
versionConfig.load();
if (!getHologramConfiguration().areVersionNotificationsMuted()) {
if (getHologramConfiguration().areVersionNotificationsEnabled()) {
checkForNewerVersion();
}
@@ -323,7 +323,7 @@ public final class FancyHolograms extends JavaPlugin implements FancyHologramsPl
Metrics metrics = new Metrics(this, 17990);
metrics.addCustomChart(new Metrics.SingleLineChart("total_holograms", () -> hologramsManager.getHolograms().size()));
metrics.addCustomChart(new Metrics.SimplePie("update_notifications", () -> configuration.areVersionNotificationsMuted() ? "No" : "Yes"));
metrics.addCustomChart(new Metrics.SimplePie("update_notifications", () -> configuration.areVersionNotificationsEnabled() ? "Yes" : "No"));
metrics.addCustomChart(new Metrics.SimplePie("using_development_build", () -> isDevelopmentBuild ? "Yes" : "No"));
fancyAnalytics = new FancyAnalyticsAPI("3b77bd59-2b01-46f2-b3aa-a9584401797f", "E2gW5zc2ZTk1OGFkNGY2ZDQ0ODlM6San");
@@ -363,7 +363,7 @@ public final class FancyHolograms extends JavaPlugin implements FancyHologramsPl
}));
fancyAnalytics.registerNumberMetric(new MetricSupplier<>("amount_holograms", () -> (double) hologramsManager.getHolograms().size()));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_update_notifications", () -> configuration.areVersionNotificationsMuted() ? "false" : "true"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("enabled_update_notifications", () -> configuration.areVersionNotificationsEnabled() ? "true" : "false"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("fflag_disable_holograms_for_bedrock_players", () -> FHFeatureFlags.DISABLE_HOLOGRAMS_FOR_BEDROCK_PLAYERS.isEnabled() ? "true" : "false"));
fancyAnalytics.registerStringMetric(new MetricSupplier<>("using_development_build", () -> isDevelopmentBuild ? "true" : "false"));

View File

@@ -3,9 +3,13 @@ package de.oliver.fancyholograms;
import de.oliver.fancyholograms.api.FancyHologramsPlugin;
import de.oliver.fancyholograms.api.HologramConfiguration;
import de.oliver.fancylib.ConfigHelper;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* The FancyHologramsConfig class is responsible for managing the configuration of the FancyHolograms plugin.
@@ -13,30 +17,47 @@ import java.util.List;
*/
public final class FancyHologramsConfiguration implements HologramConfiguration {
/**
* Indicates whether version notifications are muted.
*/
private boolean versionNotifsMuted;
/**
* Indicates whether autosave is enabled.
*/
private boolean autosaveEnabled;
private static final String CONFIG_AUTOSAVE_ENABLED = "saving.autosave.enabled";
/**
* The interval at which autosave is performed.
*/
private int autosaveInterval;
private static final String CONFIG_AUTOSAVE_INTERVAL = "saving.autosave.interval";
/**
* Indicates whether the plugin should save holograms when they are changed.
*/
private boolean saveOnChangedEnabled;
private static final String CONFIG_SAVE_ON_CHANGED = "saving.save_on_changed";
/**
* The log level for the plugin.
*/
private String logLevel;
private static final String CONFIG_LOG_LEVEL = "logging.log_level";
/**
* Indicates whether hologram loading should be logged on world loading.
*/
private boolean hologramLoadLogging;
private static final String CONFIG_LOG_ON_WORLD_LOAD = "logging.log_on_world_load";
/**
* Indicates whether version notifications are enabled or disabled.
*/
private boolean versionNotifs;
private static final String CONFIG_VERSION_NOTIFICATIONS = "logging.version_notifications";
/**
* The default visibility distance for holograms.
*/
private int defaultVisibilityDistance;
private static final String CONFIG_VISIBILITY_DISTANCE = "visibility_distance";
/**
* Indicates whether commands should be registered.
@@ -44,52 +65,109 @@ public final class FancyHologramsConfiguration implements HologramConfiguration
* This is useful for users who want to use the plugin's API only.
*/
private boolean registerCommands;
/**
* The log level for the plugin.
*/
private String logLevel;
private static final String CONFIG_REGISTER_COMMANDS = "register_commands";
/**
* The interval at which hologram visibility is updated.
*/
private int updateVisibilityInterval;
private static final String CONFIG_UPDATE_VISIBILITY_INTERVAL = "update_visibility_interval";
private static final String CONFIG_REPORT_ERRORS_TO_SENTRY = "report_errors_to_sentry";
private static final String CONFIG_VERSION = "config_version";
private static final Map<String, List<String>> CONFIG_COMMENTS = Map.of(
CONFIG_VERSION, List.of("Config version, do not modify."),
CONFIG_AUTOSAVE_ENABLED, List.of("Whether autosave is enabled."),
CONFIG_AUTOSAVE_INTERVAL, List.of("The interval at which autosave is performed in minutes."),
CONFIG_SAVE_ON_CHANGED, List.of("Whether the plugin should save holograms when they are changed."),
CONFIG_LOG_LEVEL, List.of("The log level for the plugin (DEBUG, INFO, WARN, ERROR)."),
CONFIG_LOG_ON_WORLD_LOAD, List.of("Whether hologram loading should be logged on world loading. Disable this if you load worlds dynamically to prevent console spam."),
CONFIG_VERSION_NOTIFICATIONS, List.of("Whether the plugin should send notifications for new updates."),
CONFIG_VISIBILITY_DISTANCE, List.of("The default visibility distance for holograms."),
CONFIG_REGISTER_COMMANDS, List.of("Whether the plugin should register its commands."),
CONFIG_UPDATE_VISIBILITY_INTERVAL, List.of("The interval at which hologram visibility is updated in ticks.")
);
private void updateChecker(@NotNull FancyHolograms plugin, @NotNull FileConfiguration config) {
final int latestVersion = 1;
int configVersion = (int) ConfigHelper.getOrDefault(config, CONFIG_VERSION, 0);
if (configVersion >= latestVersion ) {
setOptions(config);
return;
}
plugin.getFancyLogger().warn("Outdated config detected! Attempting to migrate previous settings to new config...");
var oldConfig = plugin.getConfig();
try {
File backupFile = new File(plugin.getDataFolder(), "config_old.yml");
oldConfig.save(backupFile);
} catch (IOException e) {
plugin.getFancyLogger().warn("Unable to backup config to config_old.yml:" + e);
}
var newConfig = plugin.getConfig();
Map<String, Object> oldConfigValues = oldConfig.getValues(true);
Map<String, String> keyMap = Map.of(
"enable_autosave", CONFIG_AUTOSAVE_ENABLED,
"autosave_interval", CONFIG_AUTOSAVE_INTERVAL,
"save_on_changed", CONFIG_SAVE_ON_CHANGED,
"log_level", CONFIG_LOG_LEVEL,
"mute_version_notifications", CONFIG_VERSION_NOTIFICATIONS
);
oldConfigValues.forEach((key, value) -> {
String newKey = keyMap.getOrDefault(key, null);
if (newKey != null) {
if (newKey.equals(CONFIG_VERSION_NOTIFICATIONS)) {
newConfig.set(newKey, !(Boolean) value);
} else {
newConfig.set(newKey, value);
}
plugin.getFancyLogger().info("> CONFIG: Set option '" + key + "' to '" + value + "' from old config.");
} else {
plugin.getFancyLogger().warn("> CONFIG: Option '" + key + "' is deprecated/invalid! Please migrate this manually from config_old.yml");
}
});
newConfig.set(CONFIG_VERSION, latestVersion);
setOptions(newConfig);
CONFIG_COMMENTS.forEach(config::setInlineComments);
plugin.getFancyLogger().info("Configuration has finished migrating. Please double check your settings in config.yml.");
}
private void setOptions(@NotNull FileConfiguration config) {
// saving
autosaveEnabled = (boolean) ConfigHelper.getOrDefault(config, CONFIG_AUTOSAVE_ENABLED, true);
autosaveInterval = (int) ConfigHelper.getOrDefault(config, CONFIG_AUTOSAVE_INTERVAL, 15);
saveOnChangedEnabled = (boolean) ConfigHelper.getOrDefault(config, CONFIG_SAVE_ON_CHANGED, true);
// logging
logLevel = (String) ConfigHelper.getOrDefault(config, CONFIG_LOG_LEVEL, "INFO");
hologramLoadLogging = (boolean) ConfigHelper.getOrDefault(config, CONFIG_LOG_ON_WORLD_LOAD, true);
versionNotifs = (boolean) ConfigHelper.getOrDefault(config, CONFIG_VERSION_NOTIFICATIONS, true);
// options
defaultVisibilityDistance = (int) ConfigHelper.getOrDefault(config, CONFIG_VISIBILITY_DISTANCE, 20);
registerCommands = (boolean) ConfigHelper.getOrDefault(config, CONFIG_REGISTER_COMMANDS, true);
updateVisibilityInterval = (int) ConfigHelper.getOrDefault(config, CONFIG_UPDATE_VISIBILITY_INTERVAL, 100);
config.set(CONFIG_REPORT_ERRORS_TO_SENTRY, null);
}
@Override
public void reload(@NotNull FancyHologramsPlugin plugin) {
public synchronized void reload(@NotNull FancyHologramsPlugin plugin) {
FancyHolograms pluginImpl = (FancyHolograms) plugin;
pluginImpl.reloadConfig();
final var config = pluginImpl.getConfig();
var config = pluginImpl.getConfig();
updateChecker(pluginImpl, config);
versionNotifsMuted = (boolean) ConfigHelper.getOrDefault(config, "mute_version_notification", false);
config.setInlineComments("mute_version_notification", List.of("Whether version notifications are muted."));
autosaveEnabled = (boolean) ConfigHelper.getOrDefault(config, "enable_autosave", true);
config.setInlineComments("enable_autosave", List.of("Whether autosave is enabled."));
autosaveInterval = (int) ConfigHelper.getOrDefault(config, "autosave_interval", 15);
config.setInlineComments("autosave_interval", List.of("The interval at which autosave is performed in minutes."));
saveOnChangedEnabled = (boolean) ConfigHelper.getOrDefault(config, "save_on_changed", true);
config.setInlineComments("save_on_changed", List.of("Whether the plugin should save holograms when they are changed."));
defaultVisibilityDistance = (int) ConfigHelper.getOrDefault(config, "visibility_distance", 20);
config.setInlineComments("visibility_distance", List.of("The default visibility distance for holograms."));
registerCommands = (boolean) ConfigHelper.getOrDefault(config, "register_commands", true);
config.setInlineComments("register_commands", List.of("Whether the plugin should register its commands."));
config.set("report_errors_to_sentry", null);
config.setInlineComments("report_errors_to_sentry", null);
config.setInlineComments("log_level", List.of("The log level for the plugin (DEBUG, INFO, WARN, ERROR)."));
logLevel = (String) ConfigHelper.getOrDefault(config, "log_level", "INFO");
updateVisibilityInterval = (int) ConfigHelper.getOrDefault(config, "update_visibility_interval", 20);
config.setInlineComments("update_visibility_interval", List.of("The interval at which hologram visibility is updated in ticks."));
if (pluginImpl.isEnabled()) {
if (pluginImpl.isEnabled() && !plugin.getHologramThread().isShutdown()) {
plugin.getHologramThread().submit(pluginImpl::saveConfig);
} else {
// Can't dispatch task if plugin is disabled
@@ -97,11 +175,6 @@ public final class FancyHologramsConfiguration implements HologramConfiguration
}
}
@Override
public boolean areVersionNotificationsMuted() {
return versionNotifsMuted;
}
@Override
public boolean isAutosaveEnabled() {
return autosaveEnabled;
@@ -117,6 +190,21 @@ public final class FancyHologramsConfiguration implements HologramConfiguration
return saveOnChangedEnabled;
}
@Override
public String getLogLevel() {
return logLevel;
}
@Override
public boolean isHologramLoadLogging() {
return hologramLoadLogging;
}
@Override
public boolean areVersionNotificationsEnabled() {
return versionNotifs;
}
@Override
public int getDefaultVisibilityDistance() {
return defaultVisibilityDistance;
@@ -127,13 +215,8 @@ public final class FancyHologramsConfiguration implements HologramConfiguration
return registerCommands;
}
@Override
public String getLogLevel() {
return logLevel;
}
@Override
public int getUpdateVisibilityInterval() {
return updateVisibilityInterval;
}
}
}

View File

@@ -47,8 +47,15 @@ public final class HologramManagerImpl implements HologramManager {
HologramManagerImpl(@NotNull final FancyHolograms plugin, @NotNull final Function<HologramData, Hologram> adapter) {
this.plugin = plugin;
this.adapter = adapter;
hologramLoadLogging = plugin.getHologramConfiguration().isHologramLoadLogging();
}
/**
* Whether hologram loading should be logged on world loading.
*/
private final boolean hologramLoadLogging;
/**
* @return A read-only collection of loaded holograms.
*/
@@ -156,7 +163,7 @@ public final class HologramManagerImpl implements HologramManager {
FancyHolograms.get().getHologramThread().submit(() -> Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(allLoaded))));
FancyHolograms.get().getFancyLogger().info(String.format("Loaded %d holograms for all loaded worlds", allLoaded.size()));
if (hologramLoadLogging) FancyHolograms.get().getFancyLogger().info(String.format("Loaded %d holograms for all loaded worlds", allLoaded.size()));
}
public void loadHolograms(String world) {
@@ -167,7 +174,7 @@ public final class HologramManagerImpl implements HologramManager {
Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(loaded)));
FancyHolograms.get().getFancyLogger().info(String.format("Loaded %d holograms for world %s", loaded.size(), world));
if (hologramLoadLogging) FancyHolograms.get().getFancyLogger().info(String.format("Loaded %d holograms for world %s", loaded.size(), world));
}
/**
@@ -186,7 +193,7 @@ public final class HologramManagerImpl implements HologramManager {
hologram.forceUpdateShownStateFor(player);
}
}
}, 0, plugin.getHologramConfiguration().getUpdateVisibilityInterval() * 50, TimeUnit.MILLISECONDS);
}, 0, plugin.getHologramConfiguration().getUpdateVisibilityInterval() * 50L, TimeUnit.MILLISECONDS);
});
final var updateTimes = CacheBuilder.newBuilder()

View File

@@ -8,14 +8,11 @@ import de.oliver.fancyholograms.storage.converter.FHConversionRegistry;
import de.oliver.fancyholograms.storage.converter.HologramConversionSession;
import de.oliver.fancyholograms.util.Constants;
import de.oliver.fancylib.MessageHelper;
import de.oliver.fancylib.translations.message.Message;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Stream;
public final class FancyHologramsCMD extends Command {
@@ -51,11 +48,7 @@ public final class FancyHologramsCMD extends Command {
MessageHelper.success(sender, "Reloaded config and holograms");
}
case "version" -> {
FancyHolograms.get().getHologramThread().submit(() -> {
FancyHolograms.get().getVersionConfig().checkVersionAndDisplay(sender, false);
});
}
case "version" -> FancyHolograms.get().getHologramThread().submit(() -> FancyHolograms.get().getVersionConfig().checkVersionAndDisplay(sender, false));
case "convert" -> {
if (args.length < 3) {
MessageHelper.info(sender, "Usage: /fancyholograms convert <type> <targets> [args...]");

View File

@@ -29,12 +29,12 @@ public class AddLineCMD implements Subcommand {
return false;
}
String text = "";
StringBuilder text = new StringBuilder();
for (int i = 3; i < args.length; i++) {
text += args[i] + " ";
text.append(args[i]).append(" ");
}
text = text.substring(0, text.length() - 1);
text = new StringBuilder(text.substring(0, text.length() - 1));
return SetLineCMD.setLine(player, hologram, Integer.MAX_VALUE, text);
return SetLineCMD.setLine(player, hologram, Integer.MAX_VALUE, text.toString());
}
}

View File

@@ -46,7 +46,7 @@ public class BrightnessCMD implements Subcommand {
return false;
}
final var brightnessValue = parsedNumber.get();
final int brightnessValue = parsedNumber.get();
if(brightnessValue < 0 || brightnessValue > 15) {
MessageHelper.error(player, "Invalid brightness value, must be between 0 and 15");

View File

@@ -58,18 +58,7 @@ public class CreateCMD implements Subcommand {
return false;
}
DisplayHologramData displayData = null;
switch (type) {
case TEXT -> displayData = new TextHologramData(name, player.getLocation());
case ITEM -> {
displayData = new ItemHologramData(name, player.getLocation());
displayData.setBillboard(Display.Billboard.FIXED);
}
case BLOCK -> {
displayData = new BlockHologramData(name, player.getLocation());
displayData.setBillboard(Display.Billboard.FIXED);
}
}
DisplayHologramData displayData = getDisplayHologramData(player, type, name);
final var holo = FancyHolograms.get().getHologramsManager().create(displayData);
if (!new HologramCreateEvent(holo, player).callEvent()) {
@@ -87,4 +76,21 @@ public class CreateCMD implements Subcommand {
MessageHelper.success(player, "Created the hologram");
return true;
}
private static @Nullable DisplayHologramData getDisplayHologramData(Player player, HologramType type, String name) {
DisplayHologramData displayData = null;
switch (type) {
case TEXT -> displayData = new TextHologramData(name, player.getLocation());
case ITEM -> {
displayData = new ItemHologramData(name, player.getLocation());
displayData.setBillboard(Display.Billboard.FIXED);
}
case BLOCK -> {
displayData = new BlockHologramData(name, player.getLocation());
displayData.setBillboard(Display.Billboard.FIXED);
}
}
return displayData;
}
}

View File

@@ -51,30 +51,34 @@ public class InfoCMD implements Subcommand {
MessageHelper.info(player, "Linked npc: <gray>" + data.getLinkedNpcName());
}
if (data instanceof TextHologramData textData) {
MessageHelper.info(player, "Text: ");
for (String line : textData.getText()) {
MessageHelper.info(player, " <reset> " + line);
}
switch (data) {
case TextHologramData textData -> {
MessageHelper.info(player, "Text: ");
for (String line : textData.getText()) {
MessageHelper.info(player, " <reset> " + line);
}
if (textData.getBackground() != null) {
MessageHelper.info(player, "Background: <gray>" + '#' + Integer.toHexString(textData.getBackground().asARGB()));
} else {
MessageHelper.info(player, "Background: <gray>default");
}
if (textData.getBackground() != null) {
MessageHelper.info(player, "Background: <gray>" + '#' + Integer.toHexString(textData.getBackground().asARGB()));
} else {
MessageHelper.info(player, "Background: <gray>default");
}
MessageHelper.info(player, "Text alignment: <gray>" + textData.getTextAlignment().name());
MessageHelper.info(player, "See through: <gray>" + (textData.isSeeThrough() ? "enabled" : "disabled"));
MessageHelper.info(player, "Text shadow: <gray>" + (textData.hasTextShadow() ? "enabled" : "disabled"));
if (textData.getTextUpdateInterval() == -1) {
MessageHelper.info(player, "Update text interval: <gray>not updating");
} else {
MessageHelper.info(player, "Update text interval: <gray>" + textData.getTextUpdateInterval() + " ticks");
MessageHelper.info(player, "Text alignment: <gray>" + textData.getTextAlignment().name());
MessageHelper.info(player, "See through: <gray>" + (textData.isSeeThrough() ? "enabled" : "disabled"));
MessageHelper.info(player, "Text shadow: <gray>" + (textData.hasTextShadow() ? "enabled" : "disabled"));
if (textData.getTextUpdateInterval() == -1) {
MessageHelper.info(player, "Update text interval: <gray>not updating");
} else {
MessageHelper.info(player, "Update text interval: <gray>" + textData.getTextUpdateInterval() + " ticks");
}
}
case BlockHologramData blockData ->
MessageHelper.info(player, "Block: <gray>" + blockData.getBlock().name());
case ItemHologramData itemData ->
MessageHelper.info(player, "Item: <gray>" + itemData.getItemStack().getType().name());
default -> {
}
} else if (data instanceof BlockHologramData blockData) {
MessageHelper.info(player, "Block: <gray>" + blockData.getBlock().name());
} else if (data instanceof ItemHologramData itemData) {
MessageHelper.info(player, "Item: <gray>" + itemData.getItemStack().getType().name());
}
return true;

View File

@@ -2,9 +2,9 @@ package de.oliver.fancyholograms.commands.hologram;
import com.google.common.primitives.Ints;
import de.oliver.fancyholograms.FancyHolograms;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.api.events.HologramUpdateEvent;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.commands.HologramCMD;
import de.oliver.fancyholograms.commands.Subcommand;
import de.oliver.fancylib.MessageHelper;
@@ -46,9 +46,9 @@ public class InsertAfterCMD implements Subcommand {
return false;
}
String text = "";
StringBuilder text = new StringBuilder();
for (int i = 4; i < args.length; i++) {
text += args[i] + " ";
text.append(args[i]).append(" ");
}
if (text.isEmpty()) {
@@ -56,10 +56,10 @@ public class InsertAfterCMD implements Subcommand {
return true;
}
text = text.substring(0, text.length() - 1);
text = new StringBuilder(text.substring(0, text.length() - 1));
final var lines = new ArrayList<>(textData.getText());
lines.add(Math.min(index, lines.size()), text);
lines.add(Math.min(index, lines.size()), text.toString());
final var copied = textData.copy(textData.getName());
copied.setText(lines);

View File

@@ -48,9 +48,9 @@ public class InsertBeforeCMD implements Subcommand {
return false;
}
String text = "";
StringBuilder text = new StringBuilder();
for (int i = 4; i < args.length; i++) {
text += args[i] + " ";
text.append(args[i]).append(" ");
}
if (text.isEmpty()) {
@@ -58,10 +58,10 @@ public class InsertBeforeCMD implements Subcommand {
return true;
}
text = text.substring(0, text.length() - 1);
text = new StringBuilder(text.substring(0, text.length() - 1));
final var lines = new ArrayList<>(textData.getText());
lines.add(Math.min(index, lines.size()), text);
lines.add(Math.min(index, lines.size()), text.toString());
final var copied = textData.copy(textData.getName());
copied.setText(lines);

View File

@@ -2,9 +2,9 @@ package de.oliver.fancyholograms.commands.hologram;
import com.google.common.primitives.Ints;
import de.oliver.fancyholograms.FancyHolograms;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.api.events.HologramUpdateEvent;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.commands.HologramCMD;
import de.oliver.fancyholograms.commands.Subcommand;
import de.oliver.fancylib.MessageHelper;
@@ -76,12 +76,12 @@ public class SetLineCMD implements Subcommand {
index--;
String text = "";
StringBuilder text = new StringBuilder();
for (int i = 4; i < args.length; i++) {
text += args[i] + " ";
text.append(args[i]).append(" ");
}
text = text.substring(0, text.length() - 1);
text = new StringBuilder(text.substring(0, text.length() - 1));
return setLine(player, hologram, index, text);
return setLine(player, hologram, index, text.toString());
}
}

View File

@@ -60,7 +60,7 @@ public class TextAlignmentCMD implements Subcommand {
return false;
}
textData.setTextAlignment(((TextHologramData) copied).getTextAlignment());
textData.setTextAlignment(copied.getTextAlignment());
if (FancyHolograms.get().getHologramConfiguration().isSaveOnChangedEnabled()) {
FancyHolograms.get().getHologramStorage().save(hologram);

View File

@@ -2,7 +2,6 @@ package de.oliver.fancyholograms.listeners;
import de.oliver.fancyholograms.FancyHolograms;
import de.oliver.fancyholograms.api.hologram.Hologram;
import net.kyori.adventure.resource.ResourcePackStatus;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@@ -34,7 +33,7 @@ public final class PlayerListener implements Listener {
hologram.updateShownStateFor(event.getPlayer());
}
if (!this.plugin.getHologramConfiguration().areVersionNotificationsMuted() && event.getPlayer().hasPermission("fancyholograms.admin")) {
if (!this.plugin.getHologramConfiguration().areVersionNotificationsEnabled() && event.getPlayer().hasPermission("fancyholograms.admin")) {
FancyHolograms.get().getHologramThread().submit(() -> FancyHolograms.get().getVersionConfig().checkVersionAndDisplay(event.getPlayer(), true));
}
}

View File

@@ -8,10 +8,12 @@ import org.bukkit.event.world.WorldUnloadEvent;
public class WorldListener implements Listener {
private final boolean hologramLoadLogging = FancyHolograms.get().getHologramConfiguration().isHologramLoadLogging();
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
FancyHolograms.get().getHologramThread().submit(() -> {
FancyHolograms.get().getFancyLogger().info("Loading holograms for world " + event.getWorld().getName());
if (hologramLoadLogging) FancyHolograms.get().getFancyLogger().info("Loading holograms for world " + event.getWorld().getName());
FancyHolograms.get().getHologramsManager().loadHolograms(event.getWorld().getName());
});
}
@@ -19,7 +21,7 @@ public class WorldListener implements Listener {
@EventHandler
public void onWorldUnload(WorldUnloadEvent event) {
FancyHolograms.get().getHologramThread().submit(() -> {
FancyHolograms.get().getFancyLogger().info("Unloading holograms for world " + event.getWorld().getName());
if (hologramLoadLogging) FancyHolograms.get().getFancyLogger().info("Unloading holograms for world " + event.getWorld().getName());
FancyHolograms.get().getHologramsManager().unloadHolograms(event.getWorld().getName());
});
}

View File

@@ -2,10 +2,6 @@ package de.oliver.fancyholograms.storage.converter;
import de.oliver.fancyholograms.api.data.HologramData;
import de.oliver.fancylib.MessageHelper;
import de.oliver.fancylib.translations.message.Message;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;