Loading & Saving support for MongoDB

This commit is contained in:
simon
2018-01-02 17:45:58 -05:00
parent e2763faeee
commit 4e76d57ef9
43 changed files with 702 additions and 412 deletions

View File

@@ -1,10 +1,10 @@
package net.simon987.mischwplugin;
import com.mongodb.BasicDBObject;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.assembly.Util;
import org.json.simple.JSONObject;
public class Clock extends CpuHardware {
@@ -28,15 +28,18 @@ public class Clock extends CpuHardware {
return HWID;
}
public static Clock deserialize(JSONObject hwJSON) {
public static Clock deserialize() {
return new Clock();
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
return json;
@Override
public BasicDBObject mongoSerialise() {
BasicDBObject dbObject = new BasicDBObject();
dbObject.put("hwid", (int) HWID);
return dbObject;
}
}

View File

@@ -1,12 +1,12 @@
package net.simon987.mischwplugin;
import com.mongodb.DBObject;
import net.simon987.mischwplugin.event.CpuInitialisationListener;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.io.CpuHardwareDeserializer;
import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin;
import org.json.simple.JSONObject;
public class MiscHWPlugin extends ServerPlugin implements CpuHardwareDeserializer {
@@ -19,14 +19,14 @@ public class MiscHWPlugin extends ServerPlugin implements CpuHardwareDeserialize
}
@Override
public CpuHardware deserializeHardware(JSONObject hwJson) {
int hwid = (int) (long) hwJson.get("hwid");
public CpuHardware deserializeHardware(DBObject hwJson) {
int hwid = (int) hwJson.get("hwid");
switch (hwid) {
case RandomNumberGenerator.HWID:
return RandomNumberGenerator.deserialize(hwJson);
return RandomNumberGenerator.deserialize();
case Clock.HWID:
return Clock.deserialize(hwJson);
return Clock.deserialize();
}
return null;

View File

@@ -1,8 +1,8 @@
package net.simon987.mischwplugin;
import com.mongodb.BasicDBObject;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.json.simple.JSONObject;
import java.util.Random;
@@ -31,14 +31,16 @@ public class RandomNumberGenerator extends CpuHardware {
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
public BasicDBObject mongoSerialise() {
return json;
BasicDBObject dbObject = new BasicDBObject();
dbObject.put("hwid", (int) HWID);
return dbObject;
}
public static RandomNumberGenerator deserialize(JSONObject hwJSON) {
public static RandomNumberGenerator deserialize() {
return new RandomNumberGenerator();
}
}