Merge remote-tracking branch 'remotes/origin/master' into master-origin

This commit is contained in:
Vexatos committed 2014-08-19 21:17:14 +02:00
commit b3c74c7911
22 files changed
+123 -180

No files matched your search

@@ -167,7 +167,7 @@ public class ClassMap {
@SuppressWarnings("rawtypes")
public ClassMap(final Class targetClass) {
Field[] fields = targetClass.getFields();
Field[] fields = targetClass.getDeclaredFields();
try {
for (Field field : fields) {
@@ -175,6 +175,7 @@ public class ClassMap {
if (!isNetworkedMember(field))
continue;
field.setAccessible(true);
Type type = field.getGenericType();
if (type instanceof Class && !((Class) type).isArray()) {
@@ -41,7 +41,7 @@ public class PacketIds {
public static final int LETTER_RECIPIENT = 80;
public static final int LETTER_TEXT = 81;
public static final int TRADING_MONIKER_SET = 82;
public static final int TRADING_ADDRESS_SET = 82;
public static final int TRADING_INFO = 83;
public static final int POBOX_INFO = 85;
public static final int POBOX_INFO_REQUEST = 86;
+2 -2
View File
@@ -94,7 +94,7 @@ public class CommandMail extends CommandMC {
demand = StringUtil.append(", ", demand, dmd.stackSize + "x" + dmd.getDisplayName());
}
return String.format("%s%-12s | %-20s | %s", entry, info.address.getIdentifierName(), tradegood, demand);
return String.format("%s%-12s | %-20s | %s", entry, info.address.getName(), tradegood, demand);
}
private void commandVirtualize(ICommandSender sender, String[] arguments) {
@@ -115,6 +115,6 @@ public class CommandMail extends CommandMC {
}
trade.setVirtual(!trade.isVirtual());
sendChatMessage(sender, String.format("\u00A7aSet virtualization for '%s' to %s.", trade.getAddress().getIdentifierName(), trade.isVirtual()));
sendChatMessage(sender, String.format("\u00A7aSet virtualization for '%s' to %s.", trade.getAddress().getName(), trade.isVirtual()));
}
}
+4 -4
View File
@@ -195,7 +195,7 @@ public class Letter implements ILetter, INBTTagable {
if (recipient == null)
return false;
if (StringUtils.isBlank(recipient.getIdentifierName()))
if (StringUtils.isBlank(recipient.getName()))
return false;
return true;
@@ -234,7 +234,7 @@ public class Letter implements ILetter, INBTTagable {
for (MailAddress address : recipient) {
if (recipientString.length() > 0)
recipientString += ", ";
recipientString += address.getIdentifierName();
recipientString += address.getName();
}
return recipientString;
@@ -253,8 +253,8 @@ public class Letter implements ILetter, INBTTagable {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void addTooltip(List list) {
if (this.sender != null && StringUtils.isNotBlank(this.sender.getIdentifierName()))
list.add(StringUtil.localize("gui.mail.from") + ": " + this.sender.getIdentifierName());
if (this.sender != null && StringUtils.isNotBlank(this.sender.getName()))
list.add(StringUtil.localize("gui.mail.from") + ": " + this.sender.getName());
if (this.recipient != null && this.recipient.length > 0)
list.add(StringUtil.localize("gui.mail.to") + ": " + this.getRecipientString());
}
+8 -15
View File
@@ -15,11 +15,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraft.world.WorldSavedData;
import com.mojang.authlib.GameProfile;
import forestry.api.mail.ILetter;
import forestry.api.mail.PostManager;
import forestry.core.utils.InventoryAdapter;
@@ -29,15 +26,15 @@ public class POBox extends WorldSavedData implements IInventory {
public static final String SAVE_NAME = "POBox_";
public static final short SLOT_SIZE = 84;
private GameProfile owner;
private MailAddress address;
private final InventoryAdapter letters = new InventoryAdapter(SLOT_SIZE, "Letters");
public POBox(MailAddress address, boolean isUser) {
public POBox(MailAddress address) {
super(SAVE_NAME + address);
if (!address.isPlayer()) {
throw new IllegalArgumentException("POBox address must be a player");
}
this.owner = (GameProfile)address.getIdentifier();
this.address = address;
}
public POBox(String savename) {
@@ -46,26 +43,22 @@ public class POBox extends WorldSavedData implements IInventory {
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
if (nbttagcompound.hasKey("owner")) {
owner = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("owner"));
if (nbttagcompound.hasKey("address")) {
this.address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address"));
}
letters.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
if (this.owner != null) {
if (this.address != null) {
NBTTagCompound nbt = new NBTTagCompound();
NBTUtil.func_152460_a(nbt, owner);
nbttagcompound.setTag("owner", nbt);
this.address.writeToNBT(nbt);
nbttagcompound.setTag("address", nbt);
}
letters.writeToNBT(nbttagcompound);
}
public GameProfile getOwnerProfile() {
return this.owner;
}
public boolean storeLetter(ItemStack letterstack) {
ILetter letter = PostManager.postRegistry.getLetter(letterstack);
@@ -56,10 +56,10 @@ public class PacketHandlerMail implements IPacketHandler {
packet.readData(data);
onLetterText(player, packet);
break;
case PacketIds.TRADING_MONIKER_SET:
case PacketIds.TRADING_ADDRESS_SET:
packet = new PacketUpdate();
packet.readData(data);
onMonikerSet(player, packet);
onAddressSet(player, packet);
break;
case PacketIds.POBOX_INFO_REQUEST:
onPOBoxInfoRequest(player);
@@ -86,11 +86,11 @@ public class PacketHandlerMail implements IPacketHandler {
PluginMail.proxy.setPOBoxInfo(Proxies.common.getRenderWorld(), address, packet.poboxInfo);
}
private void onMonikerSet(EntityPlayer player, PacketUpdate packet) {
private void onAddressSet(EntityPlayer player, PacketUpdate packet) {
if (!(player.openContainer instanceof ContainerTradeName))
return;
((ContainerTradeName) player.openContainer).handleSetMoniker(packet);
((ContainerTradeName) player.openContainer).handleSetAddress(packet);
}
private void onLetterText(EntityPlayer player, PacketUpdate packet) {
+2 -15
View File
@@ -39,12 +39,9 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
private final int[] collectedPostage = new int[EnumPostage.values().length];
// / CONSTRUCTOR
public PostOffice(String s) {
super(s);
}
public PostOffice() {
public PostOffice(World world) {
super(SAVE_NAME);
refreshActiveTradeStations(world);
}
@Override
@@ -67,9 +64,6 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
@Override
public LinkedHashMap<MailAddress, ITradeStation> getActiveTradeStations(World world) {
if (activeTradeStations == null)
refreshActiveTradeStations(world);
return this.activeTradeStations;
}
@@ -101,19 +95,12 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
@Override
public void registerTradeStation(ITradeStation trade) {
if (activeTradeStations == null)
return;
if (!activeTradeStations.containsKey(trade.getAddress()))
activeTradeStations.put(trade.getAddress(), trade);
}
@Override
public void deregisterTradeStation(ITradeStation trade) {
if (activeTradeStations == null)
return;
activeTradeStations.remove(trade.getAddress());
}
+13 -25
View File
@@ -38,19 +38,13 @@ public class PostRegistry implements IPostRegistry {
public static HashMap<MailAddress, ITradeStation> cachedTradeStations = new HashMap<MailAddress, ITradeStation>();
/**
* @param world
* @param address
* @return true if the passed address is valid for poboxes.
* @param world the Minecraft world the PO box will be in
* @param address the potential address of the PO box
* @return true if the passed address is valid for PO Boxes.
*/
@Override
public boolean isValidPOBox(World world, MailAddress address) {
if (!address.isPlayer())
return false;
GameProfile userProfile = ((GameProfile)address.getIdentifier());
if (!userProfile.getName().matches("^[a-zA-Z0-9]+$"))
return false;
return true;
return address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
}
public static POBox getPOBox(World world, MailAddress address) {
@@ -68,7 +62,7 @@ public class PostRegistry implements IPostRegistry {
POBox pobox = getPOBox(world, address);
if (pobox == null) {
pobox = new POBox(address, true);
pobox = new POBox(address);
world.setItemData(POBox.SAVE_NAME + address, pobox);
pobox.markDirty();
cachedPOBoxes.put(address, pobox);
@@ -79,25 +73,19 @@ public class PostRegistry implements IPostRegistry {
}
/**
* @param world
* @param address
* @param world the Minecraft world the Trader will be in
* @param address the potential address of the Trader
* @return true if the passed address can be an address for a trade station
*/
@Override
public boolean isValidTradeAddress(World world, MailAddress address) {
if (address.isPlayer())
return false;
String moniker = (String)address.getIdentifier();
if (!moniker.matches("^[a-zA-Z0-9]+$"))
return false;
return true;
return !address.isPlayer() && address.getName().matches("^[a-zA-Z0-9]+$");
}
/**
* @param world
* @param address
* @return true if the trade moniker has not yet been used before.
* @param world the Minecraft world the Trader will be in
* @param address the potential address of the Trader
* @return true if the trade address has not yet been used before.
*/
@Override
public boolean isAvailableTradeAddress(World world, MailAddress address) {
@@ -126,7 +114,7 @@ public class PostRegistry implements IPostRegistry {
TradeStation trade = getTradeStation(world, address);
if (trade == null) {
trade = new TradeStation(owner, address, true);
trade = new TradeStation(owner, address);
world.setItemData(TradeStation.SAVE_NAME + address, trade);
trade.markDirty();
cachedTradeStations.put(address, trade);
@@ -159,7 +147,7 @@ public class PostRegistry implements IPostRegistry {
// Create office if there is none yet
if (office == null) {
office = new PostOffice();
office = new PostOffice(world);
world.setItemData(PostOffice.SAVE_NAME, office);
}
@@ -59,7 +59,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
private final InventoryAdapter inventory = new InventoryAdapter(SLOT_SIZE, "INV");
// / CONSTRUCTORS
public TradeStation(GameProfile owner, MailAddress address, boolean isMoniker) {
public TradeStation(GameProfile owner, MailAddress address) {
super(SAVE_NAME + address);
if (address.isPlayer()) {
throw new IllegalArgumentException("TradeStation address must not be a player");
@@ -85,9 +85,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
}
if (nbttagcompound.hasKey("address")) {
if (this.address == null)
this.address = new MailAddress("temp");
this.address.readFromNBT(nbttagcompound.getCompoundTag("address"));
address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address"));
}
this.isVirtual = nbttagcompound.getBoolean("VRT");
@@ -97,15 +95,15 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
if (this.owner != null) {
if (owner != null) {
NBTTagCompound nbt = new NBTTagCompound();
NBTUtil.func_152460_a(nbt, owner);
nbttagcompound.setTag("owner", nbt);
}
if (this.address != null) {
if (address != null) {
NBTTagCompound nbt = new NBTTagCompound();
this.address.writeToNBT(nbt);
address.writeToNBT(nbt);
nbttagcompound.setTag("address", nbt);
}
@@ -251,7 +249,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
nbttagcompound = new NBTTagCompound();
ILetter confirm = new Letter(this.address, new MailAddress(this.owner));
confirm.setText(ordersToFill + " order(s) from " + letter.getSender().getIdentifierName() + " were filled.");
confirm.setText(ordersToFill + " order(s) from " + letter.getSender().getName() + " were filled.");
confirm.addStamps(ForestryItem.stamps.getItemStack(1, EnumPostage.P_1.ordinal() - 1));
confirm.writeToNBT(nbttagcompound);
@@ -13,19 +13,16 @@ package forestry.mail.gadgets;
import java.util.LinkedList;
import forestry.api.mail.MailAddress;
import forestry.core.utils.StringUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTUtil;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.ITrigger;
import com.mojang.authlib.GameProfile;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ISpecialInventory;
@@ -40,12 +37,15 @@ import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.StackUtils;
import forestry.mail.TradeStation;
import forestry.plugins.PluginMail;
import org.apache.commons.lang3.StringUtils;
public class MachineTrader extends TileBase implements ISpecialInventory, ISidedInventory {
@EntityNetData
public String moniker = "";
public MailAddress address;
public MachineTrader() {
address = new MailAddress();
}
@Override
public String getInventoryName() {
@@ -63,7 +63,6 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
@Override
public void onRemoval() {
if (isLinked()) {
MailAddress address = new MailAddress(moniker);
PostManager.postRegistry.deleteTradeStation(worldObj, address);
}
}
@@ -73,8 +72,10 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
if (moniker != null) {
nbttagcompound.setString("moniker", moniker);
if (address != null) {
NBTTagCompound nbt = new NBTTagCompound();
address.writeToNBT(nbt);
nbttagcompound.setTag("address", nbt);
}
}
@@ -82,8 +83,8 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
if (nbttagcompound.hasKey("moniker")) {
moniker = nbttagcompound.getString("moniker");
if (nbttagcompound.hasKey("address")) {
address = MailAddress.loadFromNBT(nbttagcompound.getCompoundTag("address"));
}
}
@@ -109,7 +110,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
/* STATE INFORMATION */
public boolean isLinked() {
return StringUtils.isNotBlank(getMoniker());
return address.isValid();
}
private float percentOccupied(int startSlot, int countSlots) {
@@ -157,16 +158,19 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
return posted >= postage;
}
/* MONIKER */
public String getMoniker() {
return this.moniker;
/* ADDRESS */
public MailAddress getAddress() {
return address;
}
public void setMoniker(String moniker) {
public void setAddress(MailAddress address) {
if (address == null)
throw new NullPointerException("address must not be null");
if (this.address.isValid() && this.address.equals(address))
return;
if (Proxies.common.isSimulating(worldObj)) {
MailAddress address = new MailAddress(moniker);
if (!PostManager.postRegistry.isValidTradeAddress(worldObj, address)) {
setErrorState(EnumErrorCode.NOTALPHANUMERIC);
return;
@@ -177,12 +181,12 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
return;
}
this.moniker = moniker;
this.address = address;
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
setErrorState(EnumErrorCode.OK);
sendNetworkUpdate();
} else
this.moniker = moniker;
this.address = address;
}
/* TRADING */
@@ -192,10 +196,9 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
if (!Proxies.common.isSimulating(worldObj))
return new InventoryAdapter(TradeStation.SLOT_SIZE, "INV");
if (StringUtils.isBlank(this.moniker))
if (!address.isValid())
return new InventoryAdapter(TradeStation.SLOT_SIZE, "INV");
MailAddress address = new MailAddress(this.moniker);
return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
}
@@ -19,8 +19,6 @@ import forestry.api.mail.MailAddress;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import com.mojang.authlib.GameProfile;
import forestry.api.mail.ITradeStation;
import forestry.api.mail.PostManager;
import forestry.api.mail.TradeStationInfo;
@@ -13,11 +13,8 @@ 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;
@@ -143,7 +140,7 @@ public class ContainerLetter extends ContainerItemInventory {
// / Send to server
PacketPayload payload = new PacketPayload(0, 0, 2);
payload.stringPayload[0] = getRecipient().getIdentifierName();
payload.stringPayload[0] = getRecipient().getName();
payload.stringPayload[1] = this.carrier;
PacketUpdate packet = new PacketUpdate(PacketIds.LETTER_RECIPIENT, payload);
@@ -196,7 +193,7 @@ public class ContainerLetter extends ContainerItemInventory {
if (!Proxies.common.isSimulating(world))
return;
if (!address.getType().equals(EnumAddressee.asString(EnumAddressee.TRADER)))
if (address.isPlayer())
return;
ITradeStation station = PostManager.postRegistry.getTradeStation(world, address);
@@ -12,9 +12,6 @@ package forestry.mail.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.server.MinecraftServer;
import com.mojang.authlib.GameProfile;
import forestry.core.gui.ContainerForestry;
import forestry.core.network.PacketIds;
@@ -23,6 +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 org.apache.commons.lang3.StringUtils;
public class ContainerTradeName extends ContainerForestry {
@@ -36,24 +35,29 @@ public class ContainerTradeName extends ContainerForestry {
isLinked = machine.isLinked();
}
public String getMoniker() {
return machine.getMoniker();
public MailAddress getAddress() {
return machine.getAddress();
}
public void setMoniker(String moniker) {
public void setAddress(String addressName) {
if (StringUtils.isBlank(moniker))
if (StringUtils.isBlank(addressName))
return;
PacketPayload payload = new PacketPayload(0, 0, 1);
payload.stringPayload[0] = moniker;
payload.stringPayload[0] = addressName;
PacketUpdate packet = new PacketUpdate(PacketIds.TRADING_MONIKER_SET, payload);
PacketUpdate packet = new PacketUpdate(PacketIds.TRADING_ADDRESS_SET, payload);
Proxies.net.sendToServer(packet);
MailAddress address = new MailAddress(addressName);
machine.setAddress(address);
}
public void handleSetMoniker(PacketUpdate packet) {
machine.setMoniker(packet.payload.stringPayload[0]);
public void handleSetAddress(PacketUpdate packet) {
String addressName = packet.payload.stringPayload[0];
MailAddress address = new MailAddress(addressName);
machine.setAddress(address);
}
@Override
@@ -15,14 +15,13 @@ import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import com.mojang.authlib.GameProfile;
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;
public class ContainerTrader extends ContainerForestry {
@@ -73,11 +72,11 @@ public class ContainerTrader extends ContainerForestry {
}
public boolean isLinked() {
return getMoniker() != null;
return machine.isLinked();
}
public String getMoniker() {
return machine.getMoniker();
public MailAddress getAddress() {
return machine.getAddress();
}
}
@@ -10,8 +10,6 @@
******************************************************************************/
package forestry.mail.gui;
import java.util.Locale;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
@@ -93,7 +91,7 @@ public class GuiCatalogue extends GuiForestry<TileForestry> {
private void drawTradePreview(int x, int y) {
fontRendererObj.drawString("\u00A7l\u00A7n" + container.getTradeInfo().address.getIdentifierName(), x, y, fontColor.get("gui.book"));
fontRendererObj.drawString("\u00A7l\u00A7n" + container.getTradeInfo().address.getName(), x, y, fontColor.get("gui.book"));
TradeStationInfo info = container.getTradeInfo();
fontRendererObj.drawString(String.format(StringUtil.localize("gui.mail.willtrade"), info.owner.getName()), x, y + 18, fontColor.get("gui.book"));
@@ -137,7 +135,7 @@ public class GuiCatalogue extends GuiForestry<TileForestry> {
case 5:
TradeStationInfo info = container.getTradeInfo();
if(info != null) {
SessionVars.setStringVar("mail.letter.recipient", info.address.getIdentifierName());
SessionVars.setStringVar("mail.letter.recipient", info.address.getName());
SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.asString(EnumAddressee.TRADER));
}
mc.displayGuiScreen((GuiScreen)null);
@@ -97,7 +97,7 @@ public class GuiLetter extends GuiForestry<TileForestry> {
address = new GuiTextField(this.fontRendererObj, guiLeft + 46, guiTop + 13, 93, 13);
MailAddress recipient = container.getRecipient();
if (recipient != null) {
address.setText(recipient.getIdentifierName());
address.setText(recipient.getName());
setRecipient(recipient);
}
@@ -24,9 +24,9 @@ import forestry.mail.gadgets.MachineTrader;
public class GuiTradeName extends GuiForestry<MachineTrader> {
private GuiTextField moniker;
private GuiTextField addressNameField;
private boolean monikerFocus;
private boolean addressNameFocus;
private final ContainerTradeName container;
@@ -42,20 +42,23 @@ public class GuiTradeName extends GuiForestry<MachineTrader> {
public void initGui() {
super.initGui();
moniker = new GuiTextField(this.fontRendererObj, guiLeft + 44, guiTop + 39, 90, 14);
if (container.getMoniker() != null)
moniker.setText(container.getMoniker());
addressNameField = new GuiTextField(this.fontRendererObj, guiLeft + 44, guiTop + 39, 90, 14);
if (container.getAddress() != null)
addressNameField.setText(container.getAddress().getName());
addressNameField.setFocused(true);
}
@Override
protected void keyTyped(char eventCharacter, int eventKey) {
// Set focus or enter text into address
if (this.moniker.isFocused()) {
if (eventKey == Keyboard.KEY_RETURN)
this.moniker.setFocused(false);
else
this.moniker.textboxKeyTyped(eventCharacter, eventKey);
if (addressNameField.isFocused()) {
if (eventKey == Keyboard.KEY_RETURN) {
addressNameFocus = true;
addressNameField.setFocused(false);
} else {
addressNameField.textboxKeyTyped(eventCharacter, eventKey);
}
return;
}
@@ -65,12 +68,11 @@ public class GuiTradeName extends GuiForestry<MachineTrader> {
@Override
protected void mouseClicked(int par1, int par2, int mouseButton) {
super.mouseClicked(par1, par2, mouseButton);
this.moniker.mouseClicked(par1, par2, mouseButton);
addressNameField.mouseClicked(par1, par2, mouseButton);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) {
// Close gui screen if we linked up.
if (container.machine.isLinked()) {
this.mc.displayGuiScreen((GuiScreen) null);
@@ -78,28 +80,28 @@ public class GuiTradeName extends GuiForestry<MachineTrader> {
}
// Check for focus changes
if (monikerFocus != moniker.isFocused())
setMoniker();
monikerFocus = moniker.isFocused();
if (addressNameFocus && !addressNameField.isFocused())
this.setAddress();
addressNameFocus = addressNameField.isFocused();
super.drawGuiContainerBackgroundLayer(var1, var2, var3);
String prompt = StringUtil.localize("gui.mail.nametrader");
fontRendererObj.drawString(prompt, guiLeft + this.getCenteredOffset(prompt), guiTop + 16, fontColor.get("gui.mail.text"));
moniker.drawTextBox();
addressNameField.drawTextBox();
}
@Override
public void onGuiClosed() {
setMoniker();
setAddress();
super.onGuiClosed();
}
private void setMoniker() {
String monikerText = this.moniker.getText();
if (StringUtils.isNotBlank(monikerText))
container.setMoniker(monikerText);
private void setAddress() {
String address = addressNameField.getText();
if (StringUtils.isNotBlank(address))
container.setAddress(address);
}
}
@@ -16,6 +16,7 @@ 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> {
@@ -40,7 +41,6 @@ public class GuiTrader extends GuiForestry<MachineTrader> {
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
fontRendererObj.drawString(container.getMoniker(), guiLeft + 19, guiTop + 22, fontColor.get("gui.mail.text"));
fontRendererObj.drawString(container.getAddress().getName(), guiLeft + 19, guiTop + 22, fontColor.get("gui.mail.text"));
}
}
@@ -46,8 +46,7 @@ public class PacketTradeInfo extends ForestryPacket {
data.writeShort(0);
String moniker = tradeInfo.address.getIdentifierName();
data.writeUTF(moniker);
data.writeUTF(tradeInfo.address.getName());
data.writeLong(tradeInfo.owner.getId().getMostSignificantBits());
data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits());
@@ -67,7 +66,7 @@ public class PacketTradeInfo extends ForestryPacket {
if (isNotNull < 0)
return;
String moniker = data.readUTF();
MailAddress address = new MailAddress(data.readUTF());
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
ItemStack tradegood;
ItemStack[] required;
@@ -77,7 +76,6 @@ public class PacketTradeInfo extends ForestryPacket {
for (int i = 0; i < required.length; i++)
required[i] = readItemStack(data);
MailAddress address = new MailAddress(moniker);
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]);
}
@@ -11,11 +11,8 @@
package forestry.mail.proxy;
import forestry.api.mail.MailAddress;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.core.network.ForestryPacket;
import forestry.core.network.PacketIds;
import forestry.core.proxy.Proxies;
@@ -50,15 +47,7 @@ public class ClientProxyMail extends ProxyMail {
@Override
public void setPOBoxInfo(World world, MailAddress address, POBoxInfo info) {
if (!address.isPlayer())
throw new IllegalArgumentException("POBox address must be a player");
GameProfile playerProfile = (GameProfile)address.getIdentifier();
EntityClientPlayerMP player = Proxies.common.getClientInstance().thePlayer;
if (player == null || !player.getGameProfile().equals(playerProfile))
return;
GuiMailboxInfo.instance.setPOBoxInfo(info);
if (address.isClientPlayer(world))
GuiMailboxInfo.instance.setPOBoxInfo(info);
}
}
@@ -11,11 +11,9 @@
package forestry.mail.proxy;
import forestry.api.mail.MailAddress;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.core.network.PacketIds;
import forestry.core.proxy.Proxies;
import forestry.mail.POBoxInfo;
@@ -30,18 +28,8 @@ public class ProxyMail {
}
public void setPOBoxInfo(World world, MailAddress address, POBoxInfo info) {
if (!address.isPlayer())
throw new IllegalArgumentException("address must be a player");
GameProfile playerProfile = (GameProfile)address.getIdentifier();
for (int i = 0; i < world.playerEntities.size(); i++) {
EntityPlayerMP player = (EntityPlayerMP) world.playerEntities.get(i);
if (!player.getGameProfile().equals(playerProfile))
continue;
EntityPlayer player = address.getPlayer(world);
if (player != null)
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player);
break;
}
}
}