Search in sources :

Example 61 with CoreStateInitException

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

the class SoliniaNPC method processChatInteractionEvent.

@Override
public void processChatInteractionEvent(SoliniaLivingEntity solentity, LivingEntity triggerentity, String data) {
    String[] words = data.split(" ");
    // Merchant special commands
    if (words.length > 0) {
        // Check player has sufficient faction
        if (triggerentity instanceof Player)
            if (solentity.getNpcid() > 0) {
                try {
                    ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(solentity.getNpcid());
                    if (npc.getFactionid() > 0) {
                        ISoliniaPlayer solPlayer = SoliniaPlayerAdapter.Adapt((Player) triggerentity);
                        PlayerFactionEntry factionEntry = solPlayer.getFactionEntry(npc.getFactionid());
                        if (factionEntry != null) {
                            switch(Utils.getFactionStandingType(factionEntry.getFactionId(), factionEntry.getValue())) {
                                case FACTION_THREATENLY:
                                case FACTION_SCOWLS:
                                    solentity.emote("* " + npc.getName() + " scowls angrily at " + solPlayer.getFullName());
                                    return;
                                default:
                                    break;
                            }
                        }
                    }
                } catch (CoreStateInitException e) {
                }
            }
        switch(words[0].toUpperCase()) {
            case "SHOP":
                if (triggerentity instanceof Player)
                    if (getMerchantid() > 0) {
                        if (words.length == 1) {
                            sendMerchantItemListToPlayer((Player) triggerentity, 1);
                            return;
                        }
                        int page = 1;
                        try {
                            page = Integer.parseInt(words[1]);
                        } catch (Exception e) {
                        }
                        if (page < 1)
                            page = 1;
                        sendMerchantItemListToPlayer((Player) triggerentity, page);
                    }
                return;
            case "LISTEFFECTS":
                if (triggerentity instanceof Player) {
                    if (((Player) triggerentity).isOp()) {
                        Player player = (Player) triggerentity;
                        try {
                            for (SoliniaActiveSpell spell : StateManager.getInstance().getEntityManager().getActiveEntitySpells(solentity.getBukkitLivingEntity()).getActiveSpells()) {
                                player.sendMessage(spell.getSpell().getName());
                                for (ActiveSpellEffect effect : spell.getActiveSpellEffects()) {
                                    player.sendMessage(" - " + effect.getSpellEffectType().name() + " " + effect.getBase());
                                }
                            }
                        } catch (CoreStateInitException e) {
                        // 
                        }
                    }
                }
                return;
            default:
                break;
        }
    }
    // Normal text matching
    for (ISoliniaNPCEventHandler handler : getEventHandlers()) {
        if (!handler.getInteractiontype().equals(InteractionType.CHAT))
            continue;
        if (!data.toUpperCase().contains(handler.getTriggerdata().toUpperCase()))
            continue;
        if (handler.getChatresponse() != null && !handler.getChatresponse().equals("")) {
            if ((triggerentity instanceof Player)) {
                if (!handler.playerMeetsRequirements((Player) triggerentity))
                    return;
            }
            String response = handler.getChatresponse();
            solentity.say(replaceChatWordsWithHints(response), triggerentity);
            if (triggerentity instanceof Player)
                handler.awardPlayer((Player) triggerentity);
            if (handler.getTeleportResponse() != null && !handler.getTeleportResponse().equals("")) {
                if (triggerentity instanceof Player) {
                    String[] zonedata = handler.getTeleportResponse().split(",");
                    // Dissasemble the value to ensure it is correct
                    String world = zonedata[0];
                    double x = Double.parseDouble(zonedata[1]);
                    double y = Double.parseDouble(zonedata[2]);
                    double z = Double.parseDouble(zonedata[3]);
                    Location loc = new Location(Bukkit.getWorld(world), x, y, z);
                    ((Player) triggerentity).teleport(loc);
                }
            }
        }
    }
    return;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) Location(org.bukkit.Location)

Example 62 with CoreStateInitException

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

the class SoliniaNPC method disableAllSpawners.

@Override
public void disableAllSpawners(boolean parseBoolean) {
    try {
        for (ISoliniaSpawnGroup group : StateManager.getInstance().getConfigurationManager().getSpawnGroups()) {
            if (group.getNpcid() == this.getId()) {
                System.out.println("Set Spawner Disabled Status: " + group.getId() + ":" + group.getName() + " - " + parseBoolean);
                group.setDisabled(parseBoolean);
                StateManager.getInstance().getEntityManager().getNPCEntityProvider().removeSpawnGroup(group);
            }
        }
    } catch (CoreStateInitException e) {
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaSpawnGroup(com.solinia.solinia.Interfaces.ISoliniaSpawnGroup)

Example 63 with CoreStateInitException

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

the class SoliniaNPCEventHandler method editTriggerEventSetting.

@Override
public void editTriggerEventSetting(String setting, String value) throws InvalidNPCEventSettingException {
    switch(setting.toLowerCase()) {
        case "randomisedgearsuffix":
            setRandomisedGearSuffix(value);
            break;
        case "title":
            setTitle(value);
            break;
        case "awardstitle":
            setAwardsTitle(Boolean.parseBoolean(value));
            break;
        case "triggerdata":
            if (value.equals(""))
                throw new InvalidNPCEventSettingException("Triggerdata is empty");
            if (value.contains(" "))
                throw new InvalidNPCEventSettingException("Triggerdata can only be one value");
            setTriggerdata(value.toUpperCase());
            break;
        case "chatresponse":
            if (value.equals(""))
                throw new InvalidNPCEventSettingException("Chatresponse is empty");
            setChatresponse(value);
            break;
        case "requiresquest":
            int questid = Integer.parseInt(value);
            if (questid < 1)
                throw new InvalidNPCEventSettingException("Invalid quest id");
            try {
                ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(questid);
                if (quest == null)
                    throw new InvalidNPCEventSettingException("Invalid quest id");
            } catch (CoreStateInitException e) {
                throw new InvalidNPCEventSettingException("State not initialised");
            }
            setRequiresQuest(questid);
            break;
        case "awardsquest":
            int aquestid = Integer.parseInt(value);
            if (aquestid < 1)
                throw new InvalidNPCEventSettingException("Invalid quest id");
            try {
                ISoliniaQuest quest = StateManager.getInstance().getConfigurationManager().getQuest(aquestid);
                if (quest == null)
                    throw new InvalidNPCEventSettingException("Invalid quest id");
            } catch (CoreStateInitException e) {
                throw new InvalidNPCEventSettingException("State not initialised");
            }
            setAwardsQuest(aquestid);
            break;
        case "requiresquestflag":
            setRequiresQuestFlag(value);
            break;
        case "awardsquestflag":
            setAwardsQuestFlag(value);
            break;
        case "teleportresponse":
            try {
                String[] zonedata = value.split(",");
                // Dissasemble the value to ensure it is correct
                String world = zonedata[0];
                double x = Double.parseDouble(zonedata[1]);
                double y = Double.parseDouble(zonedata[2]);
                double z = Double.parseDouble(zonedata[3]);
                setTeleportResponse(world + "," + x + "," + y + "," + z);
                break;
            } catch (Exception e) {
                throw new InvalidNPCEventSettingException("Teleport zone value must be in format: world,x,y,z");
            }
        case "awardsrandomisedgear":
            setAwardsRandomisedGear(Boolean.parseBoolean(value));
            break;
        case "awardsitem":
            int itemId = Integer.parseInt(value);
            if (itemId < 1)
                throw new InvalidNPCEventSettingException("Invalid item ID");
            if (getAwardsQuestFlag() == null || getAwardsQuestFlag().equals(""))
                throw new InvalidNPCEventSettingException("You cannot set an awardsitem to a npc event handler unless the npc awards a quest flag -  this is to prevent duplicated awards");
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                if (item == null)
                    throw new InvalidNPCEventSettingException("Invalid item id");
            } catch (CoreStateInitException e) {
                throw new InvalidNPCEventSettingException("State not initialised");
            }
            setAwardsItem(itemId);
            break;
        default:
            throw new InvalidNPCEventSettingException("Invalid NPC Event setting. Valid Options are: triggerdata,chatresponse,interactiontype,requiresquest,awardsquest,requiresquestflag,awardsquestflag,awardsitem");
    }
}
Also used : ISoliniaQuest(com.solinia.solinia.Interfaces.ISoliniaQuest) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException)

Example 64 with CoreStateInitException

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

the class SoliniaLivingEntity method doRandomChat.

@Override
public void doRandomChat() {
    if (isPlayer())
        return;
    if (this.getNpcid() < 1)
        return;
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc.getRandomchatTriggerText() == null || npc.getRandomchatTriggerText().equals(""))
            return;
        // 2% chance of saying something
        int random = Utils.RandomBetween(1, 100);
        if (random < 2) {
            this.say(npc.getRandomchatTriggerText());
        }
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 65 with CoreStateInitException

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

the class SoliniaLivingEntity method checkHitChance.

@Override
public boolean checkHitChance(SoliniaLivingEntity attacker, DamageHitInfo hit) {
    ISoliniaLivingEntity defender = this;
    if (defender.isPlayer()) {
        try {
            ISoliniaPlayer player = SoliniaPlayerAdapter.Adapt((Player) defender.getBukkitLivingEntity());
            if (player.isMeditating()) {
                return true;
            }
        } catch (CoreStateInitException e) {
        // ignore it
        }
    }
    int avoidance = defender.getTotalDefense();
    int accuracy = hit.tohit;
    // if (accuracy == -1)
    // return true;
    double hitRoll = Utils.RandomBetween(0, (int) Math.floor(accuracy));
    double avoidRoll = Utils.RandomBetween(0, (int) Math.floor(avoidance));
    // tie breaker? Don't want to be biased any one way
    return hitRoll > avoidRoll;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer)

Aggregations

CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)216 Player (org.bukkit.entity.Player)114 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)99 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)43 CommandSender (org.bukkit.command.CommandSender)42 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)41 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)36 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)36 LivingEntity (org.bukkit.entity.LivingEntity)32 ArrayList (java.util.ArrayList)31 Entity (org.bukkit.entity.Entity)21 ItemStack (org.bukkit.inventory.ItemStack)20 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)17 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)16 EventHandler (org.bukkit.event.EventHandler)16 Timestamp (java.sql.Timestamp)13 TextComponent (net.md_5.bungee.api.chat.TextComponent)12 CraftEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftEntity)11 CraftLivingEntity (org.bukkit.craftbukkit.v1_12_R1.entity.CraftLivingEntity)11 PathEntity (net.minecraft.server.v1_12_R1.PathEntity)10