-
-
Notifications
You must be signed in to change notification settings - Fork 112
More proper bow item detection #833
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
Merged
Krakenied
merged 1 commit into
LMBishop:master
from
Krakenied:fix/proper-bow-enchants-tracking
Jan 15, 2026
Merged
Changes from all commits
Commits
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
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
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
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
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
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
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
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
80 changes: 80 additions & 0 deletions
80
bukkit/src/main/java/com/leonardobishop/quests/bukkit/util/Projectile2ItemCache.java
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,80 @@ | ||
| package com.leonardobishop.quests.bukkit.util; | ||
|
|
||
| import com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent; | ||
| import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin; | ||
| import org.bukkit.entity.Entity; | ||
| import org.bukkit.entity.LivingEntity; | ||
| import org.bukkit.entity.Player; | ||
| import org.bukkit.entity.Projectile; | ||
| import org.bukkit.event.EventHandler; | ||
| import org.bukkit.event.EventPriority; | ||
| import org.bukkit.event.Listener; | ||
| import org.bukkit.event.entity.EntityShootBowEvent; | ||
| import org.bukkit.inventory.ItemStack; | ||
| import org.bukkit.plugin.PluginManager; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.WeakHashMap; | ||
|
|
||
| /** | ||
| * Provides a cache that links projectiles to the item used to fire them. | ||
| * | ||
| * <p>This cache exists because damage-related events do not expose | ||
| * information about the item from which a projectile was fired. | ||
| * By capturing this association at the time the projectile is created, | ||
| * the item can later be retrieved when handling damage events.</p> | ||
| */ | ||
| @NullMarked | ||
| public final class Projectile2ItemCache implements Listener { | ||
|
|
||
| private final Map<Entity, @Nullable ItemStack> backingMap; | ||
|
|
||
| public Projectile2ItemCache() { | ||
| this.backingMap = WeakHashMap.newWeakHashMap(1024); | ||
| } | ||
|
|
||
| public void registerEvents(final BukkitQuestsPlugin plugin) { | ||
| final PluginManager pluginManager = plugin.getServer().getPluginManager(); | ||
|
|
||
| pluginManager.registerEvents(this, plugin); | ||
|
|
||
| try { | ||
| Class.forName("com.destroystokyo.paper.event.player.PlayerLaunchProjectileEvent"); | ||
| pluginManager.registerEvents(new PlayerLaunchProjectileListener(), plugin); | ||
| } catch (final ClassNotFoundException e) { | ||
| // not supported on Spigot | ||
| } | ||
| } | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onEntityShootBow(final EntityShootBowEvent event) { | ||
| final LivingEntity shooter = event.getEntity(); | ||
| final Entity projectile = event.getProjectile(); | ||
| final ItemStack bow = event.getBow(); | ||
|
|
||
| // Currently there are no advantages of caching projectiles for non-player arrows. | ||
| // It would be needed to cache these if we needed a task to take damage from mobs. | ||
| if (shooter instanceof Player) { | ||
| this.backingMap.put(projectile, bow); | ||
| } | ||
| } | ||
|
|
||
| public final class PlayerLaunchProjectileListener implements Listener { | ||
|
|
||
| @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) | ||
| public void onPlayerLaunchProjectile(final PlayerLaunchProjectileEvent event) { | ||
| final Projectile projectile = event.getProjectile(); | ||
| final ItemStack item = event.getItemStack(); | ||
|
|
||
| // TODO: doesn't really work for tridents | ||
| // https://github.com/LMBishop/Quests/pull/833 | ||
| Projectile2ItemCache.this.backingMap.put(projectile, item); | ||
| } | ||
| } | ||
|
|
||
| public @Nullable ItemStack getItem(final Entity projectile) { | ||
| return this.backingMap.get(projectile); | ||
| } | ||
| } | ||
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
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.