Clone ItemStack before adding to player inventory.

Spigot is at it again with another breaking change to the API where the
JavaDocs have been retrofitted to match the new, ancient way of writing
software.

The addItem and removeItem methods originally just added or removed
whatever they could when called, and returned a map of items that failed
due to lack of space/items. Now, with the breaking API change, these
methods actually *mutate their arguments* - a practice that has been
heavily discouraged for decades in modern software development, and
something you usually only see in C these days. This change, like many
others in the same vein, show the complete recklessness, incompetence,
and lack of awareness from an otherwise talented team of developers.
Hopefully, they will continue to hone their skills so that we can
eventually have a stable API again.
This commit is contained in:
Andreas Troelsen 2019-02-03 14:15:40 +01:00
parent 0e037b2f72
commit fc8debca29
2 changed files with 3 additions and 2 deletions

View File

@ -12,6 +12,7 @@ These changes will (most likely) be included in the next version.
## [Unreleased]
- MobArena no longer touches the `flySpeed` player attribute when players join an arena. This should fix issues where a crash would result in players being "locked in the air" when trying to fly outside of the arena. It also introduces compatibility with plugins that use flight to augment player abilities.
- Fixed a bug introduced by a breaking API change in Spigot where a player with a nearly full inventory might cause item rewards to change stack amounts.
## [0.103.1] - 2018-12-31
- Like the other user commands, the permission for `/ma ready` now defaults to true.

View File

@ -13,12 +13,12 @@ public class ItemStackThing implements Thing {
@Override
public boolean giveTo(Player player) {
return player.getInventory().addItem(stack).isEmpty();
return player.getInventory().addItem(stack.clone()).isEmpty();
}
@Override
public boolean takeFrom(Player player) {
return player.getInventory().removeItem(stack).isEmpty();
return player.getInventory().removeItem(stack.clone()).isEmpty();
}
@Override