From f04f1ec5ce2018e3cfcc228cf19375dd6d95b9f6 Mon Sep 17 00:00:00 2001 From: Raeliana <55598870+Raeliana@users.noreply.github.com> Date: Sat, 23 Apr 2022 02:48:04 +0300 Subject: [PATCH] Create ClearWeaponsCommand.java A command to clear unlocked and unequipped artifacts --- .../command/commands/ClearWeaponsCommand.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java diff --git a/src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java b/src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java new file mode 100644 index 000000000..8fab1768b --- /dev/null +++ b/src/main/java/emu/grasscutter/command/commands/ClearWeaponsCommand.java @@ -0,0 +1,29 @@ +package emu.grasscutter.command.commands; + +import emu.grasscutter.command.Command; +import emu.grasscutter.command.CommandHandler; +import emu.grasscutter.game.GenshinPlayer; +import emu.grasscutter.game.inventory.Inventory; +import emu.grasscutter.game.inventory.ItemType; + +import java.util.List; + +@Command(label = "clearweapons", usage = "clearweapons", + description = "Deletes all unequipped and unlocked weapons, including yellow rarity ones from your inventory", + aliases = {"clearwpns"}, permission = "player.clearweapons") +public final class ClearWeaponsCommand implements CommandHandler { + + @Override + public void execute(GenshinPlayer sender, List args) { + if (sender == null) { + CommandHandler.sendMessage(null, "Run this command in-game."); + return; // TODO: clear player's weapons from console or other players + } + + Inventory playerInventory = sender.getInventory(); + playerInventory.getItems().values().stream() + .filter(item -> item.getItemType() == ItemType.ITEM_WEAPON) + .filter(item -> !item.isLocked() && !item.isEquipped()) + .forEach(item -> playerInventory.removeItem(item, item.getCount())); + } +}