Fix-up of the Mail system

Fixed several crashes and bugs. Tested by sending mail and trading with multiple real accounts and a server.
closes #176
This commit is contained in:
mezz committed 2014-09-10 03:55:32 -07:00
1 parent 07afdf63b1
commit 36da6efa91
27 files changed
+470 -258

No files matched your search

@@ -12,6 +12,7 @@ package forestry.mail.gadgets;
import java.util.LinkedList;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
@@ -26,8 +27,8 @@ import forestry.api.core.ForestryAPI;
import forestry.api.core.ISpecialInventory;
import forestry.api.mail.ILetter;
import forestry.api.mail.IPostalState;
import forestry.api.mail.MailAddress;
import forestry.api.mail.PostManager;
import forestry.api.mail.IMailAddress;
import forestry.core.config.Config;
import forestry.core.gadgets.TileBase;
@@ -86,17 +87,21 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
/* MAIL HANDLING */
public IInventory getOrCreateMailInventory() {
return getOrCreateMailInventory(null);
}
public IInventory getOrCreateMailInventory(EntityPlayer player) {
// Handle client side
if (!Proxies.common.isSimulating(worldObj))
GameProfile playerProfile;
if (player != null) {
playerProfile = player.getGameProfile();
} else {
playerProfile = getOwnerProfile();
}
if (playerProfile == null)
return new InventoryAdapter(POBox.SLOT_SIZE, "Letters");
EntityPlayer player = Proxies.common.getPlayer();
if (player == null || player.getGameProfile() == null)
return new InventoryAdapter(POBox.SLOT_SIZE, "Letters");
MailAddress address = new MailAddress(player.getGameProfile());
IMailAddress address = PostManager.postRegistry.getMailAddress(playerProfile);
return PostRegistry.getOrCreatePOBox(worldObj, address);
}