Compare commits

..
9 Commits
Author SHA1 Message Date
Pilzinsel64 84e23b3e8e add config enforceOfflinePlayerUUID 2023-04-17 17:20:15 +02:00
Pilzinsel64 eba2bf1f86 re-add .github 2023-04-17 14:03:56 +02:00
Pilzinsel64 47bd83e29e remove .github 2023-04-17 14:03:43 +02:00
Pilzinsel64 f7b49fccdd Fix invalid check for offline UUID in UserIdent.create() (#2)
See more: https://github.com/GTNewHorizons/EnderIO/pull/118
2023-04-17 13:34:53 +02:00
miozune 1a14946abb Show travel message above hotbar (#117) 2023-04-10 11:21:39 +02:00
Pilzinsel64 8ca820f71c prevent ghostloading (#115)
* prevent ghostloading by MEConduit

* prevent more ghostloading by MEConduit

* spottlessApply

* prevent ghostloading by ConduitUtil
2023-04-01 15:10:20 +02:00
D-Cysteine 4e40230bf3 Try to fix energy overflow (#114) 2023-03-29 17:25:43 +02:00
Pilzinsel64 76708883c0 needUpdateConnections only while updating cons (#113) 2023-03-23 21:12:11 +01:00
Pilzinsel64 0a1ee81780 Add comments for needUpdateConnections (#112)
* imrpove canConnectToExternal()

* needUpdateConnections

* add comments for needUpdateconnections
2023-03-23 06:46:13 +01:00
11 changed files with 164 additions and 62 deletions

No files matched your search

+43 -28
View File
@@ -1,4 +1,4 @@
//version: 1677938302
//version: 1680120787
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
@@ -65,7 +65,7 @@ plugins {
id 'org.jetbrains.kotlin.jvm' version '1.8.0' apply false
id 'org.jetbrains.kotlin.kapt' version '1.8.0' apply false
id 'com.google.devtools.ksp' version '1.8.0-1.0.9' apply false
id 'org.ajoberstar.grgit' version '4.1.1' // 4.1.1 is the last jvm8 supporting version ,unused, available for addon.gradle
id 'org.ajoberstar.grgit' version '4.1.1' // 4.1.1 is the last jvm8 supporting version, unused, available for addon.gradle
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'com.palantir.git-version' version '0.13.0' apply false // 0.13.0 is the last jvm8 supporting version
id 'de.undercouch.download' version '5.3.0'
@@ -73,7 +73,7 @@ plugins {
id 'com.diffplug.spotless' version '6.7.2' apply false
id 'com.modrinth.minotaur' version '2.+' apply false
id 'com.matthewprenger.cursegradle' version '1.4.0' apply false
id 'com.gtnewhorizons.retrofuturagradle' version '1.2.2'
id 'com.gtnewhorizons.retrofuturagradle' version '1.2.4'
}
boolean settingsupdated = verifySettingsGradle()
settingsupdated = verifyGitAttributes() || settingsupdated
@@ -153,13 +153,21 @@ java {
} else {
languageVersion.set(projectJavaVersion)
}
vendor.set(JvmVendorSpec.ADOPTIUM)
vendor.set(JvmVendorSpec.AZUL)
}
if (!noPublishedSources) {
withSourcesJar()
}
}
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}
tasks.withType(ScalaCompile).configureEach {
options.encoding = "UTF-8"
}
pluginManager.withPlugin('org.jetbrains.kotlin.jvm') {
// If Kotlin is enabled in the project
kotlin {
@@ -222,7 +230,7 @@ if (enableModernJavaSyntax.toBoolean()) {
javaCompiler.set(javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(17))
vendor.set(JvmVendorSpec.ADOPTIUM)
vendor.set(JvmVendorSpec.AZUL)
})
}
}
@@ -397,8 +405,6 @@ minecraft {
extraRunJvmArguments.add("-ea:${modGroup}")
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
extraTweakClasses.add("org.spongepowered.asm.launch.MixinTweaker")
if (usesMixinDebug.toBoolean()) {
extraRunJvmArguments.addAll([
"-Dmixin.debug.countInjections=true",
@@ -513,14 +519,6 @@ repositories {
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
allowInsecureProtocol = true
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
if (usesMixinDebug.toBoolean()) {
maven {
name = "Fabric Maven"
url = "https://maven.fabricmc.net/"
}
}
}
maven {
name 'sonatype'
url 'https://oss.sonatype.org/content/repositories/snapshots/'
@@ -559,29 +557,49 @@ repositories {
}
}
def mixinProviderGroup = "io.github.legacymoddingmc"
def mixinProviderModule = "unimixins"
def mixinProviderVersion = "0.1.6"
def mixinProviderSpecNoClassifer = "${mixinProviderGroup}:${mixinProviderModule}:${mixinProviderVersion}"
def mixinProviderSpec = "${mixinProviderSpecNoClassifer}:dev"
dependencies {
if (usesMixins.toBoolean()) {
annotationProcessor('org.ow2.asm:asm-debug-all:5.0.3')
annotationProcessor('com.google.guava:guava:24.1.1-jre')
annotationProcessor('com.google.code.gson:gson:2.8.6')
annotationProcessor('com.gtnewhorizon:gtnhmixins:2.1.13:processor')
annotationProcessor(mixinProviderSpec)
if (usesMixinDebug.toBoolean()) {
runtimeOnlyNonPublishable('org.jetbrains:intellij-fernflower:1.2.1.16')
}
}
if (usesMixins.toBoolean() || forceEnableMixins.toBoolean()) {
implementation('com.gtnewhorizon:gtnhmixins:2.1.13')
if (usesMixins.toBoolean()) {
implementation(mixinProviderSpec)
} else if (forceEnableMixins.toBoolean()) {
runtimeOnlyNonPublishable(mixinProviderSpec)
}
}
pluginManager.withPlugin('org.jetbrains.kotlin.kapt') {
if (usesMixins.toBoolean()) {
dependencies {
kapt('com.gtnewhorizon:gtnhmixins:2.1.13:processor')
kapt(mixinProviderSpec)
}
}
}
// Replace old mixin mods with unimixins
// https://docs.gradle.org/8.0.2/userguide/resolution_rules.html#sec:substitution_with_classifier
configurations.all {
resolutionStrategy.dependencySubstitution {
substitute module('com.gtnewhorizon:gtnhmixins') using module(mixinProviderSpecNoClassifer) withClassifier("dev") because("Unimixins replaces other mixin mods")
substitute module('com.github.GTNewHorizons:Mixingasm') using module(mixinProviderSpecNoClassifer) withClassifier("dev") because("Unimixins replaces other mixin mods")
substitute module('com.github.GTNewHorizons:SpongePoweredMixin') using module(mixinProviderSpecNoClassifer) withClassifier("dev") because("Unimixins replaces other mixin mods")
substitute module('com.github.GTNewHorizons:SpongeMixins') using module(mixinProviderSpecNoClassifer) withClassifier("dev") because("Unimixins replaces other mixin mods")
substitute module('io.github.legacymoddingmc:unimixins') using module(mixinProviderSpecNoClassifer) withClassifier("dev") because("Our previous unimixins upload was missing the dev classifier")
}
}
apply from: 'dependencies.gradle'
def mixingConfigRefMap = 'mixins.' + modId + '.refmap.json'
@@ -695,13 +713,13 @@ ext.java17PatchDependenciesCfg = configurations.create("java17PatchDependencies"
}
dependencies {
def lwjgl3ifyVersion = '1.1.35'
def lwjgl3ifyVersion = '1.3.3'
def asmVersion = '9.4'
if (modId != 'lwjgl3ify') {
java17Dependencies("com.github.GTNewHorizons:lwjgl3ify:${lwjgl3ifyVersion}")
}
if (modId != 'hodgepodge') {
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.0.40')
java17Dependencies('com.github.GTNewHorizons:Hodgepodge:2.2.4')
}
java17PatchDependencies('net.minecraft:launchwrapper:1.15') {transitive = false}
@@ -793,10 +811,6 @@ public abstract class RunHotswappableMinecraftTask extends RunMinecraftTask {
!file.path.contains("2.9.4-nightly-20150209") // Remove lwjgl2
}
this.classpath(project.java17DependenciesCfg)
if (!(project.usesMixins.toBoolean() || project.forceEnableMixins.toBoolean())) {
this.extraArgs.addAll("--tweakClass", "org.spongepowered.asm.launch.MixinTweaker")
}
}
}
@@ -1006,6 +1020,7 @@ idea {
}
compiler.javac {
afterEvaluate {
javacAdditionalOptions = "-encoding utf8"
moduleJavacAdditionalOptions = [
(project.name + ".main"): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ')
]
@@ -1125,7 +1140,7 @@ if (modrinthProjectId.size() != 0 && System.getenv("MODRINTH_TOKEN") != null) {
}
}
if (usesMixins.toBoolean()) {
addModrinthDep("required", "project", "gtnhmixins")
addModrinthDep("required", "project", "unimixins")
}
tasks.modrinth.dependsOn(build)
tasks.publish.dependsOn(tasks.modrinth)
@@ -1169,7 +1184,7 @@ if (curseForgeProjectId.size() != 0 && System.getenv("CURSEFORGE_TOKEN") != null
}
}
if (usesMixins.toBoolean()) {
addCurseForgeRelation("requiredDependency", "gtnhmixins")
addCurseForgeRelation("requiredDependency", "unimixins")
}
tasks.curseforge.dependsOn(build)
tasks.publish.dependsOn(tasks.curseforge)
@@ -1204,7 +1219,7 @@ def addCurseForgeRelation(String type, String name) {
// Updating
def buildscriptGradleVersion = "8.0.1"
def buildscriptGradleVersion = "8.0.2"
tasks.named('wrapper', Wrapper).configure {
gradleVersion = buildscriptGradleVersion
+1
View File
@@ -4,6 +4,7 @@ dependencies {
api('com.github.GTNewHorizons:EnderCore:0.2.13:dev')
implementation('com.github.GTNewHorizons:ForestryMC:4.5.8:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.3.35-GTNH:dev')
implementation("com.github.GTNewHorizons:GTNHLib:0.0.13:dev")
api('com.github.GTNewHorizons:BuildCraft:7.1.27:dev')
api('curse.maven:cofh-lib-220333:2388748') // https://www.curseforge.com/minecraft/mc-mods/cofh-lib/files/2388748
shadowImplementation('cglib:cglib-nodep:3.3.0')
@@ -84,7 +84,17 @@ public abstract class AbstractConduit implements IConduit {
protected boolean connectionsDirty = true;
protected boolean needUpdateConnections = false;
/**
* This shows if the currently running connection update should not finish with settings connectionsDirty to false.
* If this is true, it will trigger a reconnection on the next Tick.
* <p>
* Use the method needUpdateConnections() instead of setting this to true.
*
* @see needUpdateConnections()
*/
private boolean needUpdateConnections = false;
private boolean isUpdatingConnections = false;
protected AbstractConduit() {}
@@ -436,10 +446,13 @@ public abstract class AbstractConduit implements IConduit {
}
private void updateConnections() {
if (!connectionsDirty) {
if (!connectionsDirty && !needUpdateConnections) {
return;
}
isUpdatingConnections = true;
needUpdateConnections = false;
boolean externalConnectionsChanged = false;
List<ForgeDirection> copy = new ArrayList<ForgeDirection>(externalConnections);
// remove any no longer valid connections
@@ -463,15 +476,22 @@ public abstract class AbstractConduit implements IConduit {
connectionsChanged();
}
if (needUpdateConnections) {
needUpdateConnections = false;
} else {
connectionsDirty = false;
}
connectionsDirty = false;
isUpdatingConnections = false;
}
/**
* This method prevents connection update from getting completed successfully by not settings connectionsDirty to
* false. This will trigger an connection update at the next Tick.
* <p>
* Only use this while executing updateConnections().
* <p>
* See this PR for more info: https://github.com/GTNewHorizons/EnderIO/pull/111
*/
protected void needUpdateConnections() {
needUpdateConnections = true;
if (isUpdatingConnections) {
needUpdateConnections = true;
}
}
@Override
@@ -248,7 +248,7 @@ public class ConduitUtil {
public static <T extends IConduit> Collection<T> getConnectedConduits(World world, int x, int y, int z,
Class<T> type) {
TileEntity te = world.getTileEntity(x, y, z);
TileEntity te = world.blockExists(x, y, z) ? world.getTileEntity(x, y, z) : null;
if (!(te instanceof IConduitBundle)) {
return Collections.emptyList();
}
@@ -155,7 +155,16 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
public boolean canConnectToExternal(ForgeDirection dir, boolean ignoreDisabled) {
World world = getBundle().getWorld();
BlockCoord pos = getLocation();
TileEntity te = world.getTileEntity(pos.x + dir.offsetX, pos.y + dir.offsetY, pos.z + dir.offsetZ);
final int exactPosX = pos.x + dir.offsetX;
final int exactPosY = pos.y + dir.offsetY;
final int exactPosZ = pos.z + dir.offsetZ;
if (!world.blockExists(exactPosX, exactPosY, exactPosZ)) {
return false;
}
TileEntity te = world.getTileEntity(exactPosX, exactPosY, exactPosZ);
if (te instanceof TileConduitBundle) {
return false;
@@ -175,6 +184,7 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
node = part.getGridNode();
}
if (node == null) {
// The GridNode has not been initialized yet, let's try on the next Tick.
needUpdateConnections();
}
}
@@ -304,7 +314,11 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
private void onNodeChanged(BlockCoord location) {
World world = getBundle().getWorld();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = location.getLocation(dir).getTileEntity(world);
BlockCoord dirLocation = location.getLocation(dir);
TileEntity te = null;
if (world.blockExists(dirLocation.x, dirLocation.y, dirLocation.z)) {
te = location.getLocation(dir).getTileEntity(world);
}
if (te != null && te instanceof IGridHost && !(te instanceof IConduitBundle)) {
IGridNode node = ((IGridHost) te).getGridNode(ForgeDirection.UNKNOWN);
if (node == null) {
@@ -320,7 +334,12 @@ public class MEConduit extends AbstractConduit implements IMEConduit {
@Override
public void onAddedToBundle() {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = getLocation().getLocation(dir).getTileEntity(getBundle().getWorld());
World world = getBundle().getWorld();
BlockCoord dirLocation = getLocation().getLocation(dir);
TileEntity te = null;
if (world.blockExists(dirLocation.x, dirLocation.y, dirLocation.z)) {
te = dirLocation.getTileEntity(world);
}
if (te instanceof TileConduitBundle) {
IMEConduit cond = ((TileConduitBundle) te).getConduit(IMEConduit.class);
if (cond != null) {
@@ -84,6 +84,8 @@ public final class Config {
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;
@@ -1023,6 +1025,13 @@ public final class 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",
@@ -131,6 +131,10 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (maxReceive < 0) {
return 0;
}
int res = super.receiveEnergy(container, maxReceive, simulate);
if (res != 0 && !simulate) {
updateDamage(container);
@@ -148,6 +152,10 @@ public class ItemMagnet extends ItemEnergyContainer implements IResourceTooltipP
}
public int extractEnergyInternal(ItemStack container, int maxExtract, boolean simulate) {
if (maxExtract < 0) {
return 0;
}
int res = super.extractEnergy(container, maxExtract, simulate);
if (res != 0 && !simulate) {
updateDamage(container);
@@ -67,6 +67,12 @@ public class ItemTeleportStaff extends ItemTravelStaff {
return equipped;
}
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
// Don't allow receiving energy, since we have infinite energy.
return 0;
}
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
// Don't allow extracting energy.
@@ -103,6 +103,10 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
@Override
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
if (maxReceive < 0) {
return 0;
}
int res = super.receiveEnergy(container, maxReceive, simulate);
if (res != 0 && !simulate) {
updateDamage(container);
@@ -112,6 +116,10 @@ public class ItemTravelStaff extends ItemEnergyContainer implements IItemOfTrave
@Override
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
if (maxExtract < 0) {
return 0;
}
int res = super.extractEnergy(container, maxExtract, simulate);
if (res != 0 && !simulate) {
updateDamage(container);
@@ -17,12 +17,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovementInput;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
@@ -37,7 +32,9 @@ import com.enderio.core.common.vecmath.Vector2d;
import com.enderio.core.common.vecmath.Vector3d;
import com.google.common.collect.MultimapBuilder;
import com.google.common.collect.SetMultimap;
import com.gtnewhorizon.gtnhlib.GTNHLib;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
@@ -338,7 +335,7 @@ public class TravelController {
}
if (displayOutOfRangeMessage && distanceMap.isEmpty()) {
player.addChatComponentMessage(new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return distanceMap.values().stream().findFirst();
@@ -532,7 +529,7 @@ public class TravelController {
TravelController.instance.selectedCoord.z);
}
} else {
player.addChatComponentMessage(new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
}
}
@@ -578,8 +575,7 @@ public class TravelController {
if (te instanceof ITravelAccessable) {
ITravelAccessable ta = (ITravelAccessable) te;
if (!ta.canBlockBeAccessed(player)) {
player.addChatComponentMessage(
new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.unauthorised"));
return false;
}
}
@@ -593,14 +589,13 @@ public class TravelController {
if (!isInRangeTarget(player, coord, source.getMaxDistanceTravelledSq())) {
if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
player.addChatComponentMessage(new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.outOfRange"));
}
return false;
}
if (!isValidTarget(player, coord, source)) {
if (source != TravelSource.STAFF_BLINK && source != TravelSource.TELEPORT_STAFF_BLINK) {
player.addChatComponentMessage(
new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
showMessage(player, new ChatComponentTranslation("enderio.blockTravelPlatform.invalidTarget"));
}
return false;
}
@@ -630,7 +625,7 @@ public class TravelController {
if (requiredPower > canUsePower) {
// make sure chat is sent only once per trial
if (!insufficientPower) {
player.addChatComponentMessage(new ChatComponentTranslation("enderio.itemTravelStaff.notEnoughPower"));
showMessage(player, new ChatComponentTranslation("enderio.itemTravelStaff.notEnoughPower"));
insufficientPower = true;
}
return -1;
@@ -745,17 +740,16 @@ public class TravelController {
if (Config.travelAnchorSkipWarning) {
if (travelBlock.getRequiresPassword(player)) {
player.addChatComponentMessage(
new ChatComponentTranslation("enderio.gui.travelAccessable.skipLocked"));
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.skipLocked"));
}
if (travelBlock.getAccessMode() == ITravelAccessable.AccessMode.PRIVATE
&& !travelBlock.canUiBeAccessed(player)) {
player.addChatComponentMessage(
new ChatComponentTranslation("enderio.gui.travelAccessable.skipPrivate"));
showMessage(player, new ChatComponentTranslation("enderio.gui.travelAccessable.skipPrivate"));
}
if (!isValidTarget(player, targetBlock, TravelSource.BLOCK)) {
player.addChatComponentMessage(
showMessage(
player,
new ChatComponentTranslation("enderio.gui.travelAccessable.skipObstructed"));
}
}
@@ -944,4 +938,16 @@ public class TravelController {
}
return null;
}
private static void showMessage(EntityPlayer player, IChatComponent chatComponent) {
if (Loader.isModLoaded("gtnhlib")) {
GTNHLib.proxy.printMessageAboveHotbar(
EnumChatFormatting.WHITE + chatComponent.getFormattedText(),
60,
true,
true);
} else {
player.addChatComponentMessage(chatComponent);
}
}
}
+13 -3
View File
@@ -6,12 +6,15 @@ 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;
import com.google.common.base.Charsets;
import com.mojang.authlib.GameProfile;
import crazypants.enderio.Log;
import crazypants.enderio.config.Config;
public class UserIdent {
@@ -75,7 +78,7 @@ public class UserIdent {
* 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 {
@@ -109,8 +112,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 && (Config.enforceOfflinePlayerUUID || !isOnlineMode())) {
return new UserIdent(null, gameProfile.getName());
} else {
return new UserIdent(gameProfile.getId(), gameProfile.getName());
@@ -120,6 +122,11 @@ public class UserIdent {
}
}
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);
@@ -220,6 +227,9 @@ public class UserIdent {
@Override
public boolean equals(Object obj) {
if (obj instanceof UUID) {
return getUUID().equals(obj);
}
return this == obj;
}