summaryrefslogtreewikicommitdiff
path: root/src/main/java/net/tylermurphy/hideAndSeek/util/packet/AbstractPacket.java
blob: 9293beb3cc75fe4624cd7128165e393ea53808e3 (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
package net.tylermurphy.hideAndSeek.util.packet;

import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.PacketContainer;
import org.bukkit.entity.Player;

import java.lang.reflect.InvocationTargetException;

public class AbstractPacket {

    private static final ProtocolManager protocolManager;
    static {
        protocolManager = ProtocolLibrary.getProtocolManager();
    }

    protected final PacketContainer packet;

    protected AbstractPacket(PacketType type){
        packet = protocolManager.createPacket(type);
        packet.getModifier().writeDefaults();
    }

    public void send(Player player){
        try {
            protocolManager.sendServerPacket(player, packet);
        } catch (InvocationTargetException ignored) {}
    }

}