diff --git a/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java b/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java index c8592932..d9649f1c 100644 --- a/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java +++ b/plugin/src/main/java/org/battleplugins/arena/competition/PlayerStorage.java @@ -57,17 +57,19 @@ public PlayerStorage(ArenaPlayer player) { * * @param toStore the types to store */ - public void store(Set toStore) { + public void store(Set toStore, boolean clearState) { if (this.stored) { return; } - + for (Type type : toStore) { type.store(this); } - + this.stored = true; - this.clearState(toStore); + if (clearState) { + this.clearState(toStore); + } } private void storeAll() { @@ -82,7 +84,16 @@ private void storeAll() { } private void storeInventory() { - this.inventory = this.player.getPlayer().getInventory().getContents(); + this.inventory = new ItemStack[this.player.getPlayer().getInventory().getSize()]; + for (int i = 0; i < this.inventory.length; i++) { + ItemStack item = this.player.getPlayer().getInventory().getItem(i); + if (item == null) { + continue; + } + + this.inventory[i] = item.clone(); + } + if (BattleArena.getInstance().getMainConfig().isBackupInventories()) { InventoryBackup.save(new InventoryBackup(this.player.getPlayer().getUniqueId(), this.inventory.clone())); } diff --git a/plugin/src/main/java/org/battleplugins/arena/event/action/types/StoreAction.java b/plugin/src/main/java/org/battleplugins/arena/event/action/types/StoreAction.java index b1597e0d..56efe1e0 100644 --- a/plugin/src/main/java/org/battleplugins/arena/event/action/types/StoreAction.java +++ b/plugin/src/main/java/org/battleplugins/arena/event/action/types/StoreAction.java @@ -10,6 +10,7 @@ public class StoreAction extends EventAction { private static final String TYPES_KEY = "types"; + private static final String CLEAR_STATE = "clear-state"; public StoreAction(Map params) { super(params, TYPES_KEY); @@ -23,6 +24,7 @@ public void call(ArenaPlayer arenaPlayer, Resolvable resolvable) { toStore[i] = PlayerStorage.Type.valueOf(types[i].toUpperCase()); } - arenaPlayer.getStorage().store(Set.of(toStore)); + boolean clearState = Boolean.parseBoolean(this.getOrDefault(CLEAR_STATE, "true")); + arenaPlayer.getStorage().store(Set.of(toStore), clearState); } }