Search in sources :

Example 1 with InvalidNpcSettingException

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

the class CommandEditNpc 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.editnpc")) {
            player.sendMessage("You do not have permission to access this command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int npcid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
            if (npc != null) {
                npc.sendNpcSettingsToSender(sender);
            } else {
                sender.sendMessage("NPC ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: npcid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    // for 'text' based npc settings like trigger texts etc, get the whole thing as a string
    if (args.length > 3 && (setting.toLowerCase().contains("text") || setting.toLowerCase().contains("title"))) {
        value = "";
        int current = 0;
        for (String entry : args) {
            current++;
            if (current <= 2)
                continue;
            value = value + entry + " ";
        }
        value = value.trim();
    }
    if (npcid < 1) {
        sender.sendMessage("Invalid npc id");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid) == null) {
            sender.sendMessage("Cannot locate npc id: " + npcid);
            return false;
        }
        if (StateManager.getInstance().getConfigurationManager().getNPC(npcid).isOperatorCreated() && !sender.isOp()) {
            sender.sendMessage("This npc was op created and you are not an op. Only ops can edit op npcs");
            return false;
        }
        try {
            StateManager.getInstance().getConfigurationManager().editNPC(npcid, setting, value);
            sender.sendMessage("Updating setting on npc");
        } catch (java.io.IOException e) {
            sender.sendMessage("Failed to update NPC - If this was a request to change custom head data, the mojang servers may be unable to fetch the player skin, try the same command again in a few moments");
        }
    } catch (InvalidNpcSettingException ne) {
        sender.sendMessage("Invalid NPC setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException)

Example 2 with InvalidNpcSettingException

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

the class SoliniaNPC method editSetting.

@Override
public void editSetting(String setting, String value) throws InvalidNpcSettingException, NumberFormatException, CoreStateInitException, java.io.IOException {
    switch(setting.toLowerCase()) {
        case "name":
            if (value.equals(""))
                throw new InvalidNpcSettingException("Name is empty");
            if (value.length() > 25)
                throw new InvalidNpcSettingException("Name is longer than 25 characters");
            setName(value);
            break;
        case "mctype":
            setMctype(value);
            break;
        case "level":
            setLevel(Integer.parseInt(value));
            break;
        case "factionid":
            if (Integer.parseInt(value) == 0) {
                setFactionid(Integer.parseInt(value));
                break;
            }
            ISoliniaFaction faction = StateManager.getInstance().getConfigurationManager().getFaction(Integer.parseInt(value));
            if (faction == null)
                throw new InvalidNpcSettingException("Faction ID does not exist");
            setFactionid(Integer.parseInt(value));
            break;
        case "usedisguise":
            setUsedisguise(Boolean.parseBoolean(value));
            break;
        case "disguisetype":
            setDisguisetype(value);
            break;
        case "headitem":
            setHeaditem(value);
            break;
        case "chestitem":
            setChestitem(value);
            break;
        case "legsitem":
            setLegsitem(value);
            break;
        case "feetitem":
            setFeetitem(value);
            break;
        case "handitem":
            setHanditem(value);
            break;
        case "offhanditem":
            setOffhanditem(value);
            break;
        case "clearitems":
            setHeaditem(null);
            setChestitem(null);
            setLegsitem(null);
            setFeetitem(null);
            setHanditem(null);
            setOffhanditem(null);
        case "boss":
            setBoss(Boolean.parseBoolean(value));
            break;
        case "heroic":
            setHeroic(Boolean.parseBoolean(value));
            break;
        case "raidboss":
            setRaidboss(Boolean.parseBoolean(value));
            break;
        case "raidheroic":
            setRaidheroic(Boolean.parseBoolean(value));
            break;
        case "burning":
            setBurning(Boolean.parseBoolean(value));
            break;
        case "invisible":
            setInvisible(Boolean.parseBoolean(value));
            break;
        case "customhead":
            setCustomhead(Boolean.parseBoolean(value));
            break;
        case "customheaddata":
            // fetches custom head texture by a player name
            setCustomheaddata(Utils.getTextureFromName(value));
            break;
        case "customheaddatafromnpc":
            int npcid = Integer.parseInt(value);
            ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(npcid);
            if (npc == null)
                throw new InvalidNpcSettingException("NPCID does not exist");
            // fetches custom head texture by existing npc
            setCustomheaddata(npc.getCustomheaddata());
            break;
        case "deathgrantstitle":
            // fetches custom head texture by a player name
            setDeathGrantsTitle(value);
            break;
        case "merchantid":
            if (Integer.parseInt(value) == 0) {
                setMerchantid(Integer.parseInt(value));
                break;
            }
            if (StateManager.getInstance().getConfigurationManager().getNPCMerchant(Integer.parseInt(value)) == null)
                throw new InvalidNpcSettingException("MerchantID does not exist");
            setMerchantid(Integer.parseInt(value));
            break;
        case "upsidedown":
            setUpsidedown(Boolean.parseBoolean(value));
            break;
        case "loottableid":
            if (Integer.parseInt(value) == 0) {
                setLoottableid(0);
                break;
            }
            ISoliniaLootTable loottable = StateManager.getInstance().getConfigurationManager().getLootTable(Integer.parseInt(value));
            if (loottable == null)
                throw new InvalidNpcSettingException("Loottable ID does not exist");
            setLoottableid(Integer.parseInt(value));
            break;
        case "raceid":
            setRaceid(Integer.parseInt(value));
            break;
        case "classid":
            setClassid(Integer.parseInt(value));
            break;
        case "randomspawn":
            setRandomSpawn(Boolean.parseBoolean(value));
            break;
        case "killtriggertext":
            setKillTriggerText(value);
            break;
        case "ac":
            setAC(Integer.parseInt(value));
        case "randomchattriggertext":
            setRandomchatTriggerText(value);
            break;
        case "guard":
            setGuard(Boolean.parseBoolean(value));
            break;
        case "pet":
            setPet(Boolean.parseBoolean(value));
            break;
        case "roamer":
            setRoamer(Boolean.parseBoolean(value));
            break;
        case "undead":
            setUndead(Boolean.parseBoolean(value));
            break;
        case "animal":
            setAnimal(Boolean.parseBoolean(value));
            break;
        case "summoner":
            setSummoner(Boolean.parseBoolean(value));
            break;
        case "disablespawners":
            disableAllSpawners(Boolean.parseBoolean(value));
            break;
        case "accuracyrating":
            setAccuracyRating(Integer.parseInt(value));
            break;
        case "avoidancerating":
            setAvoidanceRating(Integer.parseInt(value));
            break;
        case "speaksalllanguages":
            setSpeaksAllLanguages(Boolean.parseBoolean(value));
            break;
        default:
            throw new InvalidNpcSettingException("Invalid NPC setting. Valid Options are: name,mctype,health,damage,factionid,usedisguise,disguisetype,headitem,chestitem,legsitem,feetitem,handitem,offhanditem,boss,burning,invisible,customhead,customheaddata,merchantid,upsidedown,loottableid,randomspawn,killtriggertext,randomchattriggertext,guard,roamer,undead,customheaddatafromnpc,summoner,disablespawners,animal,speaksalllanguages");
    }
}
Also used : ISoliniaFaction(com.solinia.solinia.Interfaces.ISoliniaFaction) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) ISoliniaLootTable(com.solinia.solinia.Interfaces.ISoliniaLootTable)

Example 3 with InvalidNpcSettingException

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

the class CommandCommit method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender)) {
        sender.sendMessage("This is a Player/Console only command");
        return false;
    }
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return true;
        }
    }
    sender.sendMessage("* Executing State Commit");
    try {
        StateManager.getInstance().Commit();
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        sender.sendMessage("Error: " + e.getMessage());
        return true;
    }
    if (args.length > 0 && (sender instanceof ConsoleCommandSender || sender instanceof DiscordDefaultChannelCommandSender || sender instanceof DiscordAdminChannelCommandSender)) {
        if (args[0].equals("provider")) {
            try {
                System.out.println("Recommiting all NPCs via provider");
                for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
                    try {
                        npc.editSetting("name", npc.getName());
                        StateManager.getInstance().getEntityManager().getNPCEntityProvider().updateNpc(npc);
                    } catch (NumberFormatException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (InvalidNpcSettingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            } catch (CoreStateInitException e) {
            }
        }
        if (args[0].equals("patch")) {
            System.out.println("Patching");
            Utils.Patcher();
        }
    }
    sender.sendMessage("* Completed State Commit");
    return true;
}
Also used : Player(org.bukkit.entity.Player) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) DiscordAdminChannelCommandSender(com.solinia.solinia.Providers.DiscordAdminChannelCommandSender) DiscordDefaultChannelCommandSender(com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) IOException(java.io.IOException) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Aggregations

InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)3 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 CommandSender (org.bukkit.command.CommandSender)2 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)2 Player (org.bukkit.entity.Player)2 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)1 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)1 DiscordAdminChannelCommandSender (com.solinia.solinia.Providers.DiscordAdminChannelCommandSender)1 DiscordDefaultChannelCommandSender (com.solinia.solinia.Providers.DiscordDefaultChannelCommandSender)1 IOException (java.io.IOException)1