mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-11-20 01:15:15 +01:00
Code renaming
This commit is contained in:
parent
123e9fb45c
commit
d58e9fe0a9
@ -20,7 +20,7 @@ import me.filoghost.holographicdisplays.core.nms.ProtocolPacketSettings;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.Configuration;
|
||||
import me.filoghost.holographicdisplays.disk.HologramDatabase;
|
||||
import me.filoghost.holographicdisplays.disk.upgrade.LegacySymbolsUpgrader;
|
||||
import me.filoghost.holographicdisplays.disk.upgrade.LegacySymbolsUpgrade;
|
||||
import me.filoghost.holographicdisplays.legacy.api.v2.V2HologramsAPIProvider;
|
||||
import me.filoghost.holographicdisplays.listener.ChunkListener;
|
||||
import me.filoghost.holographicdisplays.listener.InteractListener;
|
||||
@ -105,9 +105,9 @@ public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacke
|
||||
|
||||
// Run only once at startup, before anything else
|
||||
try {
|
||||
LegacySymbolsUpgrader.run(configManager, errorCollector);
|
||||
LegacySymbolsUpgrade.run(configManager, errorCollector);
|
||||
} catch (ConfigException e) {
|
||||
errorCollector.add(e, "couldn't convert symbols file");
|
||||
errorCollector.add(e, "couldn't automatically convert symbols file to the new format");
|
||||
}
|
||||
|
||||
load(true, errorCollector);
|
||||
@ -161,7 +161,7 @@ public class HolographicDisplays extends FCommonsPlugin implements ProtocolPacke
|
||||
|
||||
internalHologramManager.clearAll();
|
||||
|
||||
configManager.reloadCustomPlaceholders(errorCollector);
|
||||
configManager.reloadStaticReplacements(errorCollector);
|
||||
configManager.reloadMainConfig(errorCollector);
|
||||
HologramDatabase hologramDatabase = configManager.loadHologramDatabase(errorCollector);
|
||||
try {
|
||||
|
@ -20,25 +20,25 @@ import java.nio.file.Path;
|
||||
|
||||
public class ConfigManager extends BaseConfigManager {
|
||||
|
||||
private final MappedConfigLoader<MainConfigModel> mainConfigLoader;
|
||||
private final MappedConfigLoader<ConfigurationFileModel> mainConfigLoader;
|
||||
private final ConfigLoader databaseConfigLoader;
|
||||
private final ConfigLoader placeholdersConfigLoader;
|
||||
private final ConfigLoader staticReplacementsConfigLoader;
|
||||
|
||||
public ConfigManager(Path rootDataFolder) {
|
||||
super(rootDataFolder);
|
||||
this.mainConfigLoader = getMappedConfigLoader("config.yml", MainConfigModel.class);
|
||||
this.mainConfigLoader = getMappedConfigLoader("config.yml", ConfigurationFileModel.class);
|
||||
this.databaseConfigLoader = getConfigLoader("database.yml");
|
||||
this.placeholdersConfigLoader = getConfigLoader("custom-placeholders.yml");
|
||||
this.staticReplacementsConfigLoader = getConfigLoader("custom-placeholders.yml");
|
||||
}
|
||||
|
||||
public void reloadMainConfig(ErrorCollector errorCollector) {
|
||||
MainConfigModel mainConfig;
|
||||
ConfigurationFileModel mainConfig;
|
||||
|
||||
try {
|
||||
mainConfig = mainConfigLoader.init();
|
||||
} catch (ConfigException e) {
|
||||
logConfigInitException(errorCollector, mainConfigLoader.getFile(), e);
|
||||
mainConfig = new MainConfigModel(); // Fallback: use default values
|
||||
mainConfig = new ConfigurationFileModel(); // Fallback: use default values
|
||||
}
|
||||
|
||||
Configuration.load(mainConfig, errorCollector);
|
||||
@ -67,17 +67,17 @@ public class ConfigManager extends BaseConfigManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadCustomPlaceholders(ErrorCollector errorCollector) {
|
||||
FileConfig placeholdersConfig;
|
||||
public void reloadStaticReplacements(ErrorCollector errorCollector) {
|
||||
FileConfig staticReplacementsConfig;
|
||||
|
||||
try {
|
||||
placeholdersConfig = placeholdersConfigLoader.init();
|
||||
staticReplacementsConfig = staticReplacementsConfigLoader.init();
|
||||
} catch (ConfigException e) {
|
||||
logConfigInitException(errorCollector, placeholdersConfigLoader.getFile(), e);
|
||||
placeholdersConfig = new FileConfig(placeholdersConfigLoader.getFile()); // Fallback: empty config
|
||||
logConfigInitException(errorCollector, staticReplacementsConfigLoader.getFile(), e);
|
||||
staticReplacementsConfig = new FileConfig(staticReplacementsConfigLoader.getFile()); // Fallback: empty config
|
||||
}
|
||||
|
||||
CustomPlaceholders.load(placeholdersConfig, errorCollector);
|
||||
StaticReplacements.load(staticReplacementsConfig, errorCollector);
|
||||
}
|
||||
|
||||
public Path getAnimationsFolder() {
|
||||
|
@ -43,23 +43,23 @@ public class Configuration {
|
||||
public static boolean pingerTrimMotd;
|
||||
public static Map<String, ServerAddress> pingerServerAddresses;
|
||||
|
||||
public static void load(MainConfigModel config, ErrorCollector errorCollector) {
|
||||
public static void load(ConfigurationFileModel config, ErrorCollector errorCollector) {
|
||||
spaceBetweenLines = config.spaceBetweenLines;
|
||||
quickEditCommands = config.quickEditCommands;
|
||||
timeFormat = parseTimeFormatter(config.timeFormat, config.timeZone, errorCollector);
|
||||
updateNotification = config.updateNotification;
|
||||
|
||||
imageSymbol = StringConverter.toReadableFormat(config.imageSymbol);
|
||||
transparencySymbol = StringConverter.toReadableFormat(config.transparencySymbol);
|
||||
imageSymbol = TextFormatter.toDisplayFormat(config.imageSymbol);
|
||||
transparencySymbol = TextFormatter.toDisplayFormat(config.transparencySymbol);
|
||||
transparencyColor = parseTransparencyColor(config.transparencyColor, errorCollector);
|
||||
|
||||
bungeeRefreshSeconds = parseBungeeRefreshInterval(config.bungeeRefreshSeconds, errorCollector);
|
||||
useRedisBungee = config.useRedisBungee;
|
||||
pingerEnabled = config.pingerEnable;
|
||||
pingerTimeout = parsePingerTimeout(config.pingerTimeout, errorCollector);
|
||||
pingerOfflineMotd = StringConverter.toReadableFormat(config.pingerOfflineMotd);
|
||||
pingerStatusOnline = StringConverter.toReadableFormat(config.pingerStatusOnline);
|
||||
pingerStatusOffline = StringConverter.toReadableFormat(config.pingerStatusOffline);
|
||||
pingerOfflineMotd = TextFormatter.toDisplayFormat(config.pingerOfflineMotd);
|
||||
pingerStatusOnline = TextFormatter.toDisplayFormat(config.pingerStatusOnline);
|
||||
pingerStatusOffline = TextFormatter.toDisplayFormat(config.pingerStatusOffline);
|
||||
pingerTrimMotd = config.pingerTrimMotd;
|
||||
|
||||
pingerServerAddresses = new HashMap<>();
|
||||
|
@ -12,7 +12,7 @@ import me.filoghost.fcommons.config.mapped.MappedConfig;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MainConfigModel implements MappedConfig {
|
||||
public class ConfigurationFileModel implements MappedConfig {
|
||||
|
||||
@Path("space-between-lines")
|
||||
double spaceBetweenLines = 0.02;
|
@ -33,7 +33,7 @@ public class HologramLineParser {
|
||||
if (serializedLine.trim().equalsIgnoreCase(EMPTY_LINE_PLACEHOLDER)) {
|
||||
displayText = "";
|
||||
} else {
|
||||
displayText = StringConverter.toReadableFormat(serializedLine);
|
||||
displayText = TextFormatter.toDisplayFormat(serializedLine);
|
||||
}
|
||||
|
||||
hologramLine = hologram.createTextLine(displayText, serializedLine);
|
||||
|
@ -16,57 +16,58 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class CustomPlaceholders {
|
||||
public class StaticReplacements {
|
||||
|
||||
private static final List<StaticPlaceholder> placeholders = new ArrayList<>();
|
||||
private static final List<StaticReplacement> replacements = new ArrayList<>();
|
||||
|
||||
public static void load(FileConfig config, ErrorCollector errorCollector) {
|
||||
placeholders.clear();
|
||||
replacements.clear();
|
||||
|
||||
ConfigSection placeholdersSection = config.getConfigSection("placeholders");
|
||||
if (placeholdersSection == null) {
|
||||
ConfigSection replacementsSection = config.getConfigSection("placeholders");
|
||||
if (replacementsSection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Entry<ConfigPath, String> entry : placeholdersSection.toMap(ConfigType.STRING).entrySet()) {
|
||||
String placeholder = entry.getKey().asRawKey();
|
||||
for (Entry<ConfigPath, String> entry : replacementsSection.toMap(ConfigType.STRING).entrySet()) {
|
||||
String target = entry.getKey().asRawKey();
|
||||
String replacement = Colors.addColors(entry.getValue());
|
||||
|
||||
if (placeholder.length() == 0) {
|
||||
errorCollector.add("error in \"" + config.getSourceFile() + "\": placeholder cannot be empty (skipped)");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (placeholder.length() > 100) {
|
||||
if (target.length() == 0) {
|
||||
errorCollector.add("error in \"" + config.getSourceFile() + "\":"
|
||||
+ " placeholder cannot be longer than 100 character (" + placeholder + ")");
|
||||
+ " placeholder cannot be empty (skipped)");
|
||||
continue;
|
||||
}
|
||||
|
||||
placeholders.add(new StaticPlaceholder(placeholder, replacement));
|
||||
if (target.length() > 100) {
|
||||
errorCollector.add("error in \"" + config.getSourceFile() + "\":"
|
||||
+ " placeholder cannot be longer than 100 character (" + target + ")");
|
||||
continue;
|
||||
}
|
||||
|
||||
replacements.add(new StaticReplacement(target, replacement));
|
||||
}
|
||||
}
|
||||
|
||||
public static String replaceStaticPlaceholders(String text) {
|
||||
for (StaticPlaceholder staticPlaceholder : placeholders) {
|
||||
text = text.replace(staticPlaceholder.getIdentifier(), staticPlaceholder.getReplacement());
|
||||
public static String searchAndReplace(String text) {
|
||||
for (StaticReplacement replacement : replacements) {
|
||||
text = text.replace(replacement.getTarget(), replacement.getReplacement());
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
|
||||
private static class StaticPlaceholder {
|
||||
private static class StaticReplacement {
|
||||
|
||||
private final String identifier;
|
||||
private final String target;
|
||||
private final String replacement;
|
||||
|
||||
StaticPlaceholder(String identifier, String replacement) {
|
||||
this.identifier = identifier;
|
||||
StaticReplacement(String target, String replacement) {
|
||||
this.target = target;
|
||||
this.replacement = replacement;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
public String getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public String getReplacement() {
|
@ -13,14 +13,14 @@ package me.filoghost.holographicdisplays.disk;
|
||||
|
||||
import me.filoghost.fcommons.Colors;
|
||||
|
||||
public class StringConverter {
|
||||
public class TextFormatter {
|
||||
|
||||
public static String toReadableFormat(String input) {
|
||||
public static String toDisplayFormat(String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
input = CustomPlaceholders.replaceStaticPlaceholders(input);
|
||||
input = StaticReplacements.searchAndReplace(input);
|
||||
input = Colors.addColors(input);
|
||||
return input;
|
||||
}
|
@ -22,7 +22,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class LegacySymbolsUpgrader {
|
||||
public class LegacySymbolsUpgrade {
|
||||
|
||||
public static void run(ConfigManager configManager, ErrorCollector errorCollector) throws ConfigLoadException, ConfigSaveException {
|
||||
Path oldFile = configManager.getRootDataFolder().resolve("symbols.yml");
|
@ -9,7 +9,7 @@ import me.filoghost.fcommons.config.exception.ConfigSaveException;
|
||||
import me.filoghost.fcommons.logging.ErrorCollector;
|
||||
import me.filoghost.holographicdisplays.core.DebugLogger;
|
||||
import me.filoghost.holographicdisplays.disk.ConfigManager;
|
||||
import me.filoghost.holographicdisplays.disk.StringConverter;
|
||||
import me.filoghost.holographicdisplays.disk.TextFormatter;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.Placeholder;
|
||||
import me.filoghost.holographicdisplays.api.placeholder.PlaceholderFactory;
|
||||
|
||||
@ -79,9 +79,9 @@ public class AnimationRegistry implements PlaceholderFactory {
|
||||
+ " you should add at least one more line");
|
||||
}
|
||||
|
||||
// Replace placeholders
|
||||
// Add colors and formatting to lines
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
lines.set(i, StringConverter.toReadableFormat(lines.get(i)));
|
||||
lines.set(i, TextFormatter.toDisplayFormat(lines.get(i)));
|
||||
}
|
||||
|
||||
int refreshIntervalTicks = Math.min((int) (speed * 20.0), 1);
|
||||
|
Loading…
Reference in New Issue
Block a user