Skip to content

Commit

Permalink
Add option to not clear state for store action
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 21, 2024
1 parent 24b1916 commit cbc07c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,19 @@ public PlayerStorage(ArenaPlayer player) {
*
* @param toStore the types to store
*/
public void store(Set<Type> toStore) {
public void store(Set<Type> 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() {
Expand All @@ -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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> params) {
super(params, TYPES_KEY);
Expand All @@ -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);
}
}

0 comments on commit cbc07c0

Please sign in to comment.