use of com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait in project buildinggame by stefvanschie.
the class NPCCreate method onNPCSpawn.
/**
* Called when a {@link NPC} is spawned
*
* @param event the event fired when an {@link NPC} is spawned
* @since 7.1.0
*/
@EventHandler
private void onNPCSpawn(@NotNull NPCSpawnEvent event) {
toBeSpawned.entrySet().stream().filter(entry -> event.getNPC().equals(entry.getKey())).findAny().ifPresent(entry -> {
NPC npc = entry.getKey();
toBeSpawned.remove(npc);
if (ArenaManager.getInstance().getArenas().stream().flatMap(arena -> arena.getPlots().stream()).map(Plot::getBoundary).anyMatch(boundary -> boundary.isInside(event.getLocation()))) {
Player player = entry.getValue();
TextComponent textComponent = TextComponent.of("You have spawned an NPC inside a plot, would you like to allow players to use this NPC to change their plot's floor? Please click ").color(TextColor.GOLD).append(TextComponent.of("here").color(TextColor.AQUA).clickEvent(ClickEvent.runCommand('/' + CommandUtil.createTempCommand(sender -> {
if (!sender.equals(player)) {
return;
}
npc.addTrait(new NPCFloorChangeTrait());
MessageManager.getInstance().send(player, ChatColor.GREEN + "This NPC now allows players to change their plot's floor");
})))).append(TextComponent.of(" if so, otherwise ignore this message. This will expire in 60 seconds.").color(TextColor.GOLD));
TextAdapter.sendComponent(player, textComponent);
}
});
}
Aggregations