Fixed reloading and adding of messages into config

This commit is contained in:
Dawson Hessler
2022-08-28 12:11:41 -04:00
parent 95a00a4d0a
commit 795c869fc0
6 changed files with 15 additions and 4 deletions
@@ -77,6 +77,8 @@ public class BukkitPlugin extends JavaPlugin {
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), BukkitPlugin.pluginInstance)
.get());
AntiVPN.getInstance().getMessageHandler().reloadStrings();*/
reloadConfig();
}
@Override
@@ -115,6 +115,7 @@ public class AntiVPN {
AntiVPN.getInstance().getMessageHandler().initStrings(vpnString -> new ConfigDefault<>
(vpnString.getDefaultMessage(), "messages." + vpnString.getKey(), AntiVPN.getInstance())
.get());
AntiVPN.getInstance().getMessageHandler().reloadStrings();
}
public InputStream getResource(String filename) {
@@ -158,7 +159,8 @@ public class AntiVPN {
public void reloadConfig() {
try {
ConfigurationProvider.getProvider(YamlConfiguration.class)
config = ConfigurationProvider.getProvider(YamlConfiguration.class)
.load(new File(pluginFolder.getPath() + File.separator + "config.yml"));
} catch (IOException e) {
throw new RuntimeException(e);
@@ -53,6 +53,8 @@ public class ReloadCommand extends Command {
// Updating the cache of these values in VPNConfig
AntiVPN.getInstance().getVpnConfig().update();
AntiVPN.getInstance().getMessageHandler().reloadStrings();
// Clearing the local response cache
VPNExecutor.responseCache.clear();
@@ -1,5 +1,7 @@
package dev.brighten.antivpn.message;
import dev.brighten.antivpn.AntiVPN;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
@@ -27,6 +29,8 @@ public class MessageHandler {
public void addString(VpnString string, Function<VpnString, String> getter) {
string.setConfigStringGetter(getter);
getter.apply(string);
System.out.println("Added string " + string.getKey());
messages.put(string.getKey(), string);
}
@@ -19,7 +19,6 @@ public class VpnString {
public VpnString(String key, String defaultMessage) {
this.key = key;
this.defaultMessage = defaultMessage;
this.message = defaultMessage;
}
@SneakyThrows
@@ -30,7 +29,7 @@ public class VpnString {
}
public String getFormattedMessage(Var<String, Object>... replacements) {
String formatted = message;
String formatted = configStringGetter.apply(this);
for (Var<String, Object> replacement : replacements) {
formatted = formatted
+3 -1
View File
@@ -61,7 +61,9 @@ countries:
commands: []
# The kick message that will be used if commands are configured to use the built-in kicking sytem.
# PlaceHolders: %country% (Country name), %player% (Player name), %code% (Country ISO Code)
vanillaKickReason: "&cSorry, but our server does not allow connections from\n&f%country%"
vanillaKickReason: |-
&cSorry, but our server does not allow connections from
&f%country%
# This will disable any information being sent to https://bstats.org. We recommend you keep this enabled as it helps
# us understand our users and put effort where it is needed. All information sent goes under their privacy as seen
# here: https://bstats.org/privacy-policy