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());
}
}
Aggregations