mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-11-20 20:12:17 +00:00
Actually register PacketNoSpamChat, clean up packets
Ref SleepyTrousers/EnderIO#2695
This commit is contained in:
1 parent
d1469af69d
commit
1a30e7a633
4 files changed
+64
-64
No files matched your search
@@ -16,64 +16,59 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketConfigSync implements IMessage, IMessageHandler<PacketConfigSync, PacketConfigSync>
|
||||
{
|
||||
public class PacketConfigSync implements IMessage {
|
||||
|
||||
public PacketConfigSync()
|
||||
{
|
||||
}
|
||||
public PacketConfigSync() {
|
||||
}
|
||||
|
||||
private Map<String, Object> configValues;
|
||||
private String modid;
|
||||
private Map<String, Object> configValues;
|
||||
private String modid;
|
||||
|
||||
public PacketConfigSync(ConfigProcessor toSync)
|
||||
{
|
||||
this.configValues = toSync.configValues;
|
||||
this.modid = toSync.modid;
|
||||
}
|
||||
public PacketConfigSync(ConfigProcessor toSync) {
|
||||
this.configValues = toSync.configValues;
|
||||
this.modid = toSync.modid;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteArrayOutputStream obj = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(obj);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(gzip);
|
||||
objStream.writeObject(configValues);
|
||||
objStream.close();
|
||||
|
||||
buf.writeShort(obj.size());
|
||||
buf.writeBytes(obj.toByteArray());
|
||||
|
||||
ByteBufUtils.writeUTF8String(buf, modid);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
short len = buf.readShort();
|
||||
byte[] compressedBody = new byte[len];
|
||||
|
||||
for (short i = 0; i < len; i++)
|
||||
compressedBody[i] = buf.readByte();
|
||||
|
||||
ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
|
||||
configValues = (Map<String, Object>) obj.readObject();
|
||||
obj.close();
|
||||
|
||||
modid = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PacketConfigSync, PacketConfigSync> {
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void toBytes(ByteBuf buf)
|
||||
{
|
||||
ByteArrayOutputStream obj = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzip = new GZIPOutputStream(obj);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(gzip);
|
||||
objStream.writeObject(configValues);
|
||||
objStream.close();
|
||||
|
||||
buf.writeShort(obj.size());
|
||||
buf.writeBytes(obj.toByteArray());
|
||||
|
||||
ByteBufUtils.writeUTF8String(buf, modid);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public void fromBytes(ByteBuf buf)
|
||||
{
|
||||
short len = buf.readShort();
|
||||
byte[] compressedBody = new byte[len];
|
||||
|
||||
for (short i = 0; i < len; i++)
|
||||
compressedBody[i] = buf.readByte();
|
||||
|
||||
ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
|
||||
configValues = (Map<String, Object>) obj.readObject();
|
||||
obj.close();
|
||||
|
||||
modid = ByteBufUtils.readUTF8String(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketConfigSync onMessage(PacketConfigSync message, MessageContext ctx)
|
||||
{
|
||||
ConfigProcessor processor = ConfigProcessor.processorMap.get(message.modid);
|
||||
if (processor != null)
|
||||
{
|
||||
processor.syncTo(message.configValues);
|
||||
}
|
||||
return null;
|
||||
public PacketConfigSync onMessage(PacketConfigSync message, MessageContext ctx) {
|
||||
ConfigProcessor processor = ConfigProcessor.processorMap.get(message.modid);
|
||||
if (processor != null) {
|
||||
processor.syncTo(message.configValues);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import com.enderio.core.EnderCore;
|
||||
import com.enderio.core.common.config.PacketConfigSync;
|
||||
import com.enderio.core.common.util.ChatUtil.PacketNoSpamChat;
|
||||
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
@@ -16,8 +17,9 @@ public class EnderPacketHandler {
|
||||
public static final SimpleNetworkWrapper INSTANCE = new SimpleNetworkWrapper(EnderCore.NAME);
|
||||
|
||||
public static void init() {
|
||||
INSTANCE.registerMessage(PacketConfigSync.class, PacketConfigSync.class, 0, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketProgress.class, PacketProgress.class, 1, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketConfigSync.Handler.class, PacketConfigSync.class, 0, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketProgress.Handler.class, PacketProgress.class, 1, Side.CLIENT);
|
||||
INSTANCE.registerMessage(PacketNoSpamChat.Handler.class, PacketNoSpamChat.class, 2, Side.CLIENT);
|
||||
}
|
||||
|
||||
public static void sendToAllAround(IMessage message, TileEntity te, int range) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class PacketProgress extends MessageTileEntity<TileEntity> implements IMessageHandler<PacketProgress, IMessage> {
|
||||
public class PacketProgress extends MessageTileEntity<TileEntity> {
|
||||
|
||||
private float progress;
|
||||
|
||||
@@ -37,12 +37,15 @@ public class PacketProgress extends MessageTileEntity<TileEntity> implements IMe
|
||||
progress = buf.readFloat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketProgress message, MessageContext ctx) {
|
||||
TileEntity tile = message.getTileEntity(EnderCore.proxy.getClientWorld());
|
||||
if (tile instanceof IProgressTile) {
|
||||
((IProgressTile) tile).setProgress(message.progress);
|
||||
public static class Handler implements IMessageHandler<PacketProgress, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketProgress message, MessageContext ctx) {
|
||||
TileEntity tile = message.getTileEntity(EnderCore.proxy.getClientWorld());
|
||||
if (tile instanceof IProgressTile) {
|
||||
((IProgressTile) tile).setProgress(message.progress);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,7 @@ public class ChatUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static class NoSpamChatHandler implements IMessageHandler<PacketNoSpamChat, IMessage> {
|
||||
public static class Handler implements IMessageHandler<PacketNoSpamChat, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(PacketNoSpamChat message, MessageContext ctx) {
|
||||
|
||||
Reference in new issue
Block a user