Fix player UUID lookup server issue (#380)
This commit is contained in:
@@ -54,6 +54,7 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumHand;
|
||||
@@ -82,6 +83,7 @@ import java.util.ArrayList;
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
import static appeng.client.KeyBindings.WCT;
|
||||
import static appeng.client.KeyBindings.WFT;
|
||||
@@ -372,4 +374,16 @@ public class ClientHelper extends ServerHelper {
|
||||
public boolean isActionKey(ActionKey key, int pressedKeyCode) {
|
||||
return this.bindings.get(key).isActiveAndMatches(pressedKeyCode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getPlayerByUUID(UUID uuid) {
|
||||
if (Platform.isClient()) {
|
||||
if (Minecraft.getMinecraft().player.getUniqueID().equals(uuid)) {
|
||||
return Minecraft.getMinecraft().player;
|
||||
}
|
||||
return null;
|
||||
} else {
|
||||
return super.getPlayerByUUID(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import appeng.client.ActionKey;
|
||||
import appeng.client.EffectType;
|
||||
import appeng.core.sync.AppEngPacket;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.RayTraceResult;
|
||||
import net.minecraft.world.World;
|
||||
@@ -32,6 +33,7 @@ import net.minecraft.world.World;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public abstract class CommonHelper {
|
||||
@@ -66,4 +68,5 @@ public abstract class CommonHelper {
|
||||
|
||||
public abstract boolean isActionKey(@Nonnull final ActionKey key, int pressedKeyCode);
|
||||
|
||||
public abstract EntityPlayer getPlayerByUUID(UUID uuid);
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package appeng.helpers;
|
||||
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.fml.server.FMLServerHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerHelper {
|
||||
@Nullable
|
||||
public static EntityPlayerMP getPlayerByUUID(UUID uuid) {
|
||||
final MinecraftServer server;
|
||||
if (Platform.isClientInstall()) {
|
||||
server = Minecraft.getMinecraft().getIntegratedServer();
|
||||
} else {
|
||||
server = FMLServerHandler.instance().getServer();
|
||||
}
|
||||
|
||||
if (server == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return server.getPlayerList().getPlayerByUUID(uuid);
|
||||
}
|
||||
}
|
||||
@@ -41,12 +41,12 @@ import appeng.api.util.WorldCoord;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.features.AEFeature;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketCraftingToast;
|
||||
import appeng.crafting.*;
|
||||
import appeng.helpers.PatternHelper;
|
||||
import appeng.helpers.PlayerHelper;
|
||||
import appeng.me.cache.CraftingGridCache;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
import appeng.me.helpers.MachineSource;
|
||||
@@ -57,6 +57,7 @@ import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -395,10 +396,10 @@ public final class CraftingCPUCluster implements IAECluster, ICraftingCPU {
|
||||
if (this.finalOutput == null) return;
|
||||
if (!AEConfig.instance().isFeatureEnabled(AEFeature.CRAFTING_TOASTS)) return;
|
||||
|
||||
var player = PlayerHelper.getPlayerByUUID(this.requestingPlayerUUID);
|
||||
if (player != null) {
|
||||
var player = AppEng.proxy.getPlayerByUUID(this.requestingPlayerUUID);
|
||||
if (player instanceof EntityPlayerMP playerMP) {
|
||||
try {
|
||||
NetworkHandler.instance().sendTo(new PacketCraftingToast(this.finalOutput, cancelled), player);
|
||||
NetworkHandler.instance().sendTo(new PacketCraftingToast(this.finalOutput, cancelled), playerMP);
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
public class ServerHelper extends CommonHelper {
|
||||
@@ -167,4 +168,17 @@ public class ServerHelper extends CommonHelper {
|
||||
public boolean isActionKey(ActionKey key, int pressedKeyCode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getPlayerByUUID(UUID uuid) {
|
||||
if (!Platform.isClient()) {
|
||||
final MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
|
||||
if (server != null) {
|
||||
return server.getPlayerList().getPlayerByUUID(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user