Skip to content

Commit

Permalink
Merge remote-tracking branch 'Pilzinsel64/master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream-Master committed May 1, 2023
2 parents 2e135c9 + 567cd3e commit cd72c23
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/main/java/crazypants/enderio/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ public String lc() {
public static boolean reinforcedObsidianEnabled = true;
public static boolean reinforcedObsidianUseDarkSteelBlocks = false;

public static boolean enforceOfflinePlayerUUID = false;

public static boolean useAlternateBinderRecipe = false;

public static boolean useAlternateTesseractModel = false;
Expand Down Expand Up @@ -1031,6 +1033,13 @@ public static void processConfig(Configuration config) {
"Enable per tick sampling on individual power inputs and outputs. This allows slightly more detailed messages from the RF Reader but has a negative impact on server performance.")
.getBoolean(detailedPowerTrackingEnabled);

enforceOfflinePlayerUUID = config.get(
sectionAdvanced.name,
"enforceOfflinePlayerUUID",
false,
"Enforces to use the players offline UUID. Recommendet to use before creating your world, otherwise it might breaks all secuity related things.")
.getBoolean(enforceOfflinePlayerUUID);

useSneakMouseWheelYetaWrench = config.get(
sectionPersonal.name,
"useSneakMouseWheelYetaWrench",
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/crazypants/util/UserIdent.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
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;
import com.google.common.base.Charsets;
import com.mojang.authlib.GameProfile;

import crazypants.enderio.Log;
import crazypants.enderio.config.Config;

public class UserIdent {

Expand Down Expand Up @@ -75,7 +78,7 @@ public String getUUIDString() {
* changes, implement them and write a log message.
*/
public static @Nonnull UserIdent create(@Nonnull String suuid, @Nullable String playerName) {
if (NONE_MARKER.equals(suuid)) {
if (NONE_MARKER.equals(suuid) || Config.enforceOfflinePlayerUUID) {
return new UserIdent(null, playerName);
}
try {
Expand Down Expand Up @@ -109,8 +112,7 @@ public String getUUIDString() {
*/
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 && (Config.enforceOfflinePlayerUUID || !isOnlineMode())) {
return new UserIdent(null, gameProfile.getName());
} else {
return new UserIdent(gameProfile.getId(), gameProfile.getName());
Expand All @@ -120,6 +122,11 @@ public String getUUIDString() {
}
}

private static boolean isOnlineMode() {
MinecraftServer server = MinecraftServer.getServer();
return server != null ? server.isServerInOnlineMode() : true;
}

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);
Expand Down Expand Up @@ -220,6 +227,9 @@ private Nobody() {

@Override
public boolean equals(Object obj) {
if (obj instanceof UUID) {
return getUUID().equals(obj);
}
return this == obj;
}

Expand Down

0 comments on commit cd72c23

Please sign in to comment.