mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 19:39:07 +00:00
Remove PacketHandlerClient
This commit is contained in:
1 parent
43b0e7c23b
commit
c3179b36f2
30 files changed
+238
-396
No files matched your search
@@ -1,18 +1,10 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTSizeTracker;
|
||||
import kamkeel.npcs.util.ByteBufUtils;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.village.MerchantRecipeList;
|
||||
import noppes.npcs.constants.EnumPacketClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@@ -20,47 +12,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Server {
|
||||
|
||||
public static void sendData(final EntityPlayerMP player, final EnumPacketClient enu, final Object... obs) {
|
||||
sendDataChecked(player, enu, obs);
|
||||
}
|
||||
|
||||
public static boolean sendDataChecked(EntityPlayerMP player, EnumPacketClient type, Object... obs) {
|
||||
PacketBuffer buffer = new PacketBuffer(Unpooled.buffer());
|
||||
try {
|
||||
if(!fillBuffer(buffer, type, obs))
|
||||
return false;
|
||||
CustomNpcs.Channel.sendTo(new FMLProxyPacket(buffer, "CustomNPCs"), player);
|
||||
} catch (IOException e) {
|
||||
LogWriter.error(type + " Errored", e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void sendAssociatedData(final Entity entity, final EnumPacketClient enu, final Object... obs) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
if(!fillBuffer(buffer, enu, obs))
|
||||
return;
|
||||
TargetPoint point = new TargetPoint(entity.dimension, entity.posX, entity.posY, entity.posZ, 60);
|
||||
CustomNpcs.Channel.sendToAllAround(new FMLProxyPacket(buffer,"CustomNPCs"), point);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LogWriter.error(enu + " Errored", e);
|
||||
}
|
||||
}
|
||||
public static void sendToAll(EnumPacketClient enu, Object... obs) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
if(!fillBuffer(buffer, enu, obs))
|
||||
return;
|
||||
CustomNpcs.Channel.sendToAll(new FMLProxyPacket(buffer,"CustomNPCs"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LogWriter.error(enu + " Errored", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean fillBuffer(ByteBuf buffer, Enum enu, Object... obs) throws IOException{
|
||||
buffer.writeInt(enu.ordinal());
|
||||
for(Object ob : obs){
|
||||
@@ -73,7 +24,7 @@ public class Server {
|
||||
for(String key : map.keySet()){
|
||||
int value = map.get(key);
|
||||
buffer.writeInt(value);
|
||||
writeString(buffer, key);
|
||||
ByteBufUtils.writeString(buffer, key);
|
||||
}
|
||||
}
|
||||
else if(ob instanceof MerchantRecipeList)
|
||||
@@ -82,7 +33,7 @@ public class Server {
|
||||
List<String> list = (List<String>) ob;
|
||||
buffer.writeInt(list.size());
|
||||
for(String s : list)
|
||||
writeString(buffer, s);
|
||||
ByteBufUtils.writeString(buffer, s);
|
||||
}
|
||||
else if(ob instanceof Enum)
|
||||
buffer.writeInt(((Enum<?>) ob).ordinal());
|
||||
@@ -91,7 +42,7 @@ public class Server {
|
||||
else if(ob instanceof Boolean)
|
||||
buffer.writeBoolean((Boolean) ob);
|
||||
else if(ob instanceof String)
|
||||
writeString(buffer, (String) ob);
|
||||
ByteBufUtils.writeString(buffer, (String) ob);
|
||||
else if(ob instanceof Float)
|
||||
buffer.writeFloat((Float) ob);
|
||||
else if(ob instanceof Long)
|
||||
@@ -105,7 +56,7 @@ public class Server {
|
||||
buffer.writeBytes(byteArray);
|
||||
}
|
||||
else if(ob instanceof NBTTagCompound)
|
||||
writeNBT(buffer, (NBTTagCompound) ob);
|
||||
ByteBufUtils.writeNBT(buffer, (NBTTagCompound) ob);
|
||||
}
|
||||
if(buffer.array().length >= 32767){
|
||||
LogWriter.error("Packet " + enu + " was too big to be send");
|
||||
@@ -114,33 +65,4 @@ public class Server {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void writeNBT(ByteBuf buffer, NBTTagCompound compound) throws IOException {
|
||||
byte[] bytes = CompressedStreamTools.compress(compound);
|
||||
buffer.writeShort((short)bytes.length);
|
||||
buffer.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public static NBTTagCompound readNBT(ByteBuf buffer) throws IOException {
|
||||
byte[] bytes = new byte[buffer.readShort()];
|
||||
buffer.readBytes(bytes);
|
||||
return CompressedStreamTools.func_152457_a(bytes, new NBTSizeTracker(2097152L));
|
||||
}
|
||||
|
||||
public static void writeString(ByteBuf buffer, String s){
|
||||
byte[] bytes = s.getBytes(Charsets.UTF_8);
|
||||
buffer.writeShort((short)bytes.length);
|
||||
buffer.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public static String readString(ByteBuf buffer){
|
||||
try{
|
||||
byte[] bytes = new byte[buffer.readShort()];
|
||||
buffer.readBytes(bytes);
|
||||
return new String(bytes, Charsets.UTF_8);
|
||||
}
|
||||
catch(IndexOutOfBoundsException ex){
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user