mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
JSONSerialisable objects now have a debug function #156
This commit is contained in:
@@ -42,6 +42,11 @@ public abstract class Item implements JSONSerialisable, MongoSerializable {
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject debugJsonSerialise() {
|
||||
return jsonSerialise();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document document = new Document();
|
||||
|
||||
@@ -234,6 +234,11 @@ public abstract class GameObject implements JSONSerialisable, MongoSerializable
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject debugJsonSerialise() {
|
||||
return jsonSerialise();
|
||||
}
|
||||
|
||||
|
||||
public boolean isAt(int x, int y) {
|
||||
return this.x == x && this.y == y;
|
||||
|
||||
@@ -139,6 +139,11 @@ public class TileMap implements JSONSerialisable, MongoSerializable {
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject debugJsonSerialise() {
|
||||
return jsonSerialise();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
|
||||
|
||||
@@ -6,4 +6,6 @@ public interface JSONSerialisable {
|
||||
|
||||
JSONObject jsonSerialise();
|
||||
|
||||
JSONObject debugJsonSerialise();
|
||||
|
||||
}
|
||||
|
||||
@@ -15,14 +15,14 @@ public class ObjectsRequestHandler implements MessageHandler {
|
||||
@Override
|
||||
public void handle(OnlineUser user, JSONObject json) throws IllegalStateException, IOException {
|
||||
if (json.get("t").equals("object")) {
|
||||
// LogManager.LOGGER.fine("(WS) Objects request from " + user.getUser().getUsername());
|
||||
|
||||
int x, y;
|
||||
String dimension;
|
||||
boolean sendDebugInfo;
|
||||
try {
|
||||
x = Long.valueOf((long) json.get("x")).intValue();
|
||||
y = Long.valueOf((long) json.get("y")).intValue();
|
||||
dimension = (String) json.get("dimension");
|
||||
sendDebugInfo = json.containsKey("debug") && (boolean) json.get("debug");
|
||||
} catch (Exception e) {
|
||||
LogManager.LOGGER.severe("(WS) Malformed Objects request from " + user.getUser().getUsername());
|
||||
return;
|
||||
@@ -37,7 +37,11 @@ public class ObjectsRequestHandler implements MessageHandler {
|
||||
|
||||
|
||||
for (GameObject object : world.getGameObjects()) {
|
||||
objects.add(object.jsonSerialise());
|
||||
if (sendDebugInfo) {
|
||||
objects.add(object.debugJsonSerialise());
|
||||
} else {
|
||||
objects.add(object.jsonSerialise());
|
||||
}
|
||||
}
|
||||
|
||||
response.put("t", "object");
|
||||
|
||||
@@ -105,6 +105,7 @@ public class SocketServer {
|
||||
*/
|
||||
public void tick() {
|
||||
|
||||
//TODO: refactor this function (1. Create json instance for each user 2. Extract functions 3. rename variables)
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("t", "tick");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user