mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 19:29:17 +00:00
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:
1 parent
07afdf63b1
commit
36da6efa91
27 files changed
+470
-258
No files matched your search
@@ -42,7 +42,7 @@ public class PacketIds {
|
||||
public static final int LETTER_RECIPIENT = 80;
|
||||
public static final int LETTER_TEXT = 81;
|
||||
public static final int TRADING_ADDRESS_SET = 82;
|
||||
public static final int TRADING_INFO = 83;
|
||||
public static final int LETTER_INFO = 83;
|
||||
public static final int POBOX_INFO = 85;
|
||||
public static final int POBOX_INFO_REQUEST = 86;
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.mail;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.command.ICommand;
|
||||
import net.minecraft.command.ICommandSender;
|
||||
import net.minecraft.command.WrongUsageException;
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum EnumAddressee {
|
||||
PLAYER, TRADER;
|
||||
|
||||
public static EnumAddressee fromString(String ident) {
|
||||
for(EnumAddressee addr : values()) {
|
||||
if(addr.toString().equals(ident))
|
||||
return addr;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String asString(EnumAddressee addressee) {
|
||||
return addressee.toString().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -32,15 +32,15 @@ public class Letter implements ILetter, INBTTagable {
|
||||
|
||||
private boolean isProcessed = false;
|
||||
|
||||
private MailAddress sender;
|
||||
private MailAddress[] recipient;
|
||||
private IMailAddress sender;
|
||||
private IMailAddress[] recipient;
|
||||
|
||||
private String text;
|
||||
private InventoryAdapter inventory = new InventoryAdapter(22, "INV");
|
||||
|
||||
public Letter(MailAddress sender, MailAddress recipient) {
|
||||
public Letter(IMailAddress sender, IMailAddress recipient) {
|
||||
this.sender = sender;
|
||||
this.recipient = new MailAddress[] { recipient };
|
||||
this.recipient = new IMailAddress[] { recipient };
|
||||
}
|
||||
|
||||
public Letter(NBTTagCompound nbttagcompound) {
|
||||
@@ -191,7 +191,7 @@ public class Letter implements ILetter, INBTTagable {
|
||||
if (getRecipients().length <= 0)
|
||||
return false;
|
||||
|
||||
MailAddress recipient = getRecipients()[0];
|
||||
IMailAddress recipient = getRecipients()[0];
|
||||
if (recipient == null)
|
||||
return false;
|
||||
|
||||
@@ -202,36 +202,36 @@ public class Letter implements ILetter, INBTTagable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSender(MailAddress address) {
|
||||
public void setSender(IMailAddress address) {
|
||||
this.sender = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MailAddress getSender() {
|
||||
public IMailAddress getSender() {
|
||||
return sender;
|
||||
}
|
||||
|
||||
public void setRecipients(MailAddress[] recipients) {
|
||||
public void setRecipients(IMailAddress[] recipients) {
|
||||
this.recipient = recipients;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecipient(MailAddress address) {
|
||||
public void setRecipient(IMailAddress address) {
|
||||
if (address == null)
|
||||
this.recipient = new MailAddress[] {};
|
||||
this.recipient = new IMailAddress[] {};
|
||||
else
|
||||
this.recipient = new MailAddress[] { address };
|
||||
this.recipient = new IMailAddress[] { address };
|
||||
}
|
||||
|
||||
@Override
|
||||
public MailAddress[] getRecipients() {
|
||||
public IMailAddress[] getRecipients() {
|
||||
return recipient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRecipientString() {
|
||||
String recipientString = "";
|
||||
for (MailAddress address : recipient) {
|
||||
for (IMailAddress address : recipient) {
|
||||
if (recipientString.length() > 0)
|
||||
recipientString += ", ";
|
||||
recipientString += address.getName();
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.network.EntityNetData;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
|
||||
public class MailAddress implements INBTTagable, IMailAddress {
|
||||
@EntityNetData
|
||||
private EnumAddressee type;
|
||||
@EntityNetData
|
||||
private GameProfile gameProfile; // gameProfile is a fake GameProfile for traders, and real for players
|
||||
|
||||
private static final MailAddress invalidAddress = new MailAddress();
|
||||
|
||||
public MailAddress() {
|
||||
this.type = EnumAddressee.INVALID;
|
||||
this.gameProfile = new GameProfile(new UUID(0,0), "");
|
||||
}
|
||||
|
||||
public MailAddress(GameProfile gameProfile) {
|
||||
if (gameProfile == null)
|
||||
throw new IllegalArgumentException("gameProfile must not be null");
|
||||
|
||||
this.type = EnumAddressee.PLAYER;
|
||||
this.gameProfile = gameProfile;
|
||||
}
|
||||
|
||||
public MailAddress(String name) {
|
||||
if (name == null)
|
||||
throw new IllegalArgumentException("name must not be null");
|
||||
|
||||
this.type = EnumAddressee.TRADER;
|
||||
this.gameProfile = new GameProfile(new UUID(0,0), name);
|
||||
}
|
||||
|
||||
public MailAddress(IMailAddress address) {
|
||||
this.type = address.getType();
|
||||
if (type == EnumAddressee.TRADER) {
|
||||
String name = address.getName();
|
||||
this.gameProfile = new GameProfile(new UUID(0, 0), name);
|
||||
} else if (type == EnumAddressee.PLAYER) {
|
||||
this.gameProfile = address.getPlayerProfile();
|
||||
}
|
||||
}
|
||||
|
||||
public EnumAddressee getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return gameProfile.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String name = getName().toLowerCase(Locale.ENGLISH);
|
||||
if (isPlayer()) {
|
||||
return type + "-" + name + "-" + gameProfile.getId();
|
||||
} else {
|
||||
return type + "-" + name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof MailAddress))
|
||||
return false;
|
||||
|
||||
MailAddress address = (MailAddress)o;
|
||||
return address.gameProfile.equals(gameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return gameProfile.hashCode();
|
||||
}
|
||||
|
||||
public boolean isPlayer() {
|
||||
return type == EnumAddressee.PLAYER;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
return type != EnumAddressee.INVALID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
type = EnumAddressee.INVALID;
|
||||
if(nbttagcompound.hasKey("TP")) {
|
||||
String typeName = nbttagcompound.getString("TP");
|
||||
type = EnumAddressee.fromString(typeName);
|
||||
}
|
||||
|
||||
if (!isValid()) {
|
||||
gameProfile = invalidAddress.gameProfile;
|
||||
} else if(nbttagcompound.hasKey("profile")) {
|
||||
NBTTagCompound profileTag = nbttagcompound.getCompoundTag("profile");
|
||||
gameProfile = NBTUtil.func_152459_a(profileTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setString("TP", type.toString());
|
||||
|
||||
if (gameProfile != null) {
|
||||
NBTTagCompound profileNbt = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a(profileNbt, gameProfile);
|
||||
nbttagcompound.setTag("profile", profileNbt);
|
||||
}
|
||||
}
|
||||
|
||||
public static MailAddress loadFromNBT(NBTTagCompound nbttagcompound) {
|
||||
MailAddress address = new MailAddress();
|
||||
address.readFromNBT(nbttagcompound);
|
||||
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 clientPlayer = Proxies.common.getPlayer();
|
||||
|
||||
return addressPlayer != null && clientPlayer != null && clientPlayer.equals(addressPlayer);
|
||||
}
|
||||
|
||||
public GameProfile getPlayerProfile() {
|
||||
if (!this.isPlayer())
|
||||
return null;
|
||||
return gameProfile;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -19,6 +18,7 @@ import net.minecraft.world.WorldSavedData;
|
||||
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
|
||||
public class POBox extends WorldSavedData implements IInventory {
|
||||
@@ -26,10 +26,10 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
public static final String SAVE_NAME = "POBox_";
|
||||
public static final short SLOT_SIZE = 84;
|
||||
|
||||
private MailAddress address;
|
||||
private IMailAddress address;
|
||||
private final InventoryAdapter letters = new InventoryAdapter(SLOT_SIZE, "Letters");
|
||||
|
||||
public POBox(MailAddress address) {
|
||||
public POBox(IMailAddress address) {
|
||||
super(SAVE_NAME + address);
|
||||
if (!address.isPlayer()) {
|
||||
throw new IllegalArgumentException("POBox address must be a player");
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.mail;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
@@ -24,7 +23,7 @@ import forestry.mail.gui.ContainerCatalogue;
|
||||
import forestry.mail.gui.ContainerLetter;
|
||||
import forestry.mail.gui.ContainerTradeName;
|
||||
import forestry.mail.network.PacketPOBoxInfo;
|
||||
import forestry.mail.network.PacketTradeInfo;
|
||||
import forestry.mail.network.PacketLetterInfo;
|
||||
import forestry.plugins.PluginMail;
|
||||
|
||||
public class PacketHandlerMail implements IPacketHandler {
|
||||
@@ -36,10 +35,10 @@ public class PacketHandlerMail implements IPacketHandler {
|
||||
|
||||
PacketUpdate packet;
|
||||
switch (packetID) {
|
||||
case PacketIds.TRADING_INFO:
|
||||
PacketTradeInfo packetT = new PacketTradeInfo();
|
||||
case PacketIds.LETTER_INFO:
|
||||
PacketLetterInfo packetT = new PacketLetterInfo();
|
||||
packetT.readData(data);
|
||||
onTradeInfo(packetT);
|
||||
onLetterInfo(packetT);
|
||||
break;
|
||||
case PacketIds.POBOX_INFO:
|
||||
PacketPOBoxInfo packetP = new PacketPOBoxInfo();
|
||||
@@ -70,11 +69,11 @@ public class PacketHandlerMail implements IPacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void onTradeInfo(PacketTradeInfo packet) {
|
||||
private void onLetterInfo(PacketLetterInfo packet) {
|
||||
|
||||
Container container = Proxies.common.getClientInstance().thePlayer.openContainer;
|
||||
if (container instanceof ContainerLetter) {
|
||||
((ContainerLetter) container).handleTradeInfoUpdate(packet);
|
||||
((ContainerLetter) container).handleLetterInfoUpdate(packet);
|
||||
} else if(container instanceof ContainerCatalogue) {
|
||||
((ContainerCatalogue) container).handleTradeInfoUpdate(packet);
|
||||
}
|
||||
|
||||
@@ -12,15 +12,12 @@ package forestry.mail;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSavedData;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.EnumPostage;
|
||||
import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IPostOffice;
|
||||
@@ -28,8 +25,8 @@ import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.config.ForestryItem;
|
||||
|
||||
public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
@@ -67,15 +64,15 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
}
|
||||
|
||||
/* TRADE STATION MANAGMENT */
|
||||
private LinkedHashMap<MailAddress, ITradeStation> activeTradeStations;
|
||||
private LinkedHashMap<IMailAddress, ITradeStation> activeTradeStations;
|
||||
|
||||
@Override
|
||||
public LinkedHashMap<MailAddress, ITradeStation> getActiveTradeStations(World world) {
|
||||
public LinkedHashMap<IMailAddress, ITradeStation> getActiveTradeStations(World world) {
|
||||
return this.activeTradeStations;
|
||||
}
|
||||
|
||||
private void refreshActiveTradeStations(World world) {
|
||||
activeTradeStations = new LinkedHashMap<MailAddress, ITradeStation>();
|
||||
activeTradeStations = new LinkedHashMap<IMailAddress, ITradeStation>();
|
||||
if (world == null || world.getSaveHandler() == null)
|
||||
return;
|
||||
File worldSave = world.getSaveHandler().getMapFileFromName("dummy");
|
||||
@@ -161,8 +158,8 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
return EnumDeliveryState.NOT_MAILABLE;
|
||||
|
||||
IPostalState state = EnumDeliveryState.NOT_MAILABLE;
|
||||
for (MailAddress address : letter.getRecipients()) {
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType());
|
||||
for (IMailAddress address : letter.getRecipients()) {
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType().toString());
|
||||
if (carrier == null)
|
||||
continue;
|
||||
state = carrier.deliverLetter(world, this, address, itemstack, doLodge);
|
||||
|
||||
@@ -25,8 +25,8 @@ import forestry.api.mail.IPostOffice;
|
||||
import forestry.api.mail.IPostRegistry;
|
||||
import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.mail.items.ItemLetter;
|
||||
import forestry.plugins.PluginMail;
|
||||
@@ -34,8 +34,8 @@ import forestry.plugins.PluginMail;
|
||||
public class PostRegistry implements IPostRegistry {
|
||||
|
||||
public static PostOffice cachedPostOffice;
|
||||
public static HashMap<MailAddress, POBox> cachedPOBoxes = new HashMap<MailAddress, POBox>();
|
||||
public static HashMap<MailAddress, ITradeStation> cachedTradeStations = new HashMap<MailAddress, ITradeStation>();
|
||||
public static HashMap<IMailAddress, POBox> cachedPOBoxes = new HashMap<IMailAddress, POBox>();
|
||||
public static HashMap<IMailAddress, ITradeStation> cachedTradeStations = new HashMap<IMailAddress, ITradeStation>();
|
||||
|
||||
/**
|
||||
* @param world the Minecraft world the PO box will be in
|
||||
@@ -43,11 +43,11 @@ public class PostRegistry implements IPostRegistry {
|
||||
* @return true if the passed address is valid for PO Boxes.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidPOBox(World world, MailAddress address) {
|
||||
public boolean isValidPOBox(World world, IMailAddress address) {
|
||||
return address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
public static POBox getPOBox(World world, MailAddress address) {
|
||||
public static POBox getPOBox(World world, IMailAddress address) {
|
||||
|
||||
if (cachedPOBoxes.containsKey(address))
|
||||
return cachedPOBoxes.get(address);
|
||||
@@ -58,7 +58,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
return pobox;
|
||||
}
|
||||
|
||||
public static POBox getOrCreatePOBox(World world, MailAddress address) {
|
||||
public static POBox getOrCreatePOBox(World world, IMailAddress address) {
|
||||
POBox pobox = getPOBox(world, address);
|
||||
|
||||
if (pobox == null) {
|
||||
@@ -78,7 +78,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
* @return true if the passed address can be an address for a trade station
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidTradeAddress(World world, MailAddress address) {
|
||||
public boolean isValidTradeAddress(World world, IMailAddress address) {
|
||||
return !address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
|
||||
}
|
||||
|
||||
@@ -88,12 +88,12 @@ public class PostRegistry implements IPostRegistry {
|
||||
* @return true if the trade address has not yet been used before.
|
||||
*/
|
||||
@Override
|
||||
public boolean isAvailableTradeAddress(World world, MailAddress address) {
|
||||
public boolean isAvailableTradeAddress(World world, IMailAddress address) {
|
||||
return getTradeStation(world, address) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStation getTradeStation(World world, MailAddress address) {
|
||||
public TradeStation getTradeStation(World world, IMailAddress address) {
|
||||
if (cachedTradeStations.containsKey(address))
|
||||
return (TradeStation)cachedTradeStations.get(address);
|
||||
|
||||
@@ -110,7 +110,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStation getOrCreateTradeStation(World world, GameProfile owner, MailAddress address) {
|
||||
public TradeStation getOrCreateTradeStation(World world, GameProfile owner, IMailAddress address) {
|
||||
TradeStation trade = getTradeStation(world, address);
|
||||
|
||||
if (trade == null) {
|
||||
@@ -125,7 +125,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTradeStation(World world, MailAddress address) {
|
||||
public void deleteTradeStation(World world, IMailAddress address) {
|
||||
TradeStation trade = getTradeStation(world, address);
|
||||
if (trade == null)
|
||||
return;
|
||||
@@ -157,6 +157,16 @@ public class PostRegistry implements IPostRegistry {
|
||||
return office;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress getMailAddress(GameProfile gameProfile) {
|
||||
return new MailAddress(gameProfile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMailAddress getMailAddress(String traderName) {
|
||||
return new MailAddress(traderName);
|
||||
}
|
||||
|
||||
/* CARRIER */
|
||||
private final HashMap<String, IPostalCarrier> carriers = new HashMap<String, IPostalCarrier>();
|
||||
|
||||
@@ -177,7 +187,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
/* LETTERS */
|
||||
@Override
|
||||
public ILetter createLetter(MailAddress sender, MailAddress recipient) {
|
||||
public ILetter createLetter(IMailAddress sender, IMailAddress recipient) {
|
||||
return new Letter(sender, recipient);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,6 @@ import net.minecraft.world.World;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.plugins.PluginMail;
|
||||
@@ -55,14 +53,14 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPostalState deliverLetter(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doDeliver) {
|
||||
public IPostalState deliverLetter(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doDeliver) {
|
||||
if(type == EnumAddressee.TRADER)
|
||||
return handleTradeLetter(world, office, recipient, letterstack, doDeliver);
|
||||
else
|
||||
return storeInPOBox(world, office, recipient, letterstack, doDeliver);
|
||||
}
|
||||
|
||||
private IPostalState handleTradeLetter(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
private IPostalState handleTradeLetter(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
IPostalState state = EnumDeliveryState.NOT_MAILABLE;
|
||||
|
||||
ITradeStation trade = PostManager.postRegistry.getTradeStation(world, recipient);
|
||||
@@ -74,7 +72,7 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
return state;
|
||||
}
|
||||
|
||||
private EnumDeliveryState storeInPOBox(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
private EnumDeliveryState storeInPOBox(World world, IPostOffice office, IMailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
|
||||
POBox pobox = PostRegistry.getPOBox(world, recipient);
|
||||
if (pobox == null)
|
||||
|
||||
@@ -28,9 +28,9 @@ import forestry.api.mail.ILetter;
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.StackUtils;
|
||||
@@ -56,13 +56,13 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
// / MEMBER
|
||||
private GameProfile owner;
|
||||
private MailAddress address;
|
||||
private IMailAddress address;
|
||||
private boolean isVirtual = false;
|
||||
private boolean isInvalid = false;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(SLOT_SIZE, "INV");
|
||||
|
||||
// / CONSTRUCTORS
|
||||
public TradeStation(GameProfile owner, MailAddress address) {
|
||||
public TradeStation(GameProfile owner, IMailAddress address) {
|
||||
super(SAVE_NAME + address);
|
||||
if (address.isPlayer()) {
|
||||
throw new IllegalArgumentException("TradeStation address must not be a player");
|
||||
@@ -76,7 +76,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
|
||||
@Override
|
||||
public MailAddress getAddress() {
|
||||
public IMailAddress getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
/* ILETTERHANDLER */
|
||||
@Override
|
||||
public IPostalState handleLetter(World world, MailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
public IPostalState handleLetter(World world, IMailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
|
||||
boolean sendOwnerNotice = doLodge && owner != null;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ package forestry.mail.gadgets;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -28,6 +27,8 @@ import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.mail.MailAddress;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.network.EntityNetData;
|
||||
@@ -41,7 +42,7 @@ import forestry.plugins.PluginMail;
|
||||
public class MachineTrader extends TileBase implements ISpecialInventory, ISidedInventory {
|
||||
|
||||
@EntityNetData
|
||||
public MailAddress address;
|
||||
private MailAddress address;
|
||||
|
||||
public MachineTrader() {
|
||||
address = new MailAddress();
|
||||
@@ -234,11 +235,11 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
}
|
||||
|
||||
/* ADDRESS */
|
||||
public MailAddress getAddress() {
|
||||
public IMailAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(MailAddress address) {
|
||||
public void setAddress(IMailAddress address) {
|
||||
if (address == null)
|
||||
throw new NullPointerException("address must not be null");
|
||||
|
||||
@@ -256,11 +257,11 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
return;
|
||||
}
|
||||
|
||||
this.address = address;
|
||||
this.address = new MailAddress(address);
|
||||
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
} else
|
||||
this.address = address;
|
||||
this.address = new MailAddress(address);
|
||||
}
|
||||
|
||||
/* TRADING */
|
||||
|
||||
@@ -15,26 +15,27 @@ import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Set;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.mail.network.PacketLetterInfo;
|
||||
import forestry.mail.EnumStationState;
|
||||
import forestry.core.gui.ContainerForestry;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.EnumStationState;
|
||||
import forestry.mail.network.PacketTradeInfo;
|
||||
|
||||
public class ContainerCatalogue extends ContainerForestry implements IGuiSelectable {
|
||||
|
||||
private final EntityPlayer player;
|
||||
private final LinkedHashMap<MailAddress, ITradeStation> stations;
|
||||
private final LinkedHashMap<IMailAddress, ITradeStation> stations;
|
||||
private TradeStationInfo currentTrade = null;
|
||||
private Iterator<ITradeStation> iterator = null;
|
||||
|
||||
@@ -57,7 +58,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta
|
||||
this.player = player;
|
||||
|
||||
// Filter out any trade stations which do not actually offer anything.
|
||||
stations = new LinkedHashMap<MailAddress, ITradeStation>();
|
||||
stations = new LinkedHashMap<IMailAddress, ITradeStation>();
|
||||
rebuildStationsList();
|
||||
}
|
||||
|
||||
@@ -183,7 +184,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta
|
||||
needsSynch = true;
|
||||
}
|
||||
|
||||
public void handleTradeInfoUpdate(PacketTradeInfo packet) {
|
||||
public void handleTradeInfoUpdate(PacketLetterInfo packet) {
|
||||
setTradeInfo(packet.tradeInfo);
|
||||
}
|
||||
|
||||
@@ -207,7 +208,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta
|
||||
crafter.sendProgressBarUpdate(this, 2, currentFilter);
|
||||
}
|
||||
|
||||
Proxies.net.sendToPlayer(new PacketTradeInfo(PacketIds.TRADING_INFO, currentTrade), player);
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, EnumAddressee.TRADER, currentTrade, null), player);
|
||||
needsSynch = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,17 +11,23 @@
|
||||
package forestry.mail.gui;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
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;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.core.gui.ContainerItemInventory;
|
||||
import forestry.core.gui.slots.SlotClosed;
|
||||
import forestry.core.gui.slots.SlotCustom;
|
||||
@@ -29,17 +35,16 @@ import forestry.core.network.PacketIds;
|
||||
import forestry.core.network.PacketPayload;
|
||||
import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.EnumAddressee;
|
||||
import forestry.mail.Letter;
|
||||
import forestry.mail.items.ItemLetter;
|
||||
import forestry.mail.items.ItemLetter.LetterInventory;
|
||||
import forestry.mail.items.ItemStamps;
|
||||
import forestry.mail.network.PacketTradeInfo;
|
||||
import forestry.mail.network.PacketLetterInfo;
|
||||
|
||||
public class ContainerLetter extends ContainerItemInventory {
|
||||
|
||||
private final LetterInventory letterInventory;
|
||||
private String carrier = EnumAddressee.PLAYER.toString().toLowerCase(Locale.ENGLISH);
|
||||
private EnumAddressee carrier = EnumAddressee.PLAYER;
|
||||
private TradeStationInfo tradeInfo = null;
|
||||
|
||||
public ContainerLetter(EntityPlayer player, LetterInventory inventory) {
|
||||
@@ -91,8 +96,10 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
|
||||
if (Proxies.common.isSimulating(entityplayer.worldObj)) {
|
||||
ILetter letter = letterInventory.getLetter();
|
||||
if (!letter.isProcessed())
|
||||
letter.setSender(new MailAddress(entityplayer.getGameProfile()));
|
||||
if (!letter.isProcessed()) {
|
||||
IMailAddress sender = PostManager.postRegistry.getMailAddress(entityplayer.getGameProfile());
|
||||
letter.setSender(sender);
|
||||
}
|
||||
}
|
||||
|
||||
super.onContainerClosed(entityplayer);
|
||||
@@ -107,11 +114,11 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
return letterInventory.getLetter();
|
||||
}
|
||||
|
||||
public void setCarrierType(String type) {
|
||||
public void setCarrierType(EnumAddressee type) {
|
||||
this.carrier = type;
|
||||
}
|
||||
|
||||
public String getCarrierType() {
|
||||
public EnumAddressee getCarrierType() {
|
||||
return this.carrier;
|
||||
}
|
||||
|
||||
@@ -128,39 +135,50 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
else
|
||||
postal = PostManager.postRegistry.getRegisteredCarriers().values().iterator().next();
|
||||
|
||||
setCarrierType(postal.getUID());
|
||||
EnumAddressee type = EnumAddressee.fromString(postal.getUID());
|
||||
setCarrierType(type);
|
||||
}
|
||||
|
||||
public void setRecipient(MailAddress address) {
|
||||
if (address == null)
|
||||
public void setRecipient(String recipientName, EnumAddressee type) {
|
||||
if (StringUtils.isBlank(recipientName) || type == EnumAddressee.INVALID)
|
||||
return;
|
||||
|
||||
getLetter().setRecipient(address);
|
||||
carrier = address.getType();
|
||||
|
||||
// / Send to server
|
||||
PacketPayload payload = new PacketPayload(0, 0, 2);
|
||||
payload.stringPayload[0] = getRecipient().getName();
|
||||
payload.stringPayload[1] = this.carrier;
|
||||
PacketPayload payload = new PacketPayload(0,0,2);
|
||||
payload.stringPayload[0] = recipientName;
|
||||
payload.stringPayload[1] = type.toString();
|
||||
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.LETTER_RECIPIENT, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
}
|
||||
|
||||
public void handleSetRecipient(EntityPlayer player, PacketUpdate packet) {
|
||||
String identifierName = packet.payload.stringPayload[0];
|
||||
String type = packet.payload.stringPayload[1];
|
||||
MailAddress recipient = MailAddress.makeMailAddress(identifierName, type);
|
||||
String recipientName = packet.payload.stringPayload[0];
|
||||
String typeName = packet.payload.stringPayload[1];
|
||||
|
||||
EnumAddressee type = EnumAddressee.fromString(typeName);
|
||||
IMailAddress recipient;
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
GameProfile gameProfile = MinecraftServer.getServer().func_152358_ax().func_152655_a(recipientName);
|
||||
if (gameProfile == null)
|
||||
gameProfile = new GameProfile(new UUID(0, 0), recipientName);
|
||||
recipient = PostManager.postRegistry.getMailAddress(gameProfile);
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
recipient = PostManager.postRegistry.getMailAddress(recipientName);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
// Update info on client
|
||||
Proxies.net.sendToPlayer(new PacketLetterInfo(PacketIds.LETTER_INFO, type, tradeInfo, recipient), player);
|
||||
}
|
||||
|
||||
public MailAddress getRecipient() {
|
||||
public IMailAddress getRecipient() {
|
||||
if (getLetter().getRecipients().length > 0)
|
||||
return getLetter().getRecipients()[0];
|
||||
else
|
||||
@@ -188,7 +206,7 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
}
|
||||
|
||||
/* Managing Trade info */
|
||||
public void updateTradeInfo(World world, MailAddress address) {
|
||||
public void updateTradeInfo(World world, IMailAddress address) {
|
||||
// Updating is done by the server.
|
||||
if (!Proxies.common.isSimulating(world))
|
||||
return;
|
||||
@@ -203,8 +221,13 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
setTradeInfo(station.getTradeInfo());
|
||||
}
|
||||
|
||||
public void handleTradeInfoUpdate(PacketTradeInfo packet) {
|
||||
this.setTradeInfo(packet.tradeInfo);
|
||||
public void handleLetterInfoUpdate(PacketLetterInfo packet) {
|
||||
carrier = packet.type;
|
||||
if (packet.type == EnumAddressee.PLAYER) {
|
||||
getLetter().setRecipient(packet.address);
|
||||
} else if (packet.type == EnumAddressee.TRADER) {
|
||||
this.setTradeInfo(packet.tradeInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public TradeStationInfo getTradeInfo() {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -22,6 +22,7 @@ import forestry.core.gui.slots.SlotClosed;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.POBox;
|
||||
import forestry.mail.gadgets.MachineMailbox;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.plugins.PluginMail;
|
||||
|
||||
public class ContainerMailbox extends ContainerForestry {
|
||||
@@ -35,7 +36,7 @@ public class ContainerMailbox extends ContainerForestry {
|
||||
// Mailbox contents
|
||||
this.mailbox = tile;
|
||||
|
||||
IInventory inv = mailbox.getOrCreateMailInventory();
|
||||
IInventory inv = mailbox.getOrCreateMailInventory(player.player);
|
||||
if (inv instanceof POBox)
|
||||
mailinventory = (POBox) inv;
|
||||
|
||||
@@ -58,7 +59,7 @@ public class ContainerMailbox extends ContainerForestry {
|
||||
ItemStack stack = super.slotClick(slotIndex, button, par3, player);
|
||||
|
||||
if (Proxies.common.isSimulating(player.worldObj) && mailinventory != null) {
|
||||
MailAddress address = new MailAddress(mailbox.getOwnerProfile());
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(mailbox.getOwnerProfile());
|
||||
PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), address, mailinventory.getPOBoxInfo());
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,8 @@ import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.mail.gadgets.MachineTrader;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -35,7 +36,7 @@ public class ContainerTradeName extends ContainerForestry {
|
||||
isLinked = machine.isLinked();
|
||||
}
|
||||
|
||||
public MailAddress getAddress() {
|
||||
public IMailAddress getAddress() {
|
||||
return machine.getAddress();
|
||||
}
|
||||
|
||||
@@ -50,13 +51,13 @@ public class ContainerTradeName extends ContainerForestry {
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.TRADING_ADDRESS_SET, payload);
|
||||
Proxies.net.sendToServer(packet);
|
||||
|
||||
MailAddress address = new MailAddress(addressName);
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
machine.setAddress(address);
|
||||
}
|
||||
|
||||
public void handleSetAddress(PacketUpdate packet) {
|
||||
String addressName = packet.payload.stringPayload[0];
|
||||
MailAddress address = new MailAddress(addressName);
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(addressName);
|
||||
machine.setAddress(address);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,11 @@ import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
import forestry.core.gui.ContainerForestry;
|
||||
import forestry.core.gui.slots.SlotClosed;
|
||||
import forestry.core.gui.slots.SlotCustom;
|
||||
import forestry.mail.TradeStation;
|
||||
import forestry.mail.gadgets.MachineTrader;
|
||||
import forestry.mail.items.ItemStamps;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
|
||||
public class ContainerTrader extends ContainerForestry {
|
||||
|
||||
@@ -75,7 +74,7 @@ public class ContainerTrader extends ContainerForestry {
|
||||
return machine.isLinked();
|
||||
}
|
||||
|
||||
public MailAddress getAddress() {
|
||||
public IMailAddress getAddress() {
|
||||
return machine.getAddress();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import forestry.core.config.SessionVars;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.gui.GuiForestry;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
|
||||
public class GuiCatalogue extends GuiForestry<TileForestry> {
|
||||
|
||||
@@ -136,7 +136,7 @@ public class GuiCatalogue extends GuiForestry<TileForestry> {
|
||||
TradeStationInfo info = container.getTradeInfo();
|
||||
if(info != null) {
|
||||
SessionVars.setStringVar("mail.letter.recipient", info.address.getName());
|
||||
SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.asString(EnumAddressee.TRADER));
|
||||
SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.TRADER.toString());
|
||||
}
|
||||
mc.displayGuiScreen((GuiScreen)null);
|
||||
break;
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.SessionVars;
|
||||
@@ -30,7 +30,7 @@ import forestry.core.gui.GuiTextBox;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.mail.items.ItemLetter.LetterInventory;
|
||||
|
||||
public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
@@ -48,7 +48,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0F);
|
||||
//mc.renderEngine.bindTexture(Defaults.TEXTURE_PATH_GUI + "/letter.png");
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(container.getCarrierType());
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(container.getCarrierType().toString());
|
||||
if(carrier != null)
|
||||
drawTexturedModelRectFromIcon(startX + xPos, startY + yPos - 5, carrier.getIcon(), 26, 26);
|
||||
|
||||
@@ -56,7 +56,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
|
||||
@Override
|
||||
protected String getLegacyTooltip(EntityPlayer player) {
|
||||
return StringUtil.localize("gui.addressee." + container.getCarrierType().toLowerCase(Locale.ENGLISH));
|
||||
return StringUtil.localize("gui.addressee." + container.getCarrierType().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,10 +95,9 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
|
||||
address = new GuiTextField(this.fontRendererObj, guiLeft + 46, guiTop + 13, 93, 13);
|
||||
MailAddress recipient = container.getRecipient();
|
||||
IMailAddress recipient = container.getRecipient();
|
||||
if (recipient != null) {
|
||||
address.setText(recipient.getName());
|
||||
setRecipient(recipient);
|
||||
}
|
||||
|
||||
text = new GuiTextBox(this.fontRendererObj, guiLeft + 17, guiTop + 31, 122, 57);
|
||||
@@ -158,8 +157,8 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
if (addressFocus != address.isFocused()) {
|
||||
String recipient = this.address.getText();
|
||||
if (StringUtils.isNotBlank(recipient)) {
|
||||
MailAddress recipientAddress = MailAddress.makeMailAddress(recipient, container.getCarrierType());
|
||||
setRecipient(recipientAddress);
|
||||
EnumAddressee recipientType = container.getCarrierType();
|
||||
setRecipient(recipient, recipientType);
|
||||
}
|
||||
}
|
||||
addressFocus = address.isFocused();
|
||||
@@ -174,7 +173,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
fontRendererObj.drawSplitString(text.getText(), guiLeft + 20, guiTop + 34, 119, fontColor.get("gui.mail.lettertext"));
|
||||
} else {
|
||||
address.drawTextBox();
|
||||
if (container.getCarrierType().equals(EnumAddressee.TRADER.toString().toLowerCase(Locale.ENGLISH)))
|
||||
if (container.getCarrierType() == EnumAddressee.TRADER)
|
||||
drawTradePreview(guiLeft + 18, guiTop + 32);
|
||||
else
|
||||
text.drawTextBox();
|
||||
@@ -215,9 +214,9 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
MailAddress recipientAddress = MailAddress.makeMailAddress(this.address.getText(), container.getCarrierType());
|
||||
|
||||
setRecipient(recipientAddress);
|
||||
String recipientName = this.address.getText();
|
||||
EnumAddressee recipientType = container.getCarrierType();
|
||||
setRecipient(recipientName, recipientType);
|
||||
setText();
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
super.onGuiClosed();
|
||||
@@ -233,24 +232,24 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
return;
|
||||
|
||||
String recipient = SessionVars.getStringVar("mail.letter.recipient");
|
||||
String type = SessionVars.getStringVar("mail.letter.addressee");
|
||||
String typeName = SessionVars.getStringVar("mail.letter.addressee");
|
||||
|
||||
if (recipient != null && type != null) {
|
||||
if (StringUtils.isNotBlank(recipient) && StringUtils.isNotBlank(typeName)) {
|
||||
address.setText(recipient);
|
||||
MailAddress recipientAddress = MailAddress.makeMailAddress(recipient, type);
|
||||
setRecipient(recipientAddress);
|
||||
|
||||
EnumAddressee type = EnumAddressee.fromString(typeName);
|
||||
setRecipient(recipient, type);
|
||||
}
|
||||
|
||||
SessionVars.clearStringVar("mail.letter.recipient");
|
||||
SessionVars.clearStringVar("mail.letter.addressee");
|
||||
}
|
||||
|
||||
private void setRecipient(MailAddress recipientAddress) {
|
||||
if (this.isProcessedLetter || recipientAddress == null)
|
||||
private void setRecipient(String recipientName, EnumAddressee type) {
|
||||
if (this.isProcessedLetter || StringUtils.isBlank(recipientName) || type == null || type == EnumAddressee.INVALID)
|
||||
return;
|
||||
|
||||
container.setRecipient(recipientAddress);
|
||||
container.updateTradeInfo(this.mc.theWorld, recipientAddress);
|
||||
container.setRecipient(recipientName, type);
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
|
||||
@@ -16,7 +16,6 @@ import forestry.core.config.Defaults;
|
||||
import forestry.core.gui.GuiForestry;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.mail.gadgets.MachineTrader;
|
||||
import forestry.api.mail.MailAddress;
|
||||
|
||||
public class GuiTrader extends GuiForestry<MachineTrader> {
|
||||
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.mail.EnumStationState;
|
||||
|
||||
public class PacketLetterInfo extends ForestryPacket {
|
||||
|
||||
public EnumAddressee type;
|
||||
public TradeStationInfo tradeInfo;
|
||||
public IMailAddress address;
|
||||
|
||||
public PacketLetterInfo() {
|
||||
}
|
||||
|
||||
public PacketLetterInfo(int id, EnumAddressee type, TradeStationInfo info, IMailAddress address) {
|
||||
super(id);
|
||||
this.type = type;
|
||||
if (type == EnumAddressee.TRADER)
|
||||
this.tradeInfo = info;
|
||||
else if (type == EnumAddressee.PLAYER)
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
|
||||
if (type == null || type == EnumAddressee.INVALID) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeUTF(type.toString());
|
||||
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
|
||||
if (address == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
data.writeShort(0);
|
||||
|
||||
GameProfile profile = address.getPlayerProfile();
|
||||
|
||||
data.writeLong(profile.getId().getMostSignificantBits());
|
||||
data.writeLong(profile.getId().getLeastSignificantBits());
|
||||
data.writeUTF(profile.getName());
|
||||
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
|
||||
if (tradeInfo == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeUTF(tradeInfo.address.getName());
|
||||
|
||||
data.writeLong(tradeInfo.owner.getId().getMostSignificantBits());
|
||||
data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(tradeInfo.owner.getName());
|
||||
|
||||
writeItemStack(tradeInfo.tradegood, data);
|
||||
data.writeShort(tradeInfo.required.length);
|
||||
for (int i = 0; i < tradeInfo.required.length; i++)
|
||||
writeItemStack(tradeInfo.required[i], data);
|
||||
data.writeShort(tradeInfo.state.ordinal());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
|
||||
if (data.readShort() < 0)
|
||||
return;
|
||||
|
||||
type = EnumAddressee.fromString(data.readUTF());
|
||||
|
||||
if (type == EnumAddressee.PLAYER) {
|
||||
if (data.readShort() < 0)
|
||||
return;
|
||||
GameProfile player = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
this.address = PostManager.postRegistry.getMailAddress(player);
|
||||
|
||||
} else if (type == EnumAddressee.TRADER) {
|
||||
if (data.readShort() < 0)
|
||||
return;
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(data.readUTF());
|
||||
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
ItemStack tradegood;
|
||||
ItemStack[] required;
|
||||
|
||||
tradegood = readItemStack(data);
|
||||
required = new ItemStack[data.readShort()];
|
||||
for (int i = 0; i < required.length; i++)
|
||||
required[i] = readItemStack(data);
|
||||
|
||||
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.mail.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.TradeStationInfo;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.mail.EnumStationState;
|
||||
|
||||
public class PacketTradeInfo extends ForestryPacket {
|
||||
|
||||
public TradeStationInfo tradeInfo;
|
||||
|
||||
public PacketTradeInfo() {
|
||||
}
|
||||
|
||||
public PacketTradeInfo(int id, TradeStationInfo info) {
|
||||
super(id);
|
||||
this.tradeInfo = info;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
|
||||
if (tradeInfo == null) {
|
||||
data.writeShort(-1);
|
||||
return;
|
||||
}
|
||||
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeUTF(tradeInfo.address.getName());
|
||||
|
||||
data.writeLong(tradeInfo.owner.getId().getMostSignificantBits());
|
||||
data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits());
|
||||
data.writeUTF(tradeInfo.owner.getName());
|
||||
|
||||
writeItemStack(tradeInfo.tradegood, data);
|
||||
data.writeShort(tradeInfo.required.length);
|
||||
for (int i = 0; i < tradeInfo.required.length; i++)
|
||||
writeItemStack(tradeInfo.required[i], data);
|
||||
data.writeShort(tradeInfo.state.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
|
||||
short isNotNull = data.readShort();
|
||||
if (isNotNull < 0)
|
||||
return;
|
||||
|
||||
MailAddress address = new MailAddress(data.readUTF());
|
||||
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
ItemStack tradegood;
|
||||
ItemStack[] required;
|
||||
|
||||
tradegood = readItemStack(data);
|
||||
required = new ItemStack[data.readShort()];
|
||||
for (int i = 0; i < required.length; i++)
|
||||
required[i] = readItemStack(data);
|
||||
|
||||
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.proxy;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.network.ForestryPacket;
|
||||
@@ -20,6 +20,8 @@ import forestry.mail.POBox;
|
||||
import forestry.mail.POBoxInfo;
|
||||
import forestry.mail.PostRegistry;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
import forestry.api.mail.PostManager;
|
||||
|
||||
public class ClientProxyMail extends ProxyMail {
|
||||
|
||||
@@ -38,7 +40,8 @@ public class ClientProxyMail extends ProxyMail {
|
||||
if (!Proxies.common.isSimulating(Proxies.common.getRenderWorld()))
|
||||
Proxies.net.sendToServer(new ForestryPacket(PacketIds.POBOX_INFO_REQUEST));
|
||||
else {
|
||||
MailAddress address = new MailAddress(Proxies.common.getClientInstance().thePlayer.getGameProfile());
|
||||
GameProfile profile = Proxies.common.getClientInstance().thePlayer.getGameProfile();
|
||||
IMailAddress address = PostManager.postRegistry.getMailAddress(profile);
|
||||
POBox pobox = PostRegistry.getPOBox(Proxies.common.getRenderWorld(), address);
|
||||
if (pobox != null)
|
||||
setPOBoxInfo(Proxies.common.getRenderWorld(), address, pobox.getPOBoxInfo());
|
||||
@@ -46,7 +49,7 @@ public class ClientProxyMail extends ProxyMail {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPOBoxInfo(World world, MailAddress address, POBoxInfo info) {
|
||||
public void setPOBoxInfo(World world, IMailAddress address, POBoxInfo info) {
|
||||
if (address.isClientPlayer(world))
|
||||
GuiMailboxInfo.instance.setPOBoxInfo(info);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.proxy;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -18,6 +17,7 @@ import forestry.core.network.PacketIds;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.POBoxInfo;
|
||||
import forestry.mail.network.PacketPOBoxInfo;
|
||||
import forestry.api.mail.IMailAddress;
|
||||
|
||||
public class ProxyMail {
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ProxyMail {
|
||||
public void resetMailboxInfo() {
|
||||
}
|
||||
|
||||
public void setPOBoxInfo(World world, MailAddress address, POBoxInfo info) {
|
||||
public void setPOBoxInfo(World world, IMailAddress address, POBoxInfo info) {
|
||||
EntityPlayer player = address.getPlayer(world);
|
||||
if (player != null)
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player);
|
||||
|
||||
@@ -38,7 +38,7 @@ import forestry.core.triggers.Trigger;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.ShapedRecipeCustom;
|
||||
import forestry.mail.CommandMail;
|
||||
import forestry.mail.EnumAddressee;
|
||||
import forestry.api.mail.EnumAddressee;
|
||||
import forestry.mail.GuiHandlerMail;
|
||||
import forestry.mail.PacketHandlerMail;
|
||||
import forestry.mail.PostRegistry;
|
||||
|
||||
Reference in new issue
Block a user