diff --git a/build.gradle b/build.gradle index 42b1805..bd211d2 100644 --- a/build.gradle +++ b/build.gradle @@ -51,8 +51,8 @@ dependencies { // modImplementation "dev.emi:trinkets:${project.trinkets_version}" // modImplementation "com.github.apace100:apoli:${project.apoli_version}" - modImplementation "me.lucko:fabric-permissions-api:0.2-SNAPSHOT" - include "me.lucko:fabric-permissions-api:0.2-SNAPSHOT" + modImplementation "me.lucko:fabric-permissions-api:0.4.0" + include "me.lucko:fabric-permissions-api:0.4.0" // Dev Mods - These can be commented/uncommented to test compatibility //modLocalRuntime "maven.modrinth:cloth-config:9.0.94+fabric" diff --git a/gradle.properties b/gradle.properties index 2452aaa..a9e10ca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,16 +2,16 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/develop/ -minecraft_version=1.21.5 -yarn_mappings=1.21.5+build.1 -loader_version=0.16.11 +minecraft_version=1.21.6 +yarn_mappings=1.21.6+build.1 +loader_version=0.16.14 # Mod Properties -mod_version=1.4.16 +mod_version=1.4.17 maven_group=us.potatoboy archives_base_name=InvView # Dependencies # check this on https://fabricmc.net/develop/ -fabric_version=0.119.6+1.21.5 -trinkets_version=3.10.0 -apoli_version=2.11.11 -sgui_version=1.9.0+1.21.5 +fabric_version=0.127.1+1.21.6 +# trinkets_version=3.10.0 +# apoli_version=2.12.0 +sgui_version=1.10.0+1.21.6 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index d64cd49..1b33c55 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 37f853b..ff23a68 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.13-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index 1aa94a4..23d15a9 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -84,7 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -112,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -203,7 +205,7 @@ fi DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. @@ -211,7 +213,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 7101f8e..5eed7ee 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -68,11 +70,11 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @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%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/src/main/java/us/potatoboy/invview/InvView.java b/src/main/java/us/potatoboy/invview/InvView.java index 53223f0..21f5425 100644 --- a/src/main/java/us/potatoboy/invview/InvView.java +++ b/src/main/java/us/potatoboy/invview/InvView.java @@ -1,6 +1,8 @@ package us.potatoboy.invview; import com.mojang.brigadier.tree.LiteralCommandNode; +import com.mojang.logging.LogUtils; + import me.lucko.fabric.api.permissions.v0.Permissions; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; @@ -13,12 +15,14 @@ import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.storage.NbtWriteView; +import net.minecraft.util.ErrorReporter; import net.minecraft.util.Util; import net.minecraft.util.WorldSavePath; -import org.apache.logging.log4j.LogManager; import java.io.File; -import java.io.FileOutputStream; +import java.nio.file.Files; +import java.nio.file.Path; public class InvView implements ModInitializer { private static MinecraftServer minecraftServer; @@ -90,18 +94,21 @@ public static MinecraftServer getMinecraftServer() { return minecraftServer; } + // Taken from net.minecraft.world.PlayerSaveHandler.savePlayerData(), which is a protected method public static void savePlayerData(ServerPlayerEntity player) { - File playerDataDir = minecraftServer.getSavePath(WorldSavePath.PLAYERDATA).toFile(); - try { - NbtCompound compoundTag = player.writeNbt(new NbtCompound()); - File file = File.createTempFile(player.getUuidAsString() + "-", ".dat", playerDataDir); - final FileOutputStream fos = new FileOutputStream(file); - NbtIo.writeCompressed(compoundTag, fos); - File file2 = new File(playerDataDir, player.getUuidAsString() + ".dat"); - File file3 = new File(playerDataDir, player.getUuidAsString() + ".dat_old"); - Util.backupAndReplace(file2.toPath(), file.toPath(), file3.toPath()); - } catch (Exception var6) { - LogManager.getLogger().warn("Failed to save player data for {}", player.getName().getString()); - } - } + File playerDataDir = minecraftServer.getSavePath(WorldSavePath.PLAYERDATA).toFile(); + try (ErrorReporter.Logging logging = new ErrorReporter.Logging(player.getErrorReporterContext(), LogUtils.getLogger())) { + NbtWriteView nbtWriteView = NbtWriteView.create(logging, player.getRegistryManager()); + player.writeData(nbtWriteView); + Path path = playerDataDir.toPath(); + Path path2 = Files.createTempFile(path, player.getUuidAsString() + "-", ".dat"); + NbtCompound nbtCompound = nbtWriteView.getNbt(); + NbtIo.writeCompressed(nbtCompound, path2); + Path path3 = path.resolve(player.getUuidAsString() + ".dat"); + Path path4 = path.resolve(player.getUuidAsString() + ".dat_old"); + Util.backupAndReplace(path3, path2, path4); + } catch (Exception var11) { + LogUtils.getLogger().warn("Failed to save player data for {}", player.getName().getString()); + } + } } diff --git a/src/main/java/us/potatoboy/invview/ViewCommand.java b/src/main/java/us/potatoboy/invview/ViewCommand.java index 567a51b..336b041 100644 --- a/src/main/java/us/potatoboy/invview/ViewCommand.java +++ b/src/main/java/us/potatoboy/invview/ViewCommand.java @@ -3,24 +3,26 @@ import com.mojang.authlib.GameProfile; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.serialization.Dynamic; +import com.mojang.logging.LogUtils; import eu.pb4.sgui.api.elements.GuiElementBuilder; import eu.pb4.sgui.api.gui.SimpleGui; import me.lucko.fabric.api.permissions.v0.Permissions; import net.minecraft.command.argument.GameProfileArgumentType; import net.minecraft.inventory.EnderChestInventory; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtOps; import net.minecraft.network.packet.c2s.common.SyncedClientOptions; +import net.minecraft.registry.RegistryKey; +import net.minecraft.registry.RegistryKeys; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.screen.slot.Slot; import net.minecraft.server.MinecraftServer; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; +import net.minecraft.storage.ReadView; import net.minecraft.text.Text; -import net.minecraft.world.dimension.DimensionType; +import net.minecraft.util.ErrorReporter; +import net.minecraft.util.Identifier; import us.potatoboy.invview.gui.SavingPlayerDataGui; import us.potatoboy.invview.gui.UnmodifiableSlot; import us.potatoboy.invview.mixin.EntityAccessor; @@ -48,7 +50,8 @@ public static int inv(CommandContext context) throws Comman gui.setTitle(requestedPlayer.getName()); addBackground(gui); for (int i = 0; i < requestedPlayer.getInventory().size(); i++) { - gui.setSlotRedirect(i, canModify ? new Slot(requestedPlayer.getInventory(), i, 0, 0) : new UnmodifiableSlot(requestedPlayer.getInventory(), i)); + gui.setSlotRedirect(i, canModify ? new Slot(requestedPlayer.getInventory(), i, 0, 0) + : new UnmodifiableSlot(requestedPlayer.getInventory(), i)); } gui.open(); @@ -69,19 +72,20 @@ public static int eChest(CommandContext context) throws Com if (isProtected) { context.getSource().sendError(Text.literal(msgProtected)); } else { - ScreenHandlerType screenHandlerType = switch (requestedEchest.size()) { - case 9 -> ScreenHandlerType.GENERIC_9X1; - case 18 -> ScreenHandlerType.GENERIC_9X2; - case 36 -> ScreenHandlerType.GENERIC_9X4; - case 45 -> ScreenHandlerType.GENERIC_9X5; - case 54 -> ScreenHandlerType.GENERIC_9X6; - default -> ScreenHandlerType.GENERIC_9X3; - }; + ScreenHandlerType screenHandlerType = switch (requestedEchest.size()) { + case 9 -> ScreenHandlerType.GENERIC_9X1; + case 18 -> ScreenHandlerType.GENERIC_9X2; + case 36 -> ScreenHandlerType.GENERIC_9X4; + case 45 -> ScreenHandlerType.GENERIC_9X5; + case 54 -> ScreenHandlerType.GENERIC_9X6; + default -> ScreenHandlerType.GENERIC_9X3; + }; SimpleGui gui = new SavingPlayerDataGui(screenHandlerType, player, requestedPlayer); gui.setTitle(requestedPlayer.getName()); addBackground(gui); for (int i = 0; i < requestedEchest.size(); i++) { - gui.setSlotRedirect(i, canModify ? new Slot(requestedEchest, i, 0, 0) : new UnmodifiableSlot(requestedEchest, i)); + gui.setSlotRedirect(i, + canModify ? new Slot(requestedEchest, i, 0, 0) : new UnmodifiableSlot(requestedEchest, i)); } gui.open(); @@ -161,15 +165,21 @@ private static ServerPlayerEntity getRequestedPlayer(CommandContext compoundOpt = minecraftServer.getPlayerManager().loadPlayerData(requestedPlayer); - if (compoundOpt.isPresent()) { - NbtCompound compound = compoundOpt.get(); - if (compound.contains("Dimension")) { + requestedPlayer = new ServerPlayerEntity(minecraftServer, minecraftServer.getOverworld(), requestedProfile, + SyncedClientOptions.createDefault()); + Optional readViewOpt = minecraftServer.getPlayerManager() + .loadPlayerData(requestedPlayer, new ErrorReporter.Logging(LogUtils.getLogger())); + + // Avoids player's dimension being reset to the overworld + if (readViewOpt.isPresent()) { + ReadView readView = readViewOpt.get(); + Optional dimension = readView.getOptionalString("Dimension"); + + if (dimension.isPresent()) { ServerWorld world = minecraftServer.getWorld( - DimensionType.worldFromDimensionNbt(new Dynamic<>(NbtOps.INSTANCE, compound.get("Dimension"))) - .result().get()); + RegistryKey.of(RegistryKeys.WORLD, Identifier.tryParse(dimension.get()))); if (world != null) { ((EntityAccessor) requestedPlayer).callSetWorld(world); diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index bf6280e..d12aeaf 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,6 +34,6 @@ "depends": { "fabricloader": ">=0.15.10", "fabric": "*", - "minecraft": ">=1.21.5" + "minecraft": ">=1.21.6" } -} \ No newline at end of file +}