Search in sources :

Example 1 with NPCSelectEvent

use of net.citizensnpcs.api.event.NPCSelectEvent in project Citizens2 by CitizensDev.

the class NPCSelector method select.

public void select(CommandSender sender, NPC npc) {
    // Remove existing selection if any
    List<String> selectors = npc.data().get("selectors");
    if (selectors == null) {
        selectors = Lists.newArrayList();
        npc.data().set("selectors", selectors);
    }
    if (sender instanceof Player) {
        Player player = (Player) sender;
        setMetadata(npc, player);
        selectors.add(sender.getName());
        // Remove editor if the player has one
        Editor.leave(player);
    } else if (sender instanceof BlockCommandSender) {
        Block block = ((BlockCommandSender) sender).getBlock();
        setMetadata(npc, block);
        selectors.add(toName(block));
    } else if (sender instanceof ConsoleCommandSender) {
        consoleSelectedNPC = npc.getUniqueId();
        selectors.add("console");
    }
    Bukkit.getPluginManager().callEvent(new NPCSelectEvent(npc, sender));
}
Also used : Player(org.bukkit.entity.Player) Block(org.bukkit.block.Block) NPCSelectEvent(net.citizensnpcs.api.event.NPCSelectEvent) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender) BlockCommandSender(org.bukkit.command.BlockCommandSender)

Aggregations

NPCSelectEvent (net.citizensnpcs.api.event.NPCSelectEvent)1 Block (org.bukkit.block.Block)1 BlockCommandSender (org.bukkit.command.BlockCommandSender)1 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)1 Player (org.bukkit.entity.Player)1