Skip to content

Java Edition

Trollhunters501PC edited this page Mar 19, 2025 · 14 revisions

Maven

In maven you must add the following repository:

<repository>
  <id>jitpack.io</id>
  <url>https://jitpack.io</url>
</repository>

I in dependencies:

<dependency>
 <groupId>com.github.Creadores-Program</groupId>
 <artifactId>ServerWebGamePost</artifactId>
 <version>1.2.1</version>
</dependency>

Or by the releases jar file

<dependency>
 <groupId>org.creadoresprogram</groupId>
 <artifactId>ServerWebGamePost</artifactId>
 <version>1.2.1</version>
</dependency>

Create Server

Processing Datapackets

First you need to extend the org.CreadoresProgram.ServerWebGamePost.server.ProcessDatapackServer class

And to process the datapackets that the client sends you must implement Override to the processDatapack function

Something like that:

@Override
public void processDatapack(JSONObject datapack){
      //code...
      //JSONObject= com.alibaba.fastjson2.JSONObject
      //this.server = org.CreadoresProgram.ServerWebGamePost.server.ServerWebGamePostServer instance
}

Send Datapackets

Simply in the org.CreadoresProgram.ServerWebGamePost.server.ServerWebGamePostServer class Execute the sendDataPacket function

Something like that:

//ServerWebGamePostServer = server
server.sendDataPacket(identifier, json); //identifier you must obtain from the datapacket that the client gives in its datapacket (it is a String) json Is com.alibaba.fastjson2.JSONObject

Ban IP

You can ban IPs with the banIp and unbanIp functions in ServerWebGamePostServer class (The IP is String and is only that argument)

Filter Origins

If you never run filter origins the origin header will be "*" if you run it it will only accept the given origins (Origin Header) The functions addFilterOrigin and removeFilterOrigin in ServerWebGamePostServer class only accept one string argument.

Create instance

You must create a new org.CreadoresProgram.ServerWebGamePost.server.ServerWebGamePostServer instance

ServerWebGamePostServer server = new ServerWebGamePostServer(port, imgSrc, procecerDatapacks);
// port = int(Here you must specify the port where the server opens), imgSrc = String (Directory in string of the server icon type image can be null), procecerDatapacks = ProcessDatapackServer (Datapacket handling instance class)

Implement HTTPS encryption

If you want to implement HTTPS just use the Spark java API

Get the spark service:

//ServerWebGamePostServer = server
server.getSparkServer();

Stop server

just run the stop function in the Server class

Create Client

Processing Datapackets

First you need to extend the org.CreadoresProgram.ServerWebGamePost.client.ProcessDatapackClient class

And to process the datapackets that the server sends you must implement Override to the processDatapack function

Something like that:

@Override
public void processDatapack(JSONObject datapack){
      //code...
      //JSONObject= com.alibaba.fastjson2.JSONObject
      //this.server = org.CreadoresProgram.ServerWebGamePost.client.ServerWebGamePostClient instance
}

Send Datapackets

Simply in the org.CreadoresProgram.ServerWebGamePost.client.ServerWebGamePostClient class Execute the sendDataPacket function

Something like that:

//ServerWebGamePostClient = client
client.sendDataPacket(json); //Remember to add the identifier key to the json (it is a String) json Is com.alibaba.fastjson2.JSONObject

Create Instance

You must create a new org.CreadoresProgram.ServerWebGamePost.client.ServerWebGamePostClient instance

ServerWebGamePostClient client = new ServerWebGamePostClient(domain, port, isHttps);
// domain = String(server domain or ip), port = int(Here you must specify the port where the server), isHttps = boolean(Find out if the server has HTTPS encryption or not)
ProcessDatapackClient procecerDatapacks = new ProcessDatapackClient(client);//your class extends
client.setProcessDatapacks(procecerDatapacks);
//procecerDatapacks = ProcessDatapackClient (Datapacket handling instance class)