-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Added PlayerUseBowWithoutProjectileEvent #11668 #11669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Chaosdave34
wants to merge
5
commits into
PaperMC:master
from
Chaosdave34:PlayerUseBowWithoutProjectileEvent
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3c6f17c
Added PlayerUseBowWithoutProjectileEvent when a player tries to load …
Chaosdave34 be36e73
Merge branch 'PaperMC:master' into master
Chaosdave34 59e67f1
Implemented requested changes
Chaosdave34 a385254
Fixes
Chaosdave34 b888713
Add the item which the player tries to use to PlayerUseBowWithoutProj…
Chaosdave34 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
patches/api/0501-Added-PlayerUseBowWithoutProjectileEvent.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Chaosdave34 <david.emanuel@gmx.de> | ||
| Date: Tue, 26 Nov 2024 17:10:15 +0100 | ||
| Subject: [PATCH] Added PlayerUseBowWithoutProjectileEvent | ||
|
|
||
|
|
||
| diff --git a/src/main/java/io/papermc/paper/event/player/PlayerUseBowWithoutProjectileEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerUseBowWithoutProjectileEvent.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..59e432878c2619d559eac2855fffe3b73c1f05c0 | ||
| --- /dev/null | ||
| +++ b/src/main/java/io/papermc/paper/event/player/PlayerUseBowWithoutProjectileEvent.java | ||
| @@ -0,0 +1,65 @@ | ||
| +package io.papermc.paper.event.player; | ||
| + | ||
| +import org.bukkit.entity.Player; | ||
| +import org.bukkit.event.HandlerList; | ||
| +import org.bukkit.event.player.PlayerEvent; | ||
| +import org.bukkit.inventory.ItemStack; | ||
| +import org.jetbrains.annotations.ApiStatus; | ||
| +import org.jspecify.annotations.NullMarked; | ||
| + | ||
| +/** | ||
| + * Called when a player tries to draw a bow or load a crossbow without having a suitable projectile in their inventory | ||
| + */ | ||
| +@NullMarked | ||
| +public class PlayerUseBowWithoutProjectileEvent extends PlayerEvent { | ||
| + | ||
| + private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
| + | ||
| + private final ItemStack item; | ||
| + private ItemStack projectile; | ||
| + | ||
| + @ApiStatus.Internal | ||
| + public PlayerUseBowWithoutProjectileEvent(final Player player, final ItemStack item) { | ||
| + super(player); | ||
| + this.item = item; | ||
| + this.projectile = ItemStack.empty(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Gets the item which the player tries to use | ||
| + * | ||
| + * @return the item | ||
| + */ | ||
| + public ItemStack getItem() { | ||
| + return item.clone(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Gets the projectile that should be used | ||
| + * | ||
| + * @return the projectile | ||
| + */ | ||
| + public ItemStack getProjectile() { | ||
| + return projectile.clone(); | ||
| + } | ||
| + | ||
| + /** | ||
| + * Sets the projectile that should be used | ||
| + * <p> | ||
| + * Note: setting this to {@link ItemStack#empty()} will prevent the player from using the bow/crossbow | ||
| + * | ||
| + * @param projectile the projectile | ||
| + */ | ||
| + public void setProjectile(ItemStack projectile) { | ||
| + this.projectile = projectile.clone(); | ||
| + } | ||
| + | ||
| + @Override | ||
| + public HandlerList getHandlers() { | ||
| + return HANDLER_LIST; | ||
| + } | ||
| + | ||
| + public static HandlerList getHandlerList() { | ||
| + return HANDLER_LIST; | ||
| + } | ||
| +} | ||
28 changes: 28 additions & 0 deletions
28
patches/server/1073-Call-PlayerUseBowWithoutProjectileEvent-in-Player-ge.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Chaosdave34 <david.emanuel@gmx.de> | ||
| Date: Tue, 26 Nov 2024 17:11:23 +0100 | ||
| Subject: [PATCH] Call PlayerUseBowWithoutProjectileEvent in | ||
| Player#getProjectile | ||
|
|
||
|
|
||
| diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java | ||
| index 61d412c4f1ebd55661cc3f0260468e3ac0efe0bb..6cf27e4e95b6b73212236ce739dc2514ea8dbab4 100644 | ||
| --- a/src/main/java/net/minecraft/world/entity/player/Player.java | ||
| +++ b/src/main/java/net/minecraft/world/entity/player/Player.java | ||
| @@ -2266,7 +2266,15 @@ public abstract class Player extends LivingEntity { | ||
| } | ||
| } | ||
|
|
||
| - return this.abilities.instabuild ? new ItemStack(Items.ARROW) : ItemStack.EMPTY; | ||
| + // Paper start - Call PlayerUseBowWithoutProjectileEvent in Player#getProjectile | ||
| + if (this.abilities.instabuild) { | ||
| + return new ItemStack(Items.ARROW); | ||
| + } else { | ||
| + io.papermc.paper.event.player.PlayerUseBowWithoutProjectileEvent event = new io.papermc.paper.event.player.PlayerUseBowWithoutProjectileEvent((org.bukkit.entity.Player) getBukkitEntity(), org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(stack)); | ||
| + event.callEvent(); | ||
| + return org.bukkit.craftbukkit.inventory.CraftItemStack.asNMSCopy(event.getProjectile()); | ||
| + } | ||
| + // Paper end - Call PlayerUseBowWithoutProjectileEvent in Player#getProjectile | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.