Package me.neznamy.tab.api.protocol
Class PacketBuilder
java.lang.Object
me.neznamy.tab.api.protocol.PacketBuilder
A class for packet building, methods are overridden in
platform-specific builders which extend this class to build actual packets.
Packets which don't have a method override are forwarded into
sendPacket method, where they are handled using platform's API instead.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Map<Class<? extends TabPacket>,BiFunctionWithException<TabPacket, ProtocolVersion, Object>> Function map turning custom packet class into platform-specific packets -
Constructor Summary
ConstructorsConstructorDescriptionConstructs new instance and fillsbuildMapwith abstract build methods of packets present on all platforms. -
Method Summary
Modifier and TypeMethodDescriptionbuild(PacketPlayOutBoss packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutBoss class based on custom packet classbuild(PacketPlayOutChat packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutChat class based on custom packet classbuild(PacketPlayOutPlayerInfo packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutPlayerInfo class based on custom packet classbuild(PacketPlayOutPlayerListHeaderFooter packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutPlayerListHeaderFooter class based on custom packet classbuild(PacketPlayOutScoreboardDisplayObjective packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutScoreboardDisplayObjective class based on custom packet classbuild(PacketPlayOutScoreboardObjective packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutScoreboardObjective class based on custom packet classbuild(PacketPlayOutScoreboardScore packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutScoreboardScore class based on custom packet classbuild(PacketPlayOutScoreboardTeam packet, ProtocolVersion clientVersion) Constructs platform-specific PacketPlayOutScoreboardTeam class based on custom packet classbuild(TabPacket packet, ProtocolVersion clientVersion) Converts custom packet into platform-specific packet by calling a function frombuildMap.Cuts given string to specified character length (or length-1 if last character is a color character) and translates RGB to legacy colors.jsonOrCut(String text, ProtocolVersion clientVersion, int length) IfclientVersionis >= 1.13, creates a component from given text and returns it as a serialized component, which BungeeCord uses.readDisplayObjective(Object packet) Converts platform-specific instance of display objective packet intoPacketPlayOutScoreboardDisplayObjectiveobject.readObjective(Object packet) Converts platform-specific instance of objective packet intoPacketPlayOutScoreboardObjectiveobject.readPlayerInfo(Object packet, ProtocolVersion clientVersion) Converts platform-specific instance of player info packet intoPacketPlayOutPlayerInfoobject.
-
Field Details
-
buildMap
protected final Map<Class<? extends TabPacket>,BiFunctionWithException<TabPacket, buildMapProtocolVersion, Object>> Function map turning custom packet class into platform-specific packets
-
-
Constructor Details
-
PacketBuilder
public PacketBuilder()Constructs new instance and fillsbuildMapwith abstract build methods of packets present on all platforms.
-
-
Method Details
-
build
public Object build(TabPacket packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Converts custom packet into platform-specific packet by calling a function frombuildMap.- Parameters:
packet- Packet to buildclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if reflection fails
-
build
public Object build(PacketPlayOutBoss packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Constructs platform-specific PacketPlayOutBoss class based on custom packet class- Parameters:
packet- Custom packet to be builtclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if thrown by reflective operation
-
build
public Object build(PacketPlayOutChat packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Constructs platform-specific PacketPlayOutChat class based on custom packet class- Parameters:
packet- Custom packet to be builtclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if thrown by reflective operation
-
build
public Object build(PacketPlayOutPlayerInfo packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Constructs platform-specific PacketPlayOutPlayerInfo class based on custom packet class- Parameters:
packet- Custom packet to be builtclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if thrown by reflective operation
-
build
public Object build(PacketPlayOutScoreboardDisplayObjective packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Constructs platform-specific PacketPlayOutScoreboardDisplayObjective class based on custom packet class- Parameters:
packet- Custom packet to be builtclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if thrown by reflective operation
-
build
public Object build(PacketPlayOutScoreboardObjective packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Constructs platform-specific PacketPlayOutScoreboardObjective class based on custom packet class- Parameters:
packet- Custom packet to be builtclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if thrown by reflective operation
-
build
public Object build(PacketPlayOutScoreboardScore packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Constructs platform-specific PacketPlayOutScoreboardScore class based on custom packet class- Parameters:
packet- Custom packet to be builtclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if thrown by reflective operation
-
build
public Object build(PacketPlayOutScoreboardTeam packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Constructs platform-specific PacketPlayOutScoreboardTeam class based on custom packet class- Parameters:
packet- Custom packet to be builtclientVersion- Protocol version of player to build the packet for- Returns:
- Platform-specific packet
- Throws:
ReflectiveOperationException- if thrown by reflective operation
-
cutTo
Cuts given string to specified character length (or length-1 if last character is a color character) and translates RGB to legacy colors. If string is not that long, the original string is returned. RGB codes are converted into legacy, since cutting is only needed for <1.13. Ifstringisnull, empty string is returned.- Parameters:
string- String to cutlength- Length to cut to- Returns:
- string cut to
lengthcharacters
-
jsonOrCut
IfclientVersionis >= 1.13, creates a component from given text and returns it as a serialized component, which BungeeCord uses.If
clientVersionis < 1.12, the text is cut tolengthcharacters if needed and returned.- Parameters:
text- Text to convertclientVersion- Version of player to convert text for- Returns:
- serialized component for 1.13+ clients, cut string for 1.12-
-
readPlayerInfo
public PacketPlayOutPlayerInfo readPlayerInfo(Object packet, ProtocolVersion clientVersion) throws ReflectiveOperationException Converts platform-specific instance of player info packet intoPacketPlayOutPlayerInfoobject.- Parameters:
packet- platform-specific info packetclientVersion- Version of client receiving the packet- Returns:
- The packet converted into
PacketPlayOutPlayerInfo - Throws:
ReflectiveOperationException- if thrown by reflective operation
-
readObjective
public PacketPlayOutScoreboardObjective readObjective(Object packet) throws ReflectiveOperationException Converts platform-specific instance of objective packet intoPacketPlayOutScoreboardObjectiveobject.- Parameters:
packet- platform-specific objective packet- Returns:
- The packet converted into
PacketPlayOutScoreboardObjective - Throws:
ReflectiveOperationException- if thrown by reflective operation
-
readDisplayObjective
public PacketPlayOutScoreboardDisplayObjective readDisplayObjective(Object packet) throws ReflectiveOperationException Converts platform-specific instance of display objective packet intoPacketPlayOutScoreboardDisplayObjectiveobject.- Parameters:
packet- platform-specific display objective packet- Returns:
- The packet converted into
PacketPlayOutScoreboardDisplayObjective - Throws:
ReflectiveOperationException- if thrown by reflective operation
-