Search in sources :

Example 26 with Command

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

the class ServerCommands method renameUser.

@Command(shortDescription = "Rename a user", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String renameUser(@CommandParam(value = "userName", suggester = UsernameSuggester.class) String userName, @CommandParam(value = "newUserName") String newUserName) {
    Iterable<EntityRef> clientInfoEntities = entityManager.getEntitiesWith(ClientInfoComponent.class);
    for (EntityRef clientInfo : clientInfoEntities) {
        DisplayNameComponent nameComp = clientInfo.getComponent(DisplayNameComponent.class);
        if (newUserName.equalsIgnoreCase(nameComp.name)) {
            throw new IllegalArgumentException("New user name is already in use");
        }
    }
    for (EntityRef clientInfo : clientInfoEntities) {
        DisplayNameComponent nameComp = clientInfo.getComponent(DisplayNameComponent.class);
        if (userName.equalsIgnoreCase(nameComp.name)) {
            nameComp.name = newUserName;
            clientInfo.saveComponent(nameComp);
            return "User " + userName + " has been renamed to " + newUserName;
        }
    }
    throw new IllegalArgumentException("No such user '" + userName + "'");
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 27 with Command

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

the class ServerCommands method reloadChunk.

@Command(shortDescription = "Invalidates the specified chunk and recreates it (requires storage manager disabled)", runOnServer = true)
public String reloadChunk(@CommandParam("x") int x, @CommandParam("y") int y, @CommandParam("z") int z) {
    Vector3i pos = new Vector3i(x, y, z);
    if (config.getSystem().isWriteSaveGamesEnabled()) {
        return "Writing save games is enabled! Invalidating chunk has no effect";
    }
    boolean success = chunkProvider.reloadChunk(pos);
    return success ? "Cleared chunk " + pos + " from cache and triggered reload" : "Chunk " + pos + " did not exist in the cache";
}
Also used : Vector3i(org.terasology.math.geom.Vector3i) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 28 with Command

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

the class HealthCommands method healthMax.

@Command(shortDescription = "Restores your health to max", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String healthMax(@Sender EntityRef clientEntity) {
    ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
    clientComp.character.send(new DoHealEvent(100000, clientComp.character));
    return "Health fully restored";
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 29 with Command

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

the class HealthCommands method showHealth.

@Command(shortDescription = "Show your health", requiredPermission = PermissionManager.NO_PERMISSION)
public String showHealth(@Sender EntityRef client) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
    if (health != null) {
        return "Your health:" + health.currentHealth + " max:" + health.maxHealth + " regen:" + health.regenRate;
    }
    return "I guess you're dead?";
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Command(org.terasology.logic.console.commandSystem.annotations.Command)

Example 30 with Command

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

the class HealthCommands method damageWithType.

@Command(shortDescription = "Reduce the player's health by an amount by a specific type of damage", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String damageWithType(@Sender EntityRef client, @CommandParam("damageType") String damageType, @CommandParam("amount") int amount) {
    ClientComponent clientComp = client.getComponent(ClientComponent.class);
    Prefab damageTypePrefab = prefabManager.getPrefab(damageType);
    if (damageTypePrefab != null) {
        clientComp.character.send(new DoDamageEvent(amount, damageTypePrefab, clientComp.character));
        return "Inflicted " + amount + " damage of type " + damageType;
    } else {
        return "Specified damage type does not exist.";
    }
}
Also used : ClientComponent(org.terasology.network.ClientComponent) Prefab(org.terasology.entitySystem.prefab.Prefab) Command(org.terasology.logic.console.commandSystem.annotations.Command)

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