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

import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.inventory.ItemType;
Melledy's avatar
Melledy committed
8
import emu.grasscutter.game.player.Player;
9
10
11
12
13
14
15
16
17
18

import java.util.List;

@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
19
    public void execute(Player sender, List<String> args) {
20
        int target;
21
        String cmdSwitch = "";
22
23
        if (sender == null) {
            CommandHandler.sendMessage(null, "Run this command in-game.");
24
            return;
25
26
        }
        Inventory playerInventory = sender.getInventory();
27
28
29
30
31
32
        try {
            if (args.size() == 1) {
                cmdSwitch = args.get(0);
                target = sender.getUid();
            }else {
                cmdSwitch = args.get(1);
33
                target = Integer.parseInt(args.get(0));
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
            }
            Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
            switch (cmdSwitch) {
                case "wp" -> {
                    playerInventory.getItems().values().stream()
                            .filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
                            .filter(item -> !item.isLocked() && !item.isEquipped())
                            .forEach(item -> playerInventory.removeItem(item, item.getCount()));
                    sender.dropMessage("Cleared weapons for " + targetPlayer.getNickname() + " .");
                }
                case "art" -> {
                    playerInventory.getItems().values().stream()
                            .filter(item -> item.getItemType() == ItemType.ITEM_RELIQUARY)
                            .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
                            .filter(item -> !item.isLocked() && !item.isEquipped())
                            .forEach(item -> playerInventory.removeItem(item, item.getCount()));
                    sender.dropMessage("Cleared artifacts for " + targetPlayer.getNickname() + " .");
                }
                case "mat" -> {
                    playerInventory.getItems().values().stream()
                            .filter(item -> item.getItemType() == ItemType.ITEM_MATERIAL)
                            .filter(item -> item.getLevel() == 1 && item.getExp() == 0)
                            .filter(item -> !item.isLocked() && !item.isEquipped())
                            .forEach(item -> playerInventory.removeItem(item, item.getCount()));
                    sender.dropMessage("Cleared artifacts for " + targetPlayer.getNickname() + " .");
                }
                case "all" -> {
                    playerInventory.getItems().values().stream()
                            .filter(item1 -> item1.getItemType() == ItemType.ITEM_RELIQUARY)
                            .filter(item1 -> item1.getLevel() == 1 && item1.getExp() == 0)
                            .filter(item1 -> !item1.isLocked() && !item1.isEquipped())
                            .forEach(item1 -> playerInventory.removeItem(item1, item1.getCount()));
                    sender.dropMessage("Cleared artifacts for " + targetPlayer.getNickname() + " .");
                    playerInventory.getItems().values().stream()
                            .filter(item2 -> item2.getItemType() == ItemType.ITEM_MATERIAL)
                            .filter(item2 -> !item2.isLocked() && !item2.isEquipped())
                            .forEach(item2 -> playerInventory.removeItem(item2, item2.getCount()));
                    sender.dropMessage("Cleared materials for " + targetPlayer.getNickname() + " .");
                    playerInventory.getItems().values().stream()
                            .filter(item3 -> item3.getItemType() == ItemType.ITEM_WEAPON)
                            .filter(item3 -> item3.getLevel() == 1 && item3.getExp() == 0)
                            .filter(item3 -> !item3.isLocked() && !item3.isEquipped())
                            .forEach(item3 -> playerInventory.removeItem(item3, item3.getCount()));
                    sender.dropMessage("Cleared weapons for " + targetPlayer.getNickname() + " .");
                    playerInventory.getItems().values().stream()
                            .filter(item4 -> item4.getItemType() == ItemType.ITEM_FURNITURE)
                            .filter(item4 -> !item4.isLocked() && !item4.isEquipped())
                            .forEach(item4 -> playerInventory.removeItem(item4, item4.getCount()));
                    sender.dropMessage("Cleared furniture for " + targetPlayer.getNickname() + " .");
                    playerInventory.getItems().values().stream()
                            .filter(item5 -> item5.getItemType() == ItemType.ITEM_DISPLAY)
                            .filter(item5 -> !item5.isLocked() && !item5.isEquipped())
                            .forEach(item5 -> playerInventory.removeItem(item5, item5.getCount()));
                    sender.dropMessage("Cleared displays for " + targetPlayer.getNickname() + " .");
                    playerInventory.getItems().values().stream()
                            .filter(item6 -> item6.getItemType() == ItemType.ITEM_VIRTUAL)
                            .filter(item6 -> !item6.isLocked() && !item6.isEquipped())
                            .forEach(item6 -> playerInventory.removeItem(item6, item6.getCount()));
                    sender.dropMessage("Cleared virtuals for " + targetPlayer.getNickname() + " .");
                    sender.dropMessage("Cleared everything for " + targetPlayer.getNickname() + " .");
94
95
                }
            }
96
97
98
99
100
        } catch (NumberFormatException ignored) {
            // TODO: Parse from item name using GM Handbook.
            CommandHandler.sendMessage(sender, "Invalid playerId.");
            return;
        }
101

102
        Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
103
104
105
106
107
108
        if (targetPlayer == null) {
            CommandHandler.sendMessage(sender, "Player not found.");
            return;
        }
    }
}