Search in sources :

Example 1 with PendingCommand

use of net.minecraft.server.dedicated.PendingCommand in project MinecraftForge by MinecraftForge.

the class FMLServerHandler method queryUser.

@Override
public void queryUser(StartupQuery query) throws InterruptedException {
    if (query.getResult() == null) {
        FMLLog.warning("%s", query.getText());
        query.finish();
    } else {
        String text = query.getText() + "\n\nRun the command /fml confirm or or /fml cancel to proceed." + "\nAlternatively start the server with -Dfml.queryResult=confirm or -Dfml.queryResult=cancel to preselect the answer.";
        FMLLog.warning("%s", text);
        // no-op until mc does commands in another thread (if ever)
        if (!query.isSynchronous())
            return;
        boolean done = false;
        while (!done && server.isServerRunning()) {
            if (Thread.interrupted())
                throw new InterruptedException();
            DedicatedServer dedServer = (DedicatedServer) server;
            // rudimentary command processing, check for fml confirm/cancel and stop commands
            synchronized (dedServer.pendingCommandList) {
                for (Iterator<PendingCommand> it = GenericIterableFactory.newCastingIterable(dedServer.pendingCommandList, PendingCommand.class).iterator(); it.hasNext(); ) {
                    String cmd = it.next().command.trim().toLowerCase();
                    if (cmd.equals("/fml confirm")) {
                        FMLLog.info("confirmed");
                        query.setResult(true);
                        done = true;
                        it.remove();
                    } else if (cmd.equals("/fml cancel")) {
                        FMLLog.info("cancelled");
                        query.setResult(false);
                        done = true;
                        it.remove();
                    } else if (cmd.equals("/stop")) {
                        StartupQuery.abort();
                    }
                }
            }
            Thread.sleep(10L);
        }
        query.finish();
    }
}
Also used : DedicatedServer(net.minecraft.server.dedicated.DedicatedServer) PendingCommand(net.minecraft.server.dedicated.PendingCommand)

Aggregations

DedicatedServer (net.minecraft.server.dedicated.DedicatedServer)1 PendingCommand (net.minecraft.server.dedicated.PendingCommand)1