Search in sources :

Example 1 with IIncantation

use of com.bewitchment.api.incantation.IIncantation in project Bewitchment by Um-Mitternacht.

the class CommandIncantation method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length < 1)
        throw new WrongUsageException("commands.incantation.usage");
    if (sender.getCommandSenderEntity() == null)
        return;
    final String command = args[0];
    if (ModIncantations.getCommands().containsKey(command)) {
        IIncantation incantation = ModIncantations.getCommands().get(command);
        if (sender.getCommandSenderEntity() instanceof EntityPlayer) {
            EntityPlayer player = (EntityPlayer) sender.getCommandSenderEntity();
            Optional<IEnergy> ienopt = EnergyHandler.getEnergy(player);
            if (ienopt.isPresent()) {
                if (ienopt.get().get() >= incantation.getCost()) {
                    EnergyHandler.addEnergy(player, -incantation.getCost());
                    incantation.cast(player, args);
                } else {
                    throw new CommandException("commands.incantation.no_energy", sender.getName());
                }
            } else {
                throw new CommandException("commands.incantation.no_energy", sender.getName());
            }
        }
    } else {
        throw new CommandException("commands.incantation.notFound", sender.getName());
    }
}
Also used : IIncantation(com.bewitchment.api.incantation.IIncantation) WrongUsageException(net.minecraft.command.WrongUsageException) IEnergy(com.bewitchment.api.capability.IEnergy) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CommandException(net.minecraft.command.CommandException)

Aggregations

IEnergy (com.bewitchment.api.capability.IEnergy)1 IIncantation (com.bewitchment.api.incantation.IIncantation)1 CommandException (net.minecraft.command.CommandException)1 WrongUsageException (net.minecraft.command.WrongUsageException)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1