aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranhgelus <anhgelus.morhtuuzh@proton.me>2024-08-23 14:01:38 +0000
committeranhgelus <anhgelus.morhtuuzh@proton.me>2024-08-23 14:01:38 +0000
commitc6e309f02732eb79a24db6780c4f8f718fac2a29 (patch)
treea6e226a969b652b1d1399483f7da69cb78d973cd
parenta638839550837f43216b02a9bdee359a24814f37 (diff)
feat(config): hot reload with /molehunt reload
-rw-r--r--README.md2
-rw-r--r--src/main/java/world/anhgelus/molehunt/Molehunt.java13
2 files changed, 14 insertions, 1 deletions
diff --git a/README.md b/README.md
index 401b81f..2d22e84 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,8 @@ skin file](src/client/resources/assets/molehunt/textures/skin.png)).
Also, more server-side values can be changed in the configuration file, located in your server config directory.
+Config hot reloadable with `/molehunt reload`
+
## Technologies
- Java 21
diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java
index 79903e2..4a728a0 100644
--- a/src/main/java/world/anhgelus/molehunt/Molehunt.java
+++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java
@@ -29,7 +29,7 @@ public class Molehunt implements ModInitializer {
public static final String MOD_ID = "molehunt";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
- public static final Config CONFIG = new Config(MOD_ID);
+ public static Config CONFIG = new Config(MOD_ID);
public Game game;
@@ -81,6 +81,17 @@ public class Molehunt implements ModInitializer {
return Command.SINGLE_SUCCESS;
}));
+ command.then(literal("reload").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
+ if (game != null && game.hasStarted()) {
+ game.end();
+ game = null;
+ }
+ CONFIG = new Config(MOD_ID);
+ context.getSource().getServer().getPlayerManager().getPlayerList().forEach(p -> {
+ ServerPlayNetworking.send(p, new ConfigPayload(CONFIG.showNametags, CONFIG.showSkins, CONFIG.showTab));
+ });
+ return Command.SINGLE_SUCCESS;
+ }));
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(command));