summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/Packet.java
blob: 592ffc585c7bb2c4e5c648b2c157bc60bf71b69b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package net.minecraft.server;

import java.io.IOException;

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;

public abstract class Packet {

    private static final Logger a = LogManager.getLogger();
    public final long timestamp = System.currentTimeMillis(); // CraftBukkit

    public Packet() {}

    public static Packet a(BiMap bimap, int i) {
        try {
            Class oclass = (Class) bimap.get(Integer.valueOf(i));

            return oclass == null ? null : (Packet) oclass.newInstance();
        } catch (Exception exception) {
            a.error("Couldn\'t create packet " + i, exception);
            return null;
        }
    }

    public static void a(ByteBuf bytebuf, byte[] abyte) {
        bytebuf.writeShort(abyte.length);
        bytebuf.writeBytes(abyte);
    }

    public static byte[] a(ByteBuf bytebuf) throws IOException { // CraftBukkit - added throws
        short short1 = bytebuf.readShort();

        if (short1 < 0) {
            throw new IOException("Key was smaller than nothing!  Weird key!");
        } else {
            byte[] abyte = new byte[short1];

            bytebuf.readBytes(abyte);
            return abyte;
        }
    }

    public abstract void a(PacketDataSerializer packetdataserializer) throws IOException; // CraftBukkit - added throws

    public abstract void b(PacketDataSerializer packetdataserializer) throws IOException; // CraftBukkit - added throws

    public abstract void handle(PacketListener packetlistener);

    public boolean a() {
        return false;
    }

    public String toString() {
        return this.getClass().getSimpleName();
    }

    public String b() {
        return "";
    }
}