#(7o1) NPC left and right click events not getting fired

13 messages · Page 1 of 1 (latest)

outer rock
#

Hi, this is my code, CitizensEnableEvent is fired as it should be and the message is logged, however the NPCLeftClickEvent (and right) are not. No matter if it's this npc spawned through code or through /npc create command. When I click them nothing happens. What did I miss?```java
public class NPCManager implements Listener, CommandExecutor {
private Main plugin;
private final NPCRegistry registry = CitizensAPI.createAnonymousNPCRegistry(new MemoryNPCDataStore());

public NPCManager(Main plugin) {
    this.plugin = plugin;
    Bukkit.getPluginManager().registerEvents(this, plugin);
}

@EventHandler
public void onCitizensEnable(CitizensEnableEvent event) {
    plugin.getLogger().info("CitizensEnableEvent called!");
    CitizensAPI.registerEvents(this);
}

@EventHandler
public void npcLeftClick(NPCLeftClickEvent event) {
    plugin.getLogger().info("NPCLeftClickEvent player=" + event.getClicker().getName() + " npc=" + event.getNPC().getName());
}

@EventHandler
public void npcRightClick(NPCRightClickEvent event) {
    plugin.getLogger().info("NPCRightClickEvent player=" + event.getClicker().getName() + " npc=" + event.getNPC().getName());
}

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
    if (args.length == 0 || !(sender instanceof Player player))
        return false;

    if (args[0].equalsIgnoreCase("spawn")) {
        NPC npc = registry.createNPC(EntityType.PLAYER, args[1]);
        npc.spawn(player.getLocation().clone().add(0, -2, 0));
        if (args.length >= 3 && args[2].equals("withtrait")) {
            player.sendMessage("Spawned npc with trait!");
            npc.addTrait(new TestTrait());
        }

    }
    return true;
}

}``````java
// in onEnable
this.npcManager = new NPCManager(this);
getCommand("mynpc").setExecutor(npcManager);```

stark siloBOT
#

(7o1) NPC left and right click events not getting fired

stark siloBOT
#

Hi I'm AutoThreadBot! Don't mind me, I'll just be adding the helper team to this thread so they can see it. A human will get to you soon.

outer rock
#

Here is trait code: ```java
import net.citizensnpcs.api.event.NPCLeftClickEvent;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import org.bukkit.event.EventHandler;

@TraitName("TestTrait")
public class TestTrait extends Trait {
public TestTrait() {
super("TestTrait");
}

@EventHandler  // DOESN'T WORK
public void onNPCLeftClick(NPCLeftClickEvent event) {
    event.getClicker().sendMessage("[TestTrait] You clicked on " + event.getNPC().getName());
}

// COPIED FROM WIKI
@EventHandler  // WORKS
public void click(net.citizensnpcs.api.event.NPCRightClickEvent event){
    //Handle a click on a NPC. The event has a getNPC() method.
    //Be sure to check event.getNPC() == this.getNPC() so you only handle clicks on this NPC!
    event.getClicker().sendMessage("[TestTrait] right click " + event.getNPC().getName());
}

}

#

Purpur 1.20.6,

outer rock
#

Solved

i had to set pvp=true in server.properties, looks like it prevented all left click events from happening.

humble juniperBOT
#
Resolved

Thread closed as resolved.

#
Thread Reopened

Thread was manually reopened by @outer rock.

humble juniperBOT
#
Thread Closing Reminder

Has your issue been resolved, or your question been answered?
If so, please use the </resolved:1028673926114594866> command to close your thread.
Or </invalid:1028673926898909185> if it's not possible to resolve.

If not yet resolved, please reply below to tell us what you still need.

(Note that if there is no reply for a few days, this thread will eventually close itself.)

#

@outer rock

outer rock
#

apologies, I don't know why it reopened

#

I didn't do anything to it