From 5ea0fee7e790004ceea9035b1076c5380f6cee61 Mon Sep 17 00:00:00 2001 From: Anatoly Belikov Date: Wed, 5 Jul 2023 18:04:04 +0300 Subject: [PATCH] use VERSION file to set version --- VERSION | 2 +- build.gradle | 2 +- .../Client/ClientStateMachine.java | 72 +++++++------- .../IVereyaMessageListener.java | 4 +- ...rWheeledRobotNavigationImplementation.java | 2 +- ...eeledRobotNavigationMobImplementation.java | 34 ++++++- ...obotNavigationMobImplementationServer.java | 43 ++------- .../InventoryCommandsImplementation.java | 4 +- ...InventoryCommandsImplementationServer.java | 14 +-- .../MissionHandlers/MissionBehaviour.java | 12 +-- .../SimpleCraftCommandsImplementation.java | 4 +- ...mpleCraftCommandsImplementationServer.java | 14 +-- .../Server/ServerStateMachine.java | 94 +++++++++---------- .../singularitynet/SidesMessageHandler.java | 6 +- .../java/io/singularitynet/VereyaMessage.java | 14 +-- ...essageType.java => VereyaMessageType.java} | 2 +- 16 files changed, 165 insertions(+), 158 deletions(-) rename src/main/java/io/singularitynet/{MalmoMessageType.java => VereyaMessageType.java} (98%) diff --git a/VERSION b/VERSION index 6e8bf73a..9faa1b7a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0 +0.1.5 diff --git a/build.gradle b/build.gradle index 98659cc0..cdee3752 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 -version = "0.1.4" +version = rootProject.file('VERSION').text.trim() archivesBaseName = project.archives_base_name + '-fabric_' + project.fabric_version group = project.maven_group diff --git a/src/main/java/io/singularitynet/Client/ClientStateMachine.java b/src/main/java/io/singularitynet/Client/ClientStateMachine.java index 2975678f..190785af 100755 --- a/src/main/java/io/singularitynet/Client/ClientStateMachine.java +++ b/src/main/java/io/singularitynet/Client/ClientStateMachine.java @@ -211,7 +211,7 @@ public ClientStateMachine(ClientState initialState, IMalmoModClient malmoModClie ClientTickEvents.END_CLIENT_TICK.register(client -> this.onClientTick(client)); ClientEntityEvents.ENTITY_LOAD.register(this::onEntityLoad); ClientEntityEvents.ENTITY_UNLOAD.register(this::onEntityUnoad); - SidesMessageHandler.server2client.registerForMessage(this, MalmoMessageType.SERVER_TEXT); + SidesMessageHandler.server2client.registerForMessage(this, VereyaMessageType.SERVER_TEXT); setupClientCallbacks(); } @@ -252,14 +252,14 @@ public IScreenHelper getScreenHelper() } @Override - public void onMessage(MalmoMessageType messageType, Map data) + public void onMessage(VereyaMessageType messageType, Map data) { LOGGER.info("got message type " + messageType.toString()); - if (messageType == MalmoMessageType.SERVER_TEXT) + if (messageType == VereyaMessageType.SERVER_TEXT) { LOGGER.info("got server text message" + data.toString()); } - if (messageType == MalmoMessageType.SERVER_STOPPED) { + if (messageType == VereyaMessageType.SERVER_STOPPED) { this.onServerStopped(); } } @@ -269,7 +269,7 @@ public void onServerStopped(){ } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { LOGGER.info("got message type " + messageType.toString()); } @@ -814,7 +814,7 @@ public abstract class ErrorAwareEpisode extends StateEpisode implements IVereyaM public ErrorAwareEpisode(ClientStateMachine machine) { super(machine); - // MalmoMod.MalmoMessageHandler.registerForMessage(this, MalmoMessageType.SERVER_ABORT); + // MalmoMod.MalmoMessageHandler.registerForMessage(this, VereyaMessageType.SERVER_ABORT); } protected boolean pingAgent(boolean abortIfFailed) @@ -841,14 +841,14 @@ protected boolean pingAgent(boolean abortIfFailed) } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { throw new RuntimeException("Got server message in client"); } @Override - public void onMessage(MalmoMessageType messageType, Map data) + public void onMessage(VereyaMessageType messageType, Map data) { - if (messageType == MalmoMessageType.SERVER_ABORT) + if (messageType == VereyaMessageType.SERVER_ABORT) { synchronized (this) { @@ -878,7 +878,7 @@ public void onMessage(MalmoMessageType messageType, Map data) public void cleanup() { super.cleanup(); - // MalmoMod.MalmoMessageHandler.deregisterForMessage(this, MalmoMessageType.SERVER_ABORT); + // MalmoMod.MalmoMessageHandler.deregisterForMessage(this, VereyaMessageType.SERVER_ABORT); } protected boolean inAbortState() @@ -1193,7 +1193,7 @@ public void run() { } // send mission init to server ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, - (new VereyaMessage(MalmoMessageType.CLIENT_MISSION_INIT, 0, map)).toBytes()); + (new VereyaMessage(VereyaMessageType.CLIENT_MISSION_INIT, 0, map)).toBytes()); episodeHasCompleted(ClientState.WAITING_FOR_SERVER_READY); } } else { // not needNewWorld and no world: error @@ -1220,7 +1220,7 @@ public class WaitingForServerEpisode extends ErrorAwareEpisode implements IVerey protected WaitingForServerEpisode(ClientStateMachine machine) { super(machine); - SidesMessageHandler.server2client.registerForMessage(this, MalmoMessageType.SERVER_ALLPLAYERSJOINED); + SidesMessageHandler.server2client.registerForMessage(this, VereyaMessageType.SERVER_ALLPLAYERSJOINED); } private boolean isChunkReady() @@ -1307,7 +1307,7 @@ public void onClientTick(MinecraftClient client) currentMissionBehaviour().appendExtraServerInformation(map); LOGGER.info("***Telling server we are ready - " + agentName); ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, - (new VereyaMessage(MalmoMessageType.CLIENT_AGENTREADY, 0, map)).toBytes()); + (new VereyaMessage(VereyaMessageType.CLIENT_AGENTREADY, 0, map)).toBytes()); } // We also ping our agent, just to check it is still available: @@ -1418,12 +1418,12 @@ protected void handleLan() } @Override - public void onMessage(MalmoMessageType messageType, Map data) + public void onMessage(VereyaMessageType messageType, Map data) { LOGGER.debug("ClientStateMachine:onMessage: " + messageType); super.onMessage(messageType, data); - if (messageType != MalmoMessageType.SERVER_ALLPLAYERSJOINED) + if (messageType != VereyaMessageType.SERVER_ALLPLAYERSJOINED) return; MinecraftClient client = MinecraftClient.getInstance(); if (ClientStateMachine.this.serverHandlers != null) @@ -1491,7 +1491,7 @@ public void onMessage(MalmoMessageType messageType, Map data) } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { throw new RuntimeException("Unexpected message to server"); } @@ -1538,7 +1538,7 @@ private void proceed() public void cleanup() { super.cleanup(); - SidesMessageHandler.server2client.deregisterForMessage(this, MalmoMessageType.SERVER_ALLPLAYERSJOINED); + SidesMessageHandler.server2client.deregisterForMessage(this, VereyaMessageType.SERVER_ALLPLAYERSJOINED); } } @@ -1555,8 +1555,8 @@ public class MissionRunningEpisode extends ErrorAwareEpisode implements VideoPro protected MissionRunningEpisode(ClientStateMachine machine) { super(machine); - SidesMessageHandler.server2client.registerForMessage(this, MalmoMessageType.SERVER_STOPAGENTS); - SidesMessageHandler.server2client.registerForMessage(this, MalmoMessageType.SERVER_GO); + SidesMessageHandler.server2client.registerForMessage(this, VereyaMessageType.SERVER_STOPAGENTS); + SidesMessageHandler.server2client.registerForMessage(this, VereyaMessageType.SERVER_GO); } boolean serverHasFiredStartingPistol = false; @@ -1602,7 +1602,7 @@ protected void onMissionStarted() // Tell the server we have started: HashMap map = new HashMap(); map.put("username", MinecraftClient.getInstance().player.getName().getString()); - VereyaMessage msg = new VereyaMessage(MalmoMessageType.CLIENT_AGENTRUNNING, 0, map); + VereyaMessage msg = new VereyaMessage(VereyaMessageType.CLIENT_AGENTRUNNING, 0, map); ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, msg.toBytes()); // Set up our mission handlers: @@ -1781,7 +1781,7 @@ public void onClientTick(MinecraftClient event) map.put("username", MinecraftClient.getInstance().player.getName().getString()); map.put("quitcode", this.quitCode); LOGGER.info("informing server that player has quited"); - ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, (new VereyaMessage(MalmoMessageType.CLIENT_AGENTFINISHEDMISSION, 0, map)).toBytes()); + ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, (new VereyaMessage(VereyaMessageType.CLIENT_AGENTFINISHEDMISSION, 0, map)).toBytes()); ClientStateMachine.this.cancelReservation(); onMissionEnded(ClientState.IDLING, null); } @@ -1950,11 +1950,11 @@ private boolean handleCommand(String command) } @Override - public void onMessage(MalmoMessageType messageType, Map data) + public void onMessage(VereyaMessageType messageType, Map data) { super.onMessage(messageType, data); // This message will be sent to us once the server has decided the mission is over. - if (messageType == MalmoMessageType.SERVER_STOPAGENTS) + if (messageType == VereyaMessageType.SERVER_STOPAGENTS) { this.quitCode = data.containsKey("QuitCode") ? data.get("QuitCode") : ""; /* @@ -1974,7 +1974,7 @@ public void onMessage(MalmoMessageType messageType, Map data) */ onMissionEnded(ClientState.MISSION_ENDED, null); - } else if (messageType == MalmoMessageType.SERVER_GO) { + } else if (messageType == VereyaMessageType.SERVER_GO) { this.serverHasFiredStartingPistol = true; // GO GO GO! } else { throw new RuntimeException("unexpected message received " + messageType.name()); @@ -1985,8 +1985,8 @@ public void onMessage(MalmoMessageType messageType, Map data) public void cleanup() { super.cleanup(); - SidesMessageHandler.server2client.deregisterForMessage(this, MalmoMessageType.SERVER_STOPAGENTS); - SidesMessageHandler.server2client.deregisterForMessage(this, MalmoMessageType.SERVER_GO); + SidesMessageHandler.server2client.deregisterForMessage(this, VereyaMessageType.SERVER_STOPAGENTS); + SidesMessageHandler.server2client.deregisterForMessage(this, VereyaMessageType.SERVER_GO); } } @@ -2091,7 +2091,7 @@ protected void execute() if (player != null) // Might not be a player yet. map.put("username", player.getName().getString()); map.put("error", ClientStateMachine.this.getErrorDetails()); - PacketByteBuf buf = new VereyaMessage(MalmoMessageType.CLIENT_BAILED, 0, map).toBytes(); + PacketByteBuf buf = new VereyaMessage(VereyaMessageType.CLIENT_BAILED, 0, map).toBytes(); LOGGER.debug("informing server of a failure with: " + map.toString()); ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, buf); } @@ -2188,7 +2188,7 @@ public class WaitingForServerMissionEndEpisode extends ErrorAwareEpisode protected WaitingForServerMissionEndEpisode(ClientStateMachine machine) { super(machine); - SidesMessageHandler.server2client.registerForMessage(this, MalmoMessageType.SERVER_MISSIONOVER); + SidesMessageHandler.server2client.registerForMessage(this, VereyaMessageType.SERVER_MISSIONOVER); } @Override @@ -2204,14 +2204,14 @@ protected void execute() throws Exception HashMap map = new HashMap(); map.put("agentname", agentName); ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, - new VereyaMessage(MalmoMessageType.CLIENT_AGENTSTOPPED, 0, map).toBytes()); + new VereyaMessage(VereyaMessageType.CLIENT_AGENTSTOPPED, 0, map).toBytes()); } @Override - public void onMessage(MalmoMessageType messageType, Map data) + public void onMessage(VereyaMessageType messageType, Map data) { super.onMessage(messageType, data); - if (messageType == MalmoMessageType.SERVER_MISSIONOVER) + if (messageType == VereyaMessageType.SERVER_MISSIONOVER) episodeHasCompleted(ClientState.DORMANT); } @@ -2219,7 +2219,7 @@ public void onMessage(MalmoMessageType messageType, Map data) public void cleanup() { super.cleanup(); - SidesMessageHandler.server2client.deregisterForMessage(this, MalmoMessageType.SERVER_MISSIONOVER); + SidesMessageHandler.server2client.deregisterForMessage(this, VereyaMessageType.SERVER_MISSIONOVER); } @Override @@ -2240,7 +2240,7 @@ public class MissionIdlingEpisode extends ErrorAwareEpisode protected MissionIdlingEpisode(ClientStateMachine machine) { super(machine); - SidesMessageHandler.server2client.registerForMessage(this, MalmoMessageType.SERVER_STOPAGENTS); + SidesMessageHandler.server2client.registerForMessage(this, VereyaMessageType.SERVER_STOPAGENTS); } @Override @@ -2250,11 +2250,11 @@ protected void execute() } @Override - public void onMessage(MalmoMessageType messageType, Map data) + public void onMessage(VereyaMessageType messageType, Map data) { super.onMessage(messageType, data); // This message will be sent to us once the server has decided the mission is over. - if (messageType == MalmoMessageType.SERVER_STOPAGENTS) + if (messageType == VereyaMessageType.SERVER_STOPAGENTS) episodeHasCompleted(ClientState.MISSION_ENDED); } @@ -2262,7 +2262,7 @@ public void onMessage(MalmoMessageType messageType, Map data) public void cleanup() { super.cleanup(); - SidesMessageHandler.server2client.deregisterForMessage(this, MalmoMessageType.SERVER_STOPAGENTS); + SidesMessageHandler.server2client.deregisterForMessage(this, VereyaMessageType.SERVER_STOPAGENTS); } @Override diff --git a/src/main/java/io/singularitynet/IVereyaMessageListener.java b/src/main/java/io/singularitynet/IVereyaMessageListener.java index b0fe8945..e8846add 100644 --- a/src/main/java/io/singularitynet/IVereyaMessageListener.java +++ b/src/main/java/io/singularitynet/IVereyaMessageListener.java @@ -7,6 +7,6 @@ public interface IVereyaMessageListener { - void onMessage(MalmoMessageType messageType, Map data); - void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player); + void onMessage(VereyaMessageType messageType, Map data); + void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player); } diff --git a/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationImplementation.java index 06137f99..3ac2eeca 100755 --- a/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationImplementation.java +++ b/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationImplementation.java @@ -62,7 +62,7 @@ public class CommandForWheeledRobotNavigationImplementation extends CommandBase /** Small MovementInput class that calls our own movement handling code. * This object is used by Minecraft to decide how to move the player. */ - @Environment(value= EnvType.SERVER) + @Environment(value= EnvType.CLIENT) public class AIMovementInput extends KeyboardInput { public AIMovementInput(GameOptions settings) { diff --git a/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementation.java index 92eab5f1..c233f885 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementation.java +++ b/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementation.java @@ -2,10 +2,42 @@ import io.singularitynet.VereyaMessage; import io.singularitynet.NetworkConstants; +import io.singularitynet.VereyaMessageType; import io.singularitynet.projectmalmo.MissionInit; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; +import java.util.Map; + public class CommandForWheeledRobotNavigationMobImplementation extends CommandBase { + + + public static class MotionMessage extends VereyaMessage { + + public MotionMessage(String parameters, String uuid, String value){ + super(VereyaMessageType.CLIENT_MOVE, parameters); + this.getData().put("uuid", uuid); + this.getData().put("value", value); + } + + public MotionMessage(Map data) { + super(VereyaMessageType.CLIENT_MOVE, data.get("message")); + this.getData().put("uuid", data.get("uuid")); + this.getData().put("value", data.get("value")); + } + + public String getUuid(){ + return this.getData().get("uuid"); + } + + public String getValue(){ + return this.getData().get("value"); + } + + public String getVerb(){ + return this.getData().get("message"); + } + } + @Override public boolean isOverriding() { return false; @@ -41,7 +73,7 @@ protected boolean onExecute(String verb, String parameter, MissionInit missionIn parameter = params[1]; - VereyaMessage vereyaMessage = new CommandForWheeledRobotNavigationMobImplementationServer.MotionMessage(verb, entity_uuid, parameter); + VereyaMessage vereyaMessage = new MotionMessage(verb, entity_uuid, parameter); ClientPlayNetworking.send(NetworkConstants.CLIENT2SERVER, vereyaMessage.toBytes()); return true; diff --git a/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementationServer.java b/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementationServer.java index e114a520..314c8d73 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementationServer.java +++ b/src/main/java/io/singularitynet/MissionHandlers/CommandForWheeledRobotNavigationMobImplementationServer.java @@ -3,7 +3,7 @@ import io.singularitynet.IVereyaMessageListener; import io.singularitynet.VereyaMessage; -import io.singularitynet.MalmoMessageType; +import io.singularitynet.VereyaMessageType; import io.singularitynet.SidesMessageHandler; import io.singularitynet.mixin.MobEntityAccessorMixin; import io.singularitynet.projectmalmo.ContinuousMovementCommand; @@ -33,13 +33,13 @@ public class CommandForWheeledRobotNavigationMobImplementationServer extends CommandBase implements IVereyaMessageListener { @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("calling client-side message handler on server " + messageType.toString()); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { - CommandForWheeledRobotNavigationMobImplementationServer.MotionMessage msg = new CommandForWheeledRobotNavigationMobImplementationServer.MotionMessage(data); + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { + CommandForWheeledRobotNavigationMobImplementation.MotionMessage msg = new CommandForWheeledRobotNavigationMobImplementation.MotionMessage(data); LOGGER.debug("InventoryCommandsImplementationServer.onMessage: " + msg); runCommand(msg); } @@ -49,33 +49,6 @@ protected boolean onExecute(String verb, String parameter, MissionInit missionIn return false; } - public static class MotionMessage extends VereyaMessage { - - public MotionMessage(String parameters, String uuid, String value){ - super(MalmoMessageType.CLIENT_MOVE, parameters); - this.getData().put("uuid", uuid); - this.getData().put("value", value); - } - - public MotionMessage(Map data) { - super(MalmoMessageType.CLIENT_MOVE, data.get("message")); - this.getData().put("uuid", data.get("uuid")); - this.getData().put("value", data.get("value")); - } - - public String getUuid(){ - return this.getData().get("uuid"); - } - - public String getValue(){ - return this.getData().get("value"); - } - - public String getVerb(){ - return this.getData().get("message"); - } - } - float maxAngularVelocityDegreesPerSecond = 180; private class InternalFields { MobEntity entity; @@ -155,13 +128,14 @@ private void init() ServerEntityEvents.ENTITY_LOAD.register(this::onEntityLoad); ServerEntityEvents.ENTITY_UNLOAD.register(this::onEntityUnoad); LOGGER.info("Installing CommandForWheeledRobotNavigationMobServer"); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_MOVE); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_MOVE); } private void onEntityUnoad(Entity entity, ServerWorld clientWorld) { if (entity instanceof MobEntity) { String uuid = entity.getUuidAsString(); if (motionParams.containsKey(uuid)) { + LOGGER.info("removed controllable mob: " + entity.getUuidAsString() + " " + entity.getType().getUntranslatedName()); motionParams.remove(uuid); } } @@ -171,6 +145,7 @@ private void onEntityLoad(Entity entity, ServerWorld clientWorld) { if (entity instanceof MobEntity) { MobEntity mobEntity = (MobEntity) entity; if (mobEntity.isAiDisabled()){ + LOGGER.info("created controllable mob: " + mobEntity.getUuidAsString() + " " + mobEntity.getType().getUntranslatedName()); this.motionParams.put(mobEntity.getUuidAsString(), new InternalFields()); ((MobEntityAccessorMixin)mobEntity).setMoveControl(new AIMoveControl(mobEntity)); ((MobEntityAccessorMixin)mobEntity).setJumpControl(new AIJumpControl(mobEntity)); @@ -253,7 +228,7 @@ public void setOverriding(boolean b) { } - public boolean runCommand(MotionMessage msg) + public boolean runCommand(CommandForWheeledRobotNavigationMobImplementation.MotionMessage msg) { String verb = msg.getData().get("message"); if (verb == null || verb.length() == 0) @@ -328,7 +303,7 @@ public void install(MissionInit missionInit) @Override public void deinstall(MissionInit missionInit) { - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_MOVE); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_MOVE); this.motionParams.clear(); } } diff --git a/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementation.java index 4a10c588..527a0f49 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementation.java +++ b/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementation.java @@ -45,12 +45,12 @@ public class InventoryCommandsImplementation extends CommandGroup implements IVe private static final Logger LOGGER = LogManager.getLogger(InventoryCommandsImplementation.class.getName()); @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("unexpected message from server " + messageType.toString()); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { throw new RuntimeException("Calling server-side message handler on client " + messageType.toString()); } diff --git a/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementationServer.java b/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementationServer.java index bf6a8cf1..bc925a3d 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementationServer.java +++ b/src/main/java/io/singularitynet/MissionHandlers/InventoryCommandsImplementationServer.java @@ -2,7 +2,7 @@ import io.singularitynet.IVereyaMessageListener; import io.singularitynet.VereyaMessage; -import io.singularitynet.MalmoMessageType; +import io.singularitynet.VereyaMessageType; import io.singularitynet.SidesMessageHandler; import io.singularitynet.projectmalmo.MissionInit; import net.minecraft.entity.player.PlayerInventory; @@ -28,12 +28,12 @@ public class InventoryCommandsImplementationServer extends CommandBase implement private static final Logger LOGGER = LogManager.getLogger(InventoryCommandsImplementationServer.class.getName()); @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("calling client-side message handler on server " + messageType.toString()); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { InventoryMessage msg = new InventoryMessage(data); LOGGER.debug("InventoryCommandsImplementationServer.onMessage: " + msg); runCommand(msg, player); @@ -53,13 +53,13 @@ public void setOverriding(boolean b) { public void install(MissionInit missionInit) { LOGGER.info("Installing InventoryCommandsImplementationServer"); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_INVENTORY_CHANGE); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_INVENTORY_CHANGE); } @Override public void deinstall(MissionInit missionInit) { LOGGER.info("Deinstalling InventoryCommandsImplementationServer"); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_INVENTORY_CHANGE); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_INVENTORY_CHANGE); } static ItemStack[] swapSlots(ServerPlayerEntity player, String lhsInv, int lhs, String rhsInv, int rhs, BlockPos containerPos) @@ -230,7 +230,7 @@ public static class InventoryMessage extends VereyaMessage { BlockPos containerPos; public InventoryMessage(Map data) { - super(MalmoMessageType.CLIENT_INVENTORY_CHANGE, "inventory"); + super(VereyaMessageType.CLIENT_INVENTORY_CHANGE, "inventory"); this.getData().putAll(data); this.invA = data.get("invA"); this.invB = data.get("invB"); @@ -243,7 +243,7 @@ public InventoryMessage(Map data) { } public InventoryMessage(List params, boolean combine) { - super(MalmoMessageType.CLIENT_INVENTORY_CHANGE, "inventory"); + super(VereyaMessageType.CLIENT_INVENTORY_CHANGE, "inventory"); this.invA = (String) params.get(0); this.slotA = (Integer) params.get(1); this.invB = (String) params.get(2); diff --git a/src/main/java/io/singularitynet/MissionHandlers/MissionBehaviour.java b/src/main/java/io/singularitynet/MissionHandlers/MissionBehaviour.java index e3f57741..21366827 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/MissionBehaviour.java +++ b/src/main/java/io/singularitynet/MissionHandlers/MissionBehaviour.java @@ -106,10 +106,10 @@ private Object createHandlerFromParams(Object xmlHandler, boolean isServer) { return null; } + // To avoid name collisions, the java class will have the suffix "Implementation". + String classname = "io.singularitynet.MissionHandlers." + handlerClass + "Implementation"; try { - // To avoid name collisions, the java class will have the suffix "Implementation". - String classname = "io.singularitynet.MissionHandlers." + handlerClass + "Implementation"; if (isServer) classname += "Server"; Class c = Class.forName(classname); @@ -126,18 +126,18 @@ private Object createHandlerFromParams(Object xmlHandler, boolean isServer) } catch (InstantiationException e) { - LogManager.getLogger().error("Could not instantiate specified MissionHandler.", e); + LogManager.getLogger().error("Could not instantiate specified MissionHandler. " + classname, e); this.failedHandlers += "Failed to create " + handlerClass + "\n"; } catch (IllegalAccessException e) { - LogManager.getLogger().error("Could not instantiate specified MissionHandler.", e); + LogManager.getLogger().error("Could not instantiate specified MissionHandler. " + classname, e); this.failedHandlers += "Failed to access " + handlerClass + "\n"; } catch (InvocationTargetException e) { - LogManager.getLogger().error("Could not instantiate specified MissionHandler.", e); + LogManager.getLogger().error("Could not instantiate specified MissionHandler. " + classname, e); this.failedHandlers += "Failed to access " + handlerClass + "\n"; } catch (NoSuchMethodException e) { - LogManager.getLogger().error("Could not instantiate specified MissionHandler.", e); + LogManager.getLogger().error("Could not instantiate specified MissionHandler. " + classname, e); this.failedHandlers += "Failed to access constructor in " + handlerClass + "\n"; } return handler; diff --git a/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementation.java index 29ac12f7..4192ca1d 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementation.java +++ b/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementation.java @@ -50,12 +50,12 @@ protected boolean onExecute(String verb, String parameter, MissionInit missionIn } @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("Unexpected message to client"); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { throw new RuntimeException("calling server-side message handler on client"); } diff --git a/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementationServer.java b/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementationServer.java index ea52195c..48b3674e 100644 --- a/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementationServer.java +++ b/src/main/java/io/singularitynet/MissionHandlers/SimpleCraftCommandsImplementationServer.java @@ -2,7 +2,7 @@ import io.singularitynet.IVereyaMessageListener; import io.singularitynet.VereyaMessage; -import io.singularitynet.MalmoMessageType; +import io.singularitynet.VereyaMessageType; import io.singularitynet.SidesMessageHandler; import io.singularitynet.projectmalmo.MissionInit; import io.singularitynet.utils.CraftingHelper; @@ -23,22 +23,22 @@ public static class CraftMessage extends VereyaMessage public CraftMessage(String parameters) { - super(MalmoMessageType.CLIENT_CRAFT, parameters); + super(VereyaMessageType.CLIENT_CRAFT, parameters); } public CraftMessage(String parameters, String fuel_type){ - super(MalmoMessageType.CLIENT_CRAFT, parameters); + super(VereyaMessageType.CLIENT_CRAFT, parameters); this.getData().put("fuel_type", fuel_type); } } @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("Calling client message handler on server"); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { LOGGER.debug("Got crafting message " + messageType + " " + data.get("message")); // Try crafting recipes first: @@ -89,13 +89,13 @@ public void setOverriding(boolean b) { public void install(MissionInit missionInit) { LOGGER.debug("Installing SimpleCraftCommandsImplementationServer"); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_CRAFT); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_CRAFT); } @Override public void deinstall(MissionInit missionInit) { LOGGER.debug("Deinstalling SimpleCraftCommandsImplementationServer"); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_CRAFT); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_CRAFT); } @Override diff --git a/src/main/java/io/singularitynet/Server/ServerStateMachine.java b/src/main/java/io/singularitynet/Server/ServerStateMachine.java index 0e201895..a1d771ad 100644 --- a/src/main/java/io/singularitynet/Server/ServerStateMachine.java +++ b/src/main/java/io/singularitynet/Server/ServerStateMachine.java @@ -54,7 +54,7 @@ import java.lang.ref.WeakReference; import java.util.*; -import static io.singularitynet.MalmoMessageType.CLIENT_BAILED; +import static io.singularitynet.VereyaMessageType.CLIENT_BAILED; /** * Class designed to track and control the state of the mod, especially regarding mission launching/running.
@@ -158,7 +158,7 @@ public ActionResult onGetPotentialSpawns(Entity entity, ServerWorld world) private void onServerStopping(MinecraftServer s) { LOGGER.info("informing client that we are stopping"); - sendToAll(new VereyaMessage(MalmoMessageType.SERVER_STOPPED, 0, new HashMap<>())); + sendToAll(new VereyaMessage(VereyaMessageType.SERVER_STOPPED, 0, new HashMap<>())); } private void onServerStopped(MinecraftServer s){ @@ -251,7 +251,7 @@ protected void onPreStateChange(IState toState) Map data = new HashMap(); data.put("text", text); data.put("category", ScreenHelper.TextCategory.TXT_SERVER_STATE.name()); - sendToAll(new VereyaMessage(MalmoMessageType.SERVER_TEXT, 0, data)); + sendToAll(new VereyaMessage(VereyaMessageType.SERVER_TEXT, 0, data)); } private void sendToAll(VereyaMessage msg){ @@ -365,12 +365,12 @@ protected StateEpisode getStateEpisodeForState(IState state) } @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("ServerStateMachine.onMessage() should never be called on server!"); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { } @@ -409,12 +409,12 @@ public abstract class ErrorAwareEpisode extends StateEpisode implements IVereyaM public ErrorAwareEpisode(ServerStateMachine machine) { super(machine); - // MalmoMod.MalmoMessageHandler.registerForMessage(this, MalmoMessageType.CLIENT_BAILED); + // MalmoMod.MalmoMessageHandler.registerForMessage(this, VereyaMessageType.CLIENT_BAILED); SidesMessageHandler.client2server.registerForMessage(this, CLIENT_BAILED); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { LOGGER.debug("Got message: " + messageType.name()); LOGGER.debug(data.toString()); @@ -431,7 +431,7 @@ public void onMessage(MalmoMessageType messageType, Map data, Se } @Override - public void onMessage(MalmoMessageType messageType, Map data){ + public void onMessage(VereyaMessageType messageType, Map data){ throw new RuntimeException("Got client message in Server side"); } @@ -472,7 +472,7 @@ protected DormantEpisode(ServerStateMachine machine) { super(machine); this.ssmachine = machine; - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_MISSION_INIT); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_MISSION_INIT); if (machine.hasQueuedMissionInit()) { // This is highly suspicious - the queued mission init is a mechanism whereby the client state machine can pass its mission init @@ -557,9 +557,9 @@ protected void onReceiveMissionInit(MissionInit missionInit) @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) { + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { LOGGER.debug("ServerStateMachine.onMessage() received message of type " + messageType.toString() + " from " + player.getName().getString()); - if (messageType == MalmoMessageType.CLIENT_MISSION_INIT) { + if (messageType == VereyaMessageType.CLIENT_MISSION_INIT) { // deserialize the mission init try { MissionInit init = (MissionInit) SchemaHelper.deserialiseObject(data.get("MissionInit"), MissionInit.class); @@ -577,7 +577,7 @@ public void onMessage(MalmoMessageType messageType, Map data, Se @Override public void cleanup() { - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_MISSION_INIT); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_MISSION_INIT); } } @@ -640,8 +640,8 @@ public class WaitingForAgentsEpisode extends ErrorAwareEpisode implements IVerey protected WaitingForAgentsEpisode(ServerStateMachine machine) { super(machine); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_AGENTREADY); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_AGENTRUNNING); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_AGENTREADY); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_AGENTRUNNING); ServerStateMachine.this.clearUserConnectionWatchList(); // We will build this up as agents join us. ServerStateMachine.this.clearUserTurnSchedule(); // We will build this up too, if needed. @@ -652,8 +652,8 @@ protected WaitingForAgentsEpisode(ServerStateMachine machine) public void cleanup() { super.cleanup(); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_AGENTREADY); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_AGENTRUNNING); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_AGENTREADY); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_AGENTRUNNING); } private void addUsernameToTurnSchedule(String username, Integer requestedPosition) @@ -695,15 +695,15 @@ private void saveTurnSchedule() } @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("Unexpected message to client: " + messageType.name()); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { super.onMessage(messageType, data, player); - if (messageType == MalmoMessageType.CLIENT_AGENTREADY) + if (messageType == VereyaMessageType.CLIENT_AGENTREADY) { LOGGER.debug("SERVER: got AGENTREADY message"); // A client has joined and is waiting for us to tell us it can proceed. @@ -731,7 +731,7 @@ public void onMessage(MalmoMessageType messageType, Map data, Se onCastAssembled(); } } - else if (messageType == MalmoMessageType.CLIENT_AGENTRUNNING) + else if (messageType == VereyaMessageType.CLIENT_AGENTRUNNING) { LOGGER.debug("SERVER: got AGENTRUNNING message"); // A client has entered the running state (only happens once all CLIENT_AGENTREADY messages have arrived). @@ -914,7 +914,7 @@ private void onCastAssembled() // And tell them all they can proceed: LOGGER.debug("Sending SERVER_ALLPLAYERSJOINED to all clients."); - sendToAll(new VereyaMessage(MalmoMessageType.SERVER_ALLPLAYERSJOINED, 0, data)); + sendToAll(new VereyaMessage(VereyaMessageType.SERVER_ALLPLAYERSJOINED, 0, data)); } @Override @@ -925,7 +925,7 @@ protected void onError(Map errorData) // Do some tidying: resetPlayerGameTypes(); // And tell all the clients to abort: - sendToAll(new VereyaMessage(MalmoMessageType.SERVER_ABORT, 0, errorData)); + sendToAll(new VereyaMessage(VereyaMessageType.SERVER_ABORT, 0, errorData)); // And abort ourselves: episodeHasCompleted(ServerState.ERROR); } @@ -1013,25 +1013,25 @@ protected RunningEpisode(ServerStateMachine machine) } } // And register for the agent-finished message: - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_AGENTFINISHEDMISSION); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_SHARE_REWARD); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_TURN_TAKEN); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_AGENTFINISHEDMISSION); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_SHARE_REWARD); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_TURN_TAKEN); } @Override public void cleanup() { super.cleanup(); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_AGENTFINISHEDMISSION); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_SHARE_REWARD); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_TURN_TAKEN); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_AGENTFINISHEDMISSION); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_SHARE_REWARD); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_TURN_TAKEN); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { super.onMessage(messageType, data, player); - if (messageType == MalmoMessageType.CLIENT_AGENTFINISHEDMISSION) + if (messageType == VereyaMessageType.CLIENT_AGENTFINISHEDMISSION) { // this agentname is legacy from old malmo code // we can use player object passed from messaging code @@ -1047,11 +1047,11 @@ public void onMessage(MalmoMessageType messageType, Map data, Se ServerStateMachine.this.removeFromTurnSchedule(agentName); } } - else if (messageType == MalmoMessageType.CLIENT_SHARE_REWARD) + else if (messageType == VereyaMessageType.CLIENT_SHARE_REWARD) { - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_SHARE_REWARD, 0, data)); + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_SHARE_REWARD, 0, data)); } - else if (messageType == MalmoMessageType.CLIENT_TURN_TAKEN) + else if (messageType == VereyaMessageType.CLIENT_TURN_TAKEN) { String agentName = data.get("agentname"); //String userName = data.get("username"); @@ -1062,7 +1062,7 @@ else if (messageType == MalmoMessageType.CLIENT_TURN_TAKEN) String error = "ERROR IN TURN SCHEDULER - cannot find the successor to " + agentName; saveErrorDetails(error); System.out.println(error); - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_ABORT, 0, data)); + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_ABORT, 0, data)); episodeHasCompleted(ServerState.ERROR); } else @@ -1070,7 +1070,7 @@ else if (messageType == MalmoMessageType.CLIENT_TURN_TAKEN) // Find the relevant agent; send a message to it. if (player != null) { - VereyaMessage msg = new VereyaMessage(MalmoMessageType.SERVER_YOUR_TURN, 0, null); + VereyaMessage msg = new VereyaMessage(VereyaMessageType.SERVER_YOUR_TURN, 0, null); ServerPlayNetworking.send(player, NetworkConstants.SERVER2CLIENT, msg.toBytes()); } else if (getHandlers().worldDecorator != null) @@ -1083,7 +1083,7 @@ else if (getHandlers().worldDecorator != null) String error = "ERROR IN TURN SCHEDULER - could not find client for user " + nextAgentName; saveErrorDetails(error); LOGGER.error(error); - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_ABORT, + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_ABORT, 0, null)); episodeHasCompleted(ServerState.ERROR); } @@ -1121,7 +1121,7 @@ protected void execute() getHandlers().worldDecorator.prepare(currentMissionInit()); // Fire the starting pistol: - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_GO, 0, null)); + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_GO, 0, null)); // And start the turn schedule turning, if there is one: if (!ServerStateMachine.this.userTurnSchedule.isEmpty()) { @@ -1130,7 +1130,7 @@ protected void execute() if (player != null) { ServerPlayNetworking.send(player, NetworkConstants.SERVER2CLIENT, - new VereyaMessage(MalmoMessageType.SERVER_YOUR_TURN, 0, null).toBytes()); + new VereyaMessage(VereyaMessageType.SERVER_YOUR_TURN, 0, null).toBytes()); } else if (getHandlers().worldDecorator != null) { @@ -1235,7 +1235,7 @@ protected void onError(Map errorData) // Do some tidying: onMissionEnded(false); // Tell all the clients to abort: - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_ABORT, 0, null)); + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_ABORT, 0, null)); // And abort ourselves: episodeHasCompleted(ServerState.ERROR); } @@ -1257,7 +1257,7 @@ public class WaitingForAgentsToQuitEpisode extends ErrorAwareEpisode implements protected WaitingForAgentsToQuitEpisode(ServerStateMachine machine) { super(machine); - SidesMessageHandler.client2server.registerForMessage(this, MalmoMessageType.CLIENT_AGENTSTOPPED); + SidesMessageHandler.client2server.registerForMessage(this, VereyaMessageType.CLIENT_AGENTSTOPPED); } @Override @@ -1271,26 +1271,26 @@ protected void execute() // Now tell all the agents to stop what they are doing: Mapdata = new HashMap(); data.put("QuitCode", ServerStateMachine.this.quitCode); - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_STOPAGENTS, 0, data)); + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_STOPAGENTS, 0, data)); } @Override - public void onMessage(MalmoMessageType messageType, Map data) { + public void onMessage(VereyaMessageType messageType, Map data) { throw new RuntimeException("Unexpected message to client"); } @Override - public void onMessage(MalmoMessageType messageType, Map data, ServerPlayerEntity player) + public void onMessage(VereyaMessageType messageType, Map data, ServerPlayerEntity player) { super.onMessage(messageType, data, player); - if (messageType == MalmoMessageType.CLIENT_AGENTSTOPPED) + if (messageType == VereyaMessageType.CLIENT_AGENTSTOPPED) { String name = data.get("agentname"); this.agentsStopped.put(name, true); if (!this.agentsStopped.containsValue(false)) { // Agents are all finished and awaiting our message. - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_MISSIONOVER, 0, null)); + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_MISSIONOVER, 0, null)); episodeHasCompleted(ServerState.CLEAN_UP); } } @@ -1300,7 +1300,7 @@ public void onMessage(MalmoMessageType messageType, Map data, Se public void cleanup() { super.cleanup(); - SidesMessageHandler.client2server.deregisterForMessage(this, MalmoMessageType.CLIENT_AGENTSTOPPED); + SidesMessageHandler.client2server.deregisterForMessage(this, VereyaMessageType.CLIENT_AGENTSTOPPED); } @Override @@ -1311,7 +1311,7 @@ protected void onServerTick(MinecraftServer ev) // Something has gone wrong - we've lost a connection. // Need to respond to this, otherwise we'll sit here forever waiting for a client that no longer exists // to tell us it's finished its mission. - ServerStateMachine.this.sendToAll(new VereyaMessage(MalmoMessageType.SERVER_ABORT, 0, null)); + ServerStateMachine.this.sendToAll(new VereyaMessage(VereyaMessageType.SERVER_ABORT, 0, null)); LOGGER.warn("WaitingForAgentsToQuitEpisode.onServerTick Lost connection to client(s) - aborting mission."); episodeHasCompleted(ServerState.ERROR); } diff --git a/src/main/java/io/singularitynet/SidesMessageHandler.java b/src/main/java/io/singularitynet/SidesMessageHandler.java index c3a9cd25..f0875742 100644 --- a/src/main/java/io/singularitynet/SidesMessageHandler.java +++ b/src/main/java/io/singularitynet/SidesMessageHandler.java @@ -37,11 +37,11 @@ public class SidesMessageHandler public interface IMessage {}; - private Map> listeners = new HashMap>(); + private Map> listeners = new HashMap>(); public SidesMessageHandler() {} - public boolean registerForMessage(IVereyaMessageListener listener, MalmoMessageType messageType) + public boolean registerForMessage(IVereyaMessageListener listener, VereyaMessageType messageType) { synchronized (listeners) { if (!listeners.containsKey(messageType)) @@ -55,7 +55,7 @@ public boolean registerForMessage(IVereyaMessageListener listener, MalmoMessageT return true; } - public boolean deregisterForMessage(IVereyaMessageListener listener, MalmoMessageType messageType) + public boolean deregisterForMessage(IVereyaMessageListener listener, VereyaMessageType messageType) { synchronized (listeners) { if (!listeners.containsKey(messageType)) { diff --git a/src/main/java/io/singularitynet/VereyaMessage.java b/src/main/java/io/singularitynet/VereyaMessage.java index f20a69d5..61bc1f8e 100644 --- a/src/main/java/io/singularitynet/VereyaMessage.java +++ b/src/main/java/io/singularitynet/VereyaMessage.java @@ -16,7 +16,7 @@ */ public class VereyaMessage implements SidesMessageHandler.IMessage { - private MalmoMessageType messageType = MalmoMessageType.SERVER_NULLMESSASGE; + private VereyaMessageType messageType = VereyaMessageType.SERVER_NULLMESSASGE; private int uid = 0; private Map data = new HashMap(); @@ -27,7 +27,7 @@ public VereyaMessage() * @param messageType * @param message */ - public VereyaMessage(MalmoMessageType messageType, String message) + public VereyaMessage(VereyaMessageType messageType, String message) { this.messageType = messageType; this.uid = 0; @@ -39,7 +39,7 @@ public VereyaMessage(MalmoMessageType messageType, String message) * @param uid a hash code that (more or less) uniquely identifies the targeted listener * @param message */ - public VereyaMessage(MalmoMessageType messageType, int uid, Map data) + public VereyaMessage(VereyaMessageType messageType, int uid, Map data) { this.messageType = messageType; this.uid = uid; @@ -88,10 +88,10 @@ private void writeLargeUTF(String s, ByteBufOutputStream bbos) throws IOExceptio public void fromBytes(PacketByteBuf buf) { int i = buf.readVarInt(); // Read message type from first byte. - if (i >= 0 && i <= MalmoMessageType.values().length) - this.messageType = MalmoMessageType.values()[i]; + if (i >= 0 && i <= VereyaMessageType.values().length) + this.messageType = VereyaMessageType.values()[i]; else - this.messageType = MalmoMessageType.SERVER_NULLMESSASGE; + this.messageType = VereyaMessageType.SERVER_NULLMESSASGE; // Now read the uid: this.uid = buf.readInt(); @@ -162,7 +162,7 @@ public PacketByteBuf toBytes(){ return buf; } - public MalmoMessageType getMessageType(){ + public VereyaMessageType getMessageType(){ return this.messageType; } diff --git a/src/main/java/io/singularitynet/MalmoMessageType.java b/src/main/java/io/singularitynet/VereyaMessageType.java similarity index 98% rename from src/main/java/io/singularitynet/MalmoMessageType.java rename to src/main/java/io/singularitynet/VereyaMessageType.java index b2ea5259..54d6e7b8 100644 --- a/src/main/java/io/singularitynet/MalmoMessageType.java +++ b/src/main/java/io/singularitynet/VereyaMessageType.java @@ -1,6 +1,6 @@ package io.singularitynet; -public enum MalmoMessageType +public enum VereyaMessageType { SERVER_NULLMESSASGE, SERVER_ALLPLAYERSJOINED,