Skip to content

Commit

Permalink
Only modify behaviour of helper spawned NPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucko committed Aug 29, 2020
1 parent 90a414d commit dfbf51c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions helper/src/main/java/me/lucko/helper/npc/CitizensNpcFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,30 @@ private void init() {
// don't let players move npcs
Events.subscribe(PlayerFishEvent.class)
.filter(e -> e.getCaught() != null)
.filter(e -> e.getCaught().hasMetadata("NPC"))
.filter(e -> isHelperNpc(e.getCaught()))
.handler(e -> e.setCancelled(true))
.bindWith(this.registry);

/* Events.subscribe(ProjectileCollideEvent.class)
.filter(e -> e.getCollidedWith() != null)
.filter(e -> e.getCollidedWith().hasMetadata("NPC"))
.filter(e -> isHelperNpc(e.getCollidedWith()))
.handler(e -> e.setCancelled(true))
.bindWith(this.registry); */

Events.subscribe(EntityDamageByEntityEvent.class)
.filter(e -> e.getEntity().hasMetadata("NPC"))
.filter(e -> isHelperNpc(e.getEntity()))
.handler(e -> e.setCancelled(true))
.bindWith(this.registry);

// update npcs every 10 ticks
Schedulers.sync().runRepeating(this::tickNpcs, 10L, 10L).bindWith(this.registry);
}

private boolean isHelperNpc(Entity entity) {
NPC npc = this.npcRegistry.getNPC(entity);
return npc != null && npc.hasTrait(ClickableTrait.class);
}

private void handleClick(NPC npc, Player clicker) {
if (npc.hasTrait(ClickableTrait.class)) {
if (processMetadata(clicker)) {
Expand Down

0 comments on commit dfbf51c

Please sign in to comment.