Information:
This resource is used to send Packets from a Client to a Server or the other way around.
Basic Instructions:
Thunder. useCompressor ( true ) ; //This compresses every Packet
Thunder. setLogging (LogLevel. ERROR ) ;
//LogLevel.OFF
//LogLevel.ALL
//LogLevel.DEBUG
//LogLevel.WARNING
//LogLevel.INFO
The ThunderClient and the ThunderServer both implement the ThunderConnection.
The ThunderConnection has its own unique Methods which the Client and Server then also have.
ThunderConnection thunderConnection = (ThunderConnection ) yourObject ; //Server or Client
thunderConnection. disconnect ( ) ; //Stops the server or disconnects from the server if client
thunderConnection. addHandler (thunderListener ) ; //Adds a ThunderListener
thunderConnection. addPacketHandler (packet -> { } ) ; //Adds a packetHandler
thunderConnection. setName ( "YourName" ) ; //Sets the name of the connection
thunderConnection. sendPacket (packet ) ; //Method to send packets
boolean connected = thunderConnection. isConnected ( ) ; //Checks if connected
ThunderSession session = thunderConnection. getSession ( ) ; //Session of the Connection
PacketAdapter packetAdapter = thunderConnection. getPacketAdapter ( ) ; //Used to handle Packets
Creating a Server:
ThunderServer thunderServer = Thunder. createServer ( ) ;
thunderServer. start ( 1401 ). perform ( ) ;
Creating a Client:
ThunderClient thunderClient = Thunder. createClient ( ) ;
thunderClient. connect ( "yourHost", 1401 ). perform ( ) ;
Creating Packets:
public class SamplePacket extends Packet {
private String name ;
private int age ;
public SamplePacket ( String name, int age ) {
this. name = name ;
this. age = age ;
}
@Override
public void write (PacketBuffer buf ) {
buf. writeString ( this. name ) ;
buf. writeInt ( this. age ) ;
}
@Override
public void read (PacketBuffer buf ) {
this. name = buf. readString ( ) ;
this. age = buf. readInt ( ) ;
}
}
Sending Packets (Also works with Server):
ThunderClient thunderClient = Thunder. createClient ( ) ;
thunderClient. connect ( "yourHost", 1401 ). perform ( new Consumer <ThunderClient > ( ) {
@Override
public void accept (ThunderClient thunderClient ) {
//This will be called when the Action ( .perform() )
// is done and the client is connected
SamplePacket samplePacket = new SamplePacket ( "Name", 16 ) ;
thunderClient. sendPacket (samplePacket ) ;
}
} ) ;
Handling Packets (Also works with server):
thunderClient. addPacketHandler ( new PacketHandler ( ) {
@Override
public void handle (ThunderPacket packet ) {
//Check if packet is SamplePacket
if (packet instanceof SamplePacket ) {
SamplePacket samplePacket = (SamplePacket ) packet ;
System. out. println (samplePacket. getAge ( ) ) ;
System. out. println (samplePacket. getName ( ) ) ;
System. out. println (samplePacket. getProcessingTime ( ) + "ms" ) ; //The time the packet took
System. out. println (samplePacket. toString ( ) ) ; //Information on the Packet
}
}
} ) ;
Working with ThunderSessions:
Every ThunderConnection has its own ThunderSession.
From it you can seperate Clients and Servers from eachother.
ThunderSession thunderSession = thunderClient. getSession ( ) ;
boolean authenticated = thunderSession. isAuthenticated ( ) ; //If the session is authenticated
String sessionId = thunderSession. getSessionId ( ) ; //Name of the session (if set)
UUID uniqueId = thunderSession. getUniqueId ( ) ; //UUID of the session
long startTime = thunderSession. getStartTime ( ) ; //Time when the session started
List <ThunderSession > connectedSessions = thunderSession. getConnectedSessions ( ) ; //Connected Sessions
Channel channel = thunderSession. getChannel ( ) ; //Channel of this Session
Extra Features of the ThunderClient:
ThunderClient thunderClient = Thunder. createClient ( ) ;
thunderClient. connect ( "yourHost", 1401 ). perform ( ) ;
thunderClient. writePacket ( new SamplePacket ( "YourName", 16 ) ) ; //Sends a packet to the client
Extra Features of the ThunderServer:
ThunderServer thunderServer = Thunder. createServer ( ) ;
thunderServer. start ( 1401 ). perform ( ) ;
UUID uuid = ... uuid of the Client youre trying to find
thunderServer. sendPacket ( new SamplePacket ( "YourName", 15 ), thunderServer. getSession ( ). getSession (uuid ) ) ;
//Sends a packet only to one connection
Using the ThunderListener (Again works for Client aswell):
thunderServer. addHandler ( new ThunderListener ( ) {
@Override
public void handleConnect (ThunderConnection thunderConnection ) {
ThunderClient thunderClient = (ThunderClient ) thunderConnection ;
//This is a ThunderClient now do what you want
}
@Override
public void handleDisconnect (ThunderConnection thunderConnection ) {
ThunderClient thunderClient = (ThunderClient ) thunderConnection ;
//This is a ThunderClient now do what you want
}
@Override
public void handlePacket (ThunderPacket packet, ThunderConnection thunderConnection ) throws IOException {
//Do what you want
//Is the same as PacketHandler
}
@Override
public void read (Packet packet, ThunderConnection thunderConnection ) throws IOException {
//Do what you want
//This is the raw Packet before getting transformed into
//ThunderPacket or BufferedPacket
}
} ) ;
Global Example:
public static void main(String[] args) {
ThunderServer thunderServer = Thunder.createServer(new ThunderListener() {
@Override
public void handlePacket(Packet packet, ThunderConnection thunderConnection) throws IOException {
if (packet instanceof SamplePacket) {
packet.respond(ResponseStatus.SUCESS, "Packet Received");
}
}
@Override
public void handleConnect(ThunderConnection thunderConnection) {
System.out.println("[Server] New Connection from " + thunderConnection + "!");
}
@Override
public void handleDisconnect(ThunderConnection thunderConnection) {
System.out.println("[Server] " + thunderConnection + " has disconnected!");
}
});
ThunderClient thunderClient = Thunder.createClient();
thunderServer.start(1401).perform();
thunderClient.connect("127.0.0.1", 1401).perform(new Consumer<ThunderClient>() {
@Override
public void accept(ThunderClient thunderClient) {
thunderClient.sendPacket(new SamplePacket("Luca", 16), new Consumer<Response>() {
@Override
public void accept(Response response) {
System.out.println(response.getStatus() + " - " + response.getMessage() + " [" + response.getProcessingTime() + "ms]");
}
});
}
});
}
----------------------------------------------------------------
If you got any questions, feel free to ask them!
Would be nice if you could report any bugs to me
or maybe even review this resource if you like it.
This resource is used to send Packets from a Client to a Server or the other way around.
Basic Instructions:
Code (Java):
Thunder. useCompressor ( true ) ; //This compresses every Packet
Thunder. setLogging (LogLevel. ERROR ) ;
//LogLevel.OFF
//LogLevel.ALL
//LogLevel.DEBUG
//LogLevel.WARNING
//LogLevel.INFO
The ThunderConnection has its own unique Methods which the Client and Server then also have.
Code (Java):
ThunderConnection thunderConnection = (ThunderConnection ) yourObject ; //Server or Client
thunderConnection. disconnect ( ) ; //Stops the server or disconnects from the server if client
thunderConnection. addHandler (thunderListener ) ; //Adds a ThunderListener
thunderConnection. addPacketHandler (packet -> { } ) ; //Adds a packetHandler
thunderConnection. setName ( "YourName" ) ; //Sets the name of the connection
thunderConnection. sendPacket (packet ) ; //Method to send packets
boolean connected = thunderConnection. isConnected ( ) ; //Checks if connected
ThunderSession session = thunderConnection. getSession ( ) ; //Session of the Connection
PacketAdapter packetAdapter = thunderConnection. getPacketAdapter ( ) ; //Used to handle Packets
Code (Java):
ThunderServer thunderServer = Thunder. createServer ( ) ;
thunderServer. start ( 1401 ). perform ( ) ;
Code (Java):
ThunderClient thunderClient = Thunder. createClient ( ) ;
thunderClient. connect ( "yourHost", 1401 ). perform ( ) ;
Code (Java):
public class SamplePacket extends Packet {
private String name ;
private int age ;
public SamplePacket ( String name, int age ) {
this. name = name ;
this. age = age ;
}
@Override
public void write (PacketBuffer buf ) {
buf. writeString ( this. name ) ;
buf. writeInt ( this. age ) ;
}
@Override
public void read (PacketBuffer buf ) {
this. name = buf. readString ( ) ;
this. age = buf. readInt ( ) ;
}
}
Code (Java):
ThunderClient thunderClient = Thunder. createClient ( ) ;
thunderClient. connect ( "yourHost", 1401 ). perform ( new Consumer <ThunderClient > ( ) {
@Override
public void accept (ThunderClient thunderClient ) {
//This will be called when the Action ( .perform() )
// is done and the client is connected
SamplePacket samplePacket = new SamplePacket ( "Name", 16 ) ;
thunderClient. sendPacket (samplePacket ) ;
}
} ) ;
Code (Java):
thunderClient. addPacketHandler ( new PacketHandler ( ) {
@Override
public void handle (ThunderPacket packet ) {
//Check if packet is SamplePacket
if (packet instanceof SamplePacket ) {
SamplePacket samplePacket = (SamplePacket ) packet ;
System. out. println (samplePacket. getAge ( ) ) ;
System. out. println (samplePacket. getName ( ) ) ;
System. out. println (samplePacket. getProcessingTime ( ) + "ms" ) ; //The time the packet took
System. out. println (samplePacket. toString ( ) ) ; //Information on the Packet
}
}
} ) ;
Working with ThunderSessions:
Every ThunderConnection has its own ThunderSession.
From it you can seperate Clients and Servers from eachother.
Code (Java):
ThunderSession thunderSession = thunderClient. getSession ( ) ;
boolean authenticated = thunderSession. isAuthenticated ( ) ; //If the session is authenticated
String sessionId = thunderSession. getSessionId ( ) ; //Name of the session (if set)
UUID uniqueId = thunderSession. getUniqueId ( ) ; //UUID of the session
long startTime = thunderSession. getStartTime ( ) ; //Time when the session started
List <ThunderSession > connectedSessions = thunderSession. getConnectedSessions ( ) ; //Connected Sessions
Channel channel = thunderSession. getChannel ( ) ; //Channel of this Session
Code (Java):
ThunderClient thunderClient = Thunder. createClient ( ) ;
thunderClient. connect ( "yourHost", 1401 ). perform ( ) ;
thunderClient. writePacket ( new SamplePacket ( "YourName", 16 ) ) ; //Sends a packet to the client
Code (Java):
ThunderServer thunderServer = Thunder. createServer ( ) ;
thunderServer. start ( 1401 ). perform ( ) ;
UUID uuid = ... uuid of the Client youre trying to find
thunderServer. sendPacket ( new SamplePacket ( "YourName", 15 ), thunderServer. getSession ( ). getSession (uuid ) ) ;
//Sends a packet only to one connection
Code (Java):
thunderServer. addHandler ( new ThunderListener ( ) {
@Override
public void handleConnect (ThunderConnection thunderConnection ) {
ThunderClient thunderClient = (ThunderClient ) thunderConnection ;
//This is a ThunderClient now do what you want
}
@Override
public void handleDisconnect (ThunderConnection thunderConnection ) {
ThunderClient thunderClient = (ThunderClient ) thunderConnection ;
//This is a ThunderClient now do what you want
}
@Override
public void handlePacket (ThunderPacket packet, ThunderConnection thunderConnection ) throws IOException {
//Do what you want
//Is the same as PacketHandler
}
@Override
public void read (Packet packet, ThunderConnection thunderConnection ) throws IOException {
//Do what you want
//This is the raw Packet before getting transformed into
//ThunderPacket or BufferedPacket
}
} ) ;
Code (Text):
public static void main(String[] args) {
ThunderServer thunderServer = Thunder.createServer(new ThunderListener() {
@Override
public void handlePacket(Packet packet, ThunderConnection thunderConnection) throws IOException {
if (packet instanceof SamplePacket) {
packet.respond(ResponseStatus.SUCESS, "Packet Received");
}
}
@Override
public void handleConnect(ThunderConnection thunderConnection) {
System.out.println("[Server] New Connection from " + thunderConnection + "!");
}
@Override
public void handleDisconnect(ThunderConnection thunderConnection) {
System.out.println("[Server] " + thunderConnection + " has disconnected!");
}
});
ThunderClient thunderClient = Thunder.createClient();
thunderServer.start(1401).perform();
thunderClient.connect("127.0.0.1", 1401).perform(new Consumer<ThunderClient>() {
@Override
public void accept(ThunderClient thunderClient) {
thunderClient.sendPacket(new SamplePacket("Luca", 16), new Consumer<Response>() {
@Override
public void accept(Response response) {
System.out.println(response.getStatus() + " - " + response.getMessage() + " [" + response.getProcessingTime() + "ms]");
}
});
}
});
}
If you got any questions, feel free to ask them!
Would be nice if you could report any bugs to me
or maybe even review this resource if you like it.
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.7, 1.8, 1.9
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
Thunder - Networking Library is a free Minecraft Java mod. Compatible with Minecraft 1.7, 1.8, 1.9, 1.10 and newer. Downloaded 166 times (via Spigot). Download it and open it directly in the game.