use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class HealthCommands method heal.
@Command(shortDescription = "Restores your health by an amount", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String heal(@Sender EntityRef client, @CommandParam("amount") int amount) {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
clientComp.character.send(new DoHealEvent(amount, clientComp.character));
return "Health restored for " + amount;
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class HealthCommands method killCommand.
@Command(value = "kill", shortDescription = "Reduce the player's health to zero", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public void killCommand(@Sender EntityRef client) {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
if (health != null) {
clientComp.character.send(new DestroyEvent(clientComp.character, EntityRef.NULL, EngineDamageTypes.DIRECT.get()));
}
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class HealthCommands method setMaxHealth.
@Command(shortDescription = "Set max health", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setMaxHealth(@Sender EntityRef client, @CommandParam("max") int max) {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
float oldMaxHealth = health.maxHealth;
if (health != null) {
health.maxHealth = max;
clientComp.character.saveComponent(health);
}
return "Max health changed from " + oldMaxHealth + " to " + max;
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class HealthCommands method setRegenRate.
@Command(shortDescription = "Set health regen rate", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setRegenRate(@Sender EntityRef client, @CommandParam("rate") float rate) {
ClientComponent clientComp = client.getComponent(ClientComponent.class);
HealthComponent health = clientComp.character.getComponent(HealthComponent.class);
float oldRegenRate = health.regenRate;
if (health != null) {
health.regenRate = rate;
clientComp.character.saveComponent(health);
}
return "Health regeneration changed from " + oldRegenRate + " to " + rate;
}
use of org.terasology.logic.console.commandSystem.annotations.Command in project Terasology by MovingBlocks.
the class ItemCommands method give.
@Command(shortDescription = "Adds an item or block to your inventory", helpText = "Puts the desired number of the given item or block with the given shape into your inventory", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String give(@Sender EntityRef client, @CommandParam("prefabId or blockName") String itemPrefabName, @CommandParam(value = "amount", required = false) Integer amount, @CommandParam(value = "blockShapeName", required = false) String shapeUriParam) {
int itemAmount = amount != null ? amount : 1;
if (itemAmount < 1) {
return "Requested zero (0) items / blocks!";
}
Set<ResourceUrn> matches = assetManager.resolve(itemPrefabName, Prefab.class);
if (matches.size() == 1) {
Prefab prefab = assetManager.getAsset(matches.iterator().next(), Prefab.class).orElse(null);
if (prefab != null && prefab.getComponent(ItemComponent.class) != null) {
EntityRef playerEntity = client.getComponent(ClientComponent.class).character;
for (int quantityLeft = itemAmount; quantityLeft > 0; quantityLeft--) {
EntityRef item = entityManager.create(prefab);
if (!inventoryManager.giveItem(playerEntity, playerEntity, item)) {
item.destroy();
itemAmount -= quantityLeft;
break;
}
}
return "You received " + (itemAmount > 1 ? itemAmount + " items of " : "an item of ") + // TODO Use item display name
prefab.getName() + (shapeUriParam != null ? " (Item can not have a shape)" : "");
}
} else if (matches.size() > 1) {
StringBuilder builder = new StringBuilder();
builder.append("Requested item \"");
builder.append(itemPrefabName);
builder.append("\": matches ");
Joiner.on(" and ").appendTo(builder, matches);
builder.append(". Please fully specify one.");
return builder.toString();
}
// If no no matches are found for items, try blocks
String message = blockCommands.giveBlock(client, itemPrefabName, amount, shapeUriParam);
if (message != null) {
return message;
}
return "Could not find an item or block matching \"" + itemPrefabName + "\"";
}
Aggregations