Search in sources :

Example 36 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.

the class ChannelManager method sendMobLvlToDiscordChannel.

private void sendMobLvlToDiscordChannel(DiscordChannel discordChannel, int mobmin, int mobmax) {
    String list = "";
    String targetChannelId = getDefaultDiscordChannel();
    if (discordChannel.equals(DiscordChannel.ADMIN))
        targetChannelId = getAdminDiscordChannel();
    try {
        int count = 0;
        for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
            if (npc.isPet())
                continue;
            if (npc.getLevel() >= mobmin && npc.getLevel() <= mobmax) {
                list += npc.getName() + "(" + npc.getLevel() + ") ";
                count++;
            }
        }
        if (count > 30) {
            sendToDiscordMC(null, targetChannelId, "Too many mobs found, try lowering your level range");
        } else {
            sendToDiscordMC(null, targetChannelId, "Matching Npcs: " + list);
        }
    } catch (CoreStateInitException e) {
    // ignore it
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Example 37 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.

the class ChannelManager method sendLootListToDiscordChannel.

private void sendLootListToDiscordChannel(DiscordChannel discordChannel, String itemMatch) {
    try {
        String targetChannelId = getDefaultDiscordChannel();
        if (discordChannel.equals(DiscordChannel.ADMIN))
            targetChannelId = getAdminDiscordChannel();
        if (itemMatch.length() < 3) {
            sendToDiscordMC(null, targetChannelId, "Item search must be at least 3 characters: " + itemMatch);
            return;
        }
        List<ISoliniaItem> items = StateManager.getInstance().getConfigurationManager().getItemsByPartialName(itemMatch);
        int itemIdLookup = 0;
        try {
            itemIdLookup = Integer.parseInt(itemMatch);
            ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemIdLookup);
            items.add(item);
        } catch (Exception e) {
        }
        if (items.size() < 1) {
            sendToDiscordMC(null, targetChannelId, "Could not find item: " + itemMatch);
            return;
        }
        if (items.size() > 1) {
            String itemsMatched = "";
            for (ISoliniaItem item : items) {
                itemsMatched += item.getId() + " ";
            }
            if (itemsMatched.length() > 256) {
                itemsMatched = itemsMatched.substring(0, 250) + "...";
            }
            sendToDiscordMC(null, targetChannelId, "More than one item found with this string, please be more specific than '" + itemMatch + "' (Or Try ?loot with one of these IDs: " + itemsMatched.trim() + ")");
            return;
        }
        String itemname = "";
        for (ISoliniaItem item : items) {
            itemname = item.getDisplayname();
            List<Integer> lootDropIds = StateManager.getInstance().getConfigurationManager().getLootDropIdsWithItemId(item.getId());
            if (lootDropIds.size() < 1) {
                sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] not found in any loot drops");
                return;
            }
            List<Integer> lootTableIds = StateManager.getInstance().getConfigurationManager().getLootTablesWithLootDrops(lootDropIds);
            if (lootTableIds.size() < 1) {
                sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] not found in any loot tables");
                return;
            }
            List<String> matchingNpcList = new ArrayList<String>();
            String currentLine = "";
            for (ISoliniaNPC npc : StateManager.getInstance().getConfigurationManager().getNPCs()) {
                if (!lootTableIds.contains(npc.getLoottableid()))
                    continue;
                if ((currentLine + npc.getName() + " ").length() > 2000) {
                    matchingNpcList.add(currentLine);
                    currentLine = "";
                }
                currentLine += npc.getName() + " ";
            }
            if (!currentLine.equals("")) {
                matchingNpcList.add(currentLine);
            }
            for (String line : matchingNpcList) {
                sendToDiscordMC(null, targetChannelId, "Item [" + itemname + "] found on: " + line);
            }
        }
    } catch (CoreStateInitException e) {
    // ignore it
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ArrayList(java.util.ArrayList) EventException(org.bukkit.event.EventException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException)

Example 38 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.

the class JsonNPCRepository method reload.

@Override
public void reload() {
    List<ISoliniaNPC> file = new ArrayList<ISoliniaNPC>();
    try {
        GsonBuilder gsonbuilder = new GsonBuilder();
        gsonbuilder.registerTypeAdapterFactory(new ISoliniaNPCEventHandlerTypeAdapterFactory(SoliniaNPCEventHandler.class));
        Gson gson = gsonbuilder.create();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaNPC>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    NPCs.clear();
    for (ISoliniaNPC i : file) {
        if (i.getEventHandlers().size() > 0) {
            for (ISoliniaNPCEventHandler handler : i.getEventHandlers()) {
                if (handler.getNpcId() == 0) {
                    handler.setNpcId(i.getId());
                    System.out.println("Corrected invalid NPC event handler " + handler.getTriggerdata() + " on npc: " + i.getId());
                }
            }
        }
        NPCs.put(i.getId(), i);
    }
    System.out.println("Reloaded " + NPCs.size() + " NPCs");
}
Also used : ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) SoliniaNPCEventHandler(com.solinia.solinia.Models.SoliniaNPCEventHandler) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) ISoliniaNPCEventHandlerTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaNPCEventHandlerTypeAdapterFactory) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 39 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC 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)

Example 40 with ISoliniaNPC

use of com.solinia.solinia.Interfaces.ISoliniaNPC in project solinia3-core by mixxit.

the class SoliniaLivingEntity method say.

@Override
public void say(String message, LivingEntity messageto) {
    if (isPlayer())
        return;
    if (this.getNpcid() < 1)
        return;
    try {
        ISoliniaNPC npc = StateManager.getInstance().getConfigurationManager().getNPC(this.getNpcid());
        if (npc == null)
            return;
        String decoratedMessage = ChatColor.AQUA + npc.getName() + " says to " + messageto.getName() + " '" + message + "'" + ChatColor.RESET;
        StateManager.getInstance().getChannelManager().sendToLocalChannelLivingEntityChat(this, decoratedMessage);
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC)

Aggregations

ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)50 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)43 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)19 Player (org.bukkit.entity.Player)16 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)7 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)7 CommandSender (org.bukkit.command.CommandSender)6 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)6 LivingEntity (org.bukkit.entity.LivingEntity)6 ISoliniaNPCEventHandler (com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)5 ArrayList (java.util.ArrayList)5 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)4 Entity (org.bukkit.entity.Entity)4 ISoliniaFaction (com.solinia.solinia.Interfaces.ISoliniaFaction)3 ItemStack (org.bukkit.inventory.ItemStack)3 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)2 SoliniaItemException (com.solinia.solinia.Exceptions.SoliniaItemException)2 ISoliniaLootTable (com.solinia.solinia.Interfaces.ISoliniaLootTable)2 SoliniaNPC (com.solinia.solinia.Models.SoliniaNPC)2 SoliniaNPCEventHandler (com.solinia.solinia.Models.SoliniaNPCEventHandler)2