diff --git a/src/main/java/forestry/core/proxy/ProxyCommon.java b/src/main/java/forestry/core/proxy/ProxyCommon.java index 4fecd8093..9bfe96d34 100755 --- a/src/main/java/forestry/core/proxy/ProxyCommon.java +++ b/src/main/java/forestry/core/proxy/ProxyCommon.java @@ -113,25 +113,4 @@ public class ProxyCommon { return null; } - /** - * 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) { - if (world == null) { - throw new IllegalArgumentException("World cannot be null"); - } - - if (profile == null || profile.getName() == null) { - return FakePlayerFactory.getMinecraft((WorldServer) world); - } - - EntityPlayer player = world.getPlayerEntityByName(profile.getName()); - if (player != null) { - return player; - } else { - return FakePlayerFactory.get((WorldServer) world, profile); - } - } } diff --git a/src/main/java/forestry/core/proxy/ProxyCommonClient.java b/src/main/java/forestry/core/proxy/ProxyCommonClient.java index 7561da44a..f1368677d 100644 --- a/src/main/java/forestry/core/proxy/ProxyCommonClient.java +++ b/src/main/java/forestry/core/proxy/ProxyCommonClient.java @@ -133,9 +133,4 @@ public class ProxyCommonClient extends ProxyCommon { public EntityPlayer getPlayer() { return Minecraft.getMinecraft().thePlayer; } - - @Override - public EntityPlayer getPlayer(World world, GameProfile profile) { - return super.getPlayer(world, profile); - } } diff --git a/src/main/java/forestry/core/utils/PlayerUtil.java b/src/main/java/forestry/core/utils/PlayerUtil.java index e191030a6..e4cfe5a16 100644 --- a/src/main/java/forestry/core/utils/PlayerUtil.java +++ b/src/main/java/forestry/core/utils/PlayerUtil.java @@ -14,9 +14,13 @@ import java.util.UUID; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import com.mojang.authlib.GameProfile; +import net.minecraftforge.common.util.FakePlayerFactory; + import forestry.core.access.IOwnable; import buildcraft.api.tools.IToolWrench; @@ -77,4 +81,29 @@ public abstract class PlayerUtil { IToolWrench wrench = (IToolWrench) itemstack.getItem(); wrench.wrenchUsed(player, x, y, z); } + + /** + * 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 static EntityPlayer getPlayer(World world, GameProfile profile) { + if (world == null) { + throw new IllegalArgumentException("World cannot be null"); + } + + if (profile == null || profile.getName() == null) { + if (world instanceof WorldServer) { + return FakePlayerFactory.getMinecraft((WorldServer) world); + } else { + return null; + } + } + + EntityPlayer player = world.getPlayerEntityByName(profile.getName()); + if (player == null && world instanceof WorldServer) { + player = FakePlayerFactory.get((WorldServer) world, profile); + } + return player; + } } diff --git a/src/main/java/forestry/factory/tiles/TileCarpenter.java b/src/main/java/forestry/factory/tiles/TileCarpenter.java index 575492514..a5b4ad995 100644 --- a/src/main/java/forestry/factory/tiles/TileCarpenter.java +++ b/src/main/java/forestry/factory/tiles/TileCarpenter.java @@ -41,13 +41,13 @@ import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; import forestry.core.render.TankRenderInfo; import forestry.core.tiles.IItemStackDisplay; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.PlayerUtil; import forestry.core.utils.SlotUtil; import forestry.factory.recipes.CarpenterRecipeManager; @@ -298,7 +298,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu } private boolean removeSets(int count, ItemStack[] set) { - EntityPlayer player = Proxies.common.getPlayer(worldObj, getAccessHandler().getOwner()); + EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner()); return InventoryUtil.removeSets(getInternalInventory(), count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true); } diff --git a/src/main/java/forestry/factory/tiles/TileSqueezer.java b/src/main/java/forestry/factory/tiles/TileSqueezer.java index 1a80df140..18a07e6a6 100644 --- a/src/main/java/forestry/factory/tiles/TileSqueezer.java +++ b/src/main/java/forestry/factory/tiles/TileSqueezer.java @@ -44,12 +44,12 @@ import forestry.core.inventory.TileInventoryAdapter; import forestry.core.network.DataInputStreamForestry; import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.GuiId; -import forestry.core.proxy.Proxies; import forestry.core.render.TankRenderInfo; import forestry.core.tiles.ILiquidTankTile; import forestry.core.tiles.TilePowered; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.PlayerUtil; import forestry.factory.recipes.SqueezerRecipeManager; public class TileSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankTile, ISpeedUpgradable { @@ -140,7 +140,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve @Override public boolean workCycle() { - EntityPlayer player = Proxies.common.getPlayer(worldObj, getAccessHandler().getOwner()); + EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner()); if (!inventory.removeResources(currentRecipe.getResources(), player)) { return false; } diff --git a/src/main/java/forestry/farming/multiblock/FarmController.java b/src/main/java/forestry/farming/multiblock/FarmController.java index fba969c4b..2f04bc98b 100644 --- a/src/main/java/forestry/farming/multiblock/FarmController.java +++ b/src/main/java/forestry/farming/multiblock/FarmController.java @@ -68,6 +68,7 @@ import forestry.core.network.DataOutputStreamForestry; import forestry.core.network.PacketGuiUpdate; import forestry.core.proxy.Proxies; import forestry.core.utils.Log; +import forestry.core.utils.PlayerUtil; import forestry.core.utils.vect.Vect; import forestry.core.utils.vect.VectUtil; import forestry.farming.FarmHelper; @@ -803,7 +804,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen @Override public boolean plantGermling(IFarmable germling, World world, int x, int y, int z) { - EntityPlayer player = Proxies.common.getPlayer(world, getAccessHandler().getOwner()); + EntityPlayer player = PlayerUtil.getPlayer(world, getAccessHandler().getOwner()); return inventory.plantGermling(germling, player, x, y, z); } diff --git a/src/main/java/forestry/farming/multiblock/FarmInventory.java b/src/main/java/forestry/farming/multiblock/FarmInventory.java index 6ea880ad2..63efd6b97 100644 --- a/src/main/java/forestry/farming/multiblock/FarmInventory.java +++ b/src/main/java/forestry/farming/multiblock/FarmInventory.java @@ -26,9 +26,9 @@ import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.inventory.InventoryAdapterRestricted; import forestry.core.inventory.wrappers.InventoryMapper; -import forestry.core.proxy.Proxies; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; +import forestry.core.utils.PlayerUtil; import forestry.core.utils.SlotUtil; import forestry.plugins.PluginFarming; @@ -91,7 +91,7 @@ public class FarmInventory extends InventoryAdapterRestricted implements IFarmIn @Override public void removeResources(ItemStack[] resources) { - EntityPlayer player = Proxies.common.getPlayer(farmController.getWorld(), farmController.getAccessHandler().getOwner()); + EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorld(), farmController.getAccessHandler().getOwner()); InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true); } diff --git a/src/main/java/forestry/mail/PostRegistry.java b/src/main/java/forestry/mail/PostRegistry.java index f17350ea9..3db5f6a5f 100755 --- a/src/main/java/forestry/mail/PostRegistry.java +++ b/src/main/java/forestry/mail/PostRegistry.java @@ -32,6 +32,7 @@ import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; import forestry.core.config.ForestryItem; import forestry.core.proxy.Proxies; +import forestry.core.utils.PlayerUtil; import forestry.mail.items.ItemLetter; import forestry.mail.network.PacketPOBoxInfoResponse; @@ -73,7 +74,7 @@ public class PostRegistry implements IPostRegistry { pobox.markDirty(); cachedPOBoxes.put(address, pobox); - EntityPlayer player = Proxies.common.getPlayer(world, address.getPlayerProfile()); + EntityPlayer player = PlayerUtil.getPlayer(world, address.getPlayerProfile()); if (player != null) { Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), player); } diff --git a/src/main/java/forestry/mail/PostalCarrier.java b/src/main/java/forestry/mail/PostalCarrier.java index 6c21412d2..923f4e4d3 100755 --- a/src/main/java/forestry/mail/PostalCarrier.java +++ b/src/main/java/forestry/mail/PostalCarrier.java @@ -28,6 +28,7 @@ import forestry.api.mail.ITradeStation; import forestry.api.mail.PostManager; import forestry.core.proxy.Proxies; import forestry.core.render.TextureManager; +import forestry.core.utils.PlayerUtil; import forestry.core.utils.StringUtil; import forestry.mail.network.PacketPOBoxInfoResponse; @@ -85,7 +86,7 @@ public class PostalCarrier implements IPostalCarrier { if (!pobox.storeLetter(letterStack.copy())) { return EnumDeliveryState.MAILBOX_FULL; } else { - EntityPlayer player = Proxies.common.getPlayer(world, recipient.getPlayerProfile()); + EntityPlayer player = PlayerUtil.getPlayer(world, recipient.getPlayerProfile()); if (player instanceof EntityPlayerMP) { Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), (EntityPlayerMP) player); }