ClearCommand.java 5.77 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
@Command(label = "clear", usage = "clear <all|wp|art|mat>", //Merged /clearartifacts and /clearweapons to /clear <args> [uid]
方块君's avatar
方块君 committed
16
        description = "commands.clear.description",
17
        aliases = {"clear"}, permission = "player.clearinv", permissionTargeted = "player.clearinv.others")
18
19
20
21

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