Commit e5ff2536 authored by Melledy's avatar Melledy
Browse files

Add `unlockall` command to unlock all openstates

parent 705bee05
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()));
}
}
package emu.grasscutter.server.packet.send; package emu.grasscutter.server.packet.send;
import java.util.Map;
import emu.grasscutter.net.packet.BasePacket; import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes; import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.OpenStateChangeNotifyOuterClass.OpenStateChangeNotify; import emu.grasscutter.net.proto.OpenStateChangeNotifyOuterClass.OpenStateChangeNotify;
...@@ -11,7 +13,18 @@ public class PacketOpenStateChangeNotify extends BasePacket { ...@@ -11,7 +13,18 @@ public class PacketOpenStateChangeNotify extends BasePacket {
super(PacketOpcodes.OpenStateChangeNotify); super(PacketOpcodes.OpenStateChangeNotify);
OpenStateChangeNotify proto = OpenStateChangeNotify.newBuilder() 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); this.setData(proto);
} }
......
...@@ -326,6 +326,10 @@ ...@@ -326,6 +326,10 @@
"invalid_time": "Unable to parse timestamp.", "invalid_time": "Unable to parse timestamp.",
"description": "Ban a player" "description": "Ban a player"
}, },
"unlockall": {
"success": "Unlocked all open states for %s.",
"description": "Unlocks all open states for a player."
},
"unban": { "unban": {
"success": "Successful.", "success": "Successful.",
"failure": "Failed, player not found.", "failure": "Failed, player not found.",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment