Search in sources :

Example 6 with ISoliniaNPCEventHandler

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

the class SoliniaPlayer method setInteraction.

@Override
public void setInteraction(UUID interaction, ISoliniaNPC npc) {
    if (interaction == null) {
        this.interaction = interaction;
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
        return;
    }
    Entity e = Bukkit.getEntity(interaction);
    if (e == null)
        return;
    if (!(e instanceof LivingEntity))
        return;
    if (((Creature) e).getTarget() != null) {
        if (interaction != null) {
            this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
            interaction = null;
        }
        return;
    }
    if (Bukkit.getEntity(interaction) instanceof Wolf) {
        Wolf w = (Wolf) Bukkit.getEntity(interaction);
        if (w.getOwner() != null)
            return;
    }
    this.interaction = interaction;
    if (npc != null) {
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are now interacting with " + Bukkit.getEntity(interaction).getName() + " [" + npc.getId() + "] - Anything you type will be heared by the NPC and possibly responded to. Words in pink are trigger words you can type");
        if (npc.getMerchantid() > 0) {
            try {
                StateManager.getInstance().getEntityManager().getLivingEntity((LivingEntity) e).say("i have a [" + ChatColor.LIGHT_PURPLE + "SHOP" + ChatColor.AQUA + "] available if you are interested in buying or selling something", getBukkitPlayer());
            } catch (CoreStateInitException cse) {
            // 
            }
        }
        for (ISoliniaNPCEventHandler eventHandler : npc.getEventHandlers()) {
            if (!eventHandler.getInteractiontype().equals(InteractionType.ITEM))
                continue;
            // See if player has any items that are wanted
            int itemId = Integer.parseInt(eventHandler.getTriggerdata());
            if (itemId == 0)
                continue;
            if (Utils.getPlayerTotalCountOfItemId(getBukkitPlayer(), itemId) < 1)
                continue;
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                TextComponent tc = new TextComponent();
                tc.setText(ChatColor.YELLOW + "[QUEST] ");
                TextComponent tc2 = new TextComponent();
                tc2.setText(ChatColor.GRAY + "- Click here to give " + item.getDisplayname() + ChatColor.RESET);
                tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/npcgive " + itemId));
                tc.addExtra(tc2);
                getBukkitPlayer().spigot().sendMessage(tc);
            } catch (CoreStateInitException eNotInitialised) {
                continue;
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Wolf(org.bukkit.entity.Wolf)

Example 7 with ISoliniaNPCEventHandler

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

Aggregations

ISoliniaNPCEventHandler (com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler)7 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)5 ISoliniaNPC (com.solinia.solinia.Interfaces.ISoliniaNPC)5 Player (org.bukkit.entity.Player)4 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)2 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)2 SoliniaNPCEventHandler (com.solinia.solinia.Models.SoliniaNPCEventHandler)2 CommandSender (org.bukkit.command.CommandSender)2 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)2 Entity (org.bukkit.entity.Entity)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)1 ISoliniaNPCEventHandlerTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaNPCEventHandlerTypeAdapterFactory)1 InteractionType (com.solinia.solinia.Models.InteractionType)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1