use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class CoreCommands method ping.
/**
* Your ping to the server
*
* @param sender Sender of command
* @return String containing ping or error message
*/
@Command(shortDescription = "Your ping to the server", helpText = "The time it takes the packet " + "to reach the server and back", requiredPermission = PermissionManager.NO_PERMISSION)
public String ping(@Sender EntityRef sender) {
Server server = networkSystem.getServer();
if (server == null) {
// TODO: i18n
if (networkSystem.getMode().isServer()) {
return "Your player is running on the server";
} else {
return "Please make sure you are connected to an online server (singleplayer doesn't count)";
}
}
String[] remoteAddress = server.getRemoteAddress().split("-");
String address = remoteAddress[1];
int port = Integer.parseInt(remoteAddress[2]);
try {
PingService pingService = new PingService(address, port);
long delay = pingService.call();
return String.format("%d ms", delay);
} catch (UnknownHostException e) {
return String.format("Error: Unknown host \"%s\" at %s:%s -- %s", remoteAddress[0], remoteAddress[1], remoteAddress[2], e);
} catch (IOException e) {
return String.format("Error: Failed to ping server \"%s\" at %s:%s -- %s", remoteAddress[0], remoteAddress[1], remoteAddress[2], e);
}
}
use of org.terasology.engine.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(new Vector3f());
clientInfo.addOrSaveComponent(staticSpawnLocationComponent);
return "Set spawn location to- " + staticSpawnLocationComponent.position;
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ServerCommands method shutdownServer.
@Command(shortDescription = "Shutdown the server", runOnServer = true, requiredPermission = PermissionManager.SERVER_MANAGEMENT_PERMISSION)
public String shutdownServer(@Sender EntityRef sender) {
// TODO: verify permissions of sender
EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);
logger.info("Shutdown triggered by {}", name.name);
gameEngine.shutdown();
return "Server shutdown triggered";
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ServerCommands method reloadChunk.
@Command(shortDescription = "Invalidates the specified chunk and recreates it (requires storage manager disabled)", runOnServer = true)
public String reloadChunk(@CommandParam("x") int x, @CommandParam("y") int y, @CommandParam("z") int z) {
Vector3i pos = new Vector3i(x, y, z);
if (systemConfig.writeSaveGamesEnabled.get()) {
return "Writing save games is enabled! Invalidating chunk has no effect";
}
boolean success = chunkProvider.reloadChunk(pos);
return success ? "Cleared chunk " + pos + " from cache and triggered reload" : "Chunk " + pos + " did not exist in the cache";
}
use of org.terasology.engine.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ServerCommands method renameUser.
@Command(shortDescription = "Rename a user", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String renameUser(@CommandParam(value = "userName", suggester = UsernameSuggester.class) String userName, @CommandParam(value = "newUserName") String newUserName) {
Iterable<EntityRef> clientInfoEntities = entityManager.getEntitiesWith(ClientInfoComponent.class);
for (EntityRef clientInfo : clientInfoEntities) {
DisplayNameComponent nameComp = clientInfo.getComponent(DisplayNameComponent.class);
if (newUserName.equalsIgnoreCase(nameComp.name)) {
throw new IllegalArgumentException("New user name is already in use");
}
}
for (EntityRef clientInfo : clientInfoEntities) {
DisplayNameComponent nameComp = clientInfo.getComponent(DisplayNameComponent.class);
if (userName.equalsIgnoreCase(nameComp.name)) {
nameComp.name = newUserName;
clientInfo.saveComponent(nameComp);
return "User " + userName + " has been renamed to " + newUserName;
}
}
throw new IllegalArgumentException("No such user '" + userName + "'");
}
Aggregations