Overlooked chat message support *sigh*. Fixes wierd mods that communicate through custom

chat messages rather than anything else. Hi Superior enchanting!
This commit is contained in:
Christian 2012-09-04 12:37:59 -04:00
parent 7a58542fb8
commit 6d9b9fde47
10 changed files with 126 additions and 45 deletions

View file

@ -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

View file

@ -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);
}

View file

@ -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;
}
}

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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<IConnectionHandler> connectionHandlers = Sets.newLinkedHashSet();
private Map<ModContainer, IGuiHandler> serverGuiHandlers = Maps.newHashMap();
private Map<ModContainer, IGuiHandler> clientGuiHandlers = Maps.newHashMap();
private List<IChatListener> 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;
}
}

View file

@ -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 @@
}
}
}

View file

@ -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;
}