-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix socket in test, keep working on integrator
- Loading branch information
1 parent
26a62a2
commit 2c8d2fc
Showing
8 changed files
with
171 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Integrator/src/main/java/io/github/theblueburger/burgerpanelintegrator/Packet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.github.theblueburger.burgerpanelintegrator; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
import java.io.IOException; | ||
|
||
public abstract class Packet { | ||
protected abstract void execute(JSONObject data, String id) throws IOException; | ||
} |
31 changes: 31 additions & 0 deletions
31
Integrator/src/main/java/io/github/theblueburger/burgerpanelintegrator/PacketHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.theblueburger.burgerpanelintegrator; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
public class PacketHandler { | ||
HashMap<String, Packet> packets = new HashMap<>(); | ||
void addPacket(String name, Packet packet) { | ||
packets.put(name, packet); | ||
} | ||
void execute(JSONObject data) throws IOException { | ||
Object packetNameProbablyString = data.get("packet"); | ||
if(!(packetNameProbablyString instanceof String packetName)) { | ||
BurgerPanelIntegrator.logger.error("BurgerPanel backend sent a invalid packet, .packet isn't a string!"); | ||
return; | ||
} | ||
Packet packet = packets.get(packetName); | ||
if(packet == null) { | ||
BurgerPanelIntegrator.logger.error("BurgerPanel backend sent a invalid packet, .packet isn't a valid packet!"); | ||
return; | ||
} | ||
Object packetID = data.get("id"); | ||
if(!(packetID instanceof String packetIDString)) { | ||
BurgerPanelIntegrator.logger.error("BurgerPanel backend sent a invalid packet, .id isn't a string!"); | ||
return; | ||
} | ||
packet.execute((JSONObject)data.get("data"), packetIDString); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...tor/src/main/java/io/github/theblueburger/burgerpanelintegrator/packets/StatusPacket.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.theblueburger.burgerpanelintegrator.packets; | ||
|
||
import io.github.theblueburger.burgerpanelintegrator.BurgerPanelIntegrator; | ||
import io.github.theblueburger.burgerpanelintegrator.Packet; | ||
import org.bukkit.Bukkit; | ||
import org.json.simple.JSONObject; | ||
|
||
import java.io.IOException; | ||
|
||
public class StatusPacket extends Packet { | ||
@Override | ||
protected void execute(JSONObject data, String id) throws IOException { | ||
JSONObject responseObj = new JSONObject(); | ||
responseObj.put("tps", Bukkit.getServer().getTPS()[0]); | ||
BurgerPanelIntegrator.respond(id, responseObj); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters