2014-05-02 21:31:20 +02:00
|
|
|
/*******************************************************************************
|
2014-08-07 08:29:25 +02:00
|
|
|
* 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
|
2014-08-07 02:56:58 -07:00
|
|
|
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
2014-05-02 21:31:20 +02:00
|
|
|
*
|
2014-08-07 08:29:25 +02:00
|
|
|
* Various Contributors including, but not limited to:
|
|
|
|
|
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
2014-05-02 21:31:20 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
package forestry.mail.gui;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
|
|
|
|
|
|
import forestry.core.gui.ContainerForestry;
|
|
|
|
|
import forestry.core.network.PacketIds;
|
|
|
|
|
import forestry.core.network.PacketPayload;
|
|
|
|
|
import forestry.core.network.PacketUpdate;
|
|
|
|
|
import forestry.core.proxy.Proxies;
|
2014-11-30 17:19:16 -08:00
|
|
|
import forestry.core.inventory.InventoryAdapter;
|
2014-05-02 21:31:20 +02:00
|
|
|
import forestry.mail.gadgets.MachineTrader;
|
2014-09-10 03:43:16 -07:00
|
|
|
import forestry.api.mail.PostManager;
|
|
|
|
|
import forestry.api.mail.IMailAddress;
|
2014-08-13 23:44:36 -07:00
|
|
|
|
2014-08-11 00:31:08 -07:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2014-05-02 21:31:20 +02:00
|
|
|
|
|
|
|
|
public class ContainerTradeName extends ContainerForestry {
|
|
|
|
|
|
|
|
|
|
boolean isLinked;
|
|
|
|
|
MachineTrader machine;
|
|
|
|
|
|
|
|
|
|
public ContainerTradeName(InventoryPlayer player, MachineTrader tile) {
|
|
|
|
|
super(new InventoryAdapter(0, "Empty"));
|
|
|
|
|
machine = tile;
|
|
|
|
|
isLinked = machine.isLinked();
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-10 03:43:16 -07:00
|
|
|
public IMailAddress getAddress() {
|
2014-08-13 23:44:36 -07:00
|
|
|
return machine.getAddress();
|
2014-05-02 21:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-13 23:44:36 -07:00
|
|
|
public void setAddress(String addressName) {
|
2014-05-02 21:31:20 +02:00
|
|
|
|
2014-08-13 23:44:36 -07:00
|
|
|
if (StringUtils.isBlank(addressName))
|
2014-05-02 21:31:20 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
PacketPayload payload = new PacketPayload(0, 0, 1);
|
2014-08-13 23:44:36 -07:00
|
|
|
payload.stringPayload[0] = addressName;
|
2014-05-02 21:31:20 +02:00
|
|
|
|
2014-08-13 23:44:36 -07:00
|
|
|
PacketUpdate packet = new PacketUpdate(PacketIds.TRADING_ADDRESS_SET, payload);
|
2014-05-02 21:31:20 +02:00
|
|
|
Proxies.net.sendToServer(packet);
|
2014-08-13 23:44:36 -07:00
|
|
|
|
2014-12-14 18:07:57 -08:00
|
|
|
IMailAddress address = PostManager.postRegistry.getValidMailAddress(machine.getWorld(), addressName);
|
2014-08-13 23:44:36 -07:00
|
|
|
machine.setAddress(address);
|
2014-05-02 21:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-13 23:44:36 -07:00
|
|
|
public void handleSetAddress(PacketUpdate packet) {
|
|
|
|
|
String addressName = packet.payload.stringPayload[0];
|
2014-12-14 18:07:57 -08:00
|
|
|
IMailAddress address = PostManager.postRegistry.getValidMailAddress(machine.getWorld(), addressName);
|
2014-08-13 23:44:36 -07:00
|
|
|
machine.setAddress(address);
|
2014-05-02 21:31:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|