mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 05:47:45 +01:00
Add #getEligibleHumans to SkeletonHorseTrapEvent
This commit is contained in:
parent
889192e8f8
commit
d6057372b4
@ -12,21 +12,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
@@ -0,0 +0,0 @@
|
||||
+package com.destroystokyo.paper.event.entity;
|
||||
+
|
||||
+import com.google.common.collect.ImmutableList;
|
||||
+import org.bukkit.entity.HumanEntity;
|
||||
+import org.bukkit.entity.SkeletonHorse;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.entity.EntityEvent;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
+/**
|
||||
+ * Event called when a player gets close to a skeleton horse and triggers the lightning trap
|
||||
+ */
|
||||
+public class SkeletonHorseTrapEvent extends EntityEvent implements Cancellable {
|
||||
+ private static final HandlerList handlers = new HandlerList();
|
||||
+ private boolean cancelled;
|
||||
+ private final List<HumanEntity> eligibleHumans;
|
||||
+
|
||||
+ public SkeletonHorseTrapEvent(@NotNull SkeletonHorse horse) {
|
||||
+ this(horse, ImmutableList.of());
|
||||
+ }
|
||||
+
|
||||
+ public SkeletonHorseTrapEvent(@NotNull SkeletonHorse horse, @NotNull List<HumanEntity> eligibleHumans) {
|
||||
+ super(horse);
|
||||
+ this.eligibleHumans = eligibleHumans;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
@ -46,6 +56,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ public List<HumanEntity> getEligibleHumans() {
|
||||
+ return eligibleHumans;
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return handlers;
|
||||
|
@ -30,15 +30,91 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
public void t(boolean flag) {
|
||||
if (flag != this.bx) {
|
||||
this.bx = flag;
|
||||
diff --git a/src/main/java/net/minecraft/server/IEntityAccess.java b/src/main/java/net/minecraft/server/IEntityAccess.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/IEntityAccess.java
|
||||
+++ b/src/main/java/net/minecraft/server/IEntityAccess.java
|
||||
@@ -0,0 +0,0 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
+import org.bukkit.entity.HumanEntity;
|
||||
+
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -0,0 +0,0 @@ public interface IEntityAccess {
|
||||
return entityhuman;
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ default List<HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, boolean notSpectator) {
|
||||
+ return findNearbyBukkitPlayers(x, y, z, radius, notSpectator ? IEntitySelector.notSpectator() : IEntitySelector.canAITarget());
|
||||
+ }
|
||||
+
|
||||
+ default List<HumanEntity> findNearbyBukkitPlayers(double x, double y, double z, double radius, @Nullable Predicate<Entity> predicate) {
|
||||
+ ImmutableList.Builder<HumanEntity> builder = ImmutableList.builder();
|
||||
+
|
||||
+ for (EntityHuman human : this.getPlayers()) {
|
||||
+ if (predicate == null || predicate.test(human)) {
|
||||
+ double distanceSquared = human.getDistanceSquared(x, y, z);
|
||||
+
|
||||
+ if (radius < 0.0D || distanceSquared < radius * radius) {
|
||||
+ builder.add(human.getBukkitEntity());
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return builder.build();
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
@Nullable
|
||||
default EntityHuman findNearbyPlayer(Entity entity, double d0) {
|
||||
return this.a(entity.locX(), entity.locY(), entity.locZ(), d0, false);
|
||||
diff --git a/src/main/java/net/minecraft/server/IEntitySelector.java b/src/main/java/net/minecraft/server/IEntitySelector.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/IEntitySelector.java
|
||||
+++ b/src/main/java/net/minecraft/server/IEntitySelector.java
|
||||
@@ -0,0 +0,0 @@ public final class IEntitySelector {
|
||||
public static final Predicate<Entity> f = (entity) -> {
|
||||
return !(entity instanceof EntityHuman) || !entity.isSpectator() && !((EntityHuman) entity).isCreative() && entity.world.getDifficulty() != EnumDifficulty.PEACEFUL;
|
||||
};
|
||||
+ public static Predicate<Entity> notSpectator() { return g; } // Paper - OBFHELPER
|
||||
public static final Predicate<Entity> g = (entity) -> {
|
||||
return !entity.isSpectator();
|
||||
};
|
||||
diff --git a/src/main/java/net/minecraft/server/PathfinderGoalHorseTrap.java b/src/main/java/net/minecraft/server/PathfinderGoalHorseTrap.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/PathfinderGoalHorseTrap.java
|
||||
+++ b/src/main/java/net/minecraft/server/PathfinderGoalHorseTrap.java
|
||||
@@ -0,0 +0,0 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
+import org.bukkit.entity.HumanEntity;
|
||||
+
|
||||
+import java.util.List;
|
||||
+
|
||||
public class PathfinderGoalHorseTrap extends PathfinderGoal {
|
||||
|
||||
private final EntityHorseSkeleton a;
|
||||
+ private List<HumanEntity> eligiblePlayers; // Paper
|
||||
|
||||
public PathfinderGoalHorseTrap(EntityHorseSkeleton entityhorseskeleton) {
|
||||
this.a = entityhorseskeleton;
|
||||
@@ -0,0 +0,0 @@ public class PathfinderGoalHorseTrap extends PathfinderGoal {
|
||||
|
||||
@Override
|
||||
public boolean a() {
|
||||
- return this.a.world.isPlayerNearby(this.a.locX(), this.a.locY(), this.a.locZ(), 10.0D);
|
||||
+ return !(eligiblePlayers = this.a.world.findNearbyBukkitPlayers(this.a.locX(), this.a.locY(), this.a.locZ(), 10.0D, false)).isEmpty(); // Paper
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e() {
|
||||
WorldServer worldserver = (WorldServer) this.a.world;
|
||||
+ if (!new com.destroystokyo.paper.event.entity.SkeletonHorseTrapEvent((org.bukkit.entity.SkeletonHorse) this.a.getBukkitEntity()).callEvent()) return; // Paper
|
||||
+ if (!new com.destroystokyo.paper.event.entity.SkeletonHorseTrapEvent((org.bukkit.entity.SkeletonHorse) this.a.getBukkitEntity(), eligiblePlayers).callEvent()) return; // Paper
|
||||
DifficultyDamageScaler difficultydamagescaler = worldserver.getDamageScaler(this.a.getChunkCoordinates());
|
||||
|
||||
this.a.t(false);
|
||||
|
Loading…
Reference in New Issue
Block a user