|
| 1 | +package de.sailab.mycyclingcity.mccbridge; |
| 2 | + |
| 3 | +import org.bukkit.configuration.file.FileConfiguration; |
| 4 | + |
| 5 | +import java.util.Collections; |
| 6 | +import java.util.LinkedHashMap; |
| 7 | +import java.util.Map; |
| 8 | + |
| 9 | +public final class MccBridgeConfig { |
| 10 | + private String websocketUrl; |
| 11 | + private String sharedSecret; |
| 12 | + private String serverId; |
| 13 | + private int reconnectSeconds; |
| 14 | + private int heartbeatSeconds; |
| 15 | + private boolean catalogSyncOnConnect; |
| 16 | + private boolean esguiSyncOnCatalog; |
| 17 | + private boolean esguiAddMissingItems; |
| 18 | + private int esguiDefaultSellPrice; |
| 19 | + private boolean esguiReloadAfterSync; |
| 20 | + private boolean esguiReloadCycleFallback; |
| 21 | + private String currencyName; |
| 22 | + private String currencySymbol; |
| 23 | + private String resolution; |
| 24 | + private Map<String, String> staticTeamGroups = Collections.emptyMap(); |
| 25 | + private final Map<String, String> runtimeTeamGroups = new LinkedHashMap<>(); |
| 26 | + private Map<String, String> playerOverrides; |
| 27 | + |
| 28 | + public void load(FileConfiguration config) { |
| 29 | + websocketUrl = config.getString("mcc.websocket_url", "ws://127.0.0.1:8000/ws/minecraft/events/"); |
| 30 | + sharedSecret = config.getString("mcc.shared_secret", "SECRET"); |
| 31 | + serverId = config.getString("mcc.server_id", "velo-stadt-1"); |
| 32 | + reconnectSeconds = Math.max(5, config.getInt("mcc.reconnect_seconds", 15)); |
| 33 | + heartbeatSeconds = config.getInt("mcc.heartbeat_seconds", 60); |
| 34 | + if (heartbeatSeconds < 0) { |
| 35 | + heartbeatSeconds = 0; |
| 36 | + } else if (heartbeatSeconds > 0 && heartbeatSeconds < 15) { |
| 37 | + // Keep presence fresher than MCC Admin STALE_AFTER (5 min) |
| 38 | + heartbeatSeconds = 15; |
| 39 | + } |
| 40 | + catalogSyncOnConnect = config.getBoolean("mcc.catalog_sync_on_connect", true); |
| 41 | + esguiSyncOnCatalog = config.getBoolean("mcc.esgui_sync_on_catalog", true); |
| 42 | + esguiAddMissingItems = config.getBoolean("mcc.esgui_add_missing_items", false); |
| 43 | + esguiDefaultSellPrice = config.getInt("mcc.esgui_default_sell_price", -1); |
| 44 | + esguiReloadAfterSync = config.getBoolean("mcc.esgui_reload_after_sync", true); |
| 45 | + esguiReloadCycleFallback = config.getBoolean("mcc.esgui_reload_cycle_fallback", true); |
| 46 | + currencyName = config.getString("vault.currency_name", "Velos"); |
| 47 | + currencySymbol = config.getString("vault.currency_symbol", " Velos"); |
| 48 | + resolution = config.getString("team.resolution", "luckperms"); |
| 49 | + staticTeamGroups = readStringMap(config, "team.team_groups"); |
| 50 | + runtimeTeamGroups.clear(); |
| 51 | + playerOverrides = readStringMap(config, "team.player_overrides"); |
| 52 | + } |
| 53 | + |
| 54 | + public void upsertTeamGroup(String lpGroup, String mcUsername) { |
| 55 | + if (lpGroup == null || lpGroup.isBlank() || mcUsername == null || mcUsername.isBlank()) { |
| 56 | + return; |
| 57 | + } |
| 58 | + runtimeTeamGroups.put(lpGroup, mcUsername); |
| 59 | + } |
| 60 | + |
| 61 | + public void removeTeamGroup(String lpGroup) { |
| 62 | + if (lpGroup == null || lpGroup.isBlank()) { |
| 63 | + return; |
| 64 | + } |
| 65 | + runtimeTeamGroups.remove(lpGroup); |
| 66 | + } |
| 67 | + |
| 68 | + private Map<String, String> readStringMap(FileConfiguration config, String path) { |
| 69 | + if (!config.isConfigurationSection(path)) { |
| 70 | + return Collections.emptyMap(); |
| 71 | + } |
| 72 | + Map<String, String> values = new LinkedHashMap<>(); |
| 73 | + for (String key : config.getConfigurationSection(path).getKeys(false)) { |
| 74 | + String value = config.getString(path + "." + key); |
| 75 | + if (value != null && !value.isBlank()) { |
| 76 | + values.put(key, value); |
| 77 | + } |
| 78 | + } |
| 79 | + return values; |
| 80 | + } |
| 81 | + |
| 82 | + public String websocketUrl() { |
| 83 | + return websocketUrl; |
| 84 | + } |
| 85 | + |
| 86 | + public String sharedSecret() { |
| 87 | + return sharedSecret; |
| 88 | + } |
| 89 | + |
| 90 | + public String serverId() { |
| 91 | + return serverId; |
| 92 | + } |
| 93 | + |
| 94 | + public int reconnectSeconds() { |
| 95 | + return reconnectSeconds; |
| 96 | + } |
| 97 | + |
| 98 | + /** Application HEARTBEAT interval in seconds; 0 disables. */ |
| 99 | + public int heartbeatSeconds() { |
| 100 | + return heartbeatSeconds; |
| 101 | + } |
| 102 | + |
| 103 | + public boolean catalogSyncOnConnect() { |
| 104 | + return catalogSyncOnConnect; |
| 105 | + } |
| 106 | + |
| 107 | + public boolean esguiSyncOnCatalog() { |
| 108 | + return esguiSyncOnCatalog; |
| 109 | + } |
| 110 | + |
| 111 | + public boolean esguiAddMissingItems() { |
| 112 | + return esguiAddMissingItems; |
| 113 | + } |
| 114 | + |
| 115 | + public int esguiDefaultSellPrice() { |
| 116 | + return esguiDefaultSellPrice; |
| 117 | + } |
| 118 | + |
| 119 | + public boolean esguiReloadAfterSync() { |
| 120 | + return esguiReloadAfterSync; |
| 121 | + } |
| 122 | + |
| 123 | + public boolean esguiReloadCycleFallback() { |
| 124 | + return esguiReloadCycleFallback; |
| 125 | + } |
| 126 | + |
| 127 | + public String currencyName() { |
| 128 | + return currencyName; |
| 129 | + } |
| 130 | + |
| 131 | + public String currencySymbol() { |
| 132 | + return currencySymbol; |
| 133 | + } |
| 134 | + |
| 135 | + public String resolution() { |
| 136 | + return resolution; |
| 137 | + } |
| 138 | + |
| 139 | + public Map<String, String> teamGroups() { |
| 140 | + Map<String, String> merged = new LinkedHashMap<>(staticTeamGroups); |
| 141 | + merged.putAll(runtimeTeamGroups); |
| 142 | + return merged; |
| 143 | + } |
| 144 | + |
| 145 | + public Map<String, String> playerOverrides() { |
| 146 | + return playerOverrides; |
| 147 | + } |
| 148 | +} |
0 commit comments