diff --git a/fml/client/net/minecraft/src/BaseMod.java b/fml/client/net/minecraft/src/BaseMod.java index 4a9604fde..23dafed96 100644 --- a/fml/client/net/minecraft/src/BaseMod.java +++ b/fml/client/net/minecraft/src/BaseMod.java @@ -321,19 +321,18 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr /** * Only implemented on the client side - * {@link #onChatMessageReceived(EntityPlayer, Packet3Chat)} + * {@link #serverChat(EntityPlayer, Packet3Chat)} * * @param text */ @Override - public void receiveChatPacket(String text) + public void clientChat(String text) { // TODO } /** - * Only called on the client side - * {@link #onPacket250Received(EntityPlayer, Packet250CustomPayload)} + * Called client side to receive a custom payload for this mod * * @param packet */ @@ -407,17 +406,6 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr return getName() + " " + getVersion(); } - /** - * Called when a 250 packet is received on a channel registered to this mod - * - * @param source - * @param payload - */ - @Override - public void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload) - { - } - /** * Called when a chat message is received. Return true to stop further processing * @@ -425,20 +413,10 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr * @param chat * @return true if you want to consume the message so it is not available for further processing */ - public boolean onChatMessageReceived(EntityPlayer source, Packet3Chat chat) + @Override + public void serverChat(NetServerHandler source, String message) { - return false; } - /** - * Called when a server command is received - * @param command - * @return true if you want to consume the message so it is not available for further processing - */ - public boolean onServerCommand(String command, String sender, ICommandManager listener) - { - return false; - } - /** * Called when a new client logs in. * @@ -460,17 +438,6 @@ public abstract class BaseMod implements cpw.mods.fml.common.modloader.BaseModPr } - /** - * - * Called when a client changes dimensions on the server. - * - * @param player - */ - public void onClientDimensionChanged(EntityPlayer player) - { - - } - /** * * Spawn the entity of the supplied type, if it is your mod's diff --git a/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java b/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java index bc440ec67..9bd6a52d7 100644 --- a/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java +++ b/fml/common/cpw/mods/fml/common/modloader/BaseModProxy.java @@ -77,15 +77,13 @@ public interface BaseModProxy public abstract void onClientLogin(EntityPlayer player); - public abstract void onPacket250Received(EntityPlayer source, Packet250CustomPayload payload); - public abstract void serverDisconnect(); public abstract void serverConnect(NetHandler handler); public abstract void receiveCustomPacket(Packet250CustomPayload packet); - public abstract void receiveChatPacket(String text); + public abstract void clientChat(String text); public abstract void onItemPickup(EntityPlayer player, ItemStack item); @@ -93,4 +91,6 @@ public interface BaseModProxy double entY, double entZ); public abstract void serverCustomPayload(NetServerHandler handler, Packet250CustomPayload packet); + + public abstract void serverChat(NetServerHandler source, String message); } diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderChatListener.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderChatListener.java new file mode 100644 index 000000000..8bc5e32b6 --- /dev/null +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderChatListener.java @@ -0,0 +1,32 @@ +package cpw.mods.fml.common.modloader; + +import net.minecraft.src.NetHandler; +import net.minecraft.src.NetServerHandler; +import net.minecraft.src.Packet3Chat; +import cpw.mods.fml.common.network.IChatListener; + +public class ModLoaderChatListener implements IChatListener +{ + + private BaseModProxy mod; + + public ModLoaderChatListener(BaseModProxy mod) + { + this.mod = mod; + } + + @Override + public Packet3Chat serverChat(NetHandler handler, Packet3Chat message) + { + mod.serverChat((NetServerHandler)handler, message.field_73476_b); + return message; + } + + @Override + public Packet3Chat clientChat(NetHandler handler, Packet3Chat message) + { + mod.clientChat(message.field_73476_b); + return message; + } + +} diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java index dc86e62a9..a5b052cb6 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderHelper.java @@ -40,6 +40,7 @@ import cpw.mods.fml.common.IPickupNotifier; import cpw.mods.fml.common.IWorldGenerator; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.TickType; +import cpw.mods.fml.common.network.IChatListener; import cpw.mods.fml.common.network.IConnectionHandler; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.IPacketHandler; @@ -197,4 +198,9 @@ public class ModLoaderHelper mlmc.addServerCommand(command); } } + + public static IChatListener buildChatListener(BaseModProxy mod) + { + return new ModLoaderChatListener(mod); + } } diff --git a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java index 5887b746f..7dd806c9c 100644 --- a/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java +++ b/fml/common/cpw/mods/fml/common/modloader/ModLoaderModContainer.java @@ -530,6 +530,7 @@ public class ModLoaderModContainer implements ModContainer GameRegistry.registerCraftingHandler(ModLoaderHelper.buildCraftingHelper(mod)); GameRegistry.registerPickupHandler(ModLoaderHelper.buildPickupHelper(mod)); GameRegistry.registerDispenserHandler(ModLoaderHelper.buildDispenseHelper(mod)); + NetworkRegistry.instance().registerChatListener(ModLoaderHelper.buildChatListener(mod)); NetworkRegistry.instance().registerConnectionHandler(ModLoaderHelper.buildConnectionHelper(mod)); } catch (Exception e) diff --git a/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java b/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java index b9e0b7426..04dac2fdc 100644 --- a/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java +++ b/fml/common/cpw/mods/fml/common/network/FMLNetworkHandler.java @@ -23,6 +23,7 @@ import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet; import net.minecraft.src.Packet1Login; import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.Packet3Chat; import net.minecraft.src.ServerConfigurationManager; import net.minecraft.src.World; import net.minecraft.src.WorldType; @@ -390,4 +391,9 @@ public class FMLNetworkHandler } return add; } + + public static Packet3Chat handleChatMessage(NetHandler handler, Packet3Chat chat) + { + return NetworkRegistry.instance().handleChat(handler, chat); + } } \ No newline at end of file diff --git a/fml/common/cpw/mods/fml/common/network/IChatListener.java b/fml/common/cpw/mods/fml/common/network/IChatListener.java new file mode 100644 index 000000000..a5d78b5cf --- /dev/null +++ b/fml/common/cpw/mods/fml/common/network/IChatListener.java @@ -0,0 +1,24 @@ +package cpw.mods.fml.common.network; + +import net.minecraft.src.NetHandler; +import net.minecraft.src.NetServerHandler; +import net.minecraft.src.Packet3Chat; + +public interface IChatListener +{ + /** + * Called when there is a chat message received on the server + * @param handler + * @param message + */ + public Packet3Chat serverChat(NetHandler handler, Packet3Chat message); + + /** + * Called when there is a chat message recived on the client + * + * @param handler + * @param message + * @return + */ + public Packet3Chat clientChat(NetHandler handler, Packet3Chat message); +} diff --git a/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java b/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java index fb67f8c69..bb03717c5 100644 --- a/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java +++ b/fml/common/cpw/mods/fml/common/network/NetworkRegistry.java @@ -16,6 +16,7 @@ import net.minecraft.src.NetServerHandler; import net.minecraft.src.NetworkManager; import net.minecraft.src.Packet1Login; import net.minecraft.src.Packet250CustomPayload; +import net.minecraft.src.Packet3Chat; import net.minecraft.src.World; import com.google.common.base.Charsets; @@ -36,6 +37,10 @@ import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.Side; import cpw.mods.fml.common.network.FMLPacket.Type; +/** + * @author cpw + * + */ public class NetworkRegistry { @@ -56,6 +61,7 @@ public class NetworkRegistry private Set connectionHandlers = Sets.newLinkedHashSet(); private Map serverGuiHandlers = Maps.newHashMap(); private Map clientGuiHandlers = Maps.newHashMap(); + private List chatListeners = Lists.newArrayList(); public static NetworkRegistry instance() { @@ -144,6 +150,15 @@ public class NetworkRegistry connectionHandlers.add(handler); } + /** + * Register a chat listener + * @param listener + */ + public void registerChatListener(IChatListener listener) + { + chatListeners.add(listener); + } + void playerLoggedIn(EntityPlayerMP player, NetServerHandler netHandler, NetworkManager manager) { generateChannelRegistration(player, netHandler, manager); @@ -308,4 +323,18 @@ public class NetworkRegistry IGuiHandler handler = clientGuiHandlers.get(mc); FMLCommonHandler.instance().showGuiScreen(handler.getClientGuiElement(modGuiId, player, world, x, y, z)); } + public Packet3Chat handleChat(NetHandler handler, Packet3Chat chat) + { + Side s = Side.CLIENT; + if (handler instanceof NetServerHandler) + { + s = Side.SERVER; + } + for (IChatListener listener : chatListeners) + { + chat = s.isClient() ? listener.clientChat(handler, chat) : listener.serverChat(handler, chat); + } + + return chat; + } } diff --git a/fml/patches/common/net/minecraft/src/NetServerHandler.java.patch b/fml/patches/common/net/minecraft/src/NetServerHandler.java.patch index 75ca53ec3..c5b31ea2d 100644 --- a/fml/patches/common/net/minecraft/src/NetServerHandler.java.patch +++ b/fml/patches/common/net/minecraft/src/NetServerHandler.java.patch @@ -9,7 +9,15 @@ import net.minecraft.server.MinecraftServer; public class NetServerHandler extends NetHandler -@@ -957,6 +959,11 @@ +@@ -591,6 +593,7 @@ + + public void func_72481_a(Packet3Chat p_72481_1_) + { ++ p_72481_1_ = FMLNetworkHandler.handleChatMessage(this, p_72481_1_); + if (this.field_72574_e.func_71126_v() == 2) + { + this.func_72567_b(new Packet3Chat("Cannot send chat message.")); +@@ -957,6 +960,11 @@ public void func_72501_a(Packet250CustomPayload p_72501_1_) { @@ -21,7 +29,7 @@ DataInputStream var2; ItemStack var3; ItemStack var4; -@@ -1029,4 +1036,11 @@ +@@ -1029,4 +1037,11 @@ } } } diff --git a/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch b/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch index bfcc4f39f..94707f9b8 100644 --- a/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch +++ b/fml/patches/minecraft/net/minecraft/src/NetClientHandler.java.patch @@ -41,7 +41,15 @@ this.func_72552_c(new Packet204ClientInfo(this.field_72563_h.field_71474_y.field_74363_ab, this.field_72563_h.field_71474_y.field_74339_e, this.field_72563_h.field_71474_y.field_74343_n, this.field_72563_h.field_71474_y.field_74344_o, this.field_72563_h.field_71474_y.field_74318_M)); } -@@ -1167,6 +1173,11 @@ +@@ -605,6 +611,7 @@ + + public void func_72481_a(Packet3Chat p_72481_1_) + { ++ p_72481_1_ = FMLNetworkHandler.handleChatMessage(this, p_72481_1_); + this.field_72563_h.field_71456_v.func_73827_b().func_73765_a(p_72481_1_.field_73476_b); + } + +@@ -1167,6 +1174,11 @@ public void func_72501_a(Packet250CustomPayload p_72501_1_) { @@ -53,7 +61,7 @@ if ("MC|TPack".equals(p_72501_1_.field_73630_a)) { String[] var2 = (new String(p_72501_1_.field_73629_c)).split("\u0000"); -@@ -1211,4 +1222,10 @@ +@@ -1211,4 +1223,10 @@ { return this.field_72555_g; }