Clone class chest contents before modifying them.

Certain class chest items are cloned before they are made unbreakable,
but not all. This commit changes that, so all items in the input array
are cloned prior to setting the unbreakable flag on them. The items that
were previously cloned specifically no longer need to be, since they are
included in the initial cloning.

Fixes #637
This commit is contained in:
Andreas Troelsen 2020-08-18 23:37:54 +02:00
parent 7f7fb1631c
commit b343976dc8
2 changed files with 14 additions and 6 deletions

View File

@ -24,6 +24,7 @@ These changes will (most likely) be included in the next version.
- The `soft-restore` setting has been fixed for blocks broken by players. Note that the functionality is still unreliable for non-trivial blocks.
- Config-file errors imposed by incorrect usage of `/ma setting` no longer cause "internal errors". Instead, the errors are properly communicated in the command output similar to how the `/ma reload` command works.
- Guardians and elder guardians no longer instantly retarget players when they break line of sight. This should make their behavior work a bit closer to vanilla.
- Items in class chests are now cloned before they are made unbreakable and given to players. This fixes an issue where setting `unbreakable-weapons: false` had no effect on the items. Note that any affected items in existing class chests will need to be replaced.
- The MagicSpells integration has been removed. This means that the extra `magicspells.yml` config-file (if it exists) no longer does anything and can be removed.
## [0.104.2] - 2020-01-03

View File

@ -1147,7 +1147,7 @@ public class ArenaImpl implements Arena
}
@Override
public void assignClassGiveInv(Player p, String className, ItemStack[] contents) {
public void assignClassGiveInv(Player p, String className, ItemStack[] source) {
ArenaPlayer arenaPlayer = arenaPlayerMap.get(p);
ArenaClass arenaClass = classes.get(className);
@ -1162,6 +1162,14 @@ public class ArenaImpl implements Arena
PlayerInventory inv = p.getInventory();
// Clone the source array to make sure we don't modify its contents
ItemStack[] contents = new ItemStack[source.length];
for (int i = 0; i < source.length; i++) {
if (source[i] != null) {
contents[i] = source[i].clone();
}
}
// Collect armor items, because setContents() now overwrites everyhing
ItemStack helmet = null;
ItemStack chestplate = null;
@ -1172,7 +1180,7 @@ public class ArenaImpl implements Arena
// Check the very last slot to see if it'll work as a helmet
int last = contents.length-1;
if (contents[last] != null) {
helmet = contents[last].clone();
helmet = contents[last];
if (arenaClass.hasUnbreakableArmor()) {
makeUnbreakable(helmet);
}
@ -1187,7 +1195,7 @@ public class ArenaImpl implements Arena
String type = parts[parts.length - 1];
if (type.equals("HELMET")) continue;
ItemStack stack = contents[i].clone();
ItemStack stack = contents[i];
if (arenaClass.hasUnbreakableArmor()) {
makeUnbreakable(stack);
}
@ -1202,9 +1210,8 @@ public class ArenaImpl implements Arena
}
// Equip the fifth last slot as the off-hand
ItemStack fifth = contents[contents.length - 5];
if (fifth != null) {
offhand = fifth.clone();
offhand = contents[contents.length - 5];
if (offhand != null) {
if (arenaClass.hasUnbreakableWeapons()) {
makeUnbreakable(offhand);
}