Skip to content

Commit

Permalink
Add unlockall command to unlock all openstates
Browse files Browse the repository at this point in the history
  • Loading branch information
Melledy authored and Melledy committed Jul 22, 2022
1 parent 705bee0 commit e5ff253
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.OpenState;
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<>();

for (OpenState state : OpenState.values()) {
if (state == OpenState.OPEN_STATE_NONE || state == OpenState.OPEN_STATE_LIMIT_REGION_GLOBAL) continue;

if (targetPlayer.getOpenStateManager().getOpenStateMap().getOrDefault(state.getValue(), 0) == 0) {
targetPlayer.getOpenStateManager().getOpenStateMap().put(state.getValue(), 1);
changed.put(state.getValue(), 1);
}
}

targetPlayer.sendPacket(new PacketOpenStateChangeNotify(changed));

CommandHandler.sendMessage(sender, translate(sender, "commands.unlockall.success", targetPlayer.getNickname()));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package emu.grasscutter.server.packet.send;

import java.util.Map;

import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.OpenStateChangeNotifyOuterClass.OpenStateChangeNotify;
Expand All @@ -11,7 +13,18 @@ public PacketOpenStateChangeNotify(int openState, int value) {
super(PacketOpcodes.OpenStateChangeNotify);

OpenStateChangeNotify proto = OpenStateChangeNotify.newBuilder()
.putOpenStateMap(openState,value).build();
.putOpenStateMap(openState, value)
.build();

this.setData(proto);
}

public PacketOpenStateChangeNotify(Map<Integer, Integer> map) {
super(PacketOpcodes.OpenStateChangeNotify);

OpenStateChangeNotify proto = OpenStateChangeNotify.newBuilder()
.putAllOpenStateMap(map)
.build();

this.setData(proto);
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/languages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@
"invalid_time": "Unable to parse timestamp.",
"description": "Ban a player"
},
"unlockall": {
"success": "Unlocked all open states for %s.",
"description": "Unlocks all open states for a player."
},
"unban": {
"success": "Successful.",
"failure": "Failed, player not found.",
Expand Down

0 comments on commit e5ff253

Please sign in to comment.