diff --git a/Plugin Cubot/Plugin Cubot.iml b/Plugin Cubot/Plugin Cubot.iml index 4feea78..6182e32 100644 --- a/Plugin Cubot/Plugin Cubot.iml +++ b/Plugin Cubot/Plugin Cubot.iml @@ -1,5 +1,10 @@ + + + + + @@ -15,14 +20,14 @@ - - - - - - - - + + + + + + + + diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java index dca9ab0..3da3052 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java @@ -1,13 +1,12 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.ServerConfiguration; import net.simon987.server.assembly.Memory; import net.simon987.server.game.*; import net.simon987.server.logging.LogManager; import net.simon987.server.user.User; +import org.bson.Document; import org.json.simple.JSONObject; import java.awt.*; @@ -251,8 +250,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("t", ID); @@ -276,7 +275,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr return dbObject; } - public static Cubot deserialize(DBObject obj) { + public static Cubot deserialize(Document obj) { Cubot cubot = new Cubot(); cubot.setObjectId((long) obj.get("i")); @@ -294,7 +293,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr cubot.maxShield = config.getInt("cubot_max_shield"); return cubot; - } /** diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotBattery.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotBattery.java index fc50e7a..530a7f5 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotBattery.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotBattery.java @@ -1,10 +1,9 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; +import org.bson.Document; public class CubotBattery extends CpuHardware { @@ -45,9 +44,9 @@ public class CubotBattery extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -56,7 +55,7 @@ public class CubotBattery extends CpuHardware { } - public static CubotBattery deserialize(DBObject obj) { + public static CubotBattery deserialize(Document obj) { return new CubotBattery((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java index 459ac77..176803c 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java @@ -1,12 +1,11 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; import net.simon987.server.game.GameObject; import net.simon987.server.game.Programmable; +import org.bson.Document; import java.awt.*; import java.util.ArrayList; @@ -128,9 +127,9 @@ public class CubotComPort extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -138,7 +137,7 @@ public class CubotComPort extends CpuHardware { return dbObject; } - public static CubotComPort deserialize(DBObject obj) { + public static CubotComPort deserialize(Document obj) { return new CubotComPort((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java index 021dc62..5e4d50e 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java @@ -1,10 +1,9 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; +import org.bson.Document; public class CubotCore extends CpuHardware { @@ -42,9 +41,9 @@ public class CubotCore extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -53,7 +52,7 @@ public class CubotCore extends CpuHardware { } - public static CubotCore deserialize(DBObject obj) { + public static CubotCore deserialize(Document obj) { return new CubotCore((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java index 975deab..edc7bc1 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java @@ -1,12 +1,11 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; import net.simon987.server.game.Action; import net.simon987.server.game.TileMap; +import org.bson.Document; public class CubotDrill extends CpuHardware { @@ -62,9 +61,9 @@ public class CubotDrill extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -72,7 +71,7 @@ public class CubotDrill extends CpuHardware { return dbObject; } - public static CubotDrill deserialize(DBObject obj) { + public static CubotDrill deserialize(Document obj) { return new CubotDrill((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotFloppyDrive.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotFloppyDrive.java index c4667b5..8c08a1c 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotFloppyDrive.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotFloppyDrive.java @@ -1,10 +1,9 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; +import org.bson.Document; public class CubotFloppyDrive extends CpuHardware { @@ -79,9 +78,9 @@ public class CubotFloppyDrive extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -93,12 +92,12 @@ public class CubotFloppyDrive extends CpuHardware { return dbObject; } - public static CubotFloppyDrive deserialize(DBObject obj) { + public static CubotFloppyDrive deserialize(Document obj) { CubotFloppyDrive drive = new CubotFloppyDrive((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); - if (obj.containsField("floppy")) { - drive.floppyDisk = FloppyDisk.deserialise((DBObject) obj.get("floppy")); + if (obj.containsKey("floppy")) { + drive.floppyDisk = FloppyDisk.deserialise((Document) obj.get("floppy")); } return drive; diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java index 4b89287..29060fd 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotHologram.java @@ -1,10 +1,9 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; +import org.bson.Document; public class CubotHologram extends CpuHardware { @@ -83,14 +82,14 @@ public class CubotHologram extends CpuHardware { return HWID; } - public static CubotHologram deserialize(DBObject obj) { + public static CubotHologram deserialize(Document obj) { return new CubotHologram((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotInventory.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotInventory.java index f854a2a..68a8d13 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotInventory.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotInventory.java @@ -1,10 +1,9 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; +import org.bson.Document; public class CubotInventory extends CpuHardware { @@ -52,9 +51,9 @@ public class CubotInventory extends CpuHardware { @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -62,7 +61,7 @@ public class CubotInventory extends CpuHardware { return dbObject; } - public static CubotInventory deserialize(DBObject obj) { + public static CubotInventory deserialize(Document obj) { return new CubotInventory((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotKeyboard.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotKeyboard.java index 9d19370..af15e5f 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotKeyboard.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotKeyboard.java @@ -1,10 +1,9 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; +import org.bson.Document; public class CubotKeyboard extends CpuHardware { @@ -53,9 +52,9 @@ public class CubotKeyboard extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -63,7 +62,7 @@ public class CubotKeyboard extends CpuHardware { return dbObject; } - public static CubotKeyboard deserialize(DBObject obj) { + public static CubotKeyboard deserialize(Document obj) { return new CubotKeyboard((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java index 5c27e43..a45f01a 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLaser.java @@ -1,7 +1,5 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; @@ -9,6 +7,7 @@ import net.simon987.server.game.Action; import net.simon987.server.game.Attackable; import net.simon987.server.game.GameObject; import net.simon987.server.game.InventoryHolder; +import org.bson.Document; import java.awt.*; import java.util.ArrayList; @@ -93,9 +92,9 @@ public class CubotLaser extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -103,7 +102,7 @@ public class CubotLaser extends CpuHardware { return dbObject; } - public static CubotLaser deserialize(DBObject obj) { + public static CubotLaser deserialize(Document obj) { return new CubotLaser((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLeg.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLeg.java index bb2f760..e648ee0 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLeg.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLeg.java @@ -1,13 +1,12 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; import net.simon987.server.game.Action; import net.simon987.server.game.Direction; import net.simon987.server.io.JSONSerialisable; +import org.bson.Document; import org.json.simple.JSONObject; public class CubotLeg extends CpuHardware implements JSONSerialisable { @@ -86,9 +85,9 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -96,7 +95,7 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable { return dbObject; } - public static CubotLeg deserialize(DBObject obj) { + public static CubotLeg deserialize(Document obj) { return new CubotLeg((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java index 4ae8462..aee6ad8 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotLidar.java @@ -1,7 +1,5 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Memory; @@ -10,6 +8,7 @@ import net.simon987.server.game.pathfinding.Node; import net.simon987.server.game.pathfinding.Pathfinder; import net.simon987.server.io.JSONSerialisable; import net.simon987.server.logging.LogManager; +import org.bson.Document; import org.json.simple.JSONObject; import java.util.ArrayList; @@ -150,9 +149,9 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -160,7 +159,7 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable { return dbObject; } - public static CubotLidar deserialize(DBObject obj) { + public static CubotLidar deserialize(Document obj) { return new CubotLidar((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java index b8243d1..2fb9e15 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java @@ -1,6 +1,5 @@ package net.simon987.cubotplugin; -import com.mongodb.DBObject; import net.simon987.cubotplugin.event.ChargeShieldCommandListener; import net.simon987.cubotplugin.event.CpuInitialisationListener; import net.simon987.cubotplugin.event.UserCreationListener; @@ -11,6 +10,7 @@ import net.simon987.server.io.CpuHardwareDeserializer; import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.logging.LogManager; import net.simon987.server.plugin.ServerPlugin; +import org.bson.Document; public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, CpuHardwareDeserializer { @@ -25,7 +25,7 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, } @Override - public GameObject deserializeObject(DBObject object) { + public GameObject deserializeObject(Document object) { int objType = (int) object.get("t"); @@ -38,7 +38,7 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, } @Override - public CpuHardware deserializeHardware(DBObject obj) { + public CpuHardware deserializeHardware(Document obj) { int hwid = (int) obj.get("hwid"); switch (hwid) { diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java index c45336c..7bc652e 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java @@ -1,10 +1,9 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; +import org.bson.Document; public class CubotShield extends CpuHardware { @@ -28,8 +27,8 @@ public class CubotShield extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -49,8 +48,8 @@ public class CubotShield extends CpuHardware { getCpu().getRegisterSet().getRegister("B").setValue(shield); } } - - public static CubotShield deserialize(DBObject obj) { + + public static CubotShield deserialize(Document obj) { return new CubotShield((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } \ No newline at end of file diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/FloppyDisk.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/FloppyDisk.java index 6cbd57f..017620c 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/FloppyDisk.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/FloppyDisk.java @@ -1,17 +1,16 @@ package net.simon987.cubotplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.assembly.Memory; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; +import org.bson.Document; /** * Represents a floppy disk that is inside a floppy drive. * Floppies contains 80 tracks with 18 sectors per track. * That's 1440 sectors of 512 words. (total 1,474,560 bytes / 737,280 words / 1.44Mb) */ -public class FloppyDisk implements MongoSerialisable { +public class FloppyDisk implements MongoSerializable { /** * Contents of the disk @@ -84,8 +83,8 @@ public class FloppyDisk implements MongoSerialisable { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("rwHeadTrack", rwHeadTrack); dbObject.put("memory", memory.mongoSerialise()); @@ -93,12 +92,12 @@ public class FloppyDisk implements MongoSerialisable { return dbObject; } - public static FloppyDisk deserialise(DBObject obj) { + public static FloppyDisk deserialise(Document obj) { FloppyDisk floppyDisk = new FloppyDisk(); floppyDisk.rwHeadTrack = (int) obj.get("rwHeadTrack"); - floppyDisk.memory = Memory.deserialize((DBObject) obj.get("memory")); + floppyDisk.memory = Memory.deserialize((Document) obj.get("memory")); return floppyDisk; } diff --git a/Plugin Misc HW/Plugin Misc HW.iml b/Plugin Misc HW/Plugin Misc HW.iml index 863545c..e8b738c 100644 --- a/Plugin Misc HW/Plugin Misc HW.iml +++ b/Plugin Misc HW/Plugin Misc HW.iml @@ -1,5 +1,10 @@ + + + + + @@ -14,14 +19,14 @@ - - - - - - - - + + + + + + + + diff --git a/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/Clock.java b/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/Clock.java index 886c482..a7140dc 100644 --- a/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/Clock.java +++ b/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/Clock.java @@ -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.bson.Document; /** * Hardware to get game time @@ -37,9 +37,9 @@ public class Clock extends CpuHardware { @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); diff --git a/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/MiscHWPlugin.java b/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/MiscHWPlugin.java index 099e6b6..1ff6377 100644 --- a/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/MiscHWPlugin.java +++ b/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/MiscHWPlugin.java @@ -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.bson.Document; /** * Plugin that adds miscellaneous hardware to the game @@ -22,7 +22,7 @@ public class MiscHWPlugin extends ServerPlugin implements CpuHardwareDeserialize } @Override - public CpuHardware deserializeHardware(DBObject hwJson) { + public CpuHardware deserializeHardware(Document hwJson) { int hwid = (int) hwJson.get("hwid"); switch (hwid) { diff --git a/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/RandomNumberGenerator.java b/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/RandomNumberGenerator.java index 2bceb22..c6a5cbe 100644 --- a/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/RandomNumberGenerator.java +++ b/Plugin Misc HW/src/main/java/net/simon987/mischwplugin/RandomNumberGenerator.java @@ -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.bson.Document; import java.util.Random; @@ -34,9 +34,9 @@ public class RandomNumberGenerator extends CpuHardware { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); diff --git a/Plugin NPC/Plugin NPC.iml b/Plugin NPC/Plugin NPC.iml index 9aa790c..df01d12 100644 --- a/Plugin NPC/Plugin NPC.iml +++ b/Plugin NPC/Plugin NPC.iml @@ -1,5 +1,10 @@ + + + + + @@ -17,14 +22,14 @@ - - - - - - - - + + + + + + + + diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java index 42f9323..84514a7 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java @@ -1,7 +1,5 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.Util; import net.simon987.server.game.Attackable; @@ -9,6 +7,7 @@ import net.simon987.server.game.GameObject; import net.simon987.server.game.Rechargeable; import net.simon987.server.game.Updatable; import net.simon987.server.logging.LogManager; +import org.bson.Document; import org.json.simple.JSONObject; import java.util.ArrayList; @@ -150,8 +149,8 @@ public class ElectricBox extends GameObject implements Updatable, Attackable { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); @@ -162,7 +161,7 @@ public class ElectricBox extends GameObject implements Updatable, Attackable { return dbObject; } - public static ElectricBox deserialize(DBObject obj) { + public static ElectricBox deserialize(Document obj) { ElectricBox electricBox = new ElectricBox(); electricBox.setHp((int) obj.get("hp")); diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/Factory.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/Factory.java index a76c93d..94eb7b0 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/Factory.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/Factory.java @@ -1,15 +1,14 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.game.GameObject; import net.simon987.server.game.Updatable; +import org.bson.Document; import org.json.simple.JSONObject; import java.awt.*; import java.util.ArrayList; +import java.util.List; /** * Game objects that regularly creates NonPlayerCharacters @@ -133,15 +132,15 @@ public class Factory extends GameObject implements Updatable { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); dbObject.put("y", getY()); dbObject.put("t", ID); - BasicDBList tmpNpcArray = new BasicDBList(); + List tmpNpcArray = new ArrayList<>(npcs.size()); for (NonPlayerCharacter npc : npcs) { tmpNpcArray.add(npc.getObjectId()); @@ -152,14 +151,14 @@ public class Factory extends GameObject implements Updatable { return dbObject; } - public static Factory deserialise(DBObject obj) { + public static Factory deserialise(Document obj) { Factory factory = new Factory(); factory.setObjectId((long) obj.get("i")); factory.setX((int) obj.get("x")); factory.setY((int) obj.get("y")); - factory.tmpNpcArray = ((BasicDBList) obj.get("tmpNpcArray")).toArray(); + factory.tmpNpcArray = ((ArrayList) obj.get("tmpNpcArray")).toArray(); return factory; } diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java index 43592f9..3995c6f 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java @@ -1,10 +1,9 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.event.ObjectDeathEvent; import net.simon987.server.game.Direction; +import org.bson.Document; import org.json.simple.JSONObject; @@ -80,8 +79,8 @@ public class HarvesterNPC extends NonPlayerCharacter { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); @@ -94,7 +93,7 @@ public class HarvesterNPC extends NonPlayerCharacter { return dbObject; } - public static HarvesterNPC deserialize(DBObject obj) { + public static HarvesterNPC deserialize(Document obj) { HarvesterNPC npc = new HarvesterNPC(); npc.setObjectId((long) obj.get("i")); diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java index 63526e1..0054f49 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java @@ -1,6 +1,5 @@ package net.simon987.npcplugin; -import com.mongodb.DBObject; import net.simon987.npcplugin.event.CpuInitialisationListener; import net.simon987.npcplugin.event.VaultWorldUpdateListener; import net.simon987.npcplugin.event.WorldCreationListener; @@ -11,6 +10,7 @@ import net.simon987.server.io.CpuHardwareDeserializer; import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.logging.LogManager; import net.simon987.server.plugin.ServerPlugin; +import org.bson.Document; import java.util.ArrayList; @@ -34,7 +34,7 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C } @Override - public GameObject deserializeObject(DBObject obj) { + public GameObject deserializeObject(Document obj) { int objType = (int) obj.get("t"); @@ -60,7 +60,7 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C } @Override - public CpuHardware deserializeHardware(DBObject obj) { + public CpuHardware deserializeHardware(Document obj) { int hwid = (int) obj.get("hwid"); switch (hwid) { diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java index e32ea17..dce701f 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java @@ -1,9 +1,8 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.game.Attackable; import net.simon987.server.game.GameObject; +import org.bson.Document; import org.json.simple.JSONObject; /** @@ -89,8 +88,8 @@ public class Obstacle extends GameObject implements Attackable { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); @@ -116,7 +115,7 @@ public class Obstacle extends GameObject implements Attackable { return json; } - public static Obstacle deserialize(DBObject obj) { + public static Obstacle deserialize(Document obj) { Obstacle obstacle = new Obstacle((int) obj.get("hp")); obstacle.setObjectId((long) obj.get("i")); diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/Portal.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/Portal.java index c4e6ce9..6b44973 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/Portal.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/Portal.java @@ -1,9 +1,8 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.game.*; +import org.bson.Document; import org.json.simple.JSONObject; public class Portal extends GameObject implements Enterable { @@ -48,8 +47,8 @@ public class Portal extends GameObject implements Enterable { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); @@ -64,7 +63,7 @@ public class Portal extends GameObject implements Enterable { return dbObject; } - public static Portal deserialize(DBObject obj) { + public static Portal deserialize(Document obj) { Portal portal = new Portal(); diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioReceiverHardware.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioReceiverHardware.java index c310a1c..363672c 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioReceiverHardware.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioReceiverHardware.java @@ -1,13 +1,12 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; import net.simon987.server.assembly.Util; import net.simon987.server.game.Action; import net.simon987.server.game.ControllableUnit; +import org.bson.Document; import java.util.ArrayList; @@ -67,9 +66,9 @@ public class RadioReceiverHardware extends CpuHardware { @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); @@ -77,7 +76,7 @@ public class RadioReceiverHardware extends CpuHardware { return dbObject; } - public static RadioReceiverHardware deserialize(DBObject obj) { + public static RadioReceiverHardware deserialize(Document obj) { return new RadioReceiverHardware((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); } } diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioTower.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioTower.java index f278e3b..21e8034 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioTower.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/RadioTower.java @@ -1,10 +1,9 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.game.GameObject; import net.simon987.server.game.Programmable; import net.simon987.server.game.Updatable; +import org.bson.Document; import org.json.simple.JSONObject; import java.util.ArrayList; @@ -66,8 +65,8 @@ public class RadioTower extends GameObject implements Programmable, Updatable { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); @@ -77,7 +76,7 @@ public class RadioTower extends GameObject implements Programmable, Updatable { return dbObject; } - public static RadioTower deserialize(DBObject obj) { + public static RadioTower deserialize(Document obj) { RadioTower tower = new RadioTower(); tower.setObjectId((long) obj.get("i")); diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDoor.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDoor.java index 65be131..7a3de3b 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDoor.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDoor.java @@ -1,11 +1,10 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.crypto.RandomStringGenerator; import net.simon987.server.game.*; import net.simon987.server.logging.LogManager; +import org.bson.Document; import org.json.simple.JSONObject; import java.util.Arrays; @@ -124,8 +123,8 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); @@ -152,7 +151,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up return json; } - public static VaultDoor deserialize(DBObject obj) { + public static VaultDoor deserialize(Document obj) { VaultDoor vaultDoor = new VaultDoor(0); //cypherId ? vaultDoor.setX((int) obj.get("x")); @@ -160,7 +159,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up vaultDoor.setObjectId((long) obj.get("i")); - if (obj.containsField("homeX") && obj.containsField("homeY")) { + if (obj.containsKey("homeX") && obj.containsKey("homeY")) { vaultDoor.setHomeX((int) obj.get("homeX")); vaultDoor.setHomeY((int) obj.get("homeY")); } diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultExitPortal.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultExitPortal.java index bea6435..e377391 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultExitPortal.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultExitPortal.java @@ -1,11 +1,10 @@ package net.simon987.npcplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.game.ControllableUnit; import net.simon987.server.game.GameObject; import net.simon987.server.game.Location; import net.simon987.server.logging.LogManager; +import org.bson.Document; /** * Final exit portal located in the 'last' World of a Vault dimension @@ -15,8 +14,8 @@ public class VaultExitPortal extends Portal { public static final int ID = 9; @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("i", getObjectId()); dbObject.put("x", getX()); @@ -44,7 +43,7 @@ public class VaultExitPortal extends Portal { return super.enter(object); } - public static Portal deserialize(DBObject obj) { + public static Portal deserialize(Document obj) { VaultExitPortal portal = new VaultExitPortal(); diff --git a/Plugin Plant/Plugin Plant.iml b/Plugin Plant/Plugin Plant.iml index 9aa790c..df01d12 100644 --- a/Plugin Plant/Plugin Plant.iml +++ b/Plugin Plant/Plugin Plant.iml @@ -1,5 +1,10 @@ + + + + + @@ -17,14 +22,14 @@ - - - - - - - - + + + + + + + + diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassBlob.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassBlob.java index 2e0259f..aafe0f1 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassBlob.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassBlob.java @@ -1,9 +1,8 @@ package net.simon987.biomassplugin; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.game.GameObject; import net.simon987.server.game.InventoryHolder; +import org.bson.Document; import org.json.simple.JSONObject; public class BiomassBlob extends GameObject implements InventoryHolder { @@ -43,9 +42,9 @@ public class BiomassBlob extends GameObject implements InventoryHolder { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("t", ID); dbObject.put("i", getObjectId()); @@ -65,15 +64,8 @@ public class BiomassBlob extends GameObject implements InventoryHolder { this.biomassCount = biomassCount; } -// public int getStyle() { -// return style; -// } -// -// public void setStyle(int style) { -// this.style = style; -// } - public static BiomassBlob deserialize(DBObject obj) { + public static BiomassBlob deserialize(Document obj) { BiomassBlob biomassBlob = new BiomassBlob(); diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java index fe5ab0a..d70ef59 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java @@ -1,6 +1,5 @@ package net.simon987.biomassplugin; -import com.mongodb.DBObject; import net.simon987.biomassplugin.event.ObjectDeathListener; import net.simon987.biomassplugin.event.WorldCreationListener; import net.simon987.biomassplugin.event.WorldUpdateListener; @@ -9,6 +8,8 @@ import net.simon987.server.game.GameObject; import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.logging.LogManager; import net.simon987.server.plugin.ServerPlugin; +import org.bson.Document; + public class BiomassPlugin extends ServerPlugin implements GameObjectDeserializer { @@ -23,7 +24,7 @@ public class BiomassPlugin extends ServerPlugin implements GameObjectDeserialize } @Override - public GameObject deserializeObject(DBObject object) { + public GameObject deserializeObject(Document object) { int objType = (int) object.get("t"); diff --git a/Plugin Radioactive Cloud/src/main/java/net/simon987/pluginradioactivecloud/RadioactiveCloudPlugin.java b/Plugin Radioactive Cloud/src/main/java/net/simon987/pluginradioactivecloud/RadioactiveCloudPlugin.java index bfd6e89..5ec94d0 100644 --- a/Plugin Radioactive Cloud/src/main/java/net/simon987/pluginradioactivecloud/RadioactiveCloudPlugin.java +++ b/Plugin Radioactive Cloud/src/main/java/net/simon987/pluginradioactivecloud/RadioactiveCloudPlugin.java @@ -1,11 +1,11 @@ package net.simon987.pluginradioactivecloud; -import com.mongodb.DBObject; import net.simon987.server.ServerConfiguration; import net.simon987.server.game.GameObject; import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.logging.LogManager; import net.simon987.server.plugin.ServerPlugin; +import org.bson.Document; public class RadioactiveCloudPlugin extends ServerPlugin implements GameObjectDeserializer { @@ -16,7 +16,7 @@ public class RadioactiveCloudPlugin extends ServerPlugin implements GameObjectDe } @Override - public GameObject deserializeObject(DBObject object) { + public GameObject deserializeObject(Document object) { return null; } diff --git a/Server/Server.iml b/Server/Server.iml index eb52fc3..badff86 100644 --- a/Server/Server.iml +++ b/Server/Server.iml @@ -1,5 +1,10 @@ + + + + + @@ -16,14 +21,14 @@ - - - - - - - - + + + + + + + + diff --git a/Server/pom.xml b/Server/pom.xml index 60012c3..88c0c53 100644 --- a/Server/pom.xml +++ b/Server/pom.xml @@ -107,12 +107,12 @@ org.mongodb mongo-java-driver - 2.10.1 + 3.7.0 org.springframework.security spring-security-core - 5.0.4.RELEASE + 5.0.5.RELEASE com.sparkjava diff --git a/Server/src/main/java/net/simon987/server/GameServer.java b/Server/src/main/java/net/simon987/server/GameServer.java index ad81fe1..8ac7633 100644 --- a/Server/src/main/java/net/simon987/server/GameServer.java +++ b/Server/src/main/java/net/simon987/server/GameServer.java @@ -1,7 +1,11 @@ package net.simon987.server; -import com.mongodb.*; +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.UpdateOptions; import net.simon987.server.crypto.CryptoProvider; import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventDispatcher; @@ -16,9 +20,9 @@ import net.simon987.server.user.User; import net.simon987.server.user.UserManager; import net.simon987.server.user.UserStatsHelper; import net.simon987.server.websocket.SocketServer; +import org.bson.Document; import java.io.File; -import java.net.UnknownHostException; import java.util.ArrayList; public class GameServer implements Runnable { @@ -49,17 +53,13 @@ public class GameServer implements Runnable { this.config = new ServerConfiguration("config.properties"); - try{ - mongo = new MongoClient(config.getString("mongo_address"), config.getInt("mongo_port")); - DB db = mongo.getDB(config.getString("mongo_dbname")); + mongo = new MongoClient(config.getString("mongo_address"), config.getInt("mongo_port")); + MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname")); - DBCollection userCollection = db.getCollection("user"); + MongoCollection userCollection = db.getCollection("user"); - userManager = new UserManager(userCollection); - userStatsHelper = new UserStatsHelper(userCollection); - } catch (UnknownHostException e) { - e.printStackTrace(); - } + userManager = new UserManager(userCollection); + userStatsHelper = new UserStatsHelper(userCollection); gameUniverse = new GameUniverse(config); gameUniverse.setMongo(mongo); @@ -201,14 +201,14 @@ public class GameServer implements Runnable { LogManager.LOGGER.info("Loading all data from MongoDB"); - DB db = mongo.getDB(config.getString("mongo_dbname")); + MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname")); - DBCollection worlds = db.getCollection("world"); - DBCollection server = db.getCollection("server"); + MongoCollection worlds = db.getCollection("world"); + MongoCollection server = db.getCollection("server"); - BasicDBObject whereQuery = new BasicDBObject(); + Document whereQuery = new Document(); whereQuery.put("shouldUpdate", true); - DBCursor cursor = worlds.find(whereQuery); + MongoCursor cursor = worlds.find(whereQuery).iterator(); GameUniverse universe = GameServer.INSTANCE.getGameUniverse(); while (cursor.hasNext()) { World w = World.deserialize(cursor.next()); @@ -222,9 +222,9 @@ public class GameServer implements Runnable { } //Load misc server info - cursor = server.find(); + cursor = server.find().iterator(); if (cursor.hasNext()) { - DBObject serverObj = cursor.next(); + Document serverObj = cursor.next(); gameUniverse.setTime((long) serverObj.get("time")); gameUniverse.setNextObjectId((long) serverObj.get("nextObjectId")); } @@ -237,19 +237,21 @@ public class GameServer implements Runnable { LogManager.LOGGER.info("Saving to MongoDB | W:" + gameUniverse.getWorldCount() + " | U:" + gameUniverse.getUserCount()); try{ - DB db = mongo.getDB(config.getString("mongo_dbname")); + MongoDatabase db = mongo.getDatabase(config.getString("mongo_dbname")); + UpdateOptions updateOptions = new UpdateOptions(); + updateOptions.upsert(true); int unloaded_worlds = 0; - DBCollection worlds = db.getCollection("world"); - DBCollection users = db.getCollection("user"); - DBCollection server = db.getCollection("server"); + MongoCollection worlds = db.getCollection("world"); + MongoCollection users = db.getCollection("user"); + MongoCollection server = db.getCollection("server"); int insertedWorlds = 0; GameUniverse universe = GameServer.INSTANCE.getGameUniverse(); for (World w : universe.getWorlds()) { insertedWorlds++; - worlds.save(w.mongoSerialise()); + worlds.replaceOne(new Document("_id", w.getId()), w.mongoSerialise(), updateOptions); //If the world should unload, it is removed from the Universe after having been saved. if (w.shouldUnload()){ @@ -258,18 +260,18 @@ public class GameServer implements Runnable { } } - for (User u : GameServer.INSTANCE.getGameUniverse().getUsers()) { + for (User u : GameServer.INSTANCE.getGameUniverse().getUsers()) { if (!u.isGuest()) { - users.save(u.mongoSerialise()); + users.replaceOne(new Document("_id", u.getUsername()), u.mongoSerialise(), updateOptions); } } - BasicDBObject serverObj = new BasicDBObject(); - serverObj.put("_id", "serverinfo"); //A constant id ensures only one entry is kept and updated, instead of a new entry created every save. + Document serverObj = new Document(); serverObj.put("time", gameUniverse.getTime()); serverObj.put("nextObjectId", gameUniverse.getNextObjectId()); - server.save(serverObj); + //A constant id ensures only one entry is kept and updated, instead of a new entry created every save. + server.replaceOne(new Document("_id", "serverinfo"), serverObj, updateOptions); LogManager.LOGGER.info("" + insertedWorlds + " worlds saved, " + unloaded_worlds + " unloaded"); } catch (Exception e) { diff --git a/Server/src/main/java/net/simon987/server/ServerConfiguration.java b/Server/src/main/java/net/simon987/server/ServerConfiguration.java index b5d2f8a..8cff8b6 100644 --- a/Server/src/main/java/net/simon987/server/ServerConfiguration.java +++ b/Server/src/main/java/net/simon987/server/ServerConfiguration.java @@ -3,7 +3,6 @@ package net.simon987.server; import net.simon987.server.logging.LogManager; -import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; diff --git a/Server/src/main/java/net/simon987/server/assembly/CPU.java b/Server/src/main/java/net/simon987/server/assembly/CPU.java index ba128dd..ebc869a 100755 --- a/Server/src/main/java/net/simon987/server/assembly/CPU.java +++ b/Server/src/main/java/net/simon987/server/assembly/CPU.java @@ -1,26 +1,26 @@ package net.simon987.server.assembly; -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.ServerConfiguration; import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.assembly.instruction.*; import net.simon987.server.event.CpuInitialisationEvent; import net.simon987.server.event.GameEvent; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; import net.simon987.server.logging.LogManager; import net.simon987.server.user.User; +import org.bson.Document; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; /** * CPU: Central Processing Unit. A CPU is capable of reading bytes from * a Memory object and execute them. A CPU object holds registers objects and * a Memory object. */ -public class CPU implements MongoSerialisable { +public class CPU implements MongoSerializable { /** * @@ -347,21 +347,21 @@ public class CPU implements MongoSerialisable { } @Override - public BasicDBObject mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + public Document mongoSerialise() { + Document dbObject = new Document(); dbObject.put("memory", memory.mongoSerialise()); dbObject.put("registerSet", registerSet.mongoSerialise()); dbObject.put("codeSegmentOffset", codeSectionOffset); - BasicDBList hardwareList = new BasicDBList(); + List hardwareList = new ArrayList<>(); for (Integer address : attachedHardware.keySet()) { CpuHardware hardware = attachedHardware.get(address); - BasicDBObject serialisedHw = hardware.mongoSerialise(); + Document serialisedHw = hardware.mongoSerialise(); serialisedHw.put("address", address); hardwareList.add(serialisedHw); } @@ -372,22 +372,22 @@ public class CPU implements MongoSerialisable { } - public static CPU deserialize(DBObject obj, User user) throws CancelledException { + public static CPU deserialize(Document obj, User user) throws CancelledException { CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), user); cpu.codeSectionOffset = (int) obj.get("codeSegmentOffset"); - BasicDBList hardwareList = (BasicDBList) obj.get("hardware"); + ArrayList hardwareList = (ArrayList) obj.get("hardware"); for (Object serialisedHw : hardwareList) { - CpuHardware hardware = CpuHardware.deserialize((DBObject) serialisedHw); + CpuHardware hardware = CpuHardware.deserialize((Document) serialisedHw); hardware.setCpu(cpu); - cpu.attachHardware(hardware, (int) ((BasicDBObject) serialisedHw).get("address")); + cpu.attachHardware(hardware, (int) ((Document) serialisedHw).get("address")); } - cpu.memory = Memory.deserialize((DBObject) obj.get("memory")); - cpu.registerSet = RegisterSet.deserialize((DBObject) obj.get("registerSet")); + cpu.memory = Memory.deserialize((Document) obj.get("memory")); + cpu.registerSet = RegisterSet.deserialize((Document) obj.get("registerSet")); return cpu; diff --git a/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java b/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java index 6c2283e..d53ff16 100644 --- a/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java +++ b/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java @@ -1,13 +1,13 @@ package net.simon987.server.assembly; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.io.CpuHardwareDeserializer; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; import net.simon987.server.plugin.ServerPlugin; +import org.bson.Document; -public abstract class CpuHardware implements MongoSerialisable { +public abstract class CpuHardware implements MongoSerializable { CPU cpu; @@ -26,7 +26,7 @@ public abstract class CpuHardware implements MongoSerialisable { public abstract char getId(); - public static CpuHardware deserialize(DBObject obj) { + public static CpuHardware deserialize(Document obj) { for (ServerPlugin plugin : GameServer.INSTANCE.getPluginManager().getPlugins()) { diff --git a/Server/src/main/java/net/simon987/server/assembly/Memory.java b/Server/src/main/java/net/simon987/server/assembly/Memory.java index 557a799..87d17e1 100755 --- a/Server/src/main/java/net/simon987/server/assembly/Memory.java +++ b/Server/src/main/java/net/simon987/server/assembly/Memory.java @@ -1,11 +1,10 @@ package net.simon987.server.assembly; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; import net.simon987.server.logging.LogManager; +import org.bson.Document; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -22,7 +21,7 @@ import java.util.zip.InflaterOutputStream; /** * Represents the available memory for a CPU in the game universe */ -public class Memory implements Target, MongoSerialisable { +public class Memory implements Target, MongoSerializable { /** @@ -133,9 +132,9 @@ public class Memory implements Target, MongoSerialisable { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -154,7 +153,7 @@ public class Memory implements Target, MongoSerialisable { return dbObject; } - public static Memory deserialize(DBObject obj) { + public static Memory deserialize(Document obj) { Memory memory = new Memory(0); diff --git a/Server/src/main/java/net/simon987/server/assembly/RegisterSet.java b/Server/src/main/java/net/simon987/server/assembly/RegisterSet.java index 4038dab..1da79fb 100755 --- a/Server/src/main/java/net/simon987/server/assembly/RegisterSet.java +++ b/Server/src/main/java/net/simon987/server/assembly/RegisterSet.java @@ -1,21 +1,20 @@ package net.simon987.server.assembly; -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; import net.simon987.server.logging.LogManager; +import org.bson.Document; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; /** * A set of registers for a CPU */ -public class RegisterSet implements Target, MongoSerialisable { +public class RegisterSet implements Target, MongoSerializable { /** * List of registers @@ -145,10 +144,10 @@ public class RegisterSet implements Target, MongoSerialisable { @Override - public BasicDBObject mongoSerialise() { - BasicDBList registers = new BasicDBList(); + public Document mongoSerialise() { + List registers = new ArrayList<>(); for (Integer index : this.registers.keySet()) { - JSONObject register = new JSONObject(); + Document register = new Document(); register.put("index", index); register.put("name", getRegister(index).getName()); @@ -157,24 +156,24 @@ public class RegisterSet implements Target, MongoSerialisable { registers.add(register); } - BasicDBObject obj = new BasicDBObject(); + Document obj = new Document(); obj.put("registers", registers); return obj; } - public static RegisterSet deserialize(DBObject obj) { + public static RegisterSet deserialize(Document obj) { RegisterSet registerSet = new RegisterSet(); - BasicDBList registers = (BasicDBList) obj.get("registers"); + List registers = (ArrayList) obj.get("registers"); for (Object sRegister : registers) { - Register register = new Register((String) ((DBObject) sRegister).get("name")); - register.setValue((int) ((DBObject) sRegister).get("value")); + Register register = new Register((String) ((Document) sRegister).get("name")); + register.setValue((int) ((Document) sRegister).get("value")); - registerSet.registers.put((int) ((DBObject) sRegister).get("index"), register); + registerSet.registers.put((int) ((Document) sRegister).get("index"), register); } diff --git a/Server/src/main/java/net/simon987/server/game/GameObject.java b/Server/src/main/java/net/simon987/server/game/GameObject.java index e0530a8..b88434d 100755 --- a/Server/src/main/java/net/simon987/server/game/GameObject.java +++ b/Server/src/main/java/net/simon987/server/game/GameObject.java @@ -1,11 +1,11 @@ package net.simon987.server.game; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.io.GameObjectDeserializer; import net.simon987.server.io.JSONSerialisable; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; import net.simon987.server.plugin.ServerPlugin; +import org.bson.Document; import org.json.simple.JSONObject; import java.awt.*; @@ -15,7 +15,7 @@ import java.util.ArrayList; * An INSTANCE of an object (e.g. a Tree, a character ...) inside the * game universe */ -public abstract class GameObject implements JSONSerialisable, MongoSerialisable { +public abstract class GameObject implements JSONSerialisable, MongoSerializable { private boolean dead; /** @@ -223,8 +223,8 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable return new JSONObject(); } - public static GameObject deserialize(DBObject obj) { -// + public static GameObject deserialize(Document obj) { + for (ServerPlugin plugin : GameServer.INSTANCE.getPluginManager().getPlugins()) { if (plugin instanceof GameObjectDeserializer) { diff --git a/Server/src/main/java/net/simon987/server/game/GameUniverse.java b/Server/src/main/java/net/simon987/server/game/GameUniverse.java index 18dadd5..d95e0e2 100644 --- a/Server/src/main/java/net/simon987/server/game/GameUniverse.java +++ b/Server/src/main/java/net/simon987/server/game/GameUniverse.java @@ -1,6 +1,9 @@ package net.simon987.server.game; -import com.mongodb.*; +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; +import com.mongodb.client.MongoDatabase; import net.simon987.server.GameServer; import net.simon987.server.ServerConfiguration; import net.simon987.server.assembly.Assembler; @@ -9,6 +12,7 @@ import net.simon987.server.assembly.CPU; import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.logging.LogManager; import net.simon987.server.user.User; +import org.bson.Document; import java.util.Collection; import java.util.concurrent.ConcurrentHashMap; @@ -56,12 +60,12 @@ public class GameUniverse { */ private World loadWorld(int x, int y, String dimension) { - DB db = mongo.getDB(GameServer.INSTANCE.getConfig().getString("mongo_dbname")); - DBCollection worlds = db.getCollection("world"); + MongoDatabase db = mongo.getDatabase(GameServer.INSTANCE.getConfig().getString("mongo_dbname")); + MongoCollection worlds = db.getCollection("world"); - BasicDBObject whereQuery = new BasicDBObject(); + Document whereQuery = new Document(); whereQuery.put("_id", World.idFromCoordinates(x, y, dimension)); - DBCursor cursor = worlds.find(whereQuery); + MongoCursor cursor = worlds.find(whereQuery).iterator(); if (cursor.hasNext()) { return World.deserialize(cursor.next()); } diff --git a/Server/src/main/java/net/simon987/server/game/TileMap.java b/Server/src/main/java/net/simon987/server/game/TileMap.java index 79c791c..93d0dd3 100755 --- a/Server/src/main/java/net/simon987/server/game/TileMap.java +++ b/Server/src/main/java/net/simon987/server/game/TileMap.java @@ -1,16 +1,15 @@ package net.simon987.server.game; -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.io.JSONSerialisable; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; +import org.bson.Document; import org.json.simple.JSONObject; import java.awt.*; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.util.ArrayList; import java.util.Base64; import java.util.Random; import java.util.zip.Deflater; @@ -19,7 +18,7 @@ import java.util.zip.DeflaterOutputStream; /** * A 2D map of Tile objects of size width*height */ -public class TileMap implements JSONSerialisable, MongoSerialisable { +public class TileMap implements JSONSerialisable, MongoSerializable { public static final int VOID = -1; public static final int PLAIN_TILE = 0; @@ -141,25 +140,34 @@ public class TileMap implements JSONSerialisable, MongoSerialisable { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); - dbObject.put("tiles", tiles); + //Flatten multi-dimensional array + ArrayList bsonTiles = new ArrayList<>(); + + for (int x = 0; x < this.width; x++) { + for (int y = 0; y < this.height; y++) { + bsonTiles.add(tiles[x][y]); + } + } + + dbObject.put("tiles", bsonTiles); return dbObject; } - public static TileMap deserialize(DBObject object, int size) { + public static TileMap deserialize(Document object, int size) { - BasicDBList terrain = (BasicDBList) object.get("tiles"); + ArrayList terrain = (ArrayList) object.get("tiles"); int[][] tiles = new int[size][size]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { - tiles[x][y] = (int) ((BasicDBList) terrain.get(x)).get(y); + tiles[x][y] = terrain.get(x * size + y); } } diff --git a/Server/src/main/java/net/simon987/server/game/World.java b/Server/src/main/java/net/simon987/server/game/World.java index 18d4472..2abbbf9 100644 --- a/Server/src/main/java/net/simon987/server/game/World.java +++ b/Server/src/main/java/net/simon987/server/game/World.java @@ -1,21 +1,20 @@ package net.simon987.server.game; -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.event.GameEvent; import net.simon987.server.event.WorldUpdateEvent; import net.simon987.server.game.pathfinding.Pathfinder; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; +import org.bson.Document; import java.awt.*; import java.util.ArrayList; import java.util.Collection; +import java.util.List; import java.util.Random; import java.util.concurrent.ConcurrentHashMap; -public class World implements MongoSerialisable { +public class World implements MongoSerializable { /** * Size of the side of this world @@ -171,17 +170,15 @@ public class World implements MongoSerialisable { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); - BasicDBList objects = new BasicDBList(); + List objects = new ArrayList<>(); for (GameObject obj : gameObjects.values()) { objects.add(obj.mongoSerialise()); } - - dbObject.put("_id", getId()); dbObject.put("dimension", getDimension()); dbObject.put("objects", objects); @@ -214,7 +211,7 @@ public class World implements MongoSerialisable { } - public static World deserialize(DBObject dbObject) { + public static World deserialize(Document dbObject) { World world = new World((int) dbObject.get("size")); world.x = (int) dbObject.get("x"); @@ -222,13 +219,13 @@ public class World implements MongoSerialisable { world.dimension = (String) dbObject.get("dimension"); world.updatable = (int) dbObject.get("updatable"); - world.tileMap = TileMap.deserialize((BasicDBObject) dbObject.get("terrain"), world.getWorldSize()); + world.tileMap = TileMap.deserialize((Document) dbObject.get("terrain"), world.getWorldSize()); - BasicDBList objects = (BasicDBList) dbObject.get("objects"); + ArrayList objects = (ArrayList) dbObject.get("objects"); for (Object obj : objects) { - GameObject object = GameObject.deserialize((DBObject) obj); + GameObject object = GameObject.deserialize((Document) obj); object.setWorld(world); world.addObject(object); diff --git a/Server/src/main/java/net/simon987/server/game/debug/SpawnObjCommandListener.java b/Server/src/main/java/net/simon987/server/game/debug/SpawnObjCommandListener.java index a93298a..d486e58 100644 --- a/Server/src/main/java/net/simon987/server/game/debug/SpawnObjCommandListener.java +++ b/Server/src/main/java/net/simon987/server/game/debug/SpawnObjCommandListener.java @@ -1,13 +1,12 @@ package net.simon987.server.game.debug; -import com.mongodb.DBObject; -import com.mongodb.util.JSON; import net.simon987.server.GameServer; import net.simon987.server.event.DebugCommandEvent; import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventListener; import net.simon987.server.game.GameObject; import net.simon987.server.game.World; +import org.bson.Document; import java.util.Arrays; @@ -28,7 +27,7 @@ public class SpawnObjCommandListener implements GameEventListener { World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"), false, e.getString("dimension")); - DBObject dbObj = (DBObject) JSON.parse(e.getString("data")); + Document dbObj = Document.parse(e.getString("data")); dbObj.put("i", GameServer.INSTANCE.getGameUniverse().getNextObjectId()); GameObject object = GameObject.deserialize(dbObj); diff --git a/Server/src/main/java/net/simon987/server/io/CpuHardwareDeserializer.java b/Server/src/main/java/net/simon987/server/io/CpuHardwareDeserializer.java index 8d0caca..e472eec 100644 --- a/Server/src/main/java/net/simon987/server/io/CpuHardwareDeserializer.java +++ b/Server/src/main/java/net/simon987/server/io/CpuHardwareDeserializer.java @@ -1,10 +1,10 @@ package net.simon987.server.io; -import com.mongodb.DBObject; import net.simon987.server.assembly.CpuHardware; +import org.bson.Document; public interface CpuHardwareDeserializer { - CpuHardware deserializeHardware(DBObject hwJson); + CpuHardware deserializeHardware(Document hwJson); } diff --git a/Server/src/main/java/net/simon987/server/io/GameObjectDeserializer.java b/Server/src/main/java/net/simon987/server/io/GameObjectDeserializer.java index c7b5799..bab1a67 100644 --- a/Server/src/main/java/net/simon987/server/io/GameObjectDeserializer.java +++ b/Server/src/main/java/net/simon987/server/io/GameObjectDeserializer.java @@ -1,10 +1,10 @@ package net.simon987.server.io; -import com.mongodb.DBObject; import net.simon987.server.game.GameObject; +import org.bson.Document; public interface GameObjectDeserializer { - GameObject deserializeObject(DBObject object); + GameObject deserializeObject(Document object); } diff --git a/Server/src/main/java/net/simon987/server/io/MongoSerialisable.java b/Server/src/main/java/net/simon987/server/io/MongoSerialisable.java deleted file mode 100644 index 38f0dd1..0000000 --- a/Server/src/main/java/net/simon987/server/io/MongoSerialisable.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.simon987.server.io; - -import com.mongodb.BasicDBObject; - -public interface MongoSerialisable { - - BasicDBObject mongoSerialise(); - -} diff --git a/Server/src/main/java/net/simon987/server/io/MongoSerializable.java b/Server/src/main/java/net/simon987/server/io/MongoSerializable.java new file mode 100644 index 0000000..74556a0 --- /dev/null +++ b/Server/src/main/java/net/simon987/server/io/MongoSerializable.java @@ -0,0 +1,9 @@ +package net.simon987.server.io; + +import org.bson.Document; + +public interface MongoSerializable { + + Document mongoSerialise(); + +} diff --git a/Server/src/main/java/net/simon987/server/user/User.java b/Server/src/main/java/net/simon987/server/user/User.java index 021bb95..b263731 100755 --- a/Server/src/main/java/net/simon987/server/user/User.java +++ b/Server/src/main/java/net/simon987/server/user/User.java @@ -1,19 +1,18 @@ package net.simon987.server.user; -import com.mongodb.BasicDBObject; -import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.assembly.CPU; import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.event.GameEvent; import net.simon987.server.event.UserCreationEvent; import net.simon987.server.game.ControllableUnit; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; +import org.bson.Document; /** * Represents a User (or player) of the game */ -public class User implements MongoSerialisable { +public class User implements MongoSerializable { private String username; @@ -45,9 +44,9 @@ public class User implements MongoSerialisable { } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { - BasicDBObject dbObject = new BasicDBObject(); + Document dbObject = new Document(); dbObject.put("_id", username); // a constant id ensures only one entry per user is kept and updated, instead of a new entry created every save for every user. dbObject.put("username", username); @@ -62,18 +61,18 @@ public class User implements MongoSerialisable { } - public static User deserialize(DBObject obj) throws CancelledException { + public static User deserialize(Document obj) throws CancelledException { User user = new User((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("controlledUnit"))); user.username = (String) obj.get("username"); user.userCode = (String) obj.get("code"); user.password = (String) obj.get("password"); user.moderator = (boolean) obj.get("moderator"); - user.stats = new UserStats((BasicDBObject) obj.get("stats")); + user.stats = new UserStats((Document) obj.get("stats")); user.getControlledUnit().setParent(user); - user.cpu = CPU.deserialize((DBObject) obj.get("cpu"), user); + user.cpu = CPU.deserialize((Document) obj.get("cpu"), user); return user; } diff --git a/Server/src/main/java/net/simon987/server/user/UserManager.java b/Server/src/main/java/net/simon987/server/user/UserManager.java index cf3dcc2..ef938a5 100644 --- a/Server/src/main/java/net/simon987/server/user/UserManager.java +++ b/Server/src/main/java/net/simon987/server/user/UserManager.java @@ -1,22 +1,21 @@ package net.simon987.server.user; -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; import net.simon987.server.GameServer; import net.simon987.server.assembly.exception.CancelledException; import net.simon987.server.crypto.RandomStringGenerator; import net.simon987.server.logging.LogManager; +import org.bson.Document; import org.springframework.security.crypto.bcrypt.BCrypt; import java.util.ArrayList; public class UserManager { - private DBCollection userCollection; + private MongoCollection userCollection; - public UserManager(DBCollection userCollection) { + public UserManager(MongoCollection userCollection) { this.userCollection = userCollection; } @@ -30,7 +29,7 @@ public class UserManager { ArrayList userList = new ArrayList<>(); - DBCursor cursor = userCollection.find(); + MongoCursor cursor = userCollection.find().iterator(); while (cursor.hasNext()) { try { userList.add(User.deserialize(cursor.next())); @@ -58,10 +57,10 @@ public class UserManager { } //Check if exists - DBObject where = new BasicDBObject(); + Document where = new Document(); where.put("_id", username); - if (userCollection.findOne(where) != null) { + if (userCollection.find(where).first() != null) { throw new RegistrationException("Username is already in use"); } @@ -73,9 +72,9 @@ public class UserManager { String hashedPassword = BCrypt.hashpw(password, salt); user.setPassword(hashedPassword); - DBObject dbUser = user.mongoSerialise(); + Document dbUser = user.mongoSerialise(); - userCollection.save(dbUser); + userCollection.insertOne(dbUser); } catch (Exception e) { throw new RegistrationException("An exception occurred while trying to create user: " + e.getMessage()); } @@ -89,10 +88,10 @@ public class UserManager { */ public boolean validateUser(String username, String password) { - DBObject where = new BasicDBObject(); + Document where = new Document(); where.put("_id", username); - DBObject user = userCollection.findOne(where); + Document user = userCollection.find(where).first(); return user != null && BCrypt.checkpw(password, (String) user.get("password")); } @@ -114,7 +113,7 @@ public class UserManager { String hashedPassword = BCrypt.hashpw(newPassword, salt); user.setPassword(hashedPassword); - userCollection.save(user.mongoSerialise()); //Save new password immediately + userCollection.replaceOne(new Document("_id", username), user.mongoSerialise()); //Save new password immediately } /** diff --git a/Server/src/main/java/net/simon987/server/user/UserStats.java b/Server/src/main/java/net/simon987/server/user/UserStats.java index 6d0ca22..1d82b40 100644 --- a/Server/src/main/java/net/simon987/server/user/UserStats.java +++ b/Server/src/main/java/net/simon987/server/user/UserStats.java @@ -1,28 +1,29 @@ package net.simon987.server.user; -import com.mongodb.BasicDBList; -import com.mongodb.BasicDBObject; -import net.simon987.server.io.MongoSerialisable; +import net.simon987.server.io.MongoSerializable; import net.simon987.server.logging.LogManager; +import org.bson.Document; -public class UserStats implements MongoSerialisable { +import java.util.ArrayList; - private BasicDBObject stats; +public class UserStats implements MongoSerializable { + + private Document stats; UserStats() { - this.stats = new BasicDBObject(); + this.stats = new Document(); } - UserStats(BasicDBObject stats) { + UserStats(Document stats) { if (stats != null) { this.stats = stats; } else { - this.stats = new BasicDBObject(); + this.stats = new Document(); } } @Override - public BasicDBObject mongoSerialise() { + public Document mongoSerialise() { return stats; } @@ -36,7 +37,7 @@ public class UserStats implements MongoSerialisable { public void incrementStat(String name, int count) { stats.putIfAbsent(name, 0); - stats.put(name, stats.getInt(name) + count); + stats.put(name, stats.getInteger(name) + count); } /** @@ -57,8 +58,7 @@ public class UserStats implements MongoSerialisable { * @return The value of the stat. Returns 0 if not found */ public int getInt(String name) { - - return stats.getInt(name, 0); + return stats.getInteger(name, 0); } /** @@ -69,10 +69,10 @@ public class UserStats implements MongoSerialisable { */ public void addToStringSet(String name, String value) { - stats.putIfAbsent(name, new BasicDBList()); + stats.putIfAbsent(name, new ArrayList<>()); try { - ((BasicDBList) stats.get(name)).add(value); + ((ArrayList) stats.get(name)).add(value); } catch (ClassCastException e) { LogManager.LOGGER.severe("UserStats: cannot add to list because stat already exists and is not a list"); } @@ -87,16 +87,16 @@ public class UserStats implements MongoSerialisable { */ public boolean removeFromSet(String name, String value) { - if (stats.putIfAbsent(name, new BasicDBList()) != null) { - return ((BasicDBList) stats.get(name)).remove(value); + if (stats.putIfAbsent(name, new ArrayList()) != null) { + return ((ArrayList) stats.get(name)).remove(value); } return false; } - public BasicDBList getSet(String name) { - stats.putIfAbsent(name, new BasicDBList()); + public ArrayList getSet(String name) { + stats.putIfAbsent(name, new ArrayList()); - return (BasicDBList) stats.get(name); + return (ArrayList) stats.get(name); } } \ No newline at end of file diff --git a/Server/src/main/java/net/simon987/server/user/UserStatsHelper.java b/Server/src/main/java/net/simon987/server/user/UserStatsHelper.java index 598d61f..d7097c1 100644 --- a/Server/src/main/java/net/simon987/server/user/UserStatsHelper.java +++ b/Server/src/main/java/net/simon987/server/user/UserStatsHelper.java @@ -1,11 +1,11 @@ package net.simon987.server.user; -import com.mongodb.*; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoCursor; import net.simon987.server.GameServer; +import org.bson.Document; -import java.util.AbstractMap; -import java.util.ArrayList; -import java.util.Map; +import java.util.*; /** * Retrieve user stats in a structured fashion @@ -15,12 +15,12 @@ public class UserStatsHelper { /** * Database collection of users */ - private DBCollection users; + private MongoCollection users; /** * @param users Database collection of users */ - public UserStatsHelper(DBCollection users) { + public UserStatsHelper(MongoCollection users) { this.users = users; } @@ -35,11 +35,11 @@ public class UserStatsHelper { ArrayList> rows = new ArrayList<>(); - BasicDBObject orderBy = new BasicDBObject("$stats." + statName, -1); - DBCursor cursor = users.find().sort(orderBy).limit(n); + Document orderBy = new Document("$stats." + statName, -1); + MongoCursor cursor = users.find().sort(orderBy).limit(n).iterator(); while (cursor.hasNext()) { - DBObject dbUser = cursor.next(); + Document dbUser = cursor.next(); User user = GameServer.INSTANCE.getGameUniverse().getUser((String) dbUser.get("username")); rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getInt(statName))); } @@ -54,26 +54,27 @@ public class UserStatsHelper { * @param n Maximum number of players * @return Top n players, in User,set format, in descending order */ - public ArrayList> getTopNSetLength(String statName, int n) { + public ArrayList> getTopNSetLength(String statName, int n) { - ArrayList> rows = new ArrayList<>(); + ArrayList> rows = new ArrayList<>(); - BasicDBList ifNullList = new BasicDBList(); + List ifNullList = new ArrayList<>(2); ifNullList.add("$stats." + statName); - ifNullList.add(new BasicDBList()); + ifNullList.add(new ArrayList()); - BasicDBObject project = new BasicDBObject(); - project.put("setLength", new BasicDBObject("$size", new BasicDBObject("$ifNull", ifNullList))); + Document project = new Document(); + project.put("setLength", new Document("$size", new Document("$ifNull", ifNullList))); project.put("username", 1); - Iterable results = users.aggregate( - new BasicDBObject("$project", project), - new BasicDBObject("$sort", new BasicDBObject("setLength", -1)), - new BasicDBObject("$limit", n) - ).results(); - for (DBObject dbUser : results) { - User user = GameServer.INSTANCE.getGameUniverse().getUser((String) dbUser.get("username")); + Iterator results = users.aggregate(Arrays.asList( + new Document("$project", project), + new Document("$sort", new Document("setLength", -1)), + new Document("$limit", n)) + ).iterator(); + + while (results.hasNext()) { + User user = GameServer.INSTANCE.getGameUniverse().getUser((String) results.next().get("username")); rows.add(new AbstractMap.SimpleEntry<>(user, user.getStats().getSet(statName))); } diff --git a/Server/src/main/resources/config.properties b/Server/src/main/resources/config.properties index 660cae1..c50677e 100644 --- a/Server/src/main/resources/config.properties +++ b/Server/src/main/resources/config.properties @@ -14,7 +14,7 @@ server_name=Official MAR server #Database mongo_dbname=mar_beta #Change to 'mongodb' to use in docker -mongo_address=mongodb +mongo_address=localhost mongo_port=27017 #Biomass biomass_yield=2