mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Merge branch 'mailSystemFixes' of git://github.com/mezz/ForestryMC into mezz-mailSystemFixes
This commit is contained in:
commit
ac6b684ca0
24 files changed
+216
-181
No files matched your search
@@ -64,8 +64,8 @@ public abstract class TileBase extends TileForestry implements IHintSource {
|
||||
|
||||
try {
|
||||
classmap.setData(this, payload.intPayload, payload.floatPayload, payload.stringPayload, new IndexInPayload(0, 0, 0));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return payload;
|
||||
|
||||
@@ -12,6 +12,7 @@ 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;
|
||||
@@ -96,7 +97,7 @@ public class CommandMail extends CommandMC {
|
||||
demand = StringUtil.append(", ", demand, dmd.stackSize + "x" + dmd.getDisplayName());
|
||||
}
|
||||
|
||||
return String.format("%s%-12s | %-20s | %s", entry, info.moniker, tradegood, demand);
|
||||
return String.format("%s%-12s | %-20s | %s", entry, info.address.getIdentifierName(), tradegood, demand);
|
||||
}
|
||||
|
||||
private void commandVirtualize(ICommandSender sender, String[] arguments) {
|
||||
@@ -109,14 +110,14 @@ public class CommandMail extends CommandMC {
|
||||
throw new WrongUsageException("/" + getCommandName() + " virtualize <tradestation-name>");
|
||||
|
||||
World world = getWorld(sender, arguments);
|
||||
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(arguments[1]);
|
||||
ITradeStation trade = PostManager.postRegistry.getTradeStation(world, profile);
|
||||
MailAddress address = new MailAddress(arguments[1]);
|
||||
ITradeStation trade = PostManager.postRegistry.getTradeStation(world, address);
|
||||
if (trade == null) {
|
||||
sendChatMessage(sender, String.format("\u00a7cNo tradestation by the name of '%s' was found.", arguments[1]));
|
||||
return;
|
||||
}
|
||||
|
||||
trade.setVirtual(!trade.isVirtual());
|
||||
sendChatMessage(sender, String.format("\u00A7aSet virtualization for '%s' to %s.", trade.getMoniker(), trade.isVirtual()));
|
||||
sendChatMessage(sender, String.format("\u00A7aSet virtualization for '%s' to %s.", trade.getAddress().getIdentifierName(), trade.isVirtual()));
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public enum EnumAddressee {
|
||||
PLAYER, TRADER;
|
||||
|
||||
@@ -21,4 +23,8 @@ public enum EnumAddressee {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String asString(EnumAddressee addressee) {
|
||||
return addressee.toString().toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import forestry.api.mail.IStamps;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class Letter implements ILetter, INBTTagable {
|
||||
|
||||
@@ -194,7 +195,7 @@ public class Letter implements ILetter, INBTTagable {
|
||||
if (recipient == null)
|
||||
return false;
|
||||
|
||||
if (recipient.getProfile() == null)
|
||||
if (StringUtils.isBlank(recipient.getIdentifierName()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -233,7 +234,7 @@ public class Letter implements ILetter, INBTTagable {
|
||||
for (MailAddress address : recipient) {
|
||||
if (recipientString.length() > 0)
|
||||
recipientString += ", ";
|
||||
recipientString += address.getProfile().getName();
|
||||
recipientString += address.getIdentifierName();
|
||||
}
|
||||
|
||||
return recipientString;
|
||||
@@ -252,8 +253,8 @@ public class Letter implements ILetter, INBTTagable {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public void addTooltip(List list) {
|
||||
if (this.sender != null && this.sender.getProfile() != null)
|
||||
list.add(StringUtil.localize("gui.mail.from") + ": " + this.sender.getProfile().getName());
|
||||
if (this.sender != null && StringUtils.isNotBlank(this.sender.getIdentifierName()))
|
||||
list.add(StringUtil.localize("gui.mail.from") + ": " + this.sender.getIdentifierName());
|
||||
if (this.recipient != null && this.recipient.length > 0)
|
||||
list.add(StringUtil.localize("gui.mail.to") + ": " + this.getRecipientString());
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -31,9 +32,12 @@ public class POBox extends WorldSavedData implements IInventory {
|
||||
private GameProfile owner;
|
||||
private final InventoryAdapter letters = new InventoryAdapter(SLOT_SIZE, "Letters");
|
||||
|
||||
public POBox(GameProfile owner, boolean isUser) {
|
||||
super(SAVE_NAME + owner);
|
||||
this.owner = owner;
|
||||
public POBox(MailAddress address, boolean isUser) {
|
||||
super(SAVE_NAME + address);
|
||||
if (!address.isPlayer()) {
|
||||
throw new IllegalArgumentException("POBox address must be a player");
|
||||
}
|
||||
this.owner = (GameProfile)address.getIdentifier();
|
||||
}
|
||||
|
||||
public POBox(String savename) {
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.mail;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
|
||||
@@ -81,7 +82,8 @@ public class PacketHandlerMail implements IPacketHandler {
|
||||
}
|
||||
|
||||
private void onPOBoxInfo(PacketPOBoxInfo packet) {
|
||||
PluginMail.proxy.setPOBoxInfo(Proxies.common.getRenderWorld(), Proxies.common.getClientInstance().thePlayer.getGameProfile(), packet.poboxInfo);
|
||||
MailAddress address = new MailAddress(Proxies.common.getClientInstance().thePlayer.getGameProfile());
|
||||
PluginMail.proxy.setPOBoxInfo(Proxies.common.getRenderWorld(), address, packet.poboxInfo);
|
||||
}
|
||||
|
||||
private void onMonikerSet(EntityPlayer player, PacketUpdate packet) {
|
||||
@@ -106,7 +108,8 @@ public class PacketHandlerMail implements IPacketHandler {
|
||||
}
|
||||
|
||||
private void onPOBoxInfoRequest(EntityPlayer player) {
|
||||
POBox pobox = PostRegistry.getPOBox(player.worldObj, player.getGameProfile());
|
||||
MailAddress address = new MailAddress(player.getGameProfile());
|
||||
POBox pobox = PostRegistry.getPOBox(player.worldObj, address);
|
||||
if (pobox == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -63,10 +63,10 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
}
|
||||
|
||||
/* TRADE STATION MANAGMENT */
|
||||
private LinkedHashMap<GameProfile, ITradeStation> activeTradeStations;
|
||||
private LinkedHashMap<MailAddress, ITradeStation> activeTradeStations;
|
||||
|
||||
@Override
|
||||
public LinkedHashMap<GameProfile, ITradeStation> getActiveTradeStations(World world) {
|
||||
public LinkedHashMap<MailAddress, ITradeStation> getActiveTradeStations(World world) {
|
||||
if (activeTradeStations == null)
|
||||
refreshActiveTradeStations(world);
|
||||
|
||||
@@ -74,7 +74,7 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
}
|
||||
|
||||
private void refreshActiveTradeStations(World world) {
|
||||
activeTradeStations = new LinkedHashMap<GameProfile, ITradeStation>();
|
||||
activeTradeStations = new LinkedHashMap<MailAddress, ITradeStation>();
|
||||
if (world == null || world.getSaveHandler() == null)
|
||||
return;
|
||||
File worldSave = world.getSaveHandler().getMapFileFromName("dummy");
|
||||
@@ -90,10 +90,8 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
if (!str.endsWith(".dat"))
|
||||
continue;
|
||||
|
||||
String[] parts = str.replace(TradeStation.SAVE_NAME, "").replace(".dat", "").split("_");
|
||||
if (parts.length != 2) continue;
|
||||
|
||||
ITradeStation trade = PostManager.postRegistry.getTradeStation(world, new GameProfile(UUID.fromString(parts[0]), parts[1]));
|
||||
MailAddress address = new MailAddress(str.replace(TradeStation.SAVE_NAME, "").replace(".dat", ""));
|
||||
ITradeStation trade = PostManager.postRegistry.getTradeStation(world, address);
|
||||
if (trade == null)
|
||||
continue;
|
||||
|
||||
@@ -106,8 +104,8 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
if (activeTradeStations == null)
|
||||
return;
|
||||
|
||||
if (!activeTradeStations.containsKey(trade.getMoniker()))
|
||||
activeTradeStations.put(trade.getMoniker(), trade);
|
||||
if (!activeTradeStations.containsKey(trade.getAddress()))
|
||||
activeTradeStations.put(trade.getAddress(), trade);
|
||||
|
||||
}
|
||||
|
||||
@@ -116,7 +114,7 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
if (activeTradeStations == null)
|
||||
return;
|
||||
|
||||
activeTradeStations.remove(trade.getMoniker());
|
||||
activeTradeStations.remove(trade.getAddress());
|
||||
}
|
||||
|
||||
// / STAMP MANAGMENT
|
||||
@@ -173,7 +171,7 @@ public class PostOffice extends WorldSavedData implements IPostOffice {
|
||||
IPostalCarrier carrier = PostManager.postRegistry.getCarrier(address.getType());
|
||||
if (carrier == null)
|
||||
continue;
|
||||
state = carrier.deliverLetter(world, this, address.getProfile(), itemstack, doLodge);
|
||||
state = carrier.deliverLetter(world, this, address, itemstack, doLodge);
|
||||
if (!state.isOk())
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -34,42 +34,45 @@ import forestry.plugins.PluginMail;
|
||||
public class PostRegistry implements IPostRegistry {
|
||||
|
||||
public static PostOffice cachedPostOffice;
|
||||
public static HashMap<GameProfile, POBox> cachedPOBoxes = new HashMap<GameProfile, POBox>();
|
||||
public static HashMap<GameProfile, ITradeStation> cachedTradeStations = new HashMap<GameProfile, ITradeStation>();
|
||||
public static HashMap<MailAddress, POBox> cachedPOBoxes = new HashMap<>();
|
||||
public static HashMap<MailAddress, ITradeStation> cachedTradeStations = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param username
|
||||
* @return true if the passed username is valid for poboxes.
|
||||
* @param address
|
||||
* @return true if the passed address is valid for poboxes.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidPOBox(World world, GameProfile username) {
|
||||
if (!username.getName().matches("^[a-zA-Z0-9]+$"))
|
||||
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;
|
||||
}
|
||||
|
||||
public static POBox getPOBox(World world, GameProfile username) {
|
||||
public static POBox getPOBox(World world, MailAddress address) {
|
||||
|
||||
if (cachedPOBoxes.containsKey(username))
|
||||
return cachedPOBoxes.get(username);
|
||||
if (cachedPOBoxes.containsKey(address))
|
||||
return cachedPOBoxes.get(address);
|
||||
|
||||
POBox pobox = (POBox) world.loadItemData(POBox.class, POBox.SAVE_NAME + username.getId());
|
||||
POBox pobox = (POBox) world.loadItemData(POBox.class, POBox.SAVE_NAME + address);
|
||||
if (pobox != null)
|
||||
cachedPOBoxes.put(username, pobox);
|
||||
cachedPOBoxes.put(address, pobox);
|
||||
return pobox;
|
||||
}
|
||||
|
||||
public static POBox getOrCreatePOBox(World world, GameProfile username) {
|
||||
POBox pobox = getPOBox(world, username);
|
||||
public static POBox getOrCreatePOBox(World world, MailAddress address) {
|
||||
POBox pobox = getPOBox(world, address);
|
||||
|
||||
if (pobox == null) {
|
||||
pobox = new POBox(username, true);
|
||||
world.setItemData(POBox.SAVE_NAME + username.getId(), pobox);
|
||||
pobox = new POBox(address, true);
|
||||
world.setItemData(POBox.SAVE_NAME + address, pobox);
|
||||
pobox.markDirty();
|
||||
cachedPOBoxes.put(username, pobox);
|
||||
PluginMail.proxy.setPOBoxInfo(world, username, pobox.getPOBoxInfo());
|
||||
cachedPOBoxes.put(address, pobox);
|
||||
PluginMail.proxy.setPOBoxInfo(world, address, pobox.getPOBoxInfo());
|
||||
}
|
||||
|
||||
return pobox;
|
||||
@@ -77,12 +80,15 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param moniker
|
||||
* @return true if the passed moniker can be a moniker for a trade station
|
||||
* @param address
|
||||
* @return true if the passed address can be an address for a trade station
|
||||
*/
|
||||
@Override
|
||||
public boolean isValidTradeMoniker(World world, GameProfile moniker) {
|
||||
if (!moniker.getName().matches("^[a-zA-Z0-9]+$"))
|
||||
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;
|
||||
@@ -90,24 +96,24 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
/**
|
||||
* @param world
|
||||
* @param moniker
|
||||
* @param address
|
||||
* @return true if the trade moniker has not yet been used before.
|
||||
*/
|
||||
@Override
|
||||
public boolean isAvailableTradeMoniker(World world, GameProfile moniker) {
|
||||
return getTradeStation(world, moniker) == null;
|
||||
public boolean isAvailableTradeAddress(World world, MailAddress address) {
|
||||
return getTradeStation(world, address) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStation getTradeStation(World world, GameProfile moniker) {
|
||||
if (cachedTradeStations.containsKey(moniker))
|
||||
return (TradeStation)cachedTradeStations.get(moniker);
|
||||
public TradeStation getTradeStation(World world, MailAddress address) {
|
||||
if (cachedTradeStations.containsKey(address))
|
||||
return (TradeStation)cachedTradeStations.get(address);
|
||||
|
||||
TradeStation trade = (TradeStation) world.loadItemData(TradeStation.class, TradeStation.SAVE_NAME + moniker.getId()+"_"+moniker.getName());
|
||||
TradeStation trade = (TradeStation) world.loadItemData(TradeStation.class, TradeStation.SAVE_NAME + address);
|
||||
|
||||
// Only existing and valid mail orders are returned
|
||||
if (trade != null && trade.isValid()) {
|
||||
cachedTradeStations.put(moniker, trade);
|
||||
cachedTradeStations.put(address, trade);
|
||||
getPostOffice(world).registerTradeStation(trade);
|
||||
return trade;
|
||||
}
|
||||
@@ -116,14 +122,14 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public TradeStation getOrCreateTradeStation(World world, GameProfile owner, GameProfile moniker) {
|
||||
TradeStation trade = getTradeStation(world, moniker);
|
||||
public TradeStation getOrCreateTradeStation(World world, GameProfile owner, MailAddress address) {
|
||||
TradeStation trade = getTradeStation(world, address);
|
||||
|
||||
if (trade == null) {
|
||||
trade = new TradeStation(owner, moniker, true);
|
||||
world.setItemData(TradeStation.SAVE_NAME + moniker.getId()+"_"+moniker.getName(), trade);
|
||||
trade = new TradeStation(owner, address, true);
|
||||
world.setItemData(TradeStation.SAVE_NAME + address, trade);
|
||||
trade.markDirty();
|
||||
cachedTradeStations.put(moniker, trade);
|
||||
cachedTradeStations.put(address, trade);
|
||||
getPostOffice(world).registerTradeStation(trade);
|
||||
}
|
||||
|
||||
@@ -131,14 +137,14 @@ public class PostRegistry implements IPostRegistry {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTradeStation(World world, GameProfile moniker) {
|
||||
TradeStation trade = getTradeStation(world, moniker);
|
||||
public void deleteTradeStation(World world, MailAddress address) {
|
||||
TradeStation trade = getTradeStation(world, address);
|
||||
if (trade == null)
|
||||
return;
|
||||
|
||||
// Need to be marked as invalid since WorldSavedData seems to do some caching of its own.
|
||||
trade.invalidate();
|
||||
cachedTradeStations.remove(moniker);
|
||||
cachedTradeStations.remove(address);
|
||||
getPostOffice(world).deregisterTradeStation(trade);
|
||||
File file = world.getSaveHandler().getMapFileFromName(trade.mapName);
|
||||
file.delete();
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.mail;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import forestry.api.mail.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
@@ -21,11 +22,6 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.mail.IPostOffice;
|
||||
import forestry.api.mail.IPostalCarrier;
|
||||
import forestry.api.mail.IPostalState;
|
||||
import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.plugins.PluginMail;
|
||||
@@ -59,14 +55,14 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPostalState deliverLetter(World world, IPostOffice office, GameProfile recipient, ItemStack letterstack, boolean doDeliver) {
|
||||
public IPostalState deliverLetter(World world, IPostOffice office, MailAddress 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, GameProfile recipient, ItemStack letterstack, boolean doLodge) {
|
||||
private IPostalState handleTradeLetter(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
IPostalState state = EnumDeliveryState.NOT_MAILABLE;
|
||||
|
||||
ITradeStation trade = PostManager.postRegistry.getTradeStation(world, recipient);
|
||||
@@ -78,7 +74,7 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
return state;
|
||||
}
|
||||
|
||||
private EnumDeliveryState storeInPOBox(World world, IPostOffice office, GameProfile recipient, ItemStack letterstack, boolean doLodge) {
|
||||
private EnumDeliveryState storeInPOBox(World world, IPostOffice office, MailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
|
||||
POBox pobox = PostRegistry.getPOBox(world, recipient);
|
||||
if (pobox == null)
|
||||
|
||||
@@ -36,6 +36,7 @@ import forestry.core.config.ForestryItem;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.mail.items.ItemLetter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class TradeStation extends WorldSavedData implements ITradeStation, IInventory {
|
||||
|
||||
@@ -54,16 +55,19 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
public static final short SLOT_BUFFER_COUNT = 12;
|
||||
// / MEMBER
|
||||
private GameProfile owner;
|
||||
private GameProfile moniker;
|
||||
private MailAddress address;
|
||||
private boolean isVirtual = false;
|
||||
private boolean isInvalid = false;
|
||||
private final InventoryAdapter inventory = new InventoryAdapter(SLOT_SIZE, "INV");
|
||||
|
||||
// / CONSTRUCTORS
|
||||
public TradeStation(GameProfile owner, GameProfile moniker, boolean isMoniker) {
|
||||
super(SAVE_NAME + moniker.getId()+"_"+moniker.getName());
|
||||
public TradeStation(GameProfile owner, MailAddress address, boolean isMoniker) {
|
||||
super(SAVE_NAME + address);
|
||||
if (address.isPlayer()) {
|
||||
throw new IllegalArgumentException("TradeStation address must not be a player");
|
||||
}
|
||||
this.owner = owner;
|
||||
this.moniker = moniker;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public TradeStation(String savename) {
|
||||
@@ -71,8 +75,8 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameProfile getMoniker() {
|
||||
return this.moniker;
|
||||
public MailAddress getAddress() {
|
||||
return this.address;
|
||||
}
|
||||
|
||||
// / SAVING & LOADING
|
||||
@@ -81,9 +85,13 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
if (nbttagcompound.hasKey("owner")) {
|
||||
owner = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("owner"));
|
||||
}
|
||||
if (nbttagcompound.hasKey("moniker")) {
|
||||
moniker = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("moniker"));
|
||||
|
||||
if (nbttagcompound.hasKey("address")) {
|
||||
if (this.address == null)
|
||||
this.address = new MailAddress("temp");
|
||||
this.address.readFromNBT(nbttagcompound.getCompoundTag("address"));
|
||||
}
|
||||
|
||||
this.isVirtual = nbttagcompound.getBoolean("VRT");
|
||||
this.isInvalid = nbttagcompound.getBoolean("IVL");
|
||||
inventory.readFromNBT(nbttagcompound);
|
||||
@@ -97,10 +105,10 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
nbttagcompound.setTag("owner", nbt);
|
||||
}
|
||||
|
||||
if (this.moniker != null) {
|
||||
if (this.address != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a(nbt, moniker);
|
||||
nbttagcompound.setTag("moniker", nbt);
|
||||
this.address.writeToNBT(nbt);
|
||||
nbttagcompound.setTag("address", nbt);
|
||||
}
|
||||
|
||||
nbttagcompound.setBoolean("VRT", this.isVirtual);
|
||||
@@ -148,12 +156,12 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
state = EnumStationState.INSUFFICIENT_TRADE_GOOD;
|
||||
}
|
||||
|
||||
return new TradeStationInfo(moniker, owner, inventory.getStackInSlot(SLOT_TRADEGOOD), condensedRequired, state);
|
||||
return new TradeStationInfo(address, owner, inventory.getStackInSlot(SLOT_TRADEGOOD), condensedRequired, state);
|
||||
}
|
||||
|
||||
/* ILETTERHANDLER */
|
||||
@Override
|
||||
public IPostalState handleLetter(World world, GameProfile recipient, ItemStack letterstack, boolean doLodge) {
|
||||
public IPostalState handleLetter(World world, MailAddress recipient, ItemStack letterstack, boolean doLodge) {
|
||||
|
||||
ILetter letter = PostManager.postRegistry.getLetter(letterstack);
|
||||
|
||||
@@ -182,7 +190,7 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
}
|
||||
|
||||
// Prepare and send letter
|
||||
ILetter mail = new Letter(new MailAddress(this.moniker, EnumAddressee.TRADER.toString().toLowerCase(Locale.ENGLISH)), letter.getSender());
|
||||
ILetter mail = new Letter(this.address, letter.getSender());
|
||||
mail.setText("Please find your order attached.");
|
||||
for (int i = 0; i < ordersToFill; i++) {
|
||||
mail.addAttachment(inventory.getStackInSlot(SLOT_TRADEGOOD).copy());
|
||||
@@ -229,8 +237,8 @@ public class TradeStation extends WorldSavedData implements ITradeStation, IInve
|
||||
|
||||
// Send confirmation message to seller
|
||||
if (doLodge && owner != null) {
|
||||
ILetter confirm = new Letter(new MailAddress(this.moniker, EnumAddressee.TRADER.toString().toLowerCase(Locale.ENGLISH)), new MailAddress(this.owner));
|
||||
confirm.setText(ordersToFill + " order(s) from " + letter.getSender().getProfile().getName() + " were filled.");
|
||||
ILetter confirm = new Letter(this.address, new MailAddress(this.owner));
|
||||
confirm.setText(ordersToFill + " order(s) from " + letter.getSender().getIdentifierName() + " were filled.");
|
||||
confirm.addStamps(ForestryItem.stamps.getItemStack(1, EnumPostage.P_1.ordinal()));
|
||||
nbttagcompound = new NBTTagCompound();
|
||||
confirm.writeToNBT(nbttagcompound);
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.mail.gadgets;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
@@ -72,21 +73,6 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
|
||||
player.openGui(ForestryAPI.instance, GuiId.MailboxGUI.ordinal(), player.worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound.setBoolean("LNK", this.isLinked);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
this.isLinked = nbttagcompound.getBoolean("LNK");
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
@@ -106,7 +92,8 @@ public class MachineMailbox extends TileBase implements IMailContainer, ISpecial
|
||||
if (getOwnerProfile() == null)
|
||||
return new InventoryAdapter(POBox.SLOT_SIZE, "Letters");
|
||||
|
||||
return PostRegistry.getOrCreatePOBox(worldObj, getOwnerProfile());
|
||||
MailAddress address = new MailAddress(getOwnerProfile());
|
||||
return PostRegistry.getOrCreatePOBox(worldObj, address);
|
||||
}
|
||||
|
||||
private IPostalState tryDispatchLetter(ItemStack letterstack, boolean dispatchLetter) {
|
||||
|
||||
@@ -12,6 +12,8 @@ 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;
|
||||
@@ -38,11 +40,12 @@ 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 GameProfile moniker;
|
||||
public String moniker = "";
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
@@ -59,8 +62,10 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
|
||||
@Override
|
||||
public void onRemoval() {
|
||||
if (isLinked())
|
||||
PostManager.postRegistry.deleteTradeStation(worldObj, moniker);
|
||||
if (isLinked()) {
|
||||
MailAddress address = new MailAddress(moniker);
|
||||
PostManager.postRegistry.deleteTradeStation(worldObj, address);
|
||||
}
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@@ -68,10 +73,8 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
if (this.moniker != null) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
NBTUtil.func_152460_a(nbt, moniker);
|
||||
nbttagcompound.setTag("moniker", nbt);
|
||||
if (moniker != null) {
|
||||
nbttagcompound.setString("moniker", moniker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +83,7 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
if (nbttagcompound.hasKey("moniker")) {
|
||||
moniker = NBTUtil.func_152459_a(nbttagcompound.getCompoundTag("moniker"));
|
||||
moniker = nbttagcompound.getString("moniker");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +94,6 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
if (worldObj.getTotalWorldTime() % 40 * 10 != 0)
|
||||
return;
|
||||
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
|
||||
if (!hasPaperMin(0.0f) || !hasInputBufMin(0.0f)) {
|
||||
setErrorState(EnumErrorCode.NORESOURCE);
|
||||
return;
|
||||
@@ -102,12 +103,13 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
return;
|
||||
}
|
||||
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
}
|
||||
|
||||
/* STATE INFORMATION */
|
||||
|
||||
public boolean isLinked() {
|
||||
return getMoniker() != null;
|
||||
return StringUtils.isNotBlank(getMoniker());
|
||||
}
|
||||
|
||||
private float percentOccupied(int startSlot, int countSlots) {
|
||||
@@ -156,25 +158,27 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
}
|
||||
|
||||
/* MONIKER */
|
||||
public GameProfile getMoniker() {
|
||||
public String getMoniker() {
|
||||
return this.moniker;
|
||||
}
|
||||
|
||||
public void setMoniker(GameProfile moniker) {
|
||||
public void setMoniker(String moniker) {
|
||||
|
||||
if (Proxies.common.isSimulating(worldObj)) {
|
||||
if (!PostManager.postRegistry.isValidTradeMoniker(worldObj, moniker)) {
|
||||
MailAddress address = new MailAddress(moniker);
|
||||
|
||||
if (!PostManager.postRegistry.isValidTradeAddress(worldObj, address)) {
|
||||
setErrorState(EnumErrorCode.NOTALPHANUMERIC);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!PostManager.postRegistry.isAvailableTradeMoniker(worldObj, moniker)) {
|
||||
if (!PostManager.postRegistry.isAvailableTradeAddress(worldObj, address)) {
|
||||
setErrorState(EnumErrorCode.NOTUNIQUE);
|
||||
return;
|
||||
}
|
||||
|
||||
this.moniker = moniker;
|
||||
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), this.moniker);
|
||||
PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
sendNetworkUpdate();
|
||||
} else
|
||||
@@ -188,10 +192,11 @@ public class MachineTrader extends TileBase implements ISpecialInventory, ISided
|
||||
if (!Proxies.common.isSimulating(worldObj))
|
||||
return new InventoryAdapter(TradeStation.SLOT_SIZE, "INV");
|
||||
|
||||
if (this.moniker == null)
|
||||
if (StringUtils.isBlank(this.moniker))
|
||||
return new InventoryAdapter(TradeStation.SLOT_SIZE, "INV");
|
||||
|
||||
return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), this.moniker);
|
||||
MailAddress address = new MailAddress(this.moniker);
|
||||
return PostManager.postRegistry.getOrCreateTradeStation(worldObj, getOwnerProfile(), address);
|
||||
}
|
||||
|
||||
/* ISPECIALINVENTORY */
|
||||
|
||||
@@ -15,6 +15,7 @@ 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;
|
||||
|
||||
@@ -35,7 +36,7 @@ import forestry.mail.network.PacketTradeInfo;
|
||||
public class ContainerCatalogue extends ContainerForestry implements IGuiSelectable {
|
||||
|
||||
private final EntityPlayer player;
|
||||
private final LinkedHashMap<GameProfile, ITradeStation> stations;
|
||||
private final LinkedHashMap<MailAddress, ITradeStation> stations;
|
||||
private TradeStationInfo currentTrade = null;
|
||||
private Iterator<ITradeStation> iterator = null;
|
||||
|
||||
@@ -58,7 +59,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<GameProfile, ITradeStation>();
|
||||
stations = new LinkedHashMap<MailAddress, ITradeStation>();
|
||||
rebuildStationsList();
|
||||
}
|
||||
|
||||
@@ -79,7 +80,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta
|
||||
continue;
|
||||
}
|
||||
|
||||
stations.put(station.getMoniker(), station);
|
||||
stations.put(station.getAddress(), station);
|
||||
}
|
||||
maxItPos = stations.size();
|
||||
resetIteration();
|
||||
@@ -129,7 +130,7 @@ public class ContainerCatalogue extends ContainerForestry implements IGuiSelecta
|
||||
|
||||
while(iterator.hasNext()) {
|
||||
ITradeStation current = iterator.next();
|
||||
if(!current.getMoniker().equals(currentTrade.moniker)) {
|
||||
if(!current.getAddress().equals(currentTrade.address)) {
|
||||
currentItPos++;
|
||||
previous = current;
|
||||
continue;
|
||||
|
||||
@@ -143,7 +143,7 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
|
||||
// / Send to server
|
||||
PacketPayload payload = new PacketPayload(0, 0, 2);
|
||||
payload.stringPayload[0] = getRecipient().getProfile().getName();
|
||||
payload.stringPayload[0] = getRecipient().getIdentifierName();
|
||||
payload.stringPayload[1] = this.carrier;
|
||||
|
||||
PacketUpdate packet = new PacketUpdate(PacketIds.LETTER_RECIPIENT, payload);
|
||||
@@ -151,14 +151,9 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
}
|
||||
|
||||
public void handleSetRecipient(EntityPlayer player, PacketUpdate packet) {
|
||||
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);
|
||||
String identifierName = packet.payload.stringPayload[0];
|
||||
String type = packet.payload.stringPayload[1];
|
||||
MailAddress recipient = MailAddress.makeMailAddress(identifierName, type);
|
||||
getLetter().setRecipient(recipient);
|
||||
|
||||
// Update the trading info
|
||||
@@ -201,10 +196,10 @@ public class ContainerLetter extends ContainerItemInventory {
|
||||
if (!Proxies.common.isSimulating(world))
|
||||
return;
|
||||
|
||||
if (!address.getType().equals(EnumAddressee.TRADER.toString().toLowerCase(Locale.ENGLISH)))
|
||||
if (!address.getType().equals(EnumAddressee.asString(EnumAddressee.TRADER)))
|
||||
return;
|
||||
|
||||
ITradeStation station = PostManager.postRegistry.getTradeStation(world, address.getProfile());
|
||||
ITradeStation station = PostManager.postRegistry.getTradeStation(world, address);
|
||||
if (station == null)
|
||||
return;
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.gui;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -56,8 +57,10 @@ public class ContainerMailbox extends ContainerForestry {
|
||||
public ItemStack slotClick(int slotIndex, int button, int par3, EntityPlayer player) {
|
||||
ItemStack stack = super.slotClick(slotIndex, button, par3, player);
|
||||
|
||||
if (Proxies.common.isSimulating(player.worldObj) && mailinventory != null)
|
||||
PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), mailbox.getOwnerProfile(), mailinventory.getPOBoxInfo());
|
||||
if (Proxies.common.isSimulating(player.worldObj) && mailinventory != null) {
|
||||
MailAddress address = new MailAddress(mailbox.getOwnerProfile());
|
||||
PluginMail.proxy.setPOBoxInfo(mailbox.getWorldObj(), address, mailinventory.getPOBoxInfo());
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import forestry.core.network.PacketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.mail.gadgets.MachineTrader;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class ContainerTradeName extends ContainerForestry {
|
||||
|
||||
@@ -35,13 +36,13 @@ public class ContainerTradeName extends ContainerForestry {
|
||||
isLinked = machine.isLinked();
|
||||
}
|
||||
|
||||
public GameProfile getMoniker() {
|
||||
public String getMoniker() {
|
||||
return machine.getMoniker();
|
||||
}
|
||||
|
||||
public void setMoniker(String moniker) {
|
||||
|
||||
if (moniker == null)
|
||||
if (StringUtils.isBlank(moniker))
|
||||
return;
|
||||
|
||||
PacketPayload payload = new PacketPayload(0, 0, 1);
|
||||
@@ -52,8 +53,7 @@ public class ContainerTradeName extends ContainerForestry {
|
||||
}
|
||||
|
||||
public void handleSetMoniker(PacketUpdate packet) {
|
||||
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(packet.payload.stringPayload[0]);
|
||||
machine.setMoniker(profile);
|
||||
machine.setMoniker(packet.payload.stringPayload[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -76,7 +76,7 @@ public class ContainerTrader extends ContainerForestry {
|
||||
return getMoniker() != null;
|
||||
}
|
||||
|
||||
public GameProfile getMoniker() {
|
||||
public String getMoniker() {
|
||||
return machine.getMoniker();
|
||||
}
|
||||
|
||||
|
||||
@@ -93,10 +93,10 @@ public class GuiCatalogue extends GuiForestry<TileForestry> {
|
||||
|
||||
private void drawTradePreview(int x, int y) {
|
||||
|
||||
fontRendererObj.drawString("\u00A7l\u00A7n" + container.getTradeInfo().moniker, x, y, fontColor.get("gui.book"));
|
||||
fontRendererObj.drawString("\u00A7l\u00A7n" + container.getTradeInfo().address.getIdentifierName(), x, y, fontColor.get("gui.book"));
|
||||
|
||||
TradeStationInfo info = container.getTradeInfo();
|
||||
fontRendererObj.drawString(String.format(StringUtil.localize("gui.mail.willtrade"), info.owner), x, y + 18, fontColor.get("gui.book"));
|
||||
fontRendererObj.drawString(String.format(StringUtil.localize("gui.mail.willtrade"), info.owner.getName()), x, y + 18, fontColor.get("gui.book"));
|
||||
|
||||
itemRender.renderItemAndEffectIntoGUI(fontRendererObj, mc.renderEngine, info.tradegood, x, y + 28);
|
||||
itemRender.renderItemOverlayIntoGUI(fontRendererObj, mc.renderEngine, info.tradegood, x, y + 28);
|
||||
@@ -137,8 +137,8 @@ public class GuiCatalogue extends GuiForestry<TileForestry> {
|
||||
case 5:
|
||||
TradeStationInfo info = container.getTradeInfo();
|
||||
if(info != null) {
|
||||
SessionVars.setStringVar("mail.letter.recipient", info.moniker.getName());
|
||||
SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.TRADER.toString().toLowerCase(Locale.ENGLISH));
|
||||
SessionVars.setStringVar("mail.letter.recipient", info.address.getIdentifierName());
|
||||
SessionVars.setStringVar("mail.letter.addressee", EnumAddressee.asString(EnumAddressee.TRADER));
|
||||
}
|
||||
mc.displayGuiScreen((GuiScreen)null);
|
||||
break;
|
||||
|
||||
@@ -15,8 +15,7 @@ import java.util.Locale;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
@@ -96,9 +95,10 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
|
||||
address = new GuiTextField(this.fontRendererObj, guiLeft + 46, guiTop + 13, 93, 13);
|
||||
if (container.getRecipient() != null) {
|
||||
address.setText(container.getRecipient().getProfile().getName());
|
||||
this.setRecipient(container.getRecipient().getProfile().getName(), container.getCarrierType());
|
||||
MailAddress recipient = container.getRecipient();
|
||||
if (recipient != null) {
|
||||
address.setText(recipient.getIdentifierName());
|
||||
setRecipient(recipient);
|
||||
}
|
||||
|
||||
text = new GuiTextBox(this.fontRendererObj, guiLeft + 17, guiTop + 31, 122, 57);
|
||||
@@ -155,8 +155,13 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
}
|
||||
|
||||
// Check for focus changes
|
||||
if (addressFocus != address.isFocused())
|
||||
setRecipient(this.address.getText(), container.getCarrierType());
|
||||
if (addressFocus != address.isFocused()) {
|
||||
String recipient = this.address.getText();
|
||||
if (StringUtils.isNotBlank(recipient)) {
|
||||
MailAddress recipientAddress = MailAddress.makeMailAddress(recipient, container.getCarrierType());
|
||||
setRecipient(recipientAddress);
|
||||
}
|
||||
}
|
||||
addressFocus = address.isFocused();
|
||||
if (textFocus != text.isFocused())
|
||||
setText();
|
||||
@@ -210,7 +215,9 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
setRecipient(this.address.getText(), container.getCarrierType());
|
||||
MailAddress recipientAddress = MailAddress.makeMailAddress(this.address.getText(), container.getCarrierType());
|
||||
|
||||
setRecipient(recipientAddress);
|
||||
setText();
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
super.onGuiClosed();
|
||||
@@ -230,26 +237,20 @@ public class GuiLetter extends GuiForestry<TileForestry> {
|
||||
|
||||
if (recipient != null && type != null) {
|
||||
address.setText(recipient);
|
||||
setRecipient(recipient, type);
|
||||
MailAddress recipientAddress = MailAddress.makeMailAddress(recipient, type);
|
||||
setRecipient(recipientAddress);
|
||||
}
|
||||
|
||||
SessionVars.clearStringVar("mail.letter.recipient");
|
||||
SessionVars.clearStringVar("mail.letter.addressee");
|
||||
}
|
||||
|
||||
private void setRecipient(String identifier, String type) {
|
||||
if (this.isProcessedLetter)
|
||||
return;
|
||||
|
||||
if (identifier == null || identifier == "" )
|
||||
private void setRecipient(MailAddress recipientAddress) {
|
||||
if (this.isProcessedLetter || recipientAddress == null)
|
||||
return;
|
||||
|
||||
if (type == null || type == "" )
|
||||
return;
|
||||
|
||||
MailAddress recipient = new MailAddress(new GameProfile(null, identifier), type);
|
||||
container.setRecipient(recipient);
|
||||
container.updateTradeInfo(this.mc.theWorld, recipient);
|
||||
container.setRecipient(recipientAddress);
|
||||
container.updateTradeInfo(this.mc.theWorld, recipientAddress);
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
|
||||
@@ -14,6 +14,7 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import forestry.core.config.Defaults;
|
||||
@@ -43,7 +44,7 @@ public class GuiTradeName extends GuiForestry<MachineTrader> {
|
||||
|
||||
moniker = new GuiTextField(this.fontRendererObj, guiLeft + 44, guiTop + 39, 90, 14);
|
||||
if (container.getMoniker() != null)
|
||||
moniker.setText(container.getMoniker().getName());
|
||||
moniker.setText(container.getMoniker());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,7 +97,9 @@ public class GuiTradeName extends GuiForestry<MachineTrader> {
|
||||
}
|
||||
|
||||
private void setMoniker() {
|
||||
container.setMoniker(this.moniker.getText());
|
||||
String monikerText = this.moniker.getText();
|
||||
if (StringUtils.isNotBlank(monikerText))
|
||||
container.setMoniker(monikerText);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class GuiTrader extends GuiForestry<MachineTrader> {
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
fontRendererObj.drawString(container.getMoniker().getName(), guiLeft + 19, guiTop + 22, fontColor.get("gui.mail.text"));
|
||||
fontRendererObj.drawString(container.getMoniker(), guiLeft + 19, guiTop + 22, fontColor.get("gui.mail.text"));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ 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;
|
||||
@@ -45,9 +46,8 @@ public class PacketTradeInfo extends ForestryPacket {
|
||||
|
||||
data.writeShort(0);
|
||||
|
||||
data.writeLong(tradeInfo.moniker.getId().getMostSignificantBits());
|
||||
data.writeLong(tradeInfo.moniker.getId().getLeastSignificantBits());
|
||||
data.writeUTF(tradeInfo.moniker.getName());
|
||||
String moniker = tradeInfo.address.getIdentifierName();
|
||||
data.writeUTF(moniker);
|
||||
|
||||
data.writeLong(tradeInfo.owner.getId().getMostSignificantBits());
|
||||
data.writeLong(tradeInfo.owner.getId().getLeastSignificantBits());
|
||||
@@ -67,7 +67,7 @@ public class PacketTradeInfo extends ForestryPacket {
|
||||
if (isNotNull < 0)
|
||||
return;
|
||||
|
||||
GameProfile moniker = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
String moniker = data.readUTF();
|
||||
GameProfile owner = new GameProfile(new UUID(data.readLong(), data.readLong()), data.readUTF());
|
||||
ItemStack tradegood;
|
||||
ItemStack[] required;
|
||||
@@ -77,7 +77,8 @@ public class PacketTradeInfo extends ForestryPacket {
|
||||
for (int i = 0; i < required.length; i++)
|
||||
required[i] = readItemStack(data);
|
||||
|
||||
this.tradeInfo = new TradeStationInfo(moniker, owner, tradegood, required, EnumStationState.values()[data.readShort()]);
|
||||
MailAddress address = new MailAddress(moniker);
|
||||
this.tradeInfo = new TradeStationInfo(address, owner, tradegood, required, EnumStationState.values()[data.readShort()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.proxy;
|
||||
|
||||
import com.sun.javaws.exceptions.InvalidArgumentException;
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
@@ -39,15 +42,22 @@ public class ClientProxyMail extends ProxyMail {
|
||||
if (!Proxies.common.isSimulating(Proxies.common.getRenderWorld()))
|
||||
Proxies.net.sendToServer(new ForestryPacket(PacketIds.POBOX_INFO_REQUEST));
|
||||
else {
|
||||
POBox pobox = PostRegistry.getPOBox(Proxies.common.getRenderWorld(), Proxies.common.getClientInstance().thePlayer.getGameProfile());
|
||||
MailAddress address = new MailAddress(Proxies.common.getClientInstance().thePlayer.getGameProfile());
|
||||
POBox pobox = PostRegistry.getPOBox(Proxies.common.getRenderWorld(), address);
|
||||
if (pobox != null)
|
||||
setPOBoxInfo(Proxies.common.getRenderWorld(), Proxies.common.getClientInstance().thePlayer.getGameProfile(), pobox.getPOBoxInfo());
|
||||
setPOBoxInfo(Proxies.common.getRenderWorld(), address, pobox.getPOBoxInfo());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPOBoxInfo(World world, GameProfile playername, POBoxInfo info) {
|
||||
if (Proxies.common.getClientInstance().thePlayer == null || !Proxies.common.getClientInstance().thePlayer.getGameProfile().equals(playername))
|
||||
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);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail.proxy;
|
||||
|
||||
import forestry.api.mail.MailAddress;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -28,10 +29,15 @@ public class ProxyMail {
|
||||
public void resetMailboxInfo() {
|
||||
}
|
||||
|
||||
public void setPOBoxInfo(World world, GameProfile playername, POBoxInfo info) {
|
||||
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(playername))
|
||||
if (!player.getGameProfile().equals(playerProfile))
|
||||
continue;
|
||||
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfo(PacketIds.POBOX_INFO, info), player);
|
||||
|
||||
Reference in new issue
Block a user