UnlockAllCommand.java 1.46 KB
Newer Older
1
2
3
4
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
5
import emu.grasscutter.data.GameData;
6
import emu.grasscutter.game.player.Player;
7
import emu.grasscutter.game.player.PlayerProgressManager;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import emu.grasscutter.server.packet.send.PacketOpenStateChangeNotify;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

@Command(label = "unlockall", usage = {""}, permission = "player.unlockall", permissionTargeted = "player.unlockall.others")
public final class UnlockAllCommand implements CommandHandler {

    @Override
    public void execute(Player sender, Player targetPlayer, List<String> args) {
        Map<Integer, Integer> changed = new HashMap<>();
22
23
24

        for (var state : GameData.getOpenStateList()) {
            // Don't unlock blacklisted open states.
25
            if (PlayerProgressManager.BLACKLIST_OPEN_STATES.contains(state.getId())) {
26
27
28
                continue;
            }

29
30
            if (targetPlayer.getProgressManager().getOpenState(state.getId()) == 0) {
                targetPlayer.getOpenStates().put(state.getId(), 1); 
31
                changed.put(state.getId(), 1);
32
33
34
35
36
37
38
39
            }
        }
        
        targetPlayer.sendPacket(new PacketOpenStateChangeNotify(changed));
        
        CommandHandler.sendMessage(sender, translate(sender, "commands.unlockall.success", targetPlayer.getNickname()));
    }
}