mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Created Server-safe method to get EntityPlayer from GameProfile
This commit is contained in:
1 parent
c51e01987c
commit
fe8d55f38f
9 files changed
+34
-15
No files matched your search
@@ -12,6 +12,8 @@ package forestry.core.proxy;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
@@ -90,6 +92,11 @@ public class ClientProxyCommon extends ProxyCommon {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityPlayer getPlayer(World world, GameProfile profile) {
|
||||
return world.getPlayerEntityByName(profile.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockReachDistance(EntityPlayer entityplayer) {
|
||||
if (entityplayer instanceof EntityPlayerSP)
|
||||
|
||||
@@ -12,6 +12,8 @@ package forestry.core.proxy;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.resources.IResourceManager;
|
||||
@@ -37,6 +39,8 @@ import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import cpw.mods.fml.common.versioning.VersionParser;
|
||||
import cpw.mods.fml.common.versioning.VersionRange;
|
||||
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.FakePlayerFactory;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
|
||||
@@ -153,6 +157,19 @@ public class ProxyCommon {
|
||||
return server.getConfigurationManager().func_152596_g(player.getGameProfile());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player for a given World and GameProfile.
|
||||
* If they are not in the World, returns a FakePlayer.
|
||||
* Do not store references to the return value, to prevent worlds staying in memory.
|
||||
*/
|
||||
public EntityPlayer getPlayer(World world, GameProfile profile) {
|
||||
EntityPlayer player = world.getPlayerEntityByName(profile.getName());
|
||||
if (player != null)
|
||||
return player;
|
||||
else
|
||||
return FakePlayerFactory.get((WorldServer)world, profile);
|
||||
}
|
||||
|
||||
public double getBlockReachDistance(EntityPlayer entityplayer) {
|
||||
return 4f;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
@@ -456,7 +456,7 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
}
|
||||
|
||||
private boolean removeSets(int count, ItemStack[] set) {
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, owner);
|
||||
return accessibleInventory.removeSets(count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.interfaces.ICraftingPlan;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
@@ -505,7 +506,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
|
||||
ItemStack taken;
|
||||
if (doRemove) {
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, owner);
|
||||
taken = this.takenFromSlot(SLOT_RESULT, false, player);
|
||||
} else {
|
||||
taken = this.getResult();
|
||||
|
||||
@@ -49,6 +49,7 @@ import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
@@ -351,7 +352,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
}
|
||||
|
||||
private boolean removeResources(ItemStack[] stacks) {
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, owner);
|
||||
return inventory.removeSets(1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -763,7 +763,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
EntityPlayer player = worldObj.getPlayerEntityByName(owner.getName());
|
||||
EntityPlayer player = Proxies.common.getPlayer(worldObj, owner);
|
||||
inventory.removeSets(1, resources, SLOT_RESOURCES_1, SLOT_RESOURCES_1, player, false, true, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -143,18 +143,11 @@ public class MailAddress implements INBTTagable, IMailAddress {
|
||||
return address;
|
||||
}
|
||||
|
||||
public EntityPlayer getPlayer(World world) {
|
||||
if (!this.isPlayer())
|
||||
return null;
|
||||
|
||||
return world.getPlayerEntityByName(this.gameProfile.getName());
|
||||
}
|
||||
|
||||
public boolean isClientPlayer(World world) {
|
||||
if (!this.isPlayer())
|
||||
return false;
|
||||
|
||||
EntityPlayer addressPlayer = this.getPlayer(world);
|
||||
EntityPlayer addressPlayer = Proxies.common.getPlayer(world, gameProfile);
|
||||
EntityPlayer clientPlayer = Proxies.common.getPlayer();
|
||||
|
||||
return addressPlayer != null && clientPlayer != null && clientPlayer.equals(addressPlayer);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ProxyMail {
|
||||
}
|
||||
|
||||
public void setPOBoxInfo(World world, IMailAddress address, POBoxInfo info) {
|
||||
EntityPlayer player = address.getPlayer(world);
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, address.getPlayerProfile());
|
||||
if (player != null)
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user