Skip to content

Commit 70fe58d

Browse files
authored
Expose the potential player cause of a lightning (#6782)
1 parent 06d82e0 commit 70fe58d

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

patches/api/0240-More-lightning-API.patch

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Subject: [PATCH] More lightning API
55

66

77
diff --git a/src/main/java/org/bukkit/entity/LightningStrike.java b/src/main/java/org/bukkit/entity/LightningStrike.java
8-
index be347c3d0291f44036bae29a4e7e4645d6a4cdf6..2c81a3f685588431a3c7675c84b35a28975232af 100644
8+
index be347c3d0291f44036bae29a4e7e4645d6a4cdf6..6f5b6901032eb03606c4566b24459a03baac0c73 100644
99
--- a/src/main/java/org/bukkit/entity/LightningStrike.java
1010
+++ b/src/main/java/org/bukkit/entity/LightningStrike.java
11-
@@ -31,4 +31,38 @@ public interface LightningStrike extends Entity {
11+
@@ -31,4 +31,72 @@ public interface LightningStrike extends Entity {
1212
@Override
1313
Spigot spigot();
1414
// Spigot end
@@ -45,5 +45,39 @@ index be347c3d0291f44036bae29a4e7e4645d6a4cdf6..2c81a3f685588431a3c7675c84b35a28
4545
+ * @param lifeTicks ticks the current flash will do damage for
4646
+ */
4747
+ void setLifeTicks(int lifeTicks);
48+
+
49+
+ /**
50+
+ * Returns the potential entity that caused this lightning strike to spawn in the world.
51+
+ * <p>
52+
+ * As of implementing this method, only {@link Player}s are capable of causing a lightning strike, however as this
53+
+ * might change in future minecraft releases, this method does not guarantee a player as the cause of a lightning.
54+
+ * Consumers of this method should hence validate whether or not the entity is a player if they want to use player
55+
+ * specific methods through an {@code instanceOf} check.
56+
+ * </p>
57+
+ * <p>
58+
+ * A player is, as of implementing this method, responsible for a lightning, and will hence be returned here as
59+
+ * a cause, if they channeled a {@link Trident} to summon it or were explicitly defined as the cause of this
60+
+ * lightning through {@link #setCausingPlayer(Player)}.
61+
+ * </p>
62+
+ *
63+
+ * @return the entity that caused this lightning or null if the lightning was not caused by a entity (e.g. normal
64+
+ * weather)
65+
+ */
66+
+ @org.jetbrains.annotations.Nullable
67+
+ Entity getCausingEntity();
68+
+
69+
+ /**
70+
+ * Updates the player that caused this lightning to be summoned into the world.
71+
+ * By default, players that channel their {@link Trident} will be the cause of the respective lightning.
72+
+ * <p>
73+
+ * While the respective getter method {@link #getCausingEntity()} does not guarantee a player as the cause of a
74+
+ * lightning to stay as future proof as possible, as of implementing this method, players are the only entities
75+
+ * that can cause a lightning strike and hence this setter is restricted to players.
76+
+ * </p>
77+
+ *
78+
+ * @param causingPlayer the player that should be the new cause of this lightning. {@code null} may be passed to
79+
+ * indicate that no player is responsible for this lightning.
80+
+ */
81+
+ void setCausingPlayer(@org.jetbrains.annotations.Nullable Player causingPlayer);
4882
+ // Paper end
4983
}

patches/server/0559-More-lightning-API.patch

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Subject: [PATCH] More lightning API
55

66

77
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java
8-
index f7991ff14ef9cda0327b8621bf615b49cffd7ac5..db6b158f18ad7b9171a8c041802e3495d733bc16 100644
8+
index f7991ff14ef9cda0327b8621bf615b49cffd7ac5..e515e819774bfb31ec03f05a5502921e66f2b0e2 100644
99
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java
1010
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLightningStrike.java
11-
@@ -45,4 +45,27 @@ public class CraftLightningStrike extends CraftEntity implements LightningStrike
11+
@@ -45,4 +45,38 @@ public class CraftLightningStrike extends CraftEntity implements LightningStrike
1212
return this.spigot;
1313
}
1414
// Spigot end
@@ -34,5 +34,16 @@ index f7991ff14ef9cda0327b8621bf615b49cffd7ac5..db6b158f18ad7b9171a8c041802e3495
3434
+ public void setLifeTicks(int lifeTicks) {
3535
+ getHandle().life = lifeTicks;
3636
+ }
37+
+
38+
+ @Override
39+
+ public @org.jetbrains.annotations.Nullable org.bukkit.entity.Entity getCausingEntity() {
40+
+ final var cause = this.getHandle().getCause();
41+
+ return cause == null ? null : cause.getBukkitEntity();
42+
+ }
43+
+
44+
+ @Override
45+
+ public void setCausingPlayer(@org.jetbrains.annotations.Nullable org.bukkit.entity.Player causingPlayer) {
46+
+ this.getHandle().setCause(causingPlayer == null ? null : ((CraftPlayer) causingPlayer).getHandle());
47+
+ }
3748
+ // Paper end
3849
}

0 commit comments

Comments
 (0)