diff --git a/src/main/java/forestry/core/gui/ContainerForestry.java b/src/main/java/forestry/core/gui/ContainerForestry.java index c04379acb..7b0706a95 100755 --- a/src/main/java/forestry/core/gui/ContainerForestry.java +++ b/src/main/java/forestry/core/gui/ContainerForestry.java @@ -10,6 +10,11 @@ ******************************************************************************/ package forestry.core.gui; +import forestry.core.gadgets.TileForestry; +import forestry.core.gui.slots.SlotForestry; +import forestry.core.utils.EnumAccess; +import forestry.core.utils.PlayerUtil; +import forestry.core.utils.StackUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; @@ -17,11 +22,6 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import forestry.core.gadgets.TileForestry; -import forestry.core.gui.slots.SlotForestry; -import forestry.core.utils.EnumAccess; -import forestry.core.utils.StackUtils; - public class ContainerForestry extends Container { protected IInventory inventory; @@ -44,9 +44,13 @@ public class ContainerForestry extends Container { @Override public ItemStack slotClick(int slotIndex, int button, int modifier, EntityPlayer player) { - if (inventoryForestry != null && (inventoryForestry.getAccess() != EnumAccess.SHARED) && !inventoryForestry.owner.equals(player.getGameProfile())) + if (player == null) return null; + if ((inventoryForestry != null) && (inventoryForestry.getAccess() != EnumAccess.SHARED)) + if ((inventoryForestry.owner != null) && !PlayerUtil.isSameGameProfile(inventoryForestry.owner, player.getGameProfile())) + return null; + Slot slot = slotIndex < 0 ? null : (Slot) this.inventorySlots.get(slotIndex); if (slot instanceof SlotForestry) { ((SlotForestry) slot).onSlotClick(slotIndex, button, modifier, player); diff --git a/src/main/java/forestry/core/utils/PlayerUtil.java b/src/main/java/forestry/core/utils/PlayerUtil.java new file mode 100644 index 000000000..e728d1233 --- /dev/null +++ b/src/main/java/forestry/core/utils/PlayerUtil.java @@ -0,0 +1,21 @@ +package forestry.core.utils; + +import com.mojang.authlib.GameProfile; + +import java.util.UUID; + +public class PlayerUtil { + + public static boolean isSameGameProfile(GameProfile player1, GameProfile player2) { + if (player1 == null || player2 == null) + return false; + + UUID id1 = player1.getId(); + UUID id2 = player2.getId(); + if (id1 != null && id2 != null) + return id1.equals(id2); + + return player1.getName() != null && player1.getName().equals(player2.getName()); + } + +}