mirror of
https://github.com/ashhhleyyy/player-pronouns.git
synced 2024-11-01 07:07:38 +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"
|
name = "NucleoidMC"
|
||||||
url = uri("https://maven.nucleoid.xyz/")
|
url = uri("https://maven.nucleoid.xyz/")
|
||||||
}
|
}
|
||||||
|
// permissions api
|
||||||
|
maven {
|
||||||
|
name = "Sonatype OSS"
|
||||||
|
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -31,6 +36,10 @@ dependencies {
|
||||||
// more-codecs
|
// more-codecs
|
||||||
modImplementation(libs.more.codecs)
|
modImplementation(libs.more.codecs)
|
||||||
include(libs.more.codecs)
|
include(libs.more.codecs)
|
||||||
|
|
||||||
|
// fabric-api-permissions
|
||||||
|
modImplementation(libs.fabric.permissions)
|
||||||
|
include(libs.fabric.permissions)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.processResources {
|
tasks.processResources {
|
||||||
|
|
|
@ -8,6 +8,8 @@ fabric-api = "0.37.1+1.17"
|
||||||
placeholder-api = "1.0.1+1.17"
|
placeholder-api = "1.0.1+1.17"
|
||||||
more-codecs = "0.2.0"
|
more-codecs = "0.2.0"
|
||||||
|
|
||||||
|
fabric-permissions = "0.1-SNAPSHOT"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
|
minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" }
|
||||||
yarn = { module = "net.fabricmc:yarn", version.ref = "yarn" }
|
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" }
|
placeholder-api = { module = "eu.pb4:placeholder-api", version.ref = "placeholder-api" }
|
||||||
more-codecs = { module = "xyz.nucleoid:more-codecs", version.ref = "more-codecs" }
|
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 {
|
private static void savePronounDatabase(MinecraftServer server) throws IOException {
|
||||||
Path playerData = server.getSavePath(WorldSavePath.PLAYERDATA);
|
Path playerData = server.getSavePath(WorldSavePath.PLAYERDATA);
|
||||||
if (!Files.exists(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.PlayerPronouns;
|
||||||
import io.github.ashisbored.playerpronouns.data.PronounList;
|
import io.github.ashisbored.playerpronouns.data.PronounList;
|
||||||
import io.github.ashisbored.playerpronouns.data.Pronouns;
|
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.command.ServerCommandSource;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
|
@ -46,6 +47,13 @@ public class PronounsCommand {
|
||||||
.formatted(Formatting.GREEN), false);
|
.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;
|
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) {
|
public PronounList(List<Pronoun> defaultSingle, List<Pronoun> defaultPairs, List<Pronoun> customSingle, List<Pronoun> customPairs) {
|
||||||
this.defaultSingle = defaultSingle;
|
this.defaultSingle = defaultSingle;
|
||||||
this.defaultPairs = defaultPairs;
|
this.defaultPairs = defaultPairs;
|
||||||
this.customSingle = customSingle;
|
this.customSingle = new ArrayList<>(customSingle);
|
||||||
this.customPairs = customPairs;
|
this.customPairs = new ArrayList<>(customPairs);
|
||||||
this.calculatedPronounStrings = this.computePossibleCombinations();
|
this.calculatedPronounStrings = this.computePossibleCombinations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +65,8 @@ public class PronounList {
|
||||||
|
|
||||||
public static void load(Config config) {
|
public static void load(Config config) {
|
||||||
if (INSTANCE != null) {
|
if (INSTANCE != null) {
|
||||||
throw new IllegalStateException("PronounList has already been loaded!");
|
INSTANCE.reload(config);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Pair<List<Pronoun>, List<Pronoun>> defaults = loadDefaults();
|
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() {
|
public static PronounList get() {
|
||||||
if (INSTANCE == null) {
|
if (INSTANCE == null) {
|
||||||
throw new IllegalStateException("PronounList has not been loaded!");
|
throw new IllegalStateException("PronounList has not been loaded!");
|
||||||
|
|
Loading…
Reference in a new issue