Search in sources :

Example 1 with InvalidLootTableSettingException

use of com.solinia.solinia.Exceptions.InvalidLootTableSettingException in project solinia3-core by mixxit.

the class CommandEditLootTable method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp() && !player.hasPermission("solinia.editloottable")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length < 1) {
        sender.sendMessage("Insufficient arguments: LootTableid");
        return false;
    }
    if (args.length == 0) {
        return false;
    }
    int LootTableid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaLootTable LootTable = StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid);
            if (LootTable != null) {
                LootTable.sendLootTableSettingsToSender(sender);
            } else {
                sender.sendMessage("LootTable ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: LootTableid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (LootTableid < 1) {
        sender.sendMessage("Invalid LootTable id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid) == null) {
            sender.sendMessage("Cannot locate LootTable id: " + LootTableid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getLootTable(LootTableid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This loottable was op created and you are not an op. Only ops can edit op loottable items");
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editLootTable(LootTableid, setting, value);
        sender.sendMessage("Updating setting on LootTable");
    } catch (InvalidLootTableSettingException ne) {
        sender.sendMessage("Invalid LootTable setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) InvalidLootTableSettingException(com.solinia.solinia.Exceptions.InvalidLootTableSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 InvalidLootTableSettingException (com.solinia.solinia.Exceptions.InvalidLootTableSettingException)1 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)1 CommandSender (org.bukkit.command.CommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1