diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 039ee4a..1987dd4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,24 +10,22 @@ jobs: build: strategy: matrix: - # and run on both Linux, Windows, and Mac + # and run on both Linux and Windows os: [ubuntu-24.04, windows-latest] runs-on: ${{ matrix.os }} steps: - - name: checkout repository - uses: actions/checkout@v2 - - name: validate gradle wrapper - uses: gradle/actions/wrapper-validation@v3 - - name: setup jdk 21 - uses: actions/setup-java@v1 + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup JDK 21 + uses: actions/setup-java@v4 with: + distribution: temurin java-version: 21 - - name: make gradle wrapper executable - if: ${{ runner.os != 'Windows' }} - run: chmod +x ./gradlew - - name: build + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + - name: Build artifacts run: ./gradlew build - - name: capture build artifacts + - name: Capture build artifacts if: ${{ runner.os == 'Linux' }} # Only upload artifacts built from LTS java on one OS uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f49258e..f74b847 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,20 +9,17 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - - name: Set up JDK 21 - uses: actions/setup-java@v3 + - name: Checkout repository + uses: actions/checkout@v4 + - name: Setup JDK 21 + uses: actions/setup-java@v34 with: distribution: temurin java-version: 21 - - - name: Make gradlew executable - run: chmod +x ./gradlew - + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 - name: Build artifacts run: ./gradlew clean build - - name: Upload assets to GitHub, Modrinth and CurseForge uses: Kir-Antipov/mc-publish@v3.3 with: diff --git a/README.md b/README.md index 904f782..8666d04 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # HeyThatsMine -[![build](https://img.shields.io/github/workflow/status/fabricservertools/HeyThatsMine/build)](https://github.com/fabricservertools/HeyThatsMine/actions) - +[![build]( https://img.shields.io/github/actions/workflow/status/QuiltServerTools/HeyThatsMine/main.yml?branch=master)](https://github.com/fabricservertools/HeyThatsMine/actions) [![discord](https://img.shields.io/discord/764543203772334100?label=Fabric%20Server%20Tools%20Discord)](https://discord.gg/jydqZzkyEa) - [![discord](https://img.shields.io/discord/776126068024410135?label=Potatos%20Place)](https://discord.gg/ByaVuebAPb) HTM is a fabric mod for protecting your containers and trusting people with access to them @@ -14,7 +12,7 @@ HTM is a fabric mod for protecting your containers and trusting people with acce HTM requires no additional setup apart from placing it in your mods folder. All new containers will automatically be set to private. -HTM also supports the luckperms API, which allows you to manage permissions. Permission nodes are listed in the relevant section. All nodes except admin are enabled for all users by default +HTM also supports the LuckPerms API, which allows you to manage permissions. Permission nodes are listed in the relevant section. All nodes except admin are enabled for all users by default ## Using HTM @@ -22,9 +20,11 @@ The mod has multiple commands which you can use on your containers ### Flag -`/htm flag`: Checks the flags of a specific container. Left click on the container after running this command to check +`/htm flag`: Checks the flags of a specific container. Left-click on the container after running this command to check -`/htm flag `: Left click a container to set the flag +`/htm flag `: Left-click a container to set the flag + +`/htm flag `: Left-click a container to reset the flag to the default value defined in the config file Permission node: `htm.command.flag` @@ -79,23 +79,67 @@ Toggles no message mode, which hides non-command messages like automatic protect Permission node: `htm.command.quiet` ### Config -`canTrustedPlayersBreakChests`: Toggles whether players trusted to a locked container can break the container - (set to false by default meaning only the owner can break a locked container). +The config file can be found in `/config/htm_config.json`. +`can_trusted_players_break_chests`: Toggles whether players trusted to a locked container can break the container + (is set to false by default, meaning only the owner can break a locked container). -`defaultFlags`: +`default_flags`: - - `hoppers`: Toggles whether hoppers can pull from locked containers by default - - (true by default meaning hoppers can pull from locked containers). - - - -`autolockingContainers`: List of containers which will be set to PRIVATE by default - - (remove items in the list to make them set to public by default). + - `overrides`: Overrides for default flags for containers. + + (a map of blocks or block tags to a map of flag overrides, overrides do not need to contain all flags. Empty by default) + + - `defaults`: The default flags, applicable to all blocks when no overrides are present. + + - `hoppers`: Toggles whether hoppers can pull from locked containers by default + + (is set to true by default, meaning hoppers can pull from locked containers). + - `copper_golems`: Toggles whether copper golems can take items from or put items into locked containers by default + + (is set to true by default, meaning copper golems can take items from or put items into locked containers) + +`auto_locking_containers`: List of containers which will be set to PRIVATE by default + + (add or remove blocks to the list to lock them by default, or not, block tags can also be used). + +An example config file, with custom flag overrides for copper golems: + +```json +{ + "can_trusted_players_break_chests": false, + "default_flags": { + "overrides": { + "chest": { + "copper_golems": true + }, + "#copper_chests": { + "copper_golems": true + } + }, + "default": { + "hoppers": true, + "copper_golems": false + } + }, + "auto_locking_containers": [ + "minecraft:chest", + "minecraft:trapped_chest", + "minecraft:barrel", + "minecraft:furnace", + "minecraft:blast_furnace", + "minecraft:smoker", + "#minecraft:shulker_boxes", + "#minecraft:copper_chests" + ] +} +``` + +The file above disables copper golem access to all locked containers except copper chests and normal chests. Flag overrides +can also be used to only have a specific set of locked containers allow hoppers by default. Flags can always be overridden +by players on a per-locked container instance basis. ### Additional permissions diff --git a/build.gradle b/build.gradle index b31616f..2506f18 100644 --- a/build.gradle +++ b/build.gradle @@ -1,55 +1,57 @@ plugins { - id 'fabric-loom' version '1.10.+' - id 'maven-publish' + id "fabric-loom" version "1.11.+" } -repositories { - maven { url = "https://maven.nucleoid.xyz/" } - maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } - maven { url "https://maven.nucleoid.xyz/" } -} - -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 - -archivesBaseName = project.archives_base_name version = project.mod_version group = project.maven_group -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" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" +base { + archivesName = project.archives_base_name +} - // Fabric API. This is technically optional, but you probably want it anyway. - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" +repositories { + mavenCentral() - // PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs. - // You may need to force-disable transitiveness on them. + maven{ + url = "https://maven.nucleoid.xyz/" + } +} - modImplementation include("xyz.nucleoid:server-translations-api:${project.translation_version}") +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") + modImplementation("net.fabricmc:fabric-loader:${project.loader_version}") - modImplementation include("me.lucko:fabric-permissions-api:${project.permissions_api_version}") + modImplementation("net.fabricmc.fabric-api:fabric-api:${project.fabric_version}") - modImplementation include("eu.pb4:common-protection-api:1.0.0") + modImplementation(include("xyz.nucleoid:server-translations-api:${project.translation_version}")) + modImplementation(include("me.lucko:fabric-permissions-api:${project.permissions_api_version}")) + modImplementation(include("eu.pb4:common-protection-api:${project.protection_api_version}")) } processResources { - inputs.property "version", project.version + inputs.property("version", project.version) filesMatching("fabric.mod.json") { - expand "version": project.version + expand("version": project.version) } } -// ensure that the encoding is set to UTF-8, no matter what the system default is -// this fixes some edge cases with special characters not displaying correctly -// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html -tasks.withType(JavaCompile) { +def targetJavaVersion = 21 +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html options.encoding = "UTF-8" + + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + options.release = targetJavaVersion + } } jar { - from "LICENSE" + from("LICENSE") { + rename { "${it}_${project.archives_base_name}"} + } } diff --git a/gradle.properties b/gradle.properties index 60ba24d..4b8140e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,15 +2,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=1.21.6 -yarn_mappings=1.21.6+build.1 -loader_version=0.16.14 +minecraft_version=1.21.9 +yarn_mappings=1.21.9+build.1 +loader_version=0.17.2 # Mod Properties -mod_version=1.1.17 +mod_version=1.2.0 maven_group=us.potatoboy archives_base_name=htm # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_version=0.127.1+1.21.6 -translation_version=2.5.1+1.21.5 -permissions_api_version=0.4.0-SNAPSHOT +fabric_version=0.133.14+1.21.9 +translation_version=2.5.2+1.21.9-pre3 +permissions_api_version=0.4.1 +protection_api_version=1.0.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 9bbc975..8bdaf60 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index cea7a79..2e11132 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-8.12-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index faf9300..adff685 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -172,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -212,8 +210,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 9d21a21..c4bdd3a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,10 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/settings.gradle b/settings.gradle index 5b60df3..f91a4fe 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,6 +1,5 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' diff --git a/src/main/java/com/github/fabricservertools/htm/HTM.java b/src/main/java/com/github/fabricservertools/htm/HTM.java index e0698e5..d412013 100644 --- a/src/main/java/com/github/fabricservertools/htm/HTM.java +++ b/src/main/java/com/github/fabricservertools/htm/HTM.java @@ -1,6 +1,5 @@ package com.github.fabricservertools.htm; -import com.github.fabricservertools.htm.api.LockType; import com.github.fabricservertools.htm.command.HTMCommand; import com.github.fabricservertools.htm.command.subcommands.*; import com.github.fabricservertools.htm.config.HTMConfig; @@ -11,23 +10,17 @@ import eu.pb4.common.protection.api.CommonProtection; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.util.Identifier; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.io.File; - public class HTM implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger("HTM"); - public static HTMConfig config; @Override public void onInitialize() { - LockType.init(); - - config = HTMConfig.loadConfig(new File(FabricLoader.getInstance().getConfigDir() + "/htm_config.json")); + HTMConfig.load(); CommandRegistrationCallback.EVENT.register(((dispatcher, environment, registryAccess) -> registerCommands(dispatcher))); CommonProtection.register(Identifier.of("htm", "containers"), new InteractionManager()); diff --git a/src/main/java/com/github/fabricservertools/htm/HTMTexts.java b/src/main/java/com/github/fabricservertools/htm/HTMTexts.java new file mode 100644 index 0000000..cd724fe --- /dev/null +++ b/src/main/java/com/github/fabricservertools/htm/HTMTexts.java @@ -0,0 +1,88 @@ +package com.github.fabricservertools.htm; + +import net.minecraft.screen.ScreenTexts; +import net.minecraft.text.MutableText; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +import java.util.function.UnaryOperator; + +public final class HTMTexts { + private static final String PREFIX = "text.htm."; + + public static final Text NOT_LOCKABLE = error("error.unlockable"); + public static final Text NOT_LOCKED = error("error.no_lock"); + public static final Text NOT_OWNER = error("error.not_owner"); + public static final Text ALREADY_LOCKED = error("error.already_locked"); + public static final Text INVALID_LOCK_TYPE = error("error.lock_type"); + public static final Text INVALID_FLAG_TYPE = error("error.flag_type"); + public static final Text CANNOT_TRUST_SELF = error("error.trust_self"); + public static final TranslatableTextBuilder ALREADY_TRUSTED = errorBuilder("error.already_trusted"); + public static final TranslatableTextBuilder PLAYER_NOT_TRUSTED = errorBuilder("error.not_trusted"); + public static final Text CONTAINER_LOCKED = error("locked"); + public static final Text OVERRIDING = error("overriding"); + + public static final Text CLICK_TO_SELECT = info("select"); + public static final Text DIVIDER = info("divider"); + public static final TranslatableTextBuilder CONTAINER_LOCK_TYPE = infoBuilder("type"); + public static final TranslatableTextBuilder CONTAINER_OWNER = infoBuilder("owner"); + public static final TranslatableTextBuilder CONTAINER_TRUSTED = infoBuilder("trusted"); + public static final TranslatableTextBuilder TRUSTED_GLOBALLY = infoBuilder("trusted.global"); + public static final TranslatableTextBuilder TRUST = infoBuilder("trust"); + public static final TranslatableTextBuilder UNTRUST = infoBuilder("untrust"); + public static final Text GLOBAL = info("global").formatted(Formatting.BOLD); + public static final TranslatableTextBuilder CONTAINER_TRANSFER = infoBuilder("transfer"); + public static final Text CONTAINER_UNLOCKED = info("unlocked"); + public static final TranslatableTextBuilder CONTAINER_KEY = infoBuilder("key"); + public static final TranslatableTextBuilder CONTAINER_SET = infoBuilder("set"); + public static final TranslatableTextBuilder CONTAINER_KEY_SET = infoBuilder("key_set"); + public static final TranslatableTextBuilder CONTAINER_OVERRIDE = infoBuilder("override").andThen(text -> text.append(ScreenTexts.space()).append(OVERRIDING)); + public static final TranslatableTextBuilder CONTAINER_FLAG_SET = infoBuilder("set_flag"); + public static final TranslatableTextBuilder CONTAINER_FLAG_RESET = infoBuilder("reset_flag"); + public static final TranslatableTextBuilder CONTAINER_FLAG = infoBuilder("flag"); + public static final Text ON = translatable("on") + .formatted(Formatting.GREEN, Formatting.BOLD); + public static final Text OFF = translatable("off") + .formatted(Formatting.RED, Formatting.BOLD); + public static final Text TOGGLE_PERSIST_ON = info("persist").append(ScreenTexts.SPACE).append(ON); + public static final Text TOGGLE_PERSIST_OFF = info("persist").append(ScreenTexts.SPACE).append(OFF); + public static final Text TOGGLE_NO_MSG_ON = info("no_msg").append(ScreenTexts.SPACE).append(ON); + public static final Text TOGGLE_NO_MSG_OFF = info("no_msg").append(ScreenTexts.SPACE).append(OFF); + + private static MutableText error(String key) { + return errorBuilder(key).apply(); + } + + private static TranslatableTextBuilder errorBuilder(String key) { + return builder(key, style -> style.withColor(Formatting.RED)); + } + + private static MutableText info(String key) { + return infoBuilder(key).apply(); + } + + private static TranslatableTextBuilder infoBuilder(String key) { + return builder(key, style -> style.withColor(Formatting.AQUA)); + } + + private static TranslatableTextBuilder builder(String key, UnaryOperator