Add damaged slot to PlayerItemDamageEvent#2153
Conversation
| + } else if (entityplayer.getItemInOffHand() == this) { | ||
| + slot = 104; //Shield slot: (last armor slot + 1) | ||
| + } else { | ||
| + int w = 100; //First armor slot. Based on https://bukkit.org/threads/inventory-slots.431469/ |
There was a problem hiding this comment.
I'm curious why you chose that outdated image to set your slot numbers instead of the API specification? I'm not sure where slot numbers 100-104 are going to come in handy since they cannot be used with setItem(slot), etc.
|
I initially used the slots you recommended I believe but there was a debate about future proofing and there was no decision on this and the final decision was up to project leads. I guess I could correct to it to slots you mentioned and it would make more sense to do so. |
| private static final HandlerList handlers = new HandlerList(); | ||
| private final ItemStack item; | ||
| private int damage; | ||
| + private final int slot; //Paper - add damaged slot |
There was a problem hiding this comment.
| + private final int slot; //Paper - add damaged slot | |
| + private final int slot; // Paper - add damaged slot |
| super(player); | ||
| this.item = what; | ||
| this.damage = damage; | ||
| + this.slot = -1; |
There was a problem hiding this comment.
Delegate to a new constructor instead
| this.damage = damage; | ||
| } | ||
|
|
||
| + //Paper start |
There was a problem hiding this comment.
| + //Paper start | |
| + // Paper start |
| if (entityplayer != null) { | ||
| - PlayerItemDamageEvent event = new PlayerItemDamageEvent(entityplayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), i); | ||
| + | ||
| + //Paper start - getting slot that was damaged |
There was a problem hiding this comment.
| + //Paper start - getting slot that was damaged | |
| + // Paper start - getting slot that was damaged |
| - PlayerItemDamageEvent event = new PlayerItemDamageEvent(entityplayer.getBukkitEntity(), CraftItemStack.asCraftMirror(this), i); | ||
| + | ||
| + //Paper start - getting slot that was damaged | ||
| + int slot = -1; |
There was a problem hiding this comment.
Should have a look at how e.g. book modification handling is done for getting the slot...
There was a problem hiding this comment.
I'm not sure what you are thinking of exactly
3ae7d24 to
d389925
Compare
Trigary
left a comment
There was a problem hiding this comment.
I am not sure whether using an integer slot ID is a good idea. Why not just use the EquipmentSlot enum? Sure, it would limit the event, but it would provide a much more useful API. In what kind of use case is the slot ID useful? The enum would be a lot more useful in my opinion.
| super(player); | ||
| this.item = what; | ||
| this.damage = damage; | ||
| + this.slot = -1; |
| + //Paper start | ||
| + /** | ||
| + * Gets the slot where the item took durability damage | ||
| + * |
There was a problem hiding this comment.
Maybe add an example or how this slot can be used: how to get the ItemStack at this slot from a Player instance. (But that's a stupid use case since the ItemStack is directly exposed in this method.)
|
I think using EDIT: Though this limits plugins that might call this event to slots defined by |
I suppose its possible in the future for itemstacks to be "damaged" even if they are not in one of the slots covered by the EquipmentSlot enum. That is already possible via nms, just calling the isDamaged method on the nms ItemStack. |
|
Exposing both the slot ID and the equipmentslot enum is still an option. Maybe calculate the slot id in the constructor based on the enum value (if the constructor with the enum value was used). |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
|
Talking about this in discord there were few changes suggested by @Trigary and @yannicklamprecht:
|
|
The second should be future-proof enough (and less confusing imo) for plugin devs to already check for the nullable equipment slot, depending on what they need. |
Continuation of #1834
(Unfortunately had to create a new PR because couldn't reopen the original PR)