use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class PermissionCommands method usePermissionKey.
@Command(shortDescription = "Use an one time key to get all permissions", helpText = "The config file contains a one time key which can be used to get all permissions.", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public String usePermissionKey(@CommandParam("key") String key, @Sender EntityRef client) {
PermissionConfig permissionConfig = config.getPermission();
String expectedKey = permissionConfig.getOneTimeAuthorizationKey();
if (expectedKey != null && !expectedKey.equals("") && key.equals(expectedKey)) {
permissionConfig.setOneTimeAuthorizationKey("");
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
EntityRef clientInfo = clientComponent.clientInfo;
for (String permission : findAllPermissions()) {
permissionManager.addPermission(clientInfo, permission);
}
PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
return "Permission key used: You have now the following permissions: " + permissionSetComp.permissions;
} else {
return "Key invalid or used";
}
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method setFirstPersonheldItemMountPointRotation.
@Command(shortDescription = "Sets the held item mount point rotation for the first person view")
public void setFirstPersonheldItemMountPointRotation(@CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) {
FirstPersonHeldItemMountPointComponent newComponent = localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
if (newComponent != null) {
newComponent.rotateDegrees = new Vector3f(x, y, z);
ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(), localPlayer.getCameraEntity(), newComponent);
}
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class FirstPersonClientSystem method setFirstPersonheldItemMountPointTranslation.
@Command(shortDescription = "Sets the held item mount point translation for the first person view")
public void setFirstPersonheldItemMountPointTranslation(@CommandParam("x") float x, @CommandParam("y") float y, @CommandParam("z") float z) {
FirstPersonHeldItemMountPointComponent newComponent = localPlayer.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
if (newComponent != null) {
newComponent.translate = new Vector3f(x, y, z);
ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent.newInstance(), localPlayer.getCameraEntity(), newComponent);
}
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ChatSystem method whisper.
@Command(runOnServer = true, requiredPermission = PermissionManager.CHAT_PERMISSION, shortDescription = "Sends a private message to a specified user")
public String whisper(@Sender EntityRef sender, @CommandParam(value = "user", suggester = OnlineUsernameSuggester.class) String username, @CommandParam("message") String[] message) {
String messageToString = join(message, " ");
Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
EntityRef targetClient = null;
boolean unique = true;
for (EntityRef client : clients) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
continue;
}
if (displayNameComponent.name.equalsIgnoreCase(username)) {
if (targetClient == null) {
targetClient = client;
} else {
unique = false;
break;
}
}
}
if (!unique) {
targetClient = null;
for (EntityRef client : clients) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null) {
continue;
}
if (displayNameComponent.name.equals(username)) {
if (targetClient == null) {
targetClient = client;
} else {
return FontColor.getColored("Found more users with name '" + username + "'.", ConsoleColors.ERROR);
}
}
}
}
if (targetClient == null) {
return FontColor.getColored("User with name '" + username + "' not found.", ConsoleColors.ERROR);
}
ClientComponent senderClientComponent = sender.getComponent(ClientComponent.class);
ClientComponent targetClientComponent = targetClient.getComponent(ClientComponent.class);
DisplayNameComponent targetDisplayNameComponent = targetClientComponent.clientInfo.getComponent(DisplayNameComponent.class);
String targetMessage = FontColor.getColored("*whispering* ", ConsoleColors.ERROR) + FontColor.getColored(messageToString, ConsoleColors.CHAT);
String senderMessage = "You -> " + targetDisplayNameComponent.name + ": " + FontColor.getColored(messageToString, ConsoleColors.CHAT);
targetClient.send(new ChatMessageEvent(targetMessage, senderClientComponent.clientInfo));
return senderMessage;
}
use of org.terasology.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 org.terasology.logic.console.commandSystem.annotations.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