Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 7 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -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/.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -203,15 +205,15 @@ 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.

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.
Expand Down
6 changes: 4 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##########################################################################
Expand Down Expand Up @@ -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
Expand Down
37 changes: 22 additions & 15 deletions src/main/java/us/potatoboy/invview/InvView.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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());
}
}
}
52 changes: 31 additions & 21 deletions src/main/java/us/potatoboy/invview/ViewCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,7 +50,8 @@ public static int inv(CommandContext<ServerCommandSource> 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();
Expand All @@ -69,19 +72,20 @@ public static int eChest(CommandContext<ServerCommandSource> 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();
Expand Down Expand Up @@ -161,15 +165,21 @@ private static ServerPlayerEntity getRequestedPlayer(CommandContext<ServerComman
GameProfile requestedProfile = GameProfileArgumentType.getProfileArgument(context, "target").iterator().next();
ServerPlayerEntity requestedPlayer = minecraftServer.getPlayerManager().getPlayer(requestedProfile.getName());

// If player is not currently online
if (requestedPlayer == null) {
requestedPlayer = minecraftServer.getPlayerManager().createPlayer(requestedProfile, SyncedClientOptions.createDefault());
Optional<NbtCompound> 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<ReadView> 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<String> 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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"depends": {
"fabricloader": ">=0.15.10",
"fabric": "*",
"minecraft": ">=1.21.5"
"minecraft": ">=1.21.6"
}
}
}