Search in sources :

Example 1 with NPCFloorChangeTrait

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);
        }
    });
}
Also used : NPC(net.citizensnpcs.api.npc.NPC) TextComponent(net.kyori.text.TextComponent) MessageManager(com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager) NPCSpawnEvent(net.citizensnpcs.api.event.NPCSpawnEvent) TextAdapter(net.kyori.text.adapter.bukkit.TextAdapter) PlayerCreateNPCEvent(net.citizensnpcs.api.event.PlayerCreateNPCEvent) Player(org.bukkit.entity.Player) Plot(com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot) TextComponent(net.kyori.text.TextComponent) NPC(net.citizensnpcs.api.npc.NPC) EventHandler(org.bukkit.event.EventHandler) TextColor(net.kyori.text.format.TextColor) ClickEvent(net.kyori.text.event.ClickEvent) Map(java.util.Map) NPCFloorChangeTrait(com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait) ChatColor(org.bukkit.ChatColor) NotNull(org.jetbrains.annotations.NotNull) ArenaManager(com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager) CommandUtil(com.gmail.stefvanschiedev.buildinggame.utils.CommandUtil) WeakHashMap(java.util.WeakHashMap) Listener(org.bukkit.event.Listener) Player(org.bukkit.entity.Player) NPCFloorChangeTrait(com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ArenaManager (com.gmail.stefvanschiedev.buildinggame.managers.arenas.ArenaManager)1 MessageManager (com.gmail.stefvanschiedev.buildinggame.managers.messages.MessageManager)1 CommandUtil (com.gmail.stefvanschiedev.buildinggame.utils.CommandUtil)1 NPCFloorChangeTrait (com.gmail.stefvanschiedev.buildinggame.utils.NPCFloorChangeTrait)1 Plot (com.gmail.stefvanschiedev.buildinggame.utils.plot.Plot)1 Map (java.util.Map)1 WeakHashMap (java.util.WeakHashMap)1 NPCSpawnEvent (net.citizensnpcs.api.event.NPCSpawnEvent)1 PlayerCreateNPCEvent (net.citizensnpcs.api.event.PlayerCreateNPCEvent)1 NPC (net.citizensnpcs.api.npc.NPC)1 TextComponent (net.kyori.text.TextComponent)1 TextAdapter (net.kyori.text.adapter.bukkit.TextAdapter)1 ClickEvent (net.kyori.text.event.ClickEvent)1 TextColor (net.kyori.text.format.TextColor)1 ChatColor (org.bukkit.ChatColor)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 Listener (org.bukkit.event.Listener)1 NotNull (org.jetbrains.annotations.NotNull)1