[SPIGOT-7025] Bug with getting persistent data container Created: 22/May/22 Updated: 25/Dec/24 Resolved: 05/Jun/22 |
|
Status: | Resolved |
Project: | Spigot |
Component/s: | None |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Bug | Priority: | Minor |
Reporter: | David White | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | 1.18.2, spigot |
Version: | CraftBukkit version 3465-Spigot-ffceeae-3ec79a2 (MC: 1.18.2) (Implementing API version 1.18.2-R0.1-SNAPSHOT) |
Guidelines Read: | Yes |
Description |
When an entity (other than a player) throws a projectile and you try to get the items PDC in projectile launch event it does not return it. @EventHandler public void onShoot(ProjectileLaunchEvent e) { if (e.getEntityType() == EntityType.TRIDENT && e.getEntity().getShooter() instanceof LivingEntity && ((Trident) e.getEntity()).getItem().getItemMeta().getPersistentDataContainer().has(nameKey, PersistentDataType.BYTE)) Bukkit.broadcastMessage("Thrown"); } I have only tested this with tridents, but if a player throws it the server broadcasts the message, and if a drowned throws the same exact trident it does not. |
Comments |
Comment by Doc [ 29/May/22 ] |
Ok i found the issue, the Drowned when try to perform an attack they not use the item in hands.. they generate a new item (like in the most of mobs) to perform the attack, a workarround is try to get the trident from the Equipment of the Drowned and check the PDC for this.
Created a possible PR for change the logic when get the item to the same like Skeletons for keep all the items changes in attack. https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/pull-requests/1053/overview |
Comment by David White [ 29/May/22 ] |
It is not an issue with me setting persistent data, like I said in the post if a player throws the trident it will broadcast the message but if I were to drop the trident to a drowned and it picked it up, whenever it is thrown it is not triggered. This also occurs if it spawns with the item. I set the persistent data upon my plugin load and simply use the instance of the item to spawn it. |
Comment by Marvin Rieple [ 22/May/22 ] |
Where and how do you set the persistent data? |