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