mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-19 15:09:27 +00:00
Add PreEntityShootBowEvent
This commit is contained in:
94
patches/api/0007-Add-PreEntityShootBowEvent.patch
Normal file
94
patches/api/0007-Add-PreEntityShootBowEvent.patch
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||||
|
Date: Sun, 12 Jan 2025 23:27:00 -0300
|
||||||
|
Subject: [PATCH] Add PreEntityShootBowEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/sparklypower/sparklypaper/event/entity/PreEntityShootBowEvent.java b/src/main/java/net/sparklypower/sparklypaper/event/entity/PreEntityShootBowEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..1438ad2444db2b19fd84f5147f0b68b5df7f13dc
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/net/sparklypower/sparklypaper/event/entity/PreEntityShootBowEvent.java
|
||||||
|
@@ -0,0 +1,82 @@
|
||||||
|
+package net.sparklypower.sparklypaper.event.entity;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.HumanEntity;
|
||||||
|
+import org.bukkit.event.Cancellable;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.bukkit.event.entity.EntityEvent;
|
||||||
|
+import org.bukkit.inventory.EquipmentSlot;
|
||||||
|
+import org.bukkit.inventory.ItemStack;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+import org.jetbrains.annotations.Nullable;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Called when a entity releases a bow, before the projectile is spawned
|
||||||
|
+ * <p>
|
||||||
|
+ * Compared to EntityShootBowEvent, this event is called before the projectile is spawned, before the force check is done, and before the bow release sound is played.
|
||||||
|
+ * <p>
|
||||||
|
+ * Currently this event is only called for players! To be more specific, it is only called for HumanEntity!!
|
||||||
|
+ */
|
||||||
|
+public class PreEntityShootBowEvent extends EntityEvent implements Cancellable {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+ private final ItemStack bow;
|
||||||
|
+ private final EquipmentSlot hand;
|
||||||
|
+ private final float force;
|
||||||
|
+ private boolean cancelled;
|
||||||
|
+
|
||||||
|
+ public PreEntityShootBowEvent(@NotNull final HumanEntity shooter, @Nullable final ItemStack bow, @NotNull final EquipmentSlot hand, final float force) {
|
||||||
|
+ super(shooter);
|
||||||
|
+ this.bow = bow;
|
||||||
|
+ this.hand = hand;
|
||||||
|
+ this.force = force;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the bow ItemStack used to fire the arrow.
|
||||||
|
+ *
|
||||||
|
+ * @return the bow involved in this event
|
||||||
|
+ */
|
||||||
|
+ @Nullable
|
||||||
|
+ public ItemStack getBow() {
|
||||||
|
+ return bow;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the hand from which the bow was shot.
|
||||||
|
+ *
|
||||||
|
+ * @return the hand
|
||||||
|
+ */
|
||||||
|
+ @NotNull
|
||||||
|
+ public EquipmentSlot getHand() {
|
||||||
|
+ return hand;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the force the arrow was launched with
|
||||||
|
+ *
|
||||||
|
+ * @return bow shooting force, up to 1.0
|
||||||
|
+ */
|
||||||
|
+ public float getForce() {
|
||||||
|
+ return force;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public boolean isCancelled() {
|
||||||
|
+ return cancelled;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void setCancelled(boolean cancel) {
|
||||||
|
+ cancelled = cancel;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
22
patches/server/0025-Add-PreEntityShootBowEvent.patch
Normal file
22
patches/server/0025-Add-PreEntityShootBowEvent.patch
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||||
|
Date: Sun, 12 Jan 2025 23:26:44 -0300
|
||||||
|
Subject: [PATCH] Add PreEntityShootBowEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/world/item/BowItem.java b/src/main/java/net/minecraft/world/item/BowItem.java
|
||||||
|
index bb593209c95c9cf1f9c5d52d52fab4a33ddbabcf..776c37284e9cff50fae6b937cb707e7ba7edc624 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/item/BowItem.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/item/BowItem.java
|
||||||
|
@@ -33,6 +33,11 @@ public class BowItem extends ProjectileWeaponItem {
|
||||||
|
} else {
|
||||||
|
int i = this.getUseDuration(stack, user) - remainingUseTicks;
|
||||||
|
float f = getPowerForTime(i);
|
||||||
|
+ // SparklyPaper start - Add PreEntityShootBowEvent
|
||||||
|
+ net.sparklypower.sparklypaper.event.entity.PreEntityShootBowEvent event = new net.sparklypower.sparklypaper.event.entity.PreEntityShootBowEvent(player.getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(stack), player.getUsedItemHand() == InteractionHand.MAIN_HAND ? org.bukkit.inventory.EquipmentSlot.HAND : org.bukkit.inventory.EquipmentSlot.OFF_HAND, f);
|
||||||
|
+ if (!event.callEvent())
|
||||||
|
+ return false;
|
||||||
|
+ // SparklyPaper end
|
||||||
|
if ((double)f < 0.1) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
Reference in New Issue
Block a user