mirror of
https://github.com/ashhhleyyy/player-pronouns.git
synced 2024-11-23 17:48:09 +00:00
Config reload support
This commit is contained in:
parent
915fd82f15
commit
e38c28ec60
5 changed files with 39 additions and 3 deletions
|
@ -13,6 +13,11 @@ repositories {
|
|||
name = "NucleoidMC"
|
||||
url = uri("https://maven.nucleoid.xyz/")
|
||||
}
|
||||
// permissions api
|
||||
maven {
|
||||
name = "Sonatype OSS"
|
||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
@ -31,6 +36,10 @@ dependencies {
|
|||
// more-codecs
|
||||
modImplementation(libs.more.codecs)
|
||||
include(libs.more.codecs)
|
||||
|
||||
// fabric-api-permissions
|
||||
modImplementation(libs.fabric.permissions)
|
||||
include(libs.fabric.permissions)
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
|
|
|
@ -8,6 +8,8 @@ fabric-api = "0.37.1+1.17"
|
|||
placeholder-api = "1.0.1+1.17"
|
||||
more-codecs = "0.2.0"
|
||||
|
||||
fabric-permissions = "0.1-SNAPSHOT"
|
||||
|
||||
[libraries]
|
||||
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
|
||||
yarn = { module = "net.fabricmc:yarn", version.ref = "yarn" }
|
||||
|
@ -17,3 +19,5 @@ fabric-api = { module = "net.fabricmc.fabric-api:fabric-api", version.ref = "fab
|
|||
|
||||
placeholder-api = { module = "eu.pb4:placeholder-api", version.ref = "placeholder-api" }
|
||||
more-codecs = { module = "xyz.nucleoid:more-codecs", version.ref = "more-codecs" }
|
||||
|
||||
fabric-permissions = { module = "me.lucko:fabric-permissions-api", version.ref = "fabric-permissions" }
|
||||
|
|
|
@ -93,6 +93,11 @@ public class PlayerPronouns implements ModInitializer {
|
|||
});
|
||||
}
|
||||
|
||||
public static void reloadConfig() {
|
||||
config = Config.load();
|
||||
PronounList.load(config);
|
||||
}
|
||||
|
||||
private static void savePronounDatabase(MinecraftServer server) throws IOException {
|
||||
Path playerData = server.getSavePath(WorldSavePath.PLAYERDATA);
|
||||
if (!Files.exists(playerData)) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.mojang.brigadier.CommandDispatcher;
|
|||
import io.github.ashisbored.playerpronouns.PlayerPronouns;
|
||||
import io.github.ashisbored.playerpronouns.data.PronounList;
|
||||
import io.github.ashisbored.playerpronouns.data.Pronouns;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.LiteralText;
|
||||
|
@ -46,6 +47,13 @@ public class PronounsCommand {
|
|||
.formatted(Formatting.GREEN), false);
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
).then(literal("reload-config")
|
||||
.requires(ctx -> Permissions.check(ctx, "playerpronouns.reload_config", 4))
|
||||
.executes(ctx -> {
|
||||
PlayerPronouns.reloadConfig();
|
||||
ctx.getSource().sendFeedback(new LiteralText("Reloaded the config!").formatted(Formatting.GREEN), true);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
|
|
|
@ -28,8 +28,8 @@ public class PronounList {
|
|||
public PronounList(List<Pronoun> defaultSingle, List<Pronoun> defaultPairs, List<Pronoun> customSingle, List<Pronoun> customPairs) {
|
||||
this.defaultSingle = defaultSingle;
|
||||
this.defaultPairs = defaultPairs;
|
||||
this.customSingle = customSingle;
|
||||
this.customPairs = customPairs;
|
||||
this.customSingle = new ArrayList<>(customSingle);
|
||||
this.customPairs = new ArrayList<>(customPairs);
|
||||
this.calculatedPronounStrings = this.computePossibleCombinations();
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,8 @@ public class PronounList {
|
|||
|
||||
public static void load(Config config) {
|
||||
if (INSTANCE != null) {
|
||||
throw new IllegalStateException("PronounList has already been loaded!");
|
||||
INSTANCE.reload(config);
|
||||
return;
|
||||
}
|
||||
|
||||
Pair<List<Pronoun>, List<Pronoun>> defaults = loadDefaults();
|
||||
|
@ -77,6 +78,15 @@ public class PronounList {
|
|||
);
|
||||
}
|
||||
|
||||
private void reload(Config config) {
|
||||
this.customSingle.clear();
|
||||
this.customPairs.clear();
|
||||
this.customSingle.addAll(config.getSingle());
|
||||
this.customPairs.addAll(config.getPairs());
|
||||
this.calculatedPronounStrings.clear();
|
||||
this.calculatedPronounStrings.putAll(this.computePossibleCombinations());
|
||||
}
|
||||
|
||||
public static PronounList get() {
|
||||
if (INSTANCE == null) {
|
||||
throw new IllegalStateException("PronounList has not been loaded!");
|
||||
|
|
Loading…
Reference in a new issue