diff --git a/build.gradle b/build.gradle index 2506f18..66cdd45 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "fabric-loom" version "1.11.+" + id "fabric-loom" version "1.14-SNAPSHOT" } version = project.mod_version @@ -20,7 +20,7 @@ repositories { dependencies { //to change the versions see the gradle.properties file minecraft("com.mojang:minecraft:${project.minecraft_version}") - mappings("net.fabricmc:yarn:${project.yarn_mappings}:v2") + mappings(loom.officialMojangMappings()) modImplementation("net.fabricmc:fabric-loader:${project.loader_version}") modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") diff --git a/gradle.properties b/gradle.properties index 4b8140e..9003c93 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,17 +1,19 @@ # Done to increase the memory available to gradle. org.gradle.jvmargs=-Xmx1G + # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.21.9 -yarn_mappings=1.21.9+build.1 -loader_version=0.17.2 +minecraft_version=1.21.11 +loader_version=0.18.2 + # Mod Properties -mod_version=1.2.0 +mod_version=1.2.1 maven_group=us.potatoboy archives_base_name=htm + # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.133.14+1.21.9 +fabric_version=0.139.4+1.21.11 translation_version=2.5.2+1.21.9-pre3 -permissions_api_version=0.4.1 +permissions_api_version=0.6.1 protection_api_version=1.0.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e11132..23449a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/com/github/fabricservertools/htm/HTM.java b/src/main/java/com/github/fabricservertools/htm/HTM.java index d412013..d29b4cc 100644 --- a/src/main/java/com/github/fabricservertools/htm/HTM.java +++ b/src/main/java/com/github/fabricservertools/htm/HTM.java @@ -1,17 +1,18 @@ package com.github.fabricservertools.htm; +import com.github.fabricservertools.htm.api.Lock; import com.github.fabricservertools.htm.command.HTMCommand; import com.github.fabricservertools.htm.command.subcommands.*; import com.github.fabricservertools.htm.config.HTMConfig; import com.github.fabricservertools.htm.interactions.InteractionManager; import com.github.fabricservertools.htm.listeners.PlayerEventListener; -import com.github.fabricservertools.htm.listeners.WorldEventListener; +import com.github.fabricservertools.htm.listeners.LevelEventListener; import com.mojang.brigadier.CommandDispatcher; import eu.pb4.common.protection.api.CommonProtection; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.util.Identifier; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.resources.Identifier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,25 +21,28 @@ public class HTM implements ModInitializer { @Override public void onInitialize() { + // For some reason, the Lock class has to be loaded before the HTMConfig class for the codecs to be initialised properly + // Calling a method of the class loads it. Removing the line below results in an NPE when launching Minecraft + Lock.bootstrap(); HTMConfig.load(); CommandRegistrationCallback.EVENT.register(((dispatcher, environment, registryAccess) -> registerCommands(dispatcher))); - CommonProtection.register(Identifier.of("htm", "containers"), new InteractionManager()); + CommonProtection.register(Identifier.fromNamespaceAndPath("htm", "containers"), new InteractionManager()); PlayerEventListener.init(); - WorldEventListener.init(); + LevelEventListener.init(); } - private void registerCommands(CommandDispatcher dispatcher) { - HTMCommand.register(dispatcher); - HTMCommand.registerSubCommand(new SetCommand().build()); - HTMCommand.registerSubCommand(new RemoveCommand().build()); - HTMCommand.registerSubCommand(new TrustCommand().build()); - HTMCommand.registerSubCommand(new UntrustCommand().build()); - HTMCommand.registerSubCommand(new InfoCommand().build()); - HTMCommand.registerSubCommand(new TransferCommand().build()); - HTMCommand.registerSubCommand(new FlagCommand().build()); - HTMCommand.registerSubCommand(new PersistCommand().build()); - HTMCommand.registerSubCommand(new QuietCommand().build()); - } + private void registerCommands(CommandDispatcher dispatcher) { + HTMCommand.registerSubCommand(new SetCommand()); + HTMCommand.registerSubCommand(new RemoveCommand()); + HTMCommand.registerSubCommand(new TrustCommand()); + HTMCommand.registerSubCommand(new UntrustCommand()); + HTMCommand.registerSubCommand(new InfoCommand()); + HTMCommand.registerSubCommand(new TransferCommand()); + HTMCommand.registerSubCommand(new FlagCommand()); + HTMCommand.registerSubCommand(new PersistCommand()); + HTMCommand.registerSubCommand(new QuietCommand()); + HTMCommand.register(dispatcher); + } } diff --git a/src/main/java/com/github/fabricservertools/htm/HTMComponents.java b/src/main/java/com/github/fabricservertools/htm/HTMComponents.java new file mode 100644 index 0000000..5eb6711 --- /dev/null +++ b/src/main/java/com/github/fabricservertools/htm/HTMComponents.java @@ -0,0 +1,87 @@ +package com.github.fabricservertools.htm; + +import java.util.function.UnaryOperator; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; + +public final class HTMComponents { + private static final String PREFIX = "text.htm."; + + public static final Component NOT_LOCKABLE = error("error.unlockable"); + public static final Component NOT_LOCKED = error("error.no_lock"); + public static final Component NOT_OWNER = error("error.not_owner"); + public static final Component ALREADY_LOCKED = error("error.already_locked"); + public static final Component INVALID_LOCK_TYPE = error("error.lock_type"); + public static final Component INVALID_FLAG_TYPE = error("error.flag_type"); + public static final Component CANNOT_TRUST_SELF = error("error.trust_self"); + public static final TranslatableComponentBuilder ALREADY_TRUSTED = errorBuilder("error.already_trusted"); + public static final TranslatableComponentBuilder PLAYER_NOT_TRUSTED = errorBuilder("error.not_trusted"); + public static final Component CONTAINER_LOCKED = error("locked"); + public static final Component OVERRIDING = error("overriding"); + + public static final Component CLICK_TO_SELECT = info("select"); + public static final Component DIVIDER = info("divider"); + public static final TranslatableComponentBuilder CONTAINER_LOCK_TYPE = infoBuilder("type"); + public static final TranslatableComponentBuilder CONTAINER_OWNER = infoBuilder("owner"); + public static final TranslatableComponentBuilder CONTAINER_TRUSTED = infoBuilder("trusted"); + public static final TranslatableComponentBuilder TRUSTED_GLOBALLY = infoBuilder("trusted.global"); + public static final TranslatableComponentBuilder TRUST = infoBuilder("trust"); + public static final TranslatableComponentBuilder UNTRUST = infoBuilder("untrust"); + public static final Component GLOBAL = info("global").withStyle(ChatFormatting.BOLD); + public static final TranslatableComponentBuilder CONTAINER_TRANSFER = infoBuilder("transfer"); + public static final Component CONTAINER_UNLOCKED = info("unlocked"); + public static final TranslatableComponentBuilder CONTAINER_KEY = infoBuilder("key"); + public static final TranslatableComponentBuilder CONTAINER_SET = infoBuilder("set"); + public static final TranslatableComponentBuilder CONTAINER_KEY_SET = infoBuilder("key_set"); + public static final TranslatableComponentBuilder CONTAINER_OVERRIDE = infoBuilder("override").andThen(text -> text.append(CommonComponents.space()).append(OVERRIDING)); + public static final TranslatableComponentBuilder CONTAINER_FLAG_SET = infoBuilder("set_flag"); + public static final TranslatableComponentBuilder CONTAINER_FLAG_RESET = infoBuilder("reset_flag"); + public static final TranslatableComponentBuilder CONTAINER_FLAG = infoBuilder("flag"); + public static final Component ON = translatable("on") + .withStyle(ChatFormatting.GREEN, ChatFormatting.BOLD); + public static final Component OFF = translatable("off") + .withStyle(ChatFormatting.RED, ChatFormatting.BOLD); + public static final Component TOGGLE_PERSIST_ON = info("persist").append(CommonComponents.SPACE).append(ON); + public static final Component TOGGLE_PERSIST_OFF = info("persist").append(CommonComponents.SPACE).append(OFF); + public static final Component TOGGLE_NO_MSG_ON = info("no_msg").append(CommonComponents.SPACE).append(ON); + public static final Component TOGGLE_NO_MSG_OFF = info("no_msg").append(CommonComponents.SPACE).append(OFF); + + private static MutableComponent error(String key) { + return errorBuilder(key).apply(); + } + + private static TranslatableComponentBuilder errorBuilder(String key) { + return builder(key, style -> style.withColor(ChatFormatting.RED)); + } + + private static MutableComponent info(String key) { + return infoBuilder(key).apply(); + } + + private static TranslatableComponentBuilder infoBuilder(String key) { + return builder(key, style -> style.withColor(ChatFormatting.AQUA)); + } + + private static TranslatableComponentBuilder builder(String key, UnaryOperator