use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ClientCommands method setWorldTime.
/**
* Sets the current world time for the local player in days
* @param day Float containing day to be set
* @return String message containing message to notify user
*/
@Command(shortDescription = "Sets the current world time for the local player in days", requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setWorldTime(@CommandParam("day") float day, @Sender EntityRef sender) {
worldProvider.getTime().setDays(day);
sender.send(new WorldtimeResetEvent(day));
return "World time changed";
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ServerCommands method kickUser.
@Command(shortDescription = "Kick user by name", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUser(@CommandParam("username") String username) {
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
if (username.equalsIgnoreCase(name.name)) {
return kick(clientEntity);
}
}
throw new IllegalArgumentException("No such user '" + username + "'");
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ServerCommands method kickUserByID.
@Command(shortDescription = "Kick user by ID", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String kickUserByID(@CommandParam("userId") int userId) {
for (EntityRef clientEntity : entityManager.getEntitiesWith(ClientComponent.class)) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
if (userId == nc.getNetworkId()) {
return kick(clientEntity);
}
}
throw new IllegalArgumentException("No such user with ID " + userId);
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ServerCommands method listUsers.
@Command(shortDescription = "List users", requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String listUsers() {
StringBuilder stringBuilder = new StringBuilder();
for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
DisplayNameComponent dnc = clientInfo.getComponent(DisplayNameComponent.class);
NetworkComponent nc = clientInfo.getComponent(NetworkComponent.class);
String playerText = PlayerUtil.getColoredPlayerName(clientInfo);
String line = String.format("%s - %s (%d)", playerText, dnc.description, nc.getNetworkId());
stringBuilder.append(line);
stringBuilder.append(Console.NEW_LINE);
}
return stringBuilder.toString();
}
use of org.terasology.engine.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;
}
Aggregations