use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class CoreCommands method join.
/**
* Join a game
* @param address String containing address of game server
* @param portParam Integer containing game server port
*/
@Command(shortDescription = "Join a game", requiredPermission = PermissionManager.NO_PERMISSION)
public void join(@CommandParam("address") final String address, @CommandParam(value = "port", required = false) Integer portParam) {
final int port = portParam != null ? portParam : TerasologyConstants.DEFAULT_PORT;
Callable<JoinStatus> operation = () -> networkSystem.join(address, port);
final WaitPopup<JoinStatus> popup = nuiManager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
popup.setMessage("Join Game", "Connecting to '" + address + ":" + port + "' - please wait ...");
popup.onSuccess(result -> {
if (result.getStatus() != JoinStatus.Status.FAILED) {
gameEngine.changeState(new StateLoading(result));
} else {
MessagePopup screen = nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
screen.setMessage("Failed to Join", "Could not connect to server - " + result.getErrorMessage());
}
});
popup.startOperation(operation, true);
}
use of org.terasology.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.valueOf(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.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class CoreCommands method dumpEntities.
/**
* Writes out information on all entities to a text file for debugging
* @throws IOException thrown when error with saving file occures
*/
@Command(shortDescription = "Writes out information on all entities to a text file for debugging", helpText = "Writes entity information out into a file named \"entityDump.txt\".")
public void dumpEntities() throws IOException {
EngineEntityManager engineEntityManager = (EngineEntityManager) entityManager;
PrefabSerializer prefabSerializer = new PrefabSerializer(engineEntityManager.getComponentLibrary(), engineEntityManager.getTypeSerializerLibrary());
WorldDumper worldDumper = new WorldDumper(engineEntityManager, prefabSerializer);
worldDumper.save(PathManager.getInstance().getHomePath().resolve("entityDump.txt"));
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class CoreCommands method help.
/**
* Prints out short descriptions for all available commands, or a longer help text if a command is provided.
* @param commandName String containing command for which will be displayed help
* @return String containing short description of all commands or longer help text if command is provided
*/
@Command(shortDescription = "Prints out short descriptions for all available commands, or a longer help text if a command is provided.", requiredPermission = PermissionManager.NO_PERMISSION)
public String help(@CommandParam(value = "command", required = false, suggester = CommandNameSuggester.class) Name commandName) {
if (commandName == null) {
StringBuilder msg = new StringBuilder();
// Get all commands, with appropriate sorting
List<ConsoleCommand> commands = Ordering.natural().immutableSortedCopy(console.getCommands());
for (ConsoleCommand cmd : commands) {
if (!msg.toString().isEmpty()) {
msg.append(Console.NEW_LINE);
}
msg.append(FontColor.getColored(cmd.getUsage(), ConsoleColors.COMMAND));
msg.append(" - ");
msg.append(cmd.getDescription());
}
return msg.toString();
} else {
ConsoleCommand cmd = console.getCommand(commandName);
if (cmd == null) {
return "No help available for command '" + commandName + "'. Unknown command.";
} else {
StringBuilder msg = new StringBuilder();
msg.append("=====================================================================================================================");
msg.append(Console.NEW_LINE);
msg.append(cmd.getUsage());
msg.append(Console.NEW_LINE);
msg.append("=====================================================================================================================");
msg.append(Console.NEW_LINE);
if (!cmd.getHelpText().isEmpty()) {
msg.append(cmd.getHelpText());
msg.append(Console.NEW_LINE);
msg.append("=====================================================================================================================");
msg.append(Console.NEW_LINE);
} else if (!cmd.getDescription().isEmpty()) {
msg.append(cmd.getDescription());
msg.append(Console.NEW_LINE);
msg.append("=====================================================================================================================");
msg.append(Console.NEW_LINE);
}
if (!cmd.getRequiredPermission().isEmpty()) {
msg.append("Required permission level - " + cmd.getRequiredPermission());
msg.append(Console.NEW_LINE);
msg.append("=====================================================================================================================");
msg.append(Console.NEW_LINE);
}
return msg.toString();
}
}
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class CoreCommands method spawnBlock.
/**
* Spawns a block in front of the player
* @param sender Sender of command
* @param blockName String containing name of block to spawn
* @return String containg final message
*/
@Command(shortDescription = "Spawns a block in front of the player", helpText = "Spawns the specified block as a " + "item in front of the player. You can simply pick it up.", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnBlock(@Sender EntityRef sender, @CommandParam("blockName") String blockName) {
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition();
Vector3f offset = characterLocation.getWorldDirection();
offset.scale(3);
spawnPos.add(offset);
BlockFamily block = blockManager.getBlockFamily(blockName);
if (block == null) {
return "";
}
BlockItemFactory blockItemFactory = new BlockItemFactory(entityManager);
EntityRef blockItem = blockItemFactory.newInstance(block);
blockItem.send(new DropItemEvent(spawnPos));
return "Spawned block.";
}
Aggregations