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";
}
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;
}
}
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);
}
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);
}
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);
}
Aggregations