Skip to content

Commit

Permalink
Merge pull request #54 from Cryptite/removestreams
Browse files Browse the repository at this point in the history
Remove Streams in Sneak/Interact Events
  • Loading branch information
juliarn authored Dec 1, 2021
2 parents a46d9f8 + c138984 commit 09bf51b
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/main/java/com/github/juliarn/npc/NPCPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,15 @@ public void handleQuit(PlayerQuitEvent event) {
public void handleSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();

this.npcMap.values().stream()
.filter(npc -> npc.isImitatePlayer() && npc.isShownFor(player))
.filter(npc -> npc.getLocation().getWorld().equals(player.getWorld())
&& npc.getLocation().distanceSquared(player.getLocation()) <= this.actionDistance)
.forEach(npc -> npc.metadata()
.queue(MetadataModifier.EntityMetadata.SNEAKING, event.isSneaking()).send(player));
for (NPC npc : this.npcMap.values()) {
if (npc.isImitatePlayer()
&& npc.getLocation().getWorld().equals(player.getWorld())
&& npc.isShownFor(player)
&& npc.getLocation().distanceSquared(player.getLocation()) <= this.actionDistance) {
npc.metadata()
.queue(MetadataModifier.EntityMetadata.SNEAKING, event.isSneaking()).send(player);
}
}
}

@EventHandler
Expand All @@ -350,12 +353,15 @@ public void handleClick(PlayerInteractEvent event) {

if (event.getAction() == Action.LEFT_CLICK_AIR
|| event.getAction() == Action.LEFT_CLICK_BLOCK) {
this.npcMap.values().stream()
.filter(npc -> npc.isImitatePlayer() && npc.isShownFor(player))
.filter(npc -> npc.getLocation().getWorld().equals(player.getWorld())
&& npc.getLocation().distanceSquared(player.getLocation()) <= this.actionDistance)
.forEach(npc -> npc.animation().queue(AnimationModifier.EntityAnimation.SWING_MAIN_ARM)
.send(player));
for (NPC npc : this.npcMap.values()) {
if (npc.isImitatePlayer()
&& npc.getLocation().getWorld().equals(player.getWorld())
&& npc.isShownFor(player)
&& npc.getLocation().distanceSquared(player.getLocation()) <= this.actionDistance) {
npc.animation().queue(AnimationModifier.EntityAnimation.SWING_MAIN_ARM)
.send(player);
}
}
}
}

Expand Down

0 comments on commit 09bf51b

Please sign in to comment.