From f7b49fccddf78eca583865ae623fd5dfe747d424 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 17 Apr 2023 13:34:53 +0200 Subject: [PATCH] Fix invalid check for offline UUID in `UserIdent.create()` (#2) See more: https://github.com/GTNewHorizons/EnderIO/pull/118 --- src/main/java/crazypants/util/UserIdent.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/crazypants/util/UserIdent.java b/src/main/java/crazypants/util/UserIdent.java index 45387d28..0af10512 100644 --- a/src/main/java/crazypants/util/UserIdent.java +++ b/src/main/java/crazypants/util/UserIdent.java @@ -6,6 +6,7 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.UsernameCache; import com.enderio.core.common.util.PlayerUtil; @@ -109,8 +110,7 @@ public class UserIdent { */ public static @Nonnull UserIdent create(@Nullable GameProfile gameProfile) { if (gameProfile != null && (gameProfile.getId() != null || gameProfile.getName() != null)) { - if (gameProfile.getId() != null && gameProfile.getName() != null - && gameProfile.getId().equals(offlineUUID(gameProfile.getName()))) { + if (gameProfile.getName() != null && !isOnlineMode()) { return new UserIdent(null, gameProfile.getName()); } else { return new UserIdent(gameProfile.getId(), gameProfile.getName()); @@ -120,6 +120,11 @@ public class UserIdent { } } + private static boolean isOnlineMode() { + MinecraftServer server = MinecraftServer.getServer(); + return server.isServerInOnlineMode(); + } + private static @Nonnull UUID offlineUUID(String playerName) { UUID result = UUID.nameUUIDFromBytes(("OfflinePlayer:" + playerName).getBytes(Charsets.UTF_8)); return result != null ? result : new UUID(-1, -1);