Search in sources :

Example 21 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class CoreCommands method join.

/**
 * Join a game
 * @param address String containing address of game server
 * @param portParam Integer containing game server port
 */
@Command(shortDescription = "Join a game", requiredPermission = PermissionManager.NO_PERMISSION)
public void join(@CommandParam("address") final String address, @CommandParam(value = "port", required = false) Integer portParam) {
    final int port = portParam != null ? portParam : TerasologyConstants.DEFAULT_PORT;
    Callable<JoinStatus> operation = () -> networkSystem.join(address, port);
    final WaitPopup<JoinStatus> popup = nuiManager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
    popup.setMessage("Join Game", "Connecting to '" + address + ":" + port + "' - please wait ...");
    popup.onSuccess(result -> {
        if (result.getStatus() != JoinStatus.Status.FAILED) {
            gameEngine.changeState(new StateLoading(result));
        } else {
            MessagePopup screen = nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            screen.setMessage("Failed to Join", "Could not connect to server - " + result.getErrorMessage());
        }
    });
    popup.startOperation(operation, true);
}
Also used : StateLoading(org.terasology.engine.modes.StateLoading) MessagePopup(org.terasology.rendering.nui.layers.mainMenu.MessagePopup) JoinStatus(org.terasology.network.JoinStatus) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 22 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class CoreCommands method ping.

/**
 * Your ping to the server
 * @param sender Sender of command
 * @return String containing ping or error message
 */
@Command(shortDescription = "Your ping to the server", helpText = "The time it takes the packet " + "to reach the server and back", requiredPermission = PermissionManager.NO_PERMISSION)
public String ping(@Sender EntityRef sender) {
    Server server = networkSystem.getServer();
    if (server == null) {
        // TODO: i18n
        if (networkSystem.getMode().isServer()) {
            return "Your player is running on the server";
        } else {
            return "Please make sure you are connected to an online server (singleplayer doesn't count)";
        }
    }
    String[] remoteAddress = server.getRemoteAddress().split("-");
    String address = remoteAddress[1];
    int port = Integer.valueOf(remoteAddress[2]);
    try {
        PingService pingService = new PingService(address, port);
        long delay = pingService.call();
        return String.format("%d ms", delay);
    } catch (UnknownHostException e) {
        return String.format("Error: Unknown host \"%s\" at %s:%s -- %s", remoteAddress[0], remoteAddress[1], remoteAddress[2], e);
    } catch (IOException e) {
        return String.format("Error: Failed to ping server \"%s\" at %s:%s -- %s", remoteAddress[0], remoteAddress[1], remoteAddress[2], e);
    }
}
Also used : Server(org.terasology.network.Server) UnknownHostException(java.net.UnknownHostException) PingService(org.terasology.network.PingService) IOException(java.io.IOException) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 23 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class CoreCommands method dumpEntities.

/**
 * Writes out information on all entities to a text file for debugging
 * @throws IOException thrown when error with saving file occures
 */
@Command(shortDescription = "Writes out information on all entities to a text file for debugging", helpText = "Writes entity information out into a file named \"entityDump.txt\".")
public void dumpEntities() throws IOException {
    EngineEntityManager engineEntityManager = (EngineEntityManager) entityManager;
    PrefabSerializer prefabSerializer = new PrefabSerializer(engineEntityManager.getComponentLibrary(), engineEntityManager.getTypeSerializerLibrary());
    WorldDumper worldDumper = new WorldDumper(engineEntityManager, prefabSerializer);
    worldDumper.save(PathManager.getInstance().getHomePath().resolve("entityDump.txt"));
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) WorldDumper(org.terasology.persistence.WorldDumper) PrefabSerializer(org.terasology.persistence.serializers.PrefabSerializer) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 24 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class CoreCommands method help.

/**
 * Prints out short descriptions for all available commands, or a longer help text if a command is provided.
 * @param commandName String containing command for which will be displayed help
 * @return String containing short description of all commands or longer help text if command is provided
 */
@Command(shortDescription = "Prints out short descriptions for all available commands, or a longer help text if a command is provided.", requiredPermission = PermissionManager.NO_PERMISSION)
public String help(@CommandParam(value = "command", required = false, suggester = CommandNameSuggester.class) Name commandName) {
    if (commandName == null) {
        StringBuilder msg = new StringBuilder();
        // Get all commands, with appropriate sorting
        List<ConsoleCommand> commands = Ordering.natural().immutableSortedCopy(console.getCommands());
        for (ConsoleCommand cmd : commands) {
            if (!msg.toString().isEmpty()) {
                msg.append(Console.NEW_LINE);
            }
            msg.append(FontColor.getColored(cmd.getUsage(), ConsoleColors.COMMAND));
            msg.append(" - ");
            msg.append(cmd.getDescription());
        }
        return msg.toString();
    } else {
        ConsoleCommand cmd = console.getCommand(commandName);
        if (cmd == null) {
            return "No help available for command '" + commandName + "'. Unknown command.";
        } else {
            StringBuilder msg = new StringBuilder();
            msg.append("=====================================================================================================================");
            msg.append(Console.NEW_LINE);
            msg.append(cmd.getUsage());
            msg.append(Console.NEW_LINE);
            msg.append("=====================================================================================================================");
            msg.append(Console.NEW_LINE);
            if (!cmd.getHelpText().isEmpty()) {
                msg.append(cmd.getHelpText());
                msg.append(Console.NEW_LINE);
                msg.append("=====================================================================================================================");
                msg.append(Console.NEW_LINE);
            } else if (!cmd.getDescription().isEmpty()) {
                msg.append(cmd.getDescription());
                msg.append(Console.NEW_LINE);
                msg.append("=====================================================================================================================");
                msg.append(Console.NEW_LINE);
            }
            if (!cmd.getRequiredPermission().isEmpty()) {
                msg.append("Required permission level - " + cmd.getRequiredPermission());
                msg.append(Console.NEW_LINE);
                msg.append("=====================================================================================================================");
                msg.append(Console.NEW_LINE);
            }
            return msg.toString();
        }
    }
}
Also used : ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Example 25 with Command

use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.

the class CoreCommands method spawnBlock.

/**
 * Spawns a block in front of the player
 * @param sender Sender of command
 * @param blockName String containing name of block to spawn
 * @return String containg final message
 */
@Command(shortDescription = "Spawns a block in front of the player", helpText = "Spawns the specified block as a " + "item in front of the player. You can simply pick it up.", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnBlock(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
    ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
    LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
    Vector3f spawnPos = characterLocation.getWorldPosition();
    Vector3f offset = characterLocation.getWorldDirection();
    offset.scale(3);
    spawnPos.add(offset);
    BlockFamily block = blockManager.getBlockFamily(blockName);
    if (block == null) {
        return "";
    }
    BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
    EntityRef blockItem = blockItemFactory.newInstance(block);
    blockItem.send(new DropItemEvent(spawnPos));
    return "Spawned block.";
}
Also used : DropItemEvent(org.terasology.logic.inventory.events.DropItemEvent) Vector3f(org.terasology.math.geom.Vector3f) BlockItemFactory(org.terasology.world.block.items.BlockItemFactory) BlockFamily(org.terasology.world.block.family.BlockFamily) ClientComponent(org.terasology.network.ClientComponent) LocationComponent(org.terasology.logic.location.LocationComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.logic.console.commandSystem.ConsoleCommand)

Aggregations

Command (org.terasology.logic.console.commandSystem.annotations.Command)76 ClientComponent (org.terasology.network.ClientComponent)48 EntityRef (org.terasology.entitySystem.entity.EntityRef)28 ConsoleCommand (org.terasology.logic.console.commandSystem.ConsoleCommand)16 Vector3f (org.terasology.math.geom.Vector3f)14 CharacterMovementComponent (org.terasology.logic.characters.CharacterMovementComponent)11 LocationComponent (org.terasology.logic.location.LocationComponent)10 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)9 ResourceUrn (org.terasology.assets.ResourceUrn)8 Prefab (org.terasology.entitySystem.prefab.Prefab)6 CharacterTeleportEvent (org.terasology.logic.characters.CharacterTeleportEvent)6 SimpleUri (org.terasology.engine.SimpleUri)5 BlockFamily (org.terasology.world.block.family.BlockFamily)4 Map (java.util.Map)3 AnatomyComponent (org.terasology.anatomy.component.AnatomyComponent)3 SetMovementModeEvent (org.terasology.logic.characters.events.SetMovementModeEvent)3 DropItemEvent (org.terasology.logic.inventory.events.DropItemEvent)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2