Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 19:10:09 +01:00
Make ProjectileHitEvent Cancellable
Allows cancelling things like detonating TNT from Fire Arrows
Dieser Commit ist enthalten in:
Ursprung
97b020f133
Commit
f6d3c6811e
49
Spigot-API-Patches/0261-Make-ProjectileHitEvent-Cancellable.patch
Normale Datei
49
Spigot-API-Patches/0261-Make-ProjectileHitEvent-Cancellable.patch
Normale Datei
@ -0,0 +1,49 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Sat, 16 Jan 2021 14:00:16 -0500
|
||||
Subject: [PATCH] Make ProjectileHitEvent Cancellable
|
||||
|
||||
Allows cancelling things like detonating TNT from Fire Arrows
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
|
||||
index 809c1098c16fe52eda47ae2335afab30e36746b2..000c9967e008d3340a08c4ee727a5d2de27dedcc 100644
|
||||
--- a/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/entity/ProjectileHitEvent.java
|
||||
@@ -4,6 +4,7 @@ import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Projectile;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -11,11 +12,28 @@ import org.jetbrains.annotations.Nullable;
|
||||
/**
|
||||
* Called when a projectile hits an object
|
||||
*/
|
||||
-public class ProjectileHitEvent extends EntityEvent {
|
||||
+public class ProjectileHitEvent extends EntityEvent implements Cancellable { // Paper
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final Entity hitEntity;
|
||||
private final Block hitBlock;
|
||||
private final BlockFace hitFace;
|
||||
+ // Paper start - make cancellable
|
||||
+ private boolean canceled;
|
||||
+ /**
|
||||
+ * @return If the arrow activating a block should be cancelled
|
||||
+ */
|
||||
+ public boolean isCancelled() {
|
||||
+ return canceled;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Whether or not to cancel any behavior that would occur from the arrow hitting the block
|
||||
+ * @param cancel true if you wish to cancel this event
|
||||
+ */
|
||||
+ public void setCancelled(boolean cancel) {
|
||||
+ canceled = cancel;
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
||||
public ProjectileHitEvent(@NotNull final Projectile projectile) {
|
||||
this(projectile, null, null);
|
58
Spigot-Server-Patches/0653-Make-ProjectileHitEvent-Cancellable.patch
Normale Datei
58
Spigot-Server-Patches/0653-Make-ProjectileHitEvent-Cancellable.patch
Normale Datei
@ -0,0 +1,58 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Aikar <aikar@aikar.co>
|
||||
Date: Sat, 16 Jan 2021 14:30:12 -0500
|
||||
Subject: [PATCH] Make ProjectileHitEvent Cancellable
|
||||
|
||||
Allows cancelling things like detonating TNT from Fire Arrows
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/EntityFireball.java b/src/main/java/net/minecraft/server/EntityFireball.java
|
||||
index 74ca38f8e4e1addc243c3f3b57021d26f0ce3c97..0840fdf3585407ec317f0326359619220c64db78 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityFireball.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityFireball.java
|
||||
@@ -71,7 +71,7 @@ public abstract class EntityFireball extends IProjectile {
|
||||
|
||||
// CraftBukkit start - Fire ProjectileHitEvent
|
||||
if (this.dead) {
|
||||
- CraftEventFactory.callProjectileHitEvent(this, movingobjectposition);
|
||||
+ if (!CraftEventFactory.callProjectileHitEvent(this, movingobjectposition)) return; // Paper - this is an undesired duplicate event, but make cancellable
|
||||
}
|
||||
// CraftBukkit end
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/IProjectile.java b/src/main/java/net/minecraft/server/IProjectile.java
|
||||
index 9f5ce64a60fe7c312399ee416b11b84213dd3bee..bbc089b41fcbe0141f13591db2cb44b9e688cac4 100644
|
||||
--- a/src/main/java/net/minecraft/server/IProjectile.java
|
||||
+++ b/src/main/java/net/minecraft/server/IProjectile.java
|
||||
@@ -118,7 +118,7 @@ public abstract class IProjectile extends Entity {
|
||||
}
|
||||
|
||||
protected void a(MovingObjectPosition movingobjectposition) {
|
||||
- org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition); // CraftBukkit - Call event
|
||||
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this, movingobjectposition)) return; // CraftBukkit - Call event // Paper - make cancellable
|
||||
MovingObjectPosition.EnumMovingObjectType movingobjectposition_enummovingobjecttype = movingobjectposition.getType();
|
||||
|
||||
if (movingobjectposition_enummovingobjecttype == MovingObjectPosition.EnumMovingObjectType.ENTITY) {
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
index c762015e1402b59bf28dae7f947e7737fbac5c1d..63d329dca12f902e2fb2a62ee4c86aea6453f1a3 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
||||
@@ -1295,9 +1295,9 @@ public class CraftEventFactory {
|
||||
return event;
|
||||
}
|
||||
|
||||
- public static void callProjectileHitEvent(Entity entity, MovingObjectPosition position) {
|
||||
+ public static boolean callProjectileHitEvent(Entity entity, MovingObjectPosition position) { // Paper - make cancellable
|
||||
if (position.getType() == MovingObjectPosition.EnumMovingObjectType.MISS) {
|
||||
- return;
|
||||
+ return false; // Paper - make cancellable
|
||||
}
|
||||
|
||||
Block hitBlock = null;
|
||||
@@ -1314,7 +1314,7 @@ public class CraftEventFactory {
|
||||
}
|
||||
|
||||
ProjectileHitEvent event = new ProjectileHitEvent((Projectile) entity.getBukkitEntity(), hitEntity, hitBlock, hitFace);
|
||||
- entity.world.getServer().getPluginManager().callEvent(event);
|
||||
+ return event.callEvent(); // Paper
|
||||
}
|
||||
|
||||
public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren