Added Reloadable interface to more easily keep track of classes that need something on reload

This commit is contained in:
Artemis-the-gr8 2023-03-31 12:41:43 +02:00
parent 3591a879d9
commit 0057b2c530
8 changed files with 30 additions and 12 deletions

View File

@ -102,6 +102,12 @@
<exclude>META-INF/**</exclude>
</excludes>
</filter>
<filter>
<artifact>com.artemis.the.gr8:Database:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>

View File

@ -105,6 +105,7 @@
<groupId>com.tchristofferson</groupId>
<artifactId>ConfigUpdater</artifactId>
<version>2.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -201,6 +202,12 @@
<exclude>META-INF/**</exclude>
</excludes>
</filter>
<filter>
<artifact>com.artemis.the.gr8:Database:*</artifact>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>

View File

@ -13,7 +13,6 @@ import com.artemis.the.gr8.playerstats.core.listeners.JoinListener;
import com.artemis.the.gr8.playerstats.core.msg.msgutils.LanguageKeyHandler;
import com.artemis.the.gr8.playerstats.core.sharing.ShareManager;
import com.artemis.the.gr8.playerstats.core.statistic.StatRequestManager;
import com.artemis.the.gr8.playerstats.core.utils.MyLogger;
import com.artemis.the.gr8.playerstats.core.utils.OfflinePlayerHandler;
import me.clip.placeholderapi.PlaceholderAPIPlugin;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
@ -69,11 +68,10 @@ public final class Main extends JavaPlugin implements PlayerStats {
public void reloadPlugin() {
config.reload();
MyLogger.setDebugLevel(config.getDebugLevel());
languageKeyHandler.reload();
offlinePlayerHandler.reload();
outputManager.updateSettings();
shareManager.updateSettings();
outputManager.reload();
shareManager.reload();
}
/**

View File

@ -6,8 +6,6 @@ import com.artemis.the.gr8.playerstats.core.utils.FileHandler;
import com.artemis.the.gr8.playerstats.core.utils.MyLogger;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Map;
@ -46,6 +44,7 @@ public final class ConfigHandler extends FileHandler {
public void reload() {
super.reload();
config = super.getFileConfiguration();
MyLogger.setDebugLevel(getDebugLevel());
}
/**

View File

@ -6,6 +6,7 @@ import com.artemis.the.gr8.playerstats.core.enums.StandardMessage;
import com.artemis.the.gr8.playerstats.core.msg.components.*;
import com.artemis.the.gr8.playerstats.core.msg.msgutils.FormattingFunction;
import com.artemis.the.gr8.playerstats.api.StatRequest;
import com.artemis.the.gr8.playerstats.core.utils.Reloadable;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
@ -29,7 +30,7 @@ import static com.artemis.the.gr8.playerstats.core.enums.StandardMessage.*;
* for Players (mainly to deal with the lack of hover-text,
* and for Bukkit consoles to make up for the lack of hex-colors).
*/
public final class OutputManager {
public final class OutputManager implements Reloadable {
private static BukkitAudiences adventure;
private static EnumMap<StandardMessage, Function<MessageBuilder, TextComponent>> standardMessages;
@ -46,7 +47,7 @@ public final class OutputManager {
prepareFunctions();
}
public void updateSettings() {
public void reload() {
getMessageBuilders();
}

View File

@ -2,6 +2,7 @@ package com.artemis.the.gr8.playerstats.core.sharing;
import com.artemis.the.gr8.playerstats.core.config.ConfigHandler;
import com.artemis.the.gr8.playerstats.core.utils.MyLogger;
import com.artemis.the.gr8.playerstats.core.utils.Reloadable;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
@ -23,7 +24,7 @@ import static java.time.temporal.ChronoUnit.SECONDS;
* of past stat-lookups, so the results can be retrieved
* and shared when a Player clicks the share-button.
*/
public final class ShareManager {
public final class ShareManager implements Reloadable {
private static volatile ShareManager instance;
private static boolean isEnabled;
@ -35,7 +36,7 @@ public final class ShareManager {
private ArrayBlockingQueue<Integer> sharedResults;
private ShareManager() {
updateSettings();
reload();
}
public static ShareManager getInstance() {
@ -56,7 +57,7 @@ public final class ShareManager {
return isEnabled;
}
public void updateSettings() {
public void reload() {
ConfigHandler config = ConfigHandler.getInstance();
isEnabled = config.allowStatSharing() && config.useHoverText();
waitingTime = config.getStatShareWaitingTime();

View File

@ -14,7 +14,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public abstract class FileHandler {
public abstract class FileHandler implements Reloadable {
private final String fileName;
private File file;

View File

@ -0,0 +1,6 @@
package com.artemis.the.gr8.playerstats.core.utils;
public interface Reloadable {
void reload();
}