use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class BlockCommands method listBlocks.
@Command(shortDescription = "List all available blocks\nYou can filter by adding the beginning of words after the" + "commands, e.g.: \"listBlocks engine: core:\" will list all blocks from the engine and core module", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String listBlocks(@CommandParam(value = "startsWith", required = false) String[] startsWith) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Used Blocks");
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("-----------");
stringBuilder.append(Console.NEW_LINE);
List<BlockUri> registeredBlocks = sortItems(blockManager.listRegisteredBlockUris());
for (BlockUri blockUri : registeredBlocks) {
if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
continue;
}
stringBuilder.append(blockUri.toString());
stringBuilder.append(Console.NEW_LINE);
}
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("Available Blocks");
stringBuilder.append(Console.NEW_LINE);
stringBuilder.append("----------------");
stringBuilder.append(Console.NEW_LINE);
List<BlockUri> availableBlocks = sortItems(blockExplorer.getAvailableBlockFamilies());
for (BlockUri blockUri : availableBlocks) {
if (!uriStartsWithAnyString(blockUri.toString(), startsWith)) {
continue;
}
stringBuilder.append(blockUri.toString());
stringBuilder.append(Console.NEW_LINE);
}
return stringBuilder.toString();
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class BindCommands method bindKey.
@Command(shortDescription = "Maps a key to a function", requiredPermission = PermissionManager.NO_PERMISSION)
public String bindKey(@CommandParam("key") String key, @CommandParam("function") String bind) {
Input keyInput = Keyboard.Key.find(key);
if (keyInput != null) {
bindsManager.linkBindButtonToKey(keyInput.getId(), new SimpleUri(bind));
StringBuilder builder = new StringBuilder();
builder.append("Mapped ").append(keyInput.getDisplayName()).append(" to action ");
builder.append(bind);
return builder.toString();
}
throw new IllegalArgumentException("Unknown key: " + key);
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ChatSystem method say.
@Command(runOnServer = true, requiredPermission = PermissionManager.CHAT_PERMISSION, shortDescription = "Sends a message to all other players")
public String say(@Sender EntityRef sender, @CommandParam(value = "message") String[] message) {
String messageToString = join(message, " ");
logger.debug("Received chat message from {} : '{}'", sender, messageToString);
for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
client.send(new ChatMessageEvent(messageToString, sender.getComponent(ClientComponent.class).clientInfo));
}
return "Message sent";
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class MethodCommand method registerAvailable.
/**
* Registers all available command methods annotated with {@link org.terasology.logic.console.commandSystem.annotations.Command}.
*/
public static void registerAvailable(Object provider, Console console, Context context) {
Predicate<? super Method> predicate = Predicates.<Method>and(ReflectionUtils.withModifier(Modifier.PUBLIC), ReflectionUtils.withAnnotation(Command.class));
Set<Method> commandMethods = ReflectionUtils.getAllMethods(provider.getClass(), predicate);
for (Method method : commandMethods) {
if (!hasSenderAnnotation(method)) {
logger.error("Command {} provided by {} contains a EntityRef without @Sender annotation, may cause a NullPointerException", method.getName(), provider.getClass().getSimpleName());
}
logger.debug("Registering command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
try {
SpecificAccessibleObject<Method> specificMethod = new SpecificAccessibleObject<>(method, provider);
MethodCommand command = referringTo(specificMethod, context);
console.registerCommand(command);
logger.debug("Registered command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
} catch (RuntimeException t) {
logger.error("Failed to load command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName(), t);
}
}
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ClientCommands method setSpawnLocation.
/**
* Sets the spawn location for the client to the current location
* @return String containing debug information on the entity
*/
@Command(shortDescription = "Sets the spawn location for the client to the current location", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setSpawnLocation(@Sender EntityRef sender) {
EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
StaticSpawnLocationComponent staticSpawnLocationComponent = new StaticSpawnLocationComponent();
if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
staticSpawnLocationComponent = clientInfo.getComponent(StaticSpawnLocationComponent.class);
}
staticSpawnLocationComponent.position = sender.getComponent(ClientComponent.class).character.getComponent(LocationComponent.class).getWorldPosition();
clientInfo.addOrSaveComponent(staticSpawnLocationComponent);
return "Set spawn location to- " + staticSpawnLocationComponent.position;
}
Aggregations