Paper/src/main/java/net/minecraft/server/Packet.java

64 Zeilen
1.8 KiB
Java

package net.minecraft.server;
import java.io.IOException;
2013-11-04 14:07:38 +01:00
import net.minecraft.util.com.google.common.collect.BiMap;
import net.minecraft.util.io.netty.buffer.ByteBuf;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2013-07-01 13:03:00 +02:00
public abstract class Packet {
2013-11-04 14:07:38 +01:00
private static final Logger a = LogManager.getLogger();
public final long timestamp = System.currentTimeMillis(); // CraftBukkit
2012-09-14 07:03:47 +02:00
2013-11-04 14:07:38 +01:00
public Packet() {}
2013-11-04 14:07:38 +01:00
public static Packet a(BiMap bimap, int i) {
try {
2013-11-04 14:07:38 +01:00
Class oclass = (Class) bimap.get(Integer.valueOf(i));
return oclass == null ? null : (Packet) oclass.newInstance();
} catch (Exception exception) {
2013-11-04 14:07:38 +01:00
a.error("Couldn\'t create packet " + i, exception);
return null;
}
}
2013-11-04 14:07:38 +01:00
public static void a(ByteBuf bytebuf, byte[] abyte) {
bytebuf.writeShort(abyte.length);
bytebuf.writeBytes(abyte);
2012-07-29 09:33:13 +02:00
}
2013-11-04 14:07:38 +01:00
public static byte[] a(ByteBuf bytebuf) throws IOException { // CraftBukkit - added throws
short short1 = bytebuf.readShort();
2012-07-29 09:33:13 +02:00
if (short1 < 0) {
throw new IOException("Key was smaller than nothing! Weird key!");
} else {
byte[] abyte = new byte[short1];
2013-11-04 14:07:38 +01:00
bytebuf.readBytes(abyte);
2012-07-29 09:33:13 +02:00
return abyte;
}
}
2013-11-04 14:07:38 +01:00
public abstract void a(PacketDataSerializer packetdataserializer) throws IOException; // CraftBukkit - added throws
2013-11-04 14:07:38 +01:00
public abstract void b(PacketDataSerializer packetdataserializer) throws IOException; // CraftBukkit - added throws
2013-11-04 14:07:38 +01:00
public abstract void handle(PacketListener packetlistener);
2013-11-04 14:07:38 +01:00
public boolean a() {
2012-07-29 09:33:13 +02:00
return false;
}
public String toString() {
2013-11-04 14:07:38 +01:00
return this.getClass().getSimpleName();
2011-11-20 09:01:14 +01:00
}
2013-11-04 14:07:38 +01:00
public String b() {
return "";
}
}