use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class ServerCommands method kick.
private String kick(EntityRef clientEntity) {
Client client = networkSystem.getOwner(clientEntity);
if (!client.isLocal()) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
logger.info("Kicking user {}", name.name);
networkSystem.forceDisconnect(client);
return "User kick triggered for '" + name.name + "'";
}
return "Request declined";
}
use of org.terasology.logic.common.DisplayNameComponent 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.logic.common.DisplayNameComponent 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.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class OnlineUsernameSuggester method suggest.
@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
Iterable<EntityRef> clients = entityManager.getEntitiesWith(ClientComponent.class);
Set<String> clientNames = Sets.newHashSet();
for (EntityRef client : clients) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
DisplayNameComponent displayNameComponent = clientComponent.clientInfo.getComponent(DisplayNameComponent.class);
clientNames.add(displayNameComponent.name);
}
return clientNames;
}
use of org.terasology.logic.common.DisplayNameComponent in project Terasology by MovingBlocks.
the class UsernameSuggester method suggest.
@Override
public Set<String> suggest(EntityRef sender, Object... resolvedParameters) {
Set<String> clientNames = Sets.newHashSet();
for (EntityRef clientInfo : entityManager.getEntitiesWith(ClientInfoComponent.class)) {
DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
clientNames.add(displayNameComponent.name);
}
return clientNames;
}
Aggregations