ClearCommand.java 5.85 KB
Newer Older
1
2
3
4
5
package emu.grasscutter.command.commands;

import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
6
import emu.grasscutter.game.inventory.GameItem;
7
8
import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.inventory.ItemType;
Melledy's avatar
Melledy committed
9
import emu.grasscutter.game.player.Player;
10
11
12

import java.util.List;

13
14
import static emu.grasscutter.utils.Language.translate;

15
16
17
18
19
20
21
@Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid]
        description = "Deletes unequipped unlocked items, including yellow rarity ones from your inventory",
        aliases = {"clear"}, permission = "player.clearinv")

public final class ClearCommand implements CommandHandler {

    @Override
AnimeGitB's avatar
AnimeGitB committed
22
    public void execute(Player sender, Player targetPlayer, List<String> args) {
AnimeGitB's avatar
AnimeGitB committed
23
        if (targetPlayer == null) {
24
            CommandHandler.sendMessage(sender, translate("commands.execution.need_target"));
25
            return;
26
        }
AnimeGitB's avatar
AnimeGitB committed
27
        if (args.size() < 1) {
28
            CommandHandler.sendMessage(sender, translate("commands.clear.command_usage"));
29
30
            return;
        }
AnimeGitB's avatar
AnimeGitB committed
31
        Inventory playerInventory = targetPlayer.getInventory();
32
33
        List<GameItem> toDelete = null;
        
AnimeGitB's avatar
AnimeGitB committed
34
35
        switch (args.get(0)) {
            case "wp" -> {
36
            	toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
37
38
                        .filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
                        .filter(item -> !item.isLocked() && !item.isEquipped())
39
                        .toList();
40
                CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
AnimeGitB's avatar
AnimeGitB committed
41
42
            }
            case "art" -> {
43
            	toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
44
45
46
                        .filter(item -> item.getItemType() == ItemType.ITEM_RELIQUARY)
                        .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
                        .filter(item -> !item.isLocked() && !item.isEquipped())
47
                        .toList();
48
                CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
AnimeGitB's avatar
AnimeGitB committed
49
50
            }
            case "mat" -> {
51
            	toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
52
53
54
                        .filter(item -> item.getItemType() == ItemType.ITEM_MATERIAL)
                        .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
                        .filter(item -> !item.isLocked() && !item.isEquipped())
55
                        .toList();
56
                CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
AnimeGitB's avatar
AnimeGitB committed
57
58
            }
            case "all" -> {
59
            	toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
60
61
62
                        .filter(item1 -> item1.getItemType() == ItemType.ITEM_RELIQUARY)
                        .filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
                        .filter(item1 -> !item1.isLocked() && !item1.isEquipped())
63
                        .toList();
64
65
66
                CommandHandler.sendMessage(sender, translate("commands.clear.artifacts", targetPlayer.getNickname()));
                playerInventory.removeItems(toDelete);
                
67
                toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
68
69
                        .filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
                        .filter(item2 -> !item2.isLocked() && !item2.isEquipped())
70
                        .toList();
71
72
73
                playerInventory.removeItems(toDelete);
                CommandHandler.sendMessage(sender, translate("commands.clear.materials", targetPlayer.getNickname()));
                
74
                toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
75
76
77
                        .filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
                        .filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
                        .filter(item3 -> !item3.isLocked() && !item3.isEquipped())
78
                        .toList();
79
80
81
                playerInventory.removeItems(toDelete);
                CommandHandler.sendMessage(sender, translate("commands.clear.weapons", targetPlayer.getNickname()));
                
82
                toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
83
84
                        .filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
                        .filter(item4 -> !item4.isLocked() && !item4.isEquipped())
85
                        .toList();
86
87
88
                playerInventory.removeItems(toDelete);
                CommandHandler.sendMessage(sender, translate("commands.clear.furniture", targetPlayer.getNickname()));
                
89
                toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
90
91
                        .filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
                        .filter(item5 -> !item5.isLocked() && !item5.isEquipped())
92
                        .toList();
93
94
95
                playerInventory.removeItems(toDelete);
                CommandHandler.sendMessage(sender, translate("commands.clear.displays", targetPlayer.getNickname()));
                
96
                toDelete = playerInventory.getItems().values().stream()
AnimeGitB's avatar
AnimeGitB committed
97
98
                        .filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
                        .filter(item6 -> !item6.isLocked() && !item6.isEquipped())
99
                        .toList();
100
101
                CommandHandler.sendMessage(sender, translate("commands.clear.virtuals", targetPlayer.getNickname()));
                CommandHandler.sendMessage(sender, translate("commands.clear.everything", targetPlayer.getNickname()));
AnimeGitB's avatar
AnimeGitB committed
102
            }
103
        }
104
105
106
107
        
        if (toDelete != null) {
        	playerInventory.removeItems(toDelete);
        }
108
109
    }
}