mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-17 10:55:06 +00:00
Sync mail to client on login, do not display mail indicator on logout
This commit is contained in:
1 parent
d0c8c92863
commit
e2f32ab767
8 files changed
+31
-70
No files matched your search
Executable → Regular
+18
-11
@@ -10,31 +10,38 @@
|
||||
******************************************************************************/
|
||||
package forestry.mail;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoRequest;
|
||||
|
||||
public class TickHandlerMailClient {
|
||||
private static final int THROTTLE_TIME_MS = 10000;
|
||||
private long lastInfoRequestTime;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
|
||||
public class EventHandlerMailAlert {
|
||||
@SubscribeEvent
|
||||
public void onRenderTick(TickEvent.RenderTickEvent event) {
|
||||
if (event.phase != Phase.END) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (GuiMailboxInfo.instance.hasPOBoxInfo()) {
|
||||
if (Minecraft.getMinecraft().theWorld != null && GuiMailboxInfo.instance.hasPOBoxInfo()) {
|
||||
GuiMailboxInfo.instance.render();
|
||||
} else {
|
||||
long time = System.currentTimeMillis();
|
||||
if (time - lastInfoRequestTime > THROTTLE_TIME_MS) {
|
||||
Proxies.net.sendToServer(new PacketPOBoxInfoRequest());
|
||||
lastInfoRequestTime = time;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void handlePlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||
EntityPlayer player = event.player;
|
||||
if (player != null) {
|
||||
MailAddress address = new MailAddress(player.getGameProfile());
|
||||
POBox pobox = PostRegistry.getOrCreatePOBox(player.worldObj, address);
|
||||
if (pobox != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ import forestry.api.mail.ITradeStation;
|
||||
import forestry.api.mail.PostManager;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.plugins.PluginMail;
|
||||
|
||||
public class PostRegistry implements IPostRegistry {
|
||||
@@ -75,7 +75,7 @@ public class PostRegistry implements IPostRegistry {
|
||||
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, address.getPlayerProfile());
|
||||
if (player != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
|
||||
public class PostalCarrier implements IPostalCarrier {
|
||||
|
||||
@@ -88,7 +88,7 @@ public class PostalCarrier implements IPostalCarrier {
|
||||
} else {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, recipient.getPlayerProfile());
|
||||
if (player instanceof EntityPlayerMP) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), (EntityPlayerMP) player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(pobox.getPOBoxInfo()), (EntityPlayerMP) player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import forestry.mail.POBox;
|
||||
import forestry.mail.POBoxInfo;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.tiles.TileMailbox;
|
||||
|
||||
public class ContainerMailbox extends ContainerTile<TileMailbox> {
|
||||
@@ -55,7 +55,7 @@ public class ContainerMailbox extends ContainerTile<TileMailbox> {
|
||||
if (SlotUtil.isSlotInRange(slotIndex, SLOT_LETTERS, SLOT_LETTERS_COUNT)) {
|
||||
if (!player.worldObj.isRemote && mailInventory != null) {
|
||||
POBoxInfo info = mailInventory.getPOBoxInfo();
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(info), player);
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoUpdate(info), player);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ import forestry.core.network.PacketRegistry;
|
||||
import forestry.mail.network.packets.PacketLetterInfoRequest;
|
||||
import forestry.mail.network.packets.PacketLetterInfoResponse;
|
||||
import forestry.mail.network.packets.PacketLetterTextSet;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoRequest;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoResponse;
|
||||
import forestry.mail.network.packets.PacketPOBoxInfoUpdate;
|
||||
import forestry.mail.network.packets.PacketTraderAddressRequest;
|
||||
import forestry.mail.network.packets.PacketTraderAddressResponse;
|
||||
|
||||
@@ -24,11 +23,10 @@ public class PacketRegistryMail extends PacketRegistry {
|
||||
public void registerPackets() {
|
||||
registerServerPacket(new PacketLetterInfoRequest());
|
||||
registerServerPacket(new PacketTraderAddressRequest());
|
||||
registerServerPacket(new PacketPOBoxInfoRequest());
|
||||
registerServerPacket(new PacketLetterTextSet());
|
||||
|
||||
registerClientPacket(new PacketLetterInfoResponse());
|
||||
registerClientPacket(new PacketTraderAddressResponse());
|
||||
registerClientPacket(new PacketPOBoxInfoResponse());
|
||||
registerClientPacket(new PacketPOBoxInfoUpdate());
|
||||
}
|
||||
}
|
||||
@@ -1,44 +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.packets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.IForestryPacketServer;
|
||||
import forestry.core.network.PacketIdServer;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.mail.MailAddress;
|
||||
import forestry.mail.POBox;
|
||||
import forestry.mail.PostRegistry;
|
||||
|
||||
public class PacketPOBoxInfoRequest extends ForestryPacket implements IForestryPacketServer {
|
||||
|
||||
public PacketPOBoxInfoRequest() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketIdServer getPacketId() {
|
||||
return PacketIdServer.POBOX_INFO_REQUEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(DataInputStreamForestry data, EntityPlayerMP player) throws IOException {
|
||||
MailAddress address = new MailAddress(player.getGameProfile());
|
||||
POBox pobox = PostRegistry.getOrCreatePOBox(player.worldObj, address);
|
||||
if (pobox != null) {
|
||||
Proxies.net.sendToPlayer(new PacketPOBoxInfoResponse(pobox.getPOBoxInfo()), player);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -22,14 +22,14 @@ import forestry.core.network.PacketIdClient;
|
||||
import forestry.mail.POBoxInfo;
|
||||
import forestry.mail.gui.GuiMailboxInfo;
|
||||
|
||||
public class PacketPOBoxInfoResponse extends ForestryPacket implements IForestryPacketClient {
|
||||
public class PacketPOBoxInfoUpdate extends ForestryPacket implements IForestryPacketClient {
|
||||
|
||||
public POBoxInfo poboxInfo;
|
||||
|
||||
public PacketPOBoxInfoResponse() {
|
||||
public PacketPOBoxInfoUpdate() {
|
||||
}
|
||||
|
||||
public PacketPOBoxInfoResponse(POBoxInfo info) {
|
||||
public PacketPOBoxInfoUpdate(POBoxInfo info) {
|
||||
this.poboxInfo = info;
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ import forestry.core.items.EnumElectronTube;
|
||||
import forestry.core.network.IPacketRegistry;
|
||||
import forestry.core.recipes.RecipeUtil;
|
||||
import forestry.core.tiles.MachineDefinition;
|
||||
import forestry.mail.EventHandlerMailAlert;
|
||||
import forestry.mail.PostRegistry;
|
||||
import forestry.mail.PostalCarrier;
|
||||
import forestry.mail.SaveEventHandlerMail;
|
||||
import forestry.mail.TickHandlerMailClient;
|
||||
import forestry.mail.blocks.BlockMailType;
|
||||
import forestry.mail.blocks.BlockRegistryMail;
|
||||
import forestry.mail.commands.CommandMail;
|
||||
@@ -67,7 +67,7 @@ public class PluginMail extends ForestryPlugin {
|
||||
PluginCore.rootCommand.addChildCommand(new CommandMail());
|
||||
|
||||
if (Config.mailAlertEnabled) {
|
||||
FMLCommonHandler.instance().bus().register(new TickHandlerMailClient());
|
||||
FMLCommonHandler.instance().bus().register(new EventHandlerMailAlert());
|
||||
}
|
||||
|
||||
blocks.mail.addDefinitions(
|
||||
|
||||
Reference in new issue
Block a user