Search in sources :

Example 1 with EntityFeedable

use of io.xol.chunkstories.api.entity.interfaces.EntityFeedable in project chunkstories by Hugobros3.

the class FoodCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!(emitter instanceof Player)) {
        emitter.sendMessage("You need to be a player to use this command.");
        return true;
    }
    Player player = (Player) emitter;
    if (!emitter.hasPermission("self.setfood")) {
        emitter.sendMessage("You don't have the permission.");
        return true;
    }
    if (arguments.length < 1 || !isNumeric(arguments[0])) {
        emitter.sendMessage("Syntax: /food <hp>");
        return true;
    }
    float food = Float.parseFloat(arguments[0]);
    Entity controlledEntity = player.getControlledEntity();
    if (controlledEntity != null && controlledEntity instanceof EntityFeedable) {
        ((EntityFeedable) controlledEntity).setFoodLevel(food);
        player.sendMessage("Food set to: " + food);
        return true;
    }
    emitter.sendMessage("This action doesn't apply to your current entity.");
    return true;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) EntityFeedable(io.xol.chunkstories.api.entity.interfaces.EntityFeedable)

Aggregations

Entity (io.xol.chunkstories.api.entity.Entity)1 EntityFeedable (io.xol.chunkstories.api.entity.interfaces.EntityFeedable)1 Player (io.xol.chunkstories.api.player.Player)1