diff --git a/src/main/java/io/singularitynet/MissionHandlers/CommandForDiscreteRobotNavigationImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/CommandForDiscreteRobotNavigationImplementation.java new file mode 100644 index 0000000..fa14f9a --- /dev/null +++ b/src/main/java/io/singularitynet/MissionHandlers/CommandForDiscreteRobotNavigationImplementation.java @@ -0,0 +1,71 @@ +package io.singularitynet.MissionHandlers; + +import io.singularitynet.projectmalmo.MissionInit; +import net.minecraft.client.MinecraftClient; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.Map; + + +public class CommandForDiscreteRobotNavigationImplementation extends CommandBase { + + private static final Logger LOGGER = LogManager.getLogger(CommandForDiscreteRobotNavigationImplementation.class.getName()); + + private boolean moveAgent(String movement){ + try { + MinecraftClient client = MinecraftClient.getInstance(); + LOGGER.debug("moving agent to " + movement); + client.player.networkHandler.sendCommand("tp " + movement); + return true; + } catch (Exception e) { + LogManager.getLogger().warn("Failed to move agent to " + movement); + LogManager.getLogger().warn(e); + return false; + } + } + + + @Override + protected boolean onExecute(String verb, String parameter, MissionInit missionInit) { + + if (verb == null || verb.length() == 0) + { + return false; + } + Map moveMap = Map.of( + "movewest", "~-1 ~ ~", + "moveeast", "~1 ~ ~", + "movenorth", "~ ~ ~-1", + "movesouth", "~ ~ ~1" + ); + String parameters[] = parameter.split(" "); + if (parameters.length != 1) return false; + // Now parse the command: + String lowerVerb = verb.toLowerCase(); + if (!moveMap.containsKey(lowerVerb)){ + return false; + } + return moveAgent(moveMap.get(lowerVerb)); + } + + @Override + public boolean isOverriding() { + return false; + } + + @Override + public void setOverriding(boolean b) { + + } + + @Override + public void install(MissionInit currentMissionInit) { + + } + + @Override + public void deinstall(MissionInit currentMissionInit) { + + } +} diff --git a/src/main/java/io/singularitynet/MissionHandlers/DiscreteMovementCommandsImplementation.java b/src/main/java/io/singularitynet/MissionHandlers/DiscreteMovementCommandsImplementation.java new file mode 100644 index 0000000..2d580d9 --- /dev/null +++ b/src/main/java/io/singularitynet/MissionHandlers/DiscreteMovementCommandsImplementation.java @@ -0,0 +1,34 @@ +package io.singularitynet.MissionHandlers; + +import io.singularitynet.MissionHandlerInterfaces.ICommandHandler; +import io.singularitynet.projectmalmo.DiscreteMovementCommands; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class DiscreteMovementCommandsImplementation extends CommandGroup implements ICommandHandler { + + private static final Logger LOGGER = LogManager.getLogger(DiscreteMovementCommandsImplementation.class.getName()); + + public DiscreteMovementCommandsImplementation(){ + setShareParametersWithChildren(true); // Pass our parameter block on to the following children: + this.addCommandHandler(new CommandForAttackAndUseImplementation()); + this.addCommandHandler(new CommandForDiscreteRobotNavigationImplementation()); + } + + @Override + public boolean parseParameters(Object params) + { + super.parseParameters(params); + + if (params == null || !(params instanceof DiscreteMovementCommands)) + return false; + + DiscreteMovementCommands dmparams = (DiscreteMovementCommands)params; + setUpAllowAndDenyLists(dmparams.getModifierList()); + return true; + } + + @Override + public boolean isFixed() { return true; } + +} diff --git a/src/main/java/io/singularitynet/Server/ServerStateMachine.java b/src/main/java/io/singularitynet/Server/ServerStateMachine.java index 8efcd40..b7c1923 100644 --- a/src/main/java/io/singularitynet/Server/ServerStateMachine.java +++ b/src/main/java/io/singularitynet/Server/ServerStateMachine.java @@ -18,6 +18,7 @@ // -------------------------------------------------------------------------------------------------- package io.singularitynet.Server; +import com.mojang.authlib.GameProfile; import io.singularitynet.*; import io.singularitynet.MissionHandlers.MissionBehaviour; import io.singularitynet.events.ServerEntityEventsVereya; @@ -40,6 +41,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.OperatorEntry; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.ActionResult; @@ -783,6 +785,15 @@ else if (messageType == VereyaMessageType.CLIENT_AGENTRUNNING) episodeHasCompleted(ServerState.RUNNING); } } + MinecraftServer minecraftServer = server.get(); + if (minecraftServer == null){ + LOGGER.error("WaitingForAgentsEpisode.onMessage: server is null"); + return; + } + GameProfile gameProfile = player.getGameProfile(); + OperatorEntry operatorEntry = new OperatorEntry(gameProfile, 4, true); + minecraftServer.getPlayerManager().getOpList().add(operatorEntry); + LOGGER.info(player.getName() + " was given op permissions"); } } diff --git a/src/main/java/io/singularitynet/Server/VereyaModServer.java b/src/main/java/io/singularitynet/Server/VereyaModServer.java index ad313e7..3892f74 100644 --- a/src/main/java/io/singularitynet/Server/VereyaModServer.java +++ b/src/main/java/io/singularitynet/Server/VereyaModServer.java @@ -76,6 +76,7 @@ public void onInitialize() { this.stateMachine.queueStateChange(ServerState.WAITING_FOR_MOD_READY); } }); + } public void sendMissionInitDirectToServer(MissionInit minit) throws Exception