Search in sources :

Example 36 with Command

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

the class PermissionCommands method listPermissions.

@Command(shortDescription = "Lists all permission the specified player has", helpText = "Lists all permission the specified player has", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String listPermissions(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player) {
    for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        if (clientHasName(clientComponent, player)) {
            EntityRef clientInfo = clientComponent.clientInfo;
            PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
            return Objects.toString(permissionSetComp.permissions);
        }
    }
    return "Player not found";
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 37 with Command

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

the class PermissionCommands method removePermission.

@Command(shortDescription = "Removes specified permission from player", helpText = "Removes specified permission from player", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String removePermission(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player, @CommandParam("permission") String permission, @Sender EntityRef requester) {
    boolean permissionGiven = false;
    ClientComponent requesterClientComponent = requester.getComponent(ClientComponent.class);
    EntityRef requesterClientInfo = requesterClientComponent.clientInfo;
    if (!permissionManager.hasPermission(requesterClientInfo, permission)) {
        return String.format("You can't remove the permission %s because you don't have it yourself", permission);
    }
    for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
        ClientComponent clientComponent = client.getComponent(ClientComponent.class);
        if (clientHasName(clientComponent, player)) {
            permissionManager.removePermission(clientComponent.clientInfo, permission);
            permissionGiven = true;
        }
    }
    if (permissionGiven) {
        return "Permission " + permission + " removed from player " + player;
    } else {
        return "Unable to find player " + player;
    }
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 38 with Command

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

the class AudioSystem method playTestSound.

/**
 * Plays a test dig sound at an offset from the player in the x and z axis.
 *
 * @param sender The entity sending the sound request
 * @param xOffset The x axis offset from the player to play the sound at.
 * @param zOffset The z axis offset from the player to play the sound at.
 */
@Command(shortDescription = "Plays a test sound")
public void playTestSound(@Sender EntityRef sender, @CommandParam("xOffset") float xOffset, @CommandParam("zOffset") float zOffset) {
    Vector3f position = localPlayer.getPosition(new Vector3f());
    position.add(xOffset, 0, zOffset);
    audioManager.playSound(Assets.getSound("engine:dig").get(), position);
}
Also used : Vector3f(org.joml.Vector3f) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 39 with Command

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

the class AfkClientSystem method onCommand.

@Command(value = "afk", shortDescription = "Say that you are AFK to others", requiredPermission = PermissionManager.NO_PERMISSION)
public void onCommand() {
    if (requireConnection()) {
        console.addMessage("Failed! You need to be connected to use this command.");
        return;
    }
    updateActive();
    EntityRef entity = localPlayer.getClientEntity();
    AfkComponent component = entity.getComponent(AfkComponent.class);
    component.afk = !component.afk;
    entity.addOrSaveComponent(component);
    if (component.afk) {
        console.addMessage("[AFK] You are AFK now!");
    } else {
        console.addMessage("[AFK] You are no longer AFK!");
    }
    AfkRequest request = new AfkRequest(entity, component.afk);
    entity.send(request);
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command)

Example 40 with Command

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

the class MethodCommand method referringTo.

/**
 * Creates a new {@code ReferencedCommand} to a specific method annotated with {@link Command}.
 *
 * @param specificMethod The method to reference to
 * @return The command reference object created
 */
public static MethodCommand referringTo(SpecificAccessibleObject<Method> specificMethod, Context context) {
    Method method = specificMethod.getAccessibleObject();
    Command commandAnnotation = method.getAnnotation(Command.class);
    Preconditions.checkNotNull(commandAnnotation);
    String nameString = commandAnnotation.value();
    if (nameString.length() <= 0) {
        nameString = method.getName();
    }
    Name name = new Name(nameString);
    return new MethodCommand(name, commandAnnotation.requiredPermission(), commandAnnotation.runOnServer(), commandAnnotation.shortDescription(), commandAnnotation.helpText(), specificMethod, context);
}
Also used : Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) Method(java.lang.reflect.Method) Name(org.terasology.gestalt.naming.Name)

Aggregations

Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)67 ClientComponent (org.terasology.engine.network.ClientComponent)42 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)35 Vector3f (org.joml.Vector3f)16 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)16 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 LocationComponent (org.terasology.engine.logic.location.LocationComponent)10 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)9 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)6 Map (java.util.Map)5 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)5 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)5 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 List (java.util.List)3 Locale (java.util.Locale)3