#(adriangaming) PlayerFilter Trait

14 messages · Page 1 of 1 (latest)

autumn quartz
#

Hello, I'm trying to make the NPC visible to the owner only. Here is the code which doesnt seem to be working. Unfortunately I couldnt find any help on any other forum posts on this discord.

        minersRegistry = CitizensAPI.createInMemoryNPCRegistry("Miners");
        NPC npc = minersRegistry.createNPC(EntityType.PLAYER, "Miner");

        PlayerFilter playerFilter = new PlayerFilter();
        playerFilter.setAllowlist();
        playerFilter.addPlayer(owner.getUniqueId());
        npc.addTrait(playerFilter);
        npc.spawn(location);

I'm on paper version 1.21.4 (#177) and using Citizens-2.0.37-b3714

wild ibexBOT
#

(adriangaming) PlayerFilter Trait

wild ibexBOT
#

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.

autumn quartz
#
        minersRegistry = CitizensAPI.createInMemoryNPCRegistry("Miners");
        NPC npc = minersRegistry.createNPC(EntityType.PLAYER, "Miner");

        npc.getOrAddTrait(PlayerFilter.class).setAllowlist();
        npc.getOrAddTrait(PlayerFilter.class).addPlayer(owner.getUniqueId());
        npc.spawn(location);

Seems to be doing the trick Why is this working? Looks to me like the TraitFactory does different stuff than creating the PlayerFilter Trait with default constructor

teal dirge
#

@autumn quartz do you have protocollib installed?

autumn quartz
#

nope

teal dirge
#

the TraitFactory should do the same stuff

#

but in this case, it's better to use getOrAddTrait since there is a special constructor that PlayerFilter uses

#

you can use PlayerFilter filter = npc.addTrait(PlayerFilter.class); as a safer way in future

dull sparrowBOT
#
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.)

#

@autumn quartz

autumn quartz
#

ty