From f3dfc4db935b1c6e09dda0422a6d0c72d77aff52 Mon Sep 17 00:00:00 2001 From: iProdigy Date: Sat, 5 Oct 2024 20:58:54 -0700 Subject: [PATCH] fix: migrate item keywords with asterisks --- src/main/java/dinkplugin/SettingsManager.java | 14 ++++---- .../java/dinkplugin/util/MigrationUtil.java | 33 ++++++++++++++----- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/src/main/java/dinkplugin/SettingsManager.java b/src/main/java/dinkplugin/SettingsManager.java index 7430263c..de5aff58 100644 --- a/src/main/java/dinkplugin/SettingsManager.java +++ b/src/main/java/dinkplugin/SettingsManager.java @@ -374,22 +374,20 @@ private void setFilteredNames(String configValue) { log.debug("Updated RSN Filter List to: {}", filteredNames); } - private void migrateConfig(String sourceGroup, Map keyMappings) { - Map valuesByKey = new HashMap<>(keyMappings.size() * 4 / 3); - keyMappings.forEach((sourceKey, dinkKey) -> { + private void migrateConfig(MigrationUtil.Metadata data) { + Map valuesByKey = new HashMap<>(data.mappings().size() * 4 / 3); + data.mappings().forEach((sourceKey, dinkKey) -> { Type valueType = configValueTypes.get(dinkKey); if (valueType == null) return; - Object sourceValue = configManager.getConfiguration(sourceGroup, sourceKey, valueType); + var sourceValue = configManager.getConfiguration(data.configGroup(), sourceKey, valueType); if (sourceValue != null) { - valuesByKey.put(dinkKey, sourceValue); + var transformedValue = data.transform(sourceKey, sourceValue); + valuesByKey.put(dinkKey, transformedValue); } }); handleImport(valuesByKey, true); - } - private void migrateConfig(MigrationUtil.Metadata data) { - migrateConfig(data.configGroup(), data.mappings()); if (data.notifierEnabledKey() != null && !isPluginDisabled(configManager, data.pluginClassName().toLowerCase()) && !data.notifierEnabled().test(config)) { configManager.setConfiguration(CONFIG_GROUP, data.notifierEnabledKey(), true); } diff --git a/src/main/java/dinkplugin/util/MigrationUtil.java b/src/main/java/dinkplugin/util/MigrationUtil.java index 5d2ea6d0..f63c643b 100644 --- a/src/main/java/dinkplugin/util/MigrationUtil.java +++ b/src/main/java/dinkplugin/util/MigrationUtil.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.function.Function; import java.util.function.Predicate; +import java.util.stream.Collectors; @UtilityClass public class MigrationUtil { @@ -23,7 +24,7 @@ private Metadata getAdamMappings(DinkPluginConfig config) { "sendScreenshot", "lootSendImage", "lootvalue", "minLootValue" ); - return new Metadata("discordlootlogger", mappings, "DiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled"); + return new Metadata("discordlootlogger", mappings, "DiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled", null); } private Metadata getBoredskaMappings(DinkPluginConfig config) { @@ -31,7 +32,7 @@ private Metadata getBoredskaMappings(DinkPluginConfig config) { Map mappings = Map.of("webhook", config.groupStorageWebhook().isBlank() && config.notifyGroupStorage() ? "discordWebhook" : "groupStorageWebhook" ); - return new Metadata("gimbankdiscord", mappings, "GimBankDiscordPlugin", DinkPluginConfig::notifyGroupStorage, "groupStorageEnabled"); + return new Metadata("gimbankdiscord", mappings, "GimBankDiscordPlugin", DinkPluginConfig::notifyGroupStorage, "groupStorageEnabled", null); } private Metadata getBossHusoMappings(DinkPluginConfig config) { @@ -47,7 +48,15 @@ private Metadata getBossHusoMappings(DinkPluginConfig config) { "sendEmbeddedMessage", "discordRichEmbeds", "whiteListedRSNs", config.nameFilterMode() == FilterMode.ALLOW ? "ignoredNames" : "" ); - return new Metadata("discordraredropnotificater", mappings, "DiscordRareDropNotificaterPlugin", DinkPluginConfig::notifyLoot, "lootEnabled"); + Function itemListTransformer = v -> ConfigUtil + .readDelimited(v.toString()) + .map(s -> '*' + s + '*') + .collect(Collectors.joining("\n")); + var transformers = Map.of( + "whiteListedItems", itemListTransformer, + "ignoredkeywords", itemListTransformer + ); + return new Metadata("discordraredropnotificater", mappings, "DiscordRareDropNotificaterPlugin", DinkPluginConfig::notifyLoot, "lootEnabled", transformers); } private Metadata getJakeMappings(DinkPluginConfig config) { @@ -85,7 +94,7 @@ private Metadata getJakeMappings(DinkPluginConfig config) { Map.entry("clueMinValue", "clueMinValue"), Map.entry("clueNotifMessage", "clueNotifMessage") ); - return new Metadata("universalDiscord", mappings, "UniversalDiscordPlugin", null, null); + return new Metadata("universalDiscord", mappings, "UniversalDiscordPlugin", null, null, null); } private Metadata getJamesMappings(DinkPluginConfig config) { @@ -93,7 +102,7 @@ private Metadata getJamesMappings(DinkPluginConfig config) { Map mappings = Map.of( "webhook", config.deathWebhook().isBlank() ? "discordWebhook" : "deathWebhook" ); - return new Metadata("discorddeathnotifications", mappings, "DeathNotificationsPlugin", DinkPluginConfig::notifyDeath, "deathEnabled"); + return new Metadata("discorddeathnotifications", mappings, "DeathNotificationsPlugin", DinkPluginConfig::notifyDeath, "deathEnabled", null); } private Metadata getPaulMappings(DinkPluginConfig config) { @@ -103,7 +112,7 @@ private Metadata getPaulMappings(DinkPluginConfig config) { "sendScreenshot", "collectionSendImage", "includepets", config.notifyPet() ? "" : "petEnabled" ); - return new Metadata("discordcollectionlogger", mappings, "DiscordCollectionLoggerPlugin", DinkPluginConfig::notifyCollectionLog, "collectionLogEnabled"); + return new Metadata("discordcollectionlogger", mappings, "DiscordCollectionLoggerPlugin", DinkPluginConfig::notifyCollectionLog, "collectionLogEnabled", null); } private Metadata getRinzMappings(DinkPluginConfig config) { @@ -115,7 +124,7 @@ private Metadata getRinzMappings(DinkPluginConfig config) { "valuableDropThreshold", "minLootValue", "collectionLogItem", config.notifyCollectionLog() ? "" : "collectionLogEnabled" ); - return new Metadata("betterdiscordlootlogger", mappings, "BetterDiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled"); + return new Metadata("betterdiscordlootlogger", mappings, "BetterDiscordLootLoggerPlugin", DinkPluginConfig::notifyLoot, "lootEnabled", null); } private Metadata getShamerMappings(DinkPluginConfig config) { @@ -124,7 +133,7 @@ private Metadata getShamerMappings(DinkPluginConfig config) { "webhookLink", config.deathWebhook().isBlank() ? "discordWebhook" : "deathWebhook", "captureOwnDeaths", config.notifyDeath() ? "" : "deathEnabled" ); - return new Metadata("raidshamer", mappings, "RaidShamerPlugin", DinkPluginConfig::notifyDeath, "deathEnabled"); + return new Metadata("raidshamer", mappings, "RaidShamerPlugin", DinkPluginConfig::notifyDeath, "deathEnabled", null); } private Metadata getTakamokMappings(DinkPluginConfig config) { @@ -135,7 +144,7 @@ private Metadata getTakamokMappings(DinkPluginConfig config) { "minimumLevel", "levelMinValue", "levelInterval", "levelInterval" ); - return new Metadata("discordlevelnotifications", mappings, "LevelNotificationsPlugin", DinkPluginConfig::notifyLevel, "levelEnabled"); + return new Metadata("discordlevelnotifications", mappings, "LevelNotificationsPlugin", DinkPluginConfig::notifyLevel, "levelEnabled", null); } @Value @@ -146,6 +155,12 @@ public static class Metadata { String pluginClassName; Predicate notifierEnabled; String notifierEnabledKey; + Map> configValueTransformers; + + public Object transform(String configKey, Object configValue) { + if (configValueTransformers == null) return configValue; + return configValueTransformers.getOrDefault(configKey, v -> v).apply(configValue); + } } static {