From ce35722e1b39a85832334351d720139bf352b0fc Mon Sep 17 00:00:00 2001 From: SandGrainOne Date: Sun, 10 Aug 2014 15:23:08 +0200 Subject: [PATCH 1/2] GameProfile fixes for Letter Fixes #61, also fixes #45 --- api | 2 +- forestry_common/mail/forestry/mail/Letter.java | 2 +- .../mail/forestry/mail/gui/ContainerLetter.java | 17 +++++++++++++++-- .../mail/forestry/mail/gui/GuiLetter.java | 9 ++++++++- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/api b/api index b061b02c7..87b3cd16c 160000 --- a/api +++ b/api @@ -1 +1 @@ -Subproject commit b061b02c79453b9a45a8da30cdadbf447d7f65e4 +Subproject commit 87b3cd16caccfb9a0f9f1d793d93b69ef6c1ec95 diff --git a/forestry_common/mail/forestry/mail/Letter.java b/forestry_common/mail/forestry/mail/Letter.java index 81db7b6e0..f4390beef 100755 --- a/forestry_common/mail/forestry/mail/Letter.java +++ b/forestry_common/mail/forestry/mail/Letter.java @@ -252,7 +252,7 @@ public class Letter implements ILetter, INBTTagable { @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void addTooltip(List list) { - if (this.sender != null) + if (this.sender != null && this.sender.getProfile() != null) list.add(StringUtil.localize("gui.mail.from") + ": " + this.sender.getProfile().getName()); if (this.recipient != null && this.recipient.length > 0) list.add(StringUtil.localize("gui.mail.to") + ": " + this.getRecipientString()); diff --git a/forestry_common/mail/forestry/mail/gui/ContainerLetter.java b/forestry_common/mail/forestry/mail/gui/ContainerLetter.java index b8c741d47..75f0827c4 100755 --- a/forestry_common/mail/forestry/mail/gui/ContainerLetter.java +++ b/forestry_common/mail/forestry/mail/gui/ContainerLetter.java @@ -13,11 +13,12 @@ package forestry.mail.gui; import java.util.Iterator; import java.util.Locale; +import com.mojang.authlib.GameProfile; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; import net.minecraft.world.World; - import forestry.api.mail.ILetter; import forestry.api.mail.IPostalCarrier; import forestry.api.mail.ITradeStation; @@ -134,6 +135,9 @@ public class ContainerLetter extends ContainerItemInventory { } public void setRecipient(MailAddress address) { + if (address == null) + return; + getLetter().setRecipient(address); carrier = address.getType(); @@ -147,10 +151,19 @@ public class ContainerLetter extends ContainerItemInventory { } public void handleSetRecipient(EntityPlayer player, PacketUpdate packet) { - MailAddress recipient = new MailAddress(MinecraftServer.getServer().func_152358_ax().func_152655_a(packet.payload.stringPayload[1])); + String identifier = packet.payload.stringPayload[0]; + + GameProfile recipientProfile = MinecraftServer.getServer().func_152358_ax().func_152655_a(identifier); + + if (recipientProfile == null) + return; + + MailAddress recipient = new MailAddress(recipientProfile); getLetter().setRecipient(recipient); + // Update the trading info updateTradeInfo(player.worldObj, recipient); + // Update trade info on client Proxies.net.sendToPlayer(new PacketTradeInfo(PacketIds.TRADING_INFO, tradeInfo), player); } diff --git a/forestry_common/mail/forestry/mail/gui/GuiLetter.java b/forestry_common/mail/forestry/mail/gui/GuiLetter.java index 041e9e94f..48e73c30d 100755 --- a/forestry_common/mail/forestry/mail/gui/GuiLetter.java +++ b/forestry_common/mail/forestry/mail/gui/GuiLetter.java @@ -221,7 +221,8 @@ public class GuiLetter extends GuiForestry { String recipient = SessionVars.getStringVar("mail.letter.recipient"); String type = SessionVars.getStringVar("mail.letter.addressee"); - if(type != null) { + + if (recipient != null && type != null) { address.setText(recipient); setRecipient(recipient, type); } @@ -233,6 +234,12 @@ public class GuiLetter extends GuiForestry { private void setRecipient(String identifier, String type) { if (this.isProcessedLetter) return; + + if (identifier == null || identifier == "" ) + return; + + if (type == null || type == "" ) + return; MailAddress recipient = new MailAddress(new GameProfile(null, identifier), type); container.setRecipient(recipient); From 07751641742545c559ce0c6329db6f5f42a5217d Mon Sep 17 00:00:00 2001 From: SandGrainOne Date: Mon, 11 Aug 2014 20:16:38 +0200 Subject: [PATCH 2/2] Disable hotbar keys for GuiLetter Fixes #36 --- forestry_common/mail/forestry/mail/gui/GuiLetter.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/forestry_common/mail/forestry/mail/gui/GuiLetter.java b/forestry_common/mail/forestry/mail/gui/GuiLetter.java index 48e73c30d..1da9dd312 100755 --- a/forestry_common/mail/forestry/mail/gui/GuiLetter.java +++ b/forestry_common/mail/forestry/mail/gui/GuiLetter.java @@ -16,6 +16,7 @@ import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.EntityPlayer; import com.mojang.authlib.GameProfile; + import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -214,6 +215,11 @@ public class GuiLetter extends GuiForestry { Keyboard.enableRepeatEvents(false); super.onGuiClosed(); } + + @Override + protected boolean checkHotbarKeys(int key) { + return false; + } private void setFromSessionVars() { if(SessionVars.getStringVar("mail.letter.recipient") == null)