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;
}
}
}
}
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");
}
Aggregations