WIP Restart command - For now disconnects session, preferrably just send PlayerLoginRsp so it does the login sequence all over again

This commit is contained in:
memetrollsXD 2022-04-19 19:39:54 +02:00
parent c728b9f5fe
commit 657ac2e529
2 changed files with 169 additions and 127 deletions

File diff suppressed because one or more lines are too long

View File

@ -21,6 +21,7 @@ import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.PlayerProperty;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
import emu.grasscutter.server.packet.send.PacketItemAddHintNotify; import emu.grasscutter.server.packet.send.PacketItemAddHintNotify;
import emu.grasscutter.server.packet.send.PacketPlayerLoginRsp;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import java.util.LinkedList; import java.util.LinkedList;
@ -30,8 +31,8 @@ import java.util.List;
* A container for player-related commands. * A container for player-related commands.
*/ */
public final class PlayerCommands { public final class PlayerCommands {
@Command(label = "give", aliases = {"g", "item", "giveitem"}, @Command(label = "give", aliases = { "g", "item",
usage = "Usage: give [player] <itemId|itemName> [amount]") "giveitem" }, usage = "Usage: give [player] <itemId|itemName> [amount]")
public static class GiveCommand implements CommandHandler { public static class GiveCommand implements CommandHandler {
@Override @Override
@ -57,7 +58,8 @@ public final class PlayerCommands {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
target = player.getUid(); amount = Integer.parseInt(args.get(1)); target = player.getUid();
amount = Integer.parseInt(args.get(1));
item = Integer.parseInt(args.get(0)); item = Integer.parseInt(args.get(0));
} else { } else {
item = Integer.parseInt(args.get(1)); item = Integer.parseInt(args.get(1));
@ -73,7 +75,8 @@ public final class PlayerCommands {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(player, "Invalid player ID."); return; CommandHandler.sendMessage(player, "Invalid player ID.");
return;
} }
item = Integer.parseInt(args.get(1)); item = Integer.parseInt(args.get(1));
@ -89,12 +92,14 @@ public final class PlayerCommands {
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(player, "Player not found."); return; CommandHandler.sendMessage(player, "Player not found.");
return;
} }
ItemData itemData = GenshinData.getItemDataMap().get(item); ItemData itemData = GenshinData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(player, "Invalid item id."); return; CommandHandler.sendMessage(player, "Invalid item id.");
return;
} }
this.item(targetPlayer, itemData, amount); this.item(targetPlayer, itemData, amount);
@ -103,7 +108,8 @@ public final class PlayerCommands {
/** /**
* give [player] [itemId|itemName] [amount] * give [player] [itemId|itemName] [amount]
*/ */
@Override public void execute(List<String> args) { @Override
public void execute(List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount]"); CommandHandler.sendMessage(null, "Usage: give <player> <itemId|itemName> [amount]");
return; return;
@ -112,17 +118,21 @@ public final class PlayerCommands {
try { try {
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
int item = Integer.parseInt(args.get(1)); int item = Integer.parseInt(args.get(1));
int amount = 1; if(args.size() > 2) amount = Integer.parseInt(args.get(2)); int amount = 1;
if (args.size() > 2)
amount = Integer.parseInt(args.get(2));
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return; CommandHandler.sendMessage(null, "Player not found.");
return;
} }
ItemData itemData = GenshinData.getItemDataMap().get(item); ItemData itemData = GenshinData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(null, "Invalid item id."); return; CommandHandler.sendMessage(null, "Invalid item id.");
return;
} }
this.item(targetPlayer, itemData, amount); this.item(targetPlayer, itemData, amount);
@ -137,7 +147,8 @@ public final class PlayerCommands {
List<GenshinItem> items = new LinkedList<>(); List<GenshinItem> items = new LinkedList<>();
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
items.add(genshinItem); items.add(genshinItem);
} player.getInventory().addItems(items); }
player.getInventory().addItems(items);
player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop)); player.sendPacket(new PacketItemAddHintNotify(items, ActionReason.SubfieldDrop));
} else { } else {
genshinItem.setCount(amount); genshinItem.setCount(amount);
@ -147,9 +158,8 @@ public final class PlayerCommands {
} }
} }
@Command(label = "drop", aliases = {"d", "dropitem"}, @Command(label = "drop", aliases = { "d",
usage = "Usage: drop <itemId|itemName> [amount]", "dropitem" }, usage = "Usage: drop <itemId|itemName> [amount]", execution = Command.Execution.PLAYER)
execution = Command.Execution.PLAYER)
public static class DropCommand implements CommandHandler { public static class DropCommand implements CommandHandler {
@Override @Override
@ -161,22 +171,27 @@ public final class PlayerCommands {
try { try {
int item = Integer.parseInt(args.get(0)); int item = Integer.parseInt(args.get(0));
int amount = 1; if(args.size() > 1) amount = Integer.parseInt(args.get(1)); int amount = 1;
if (args.size() > 1)
amount = Integer.parseInt(args.get(1));
ItemData itemData = GenshinData.getItemDataMap().get(item); ItemData itemData = GenshinData.getItemDataMap().get(item);
if (itemData == null) { if (itemData == null) {
CommandHandler.sendMessage(player, "Invalid item id."); return; CommandHandler.sendMessage(player, "Invalid item id.");
return;
} }
if (itemData.isEquip()) { if (itemData.isEquip()) {
float range = (5f + (.1f * amount)); float range = (5f + (.1f * amount));
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2))
.addY(3f).addZ((float) (Math.random() * range) - (range / 2));
EntityItem entity = new EntityItem(player.getScene(), player, itemData, pos, 1); EntityItem entity = new EntityItem(player.getScene(), player, itemData, pos, 1);
player.getScene().addEntity(entity); player.getScene().addEntity(entity);
} }
} else { } else {
EntityItem entity = new EntityItem(player.getScene(), player, itemData, player.getPos().clone().addY(3f), amount); EntityItem entity = new EntityItem(player.getScene(), player, itemData,
player.getPos().clone().addY(3f), amount);
player.getScene().addEntity(entity); player.getScene().addEntity(entity);
} }
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
@ -185,10 +200,11 @@ public final class PlayerCommands {
} }
} }
@Command(label = "givechar", aliases = {"givec"}, @Command(label = "givechar", aliases = {
usage = "Usage: givechar <player|avatarId> [level|avatarId] [level]") "givec" }, usage = "Usage: givechar <player|avatarId> [level|avatarId] [level]")
public static class GiveCharCommand implements CommandHandler { public static class GiveCharCommand implements CommandHandler {
@Override public void execute(GenshinPlayer player, List<String> args) { @Override
public void execute(GenshinPlayer player, List<String> args) {
int target, avatarId, level = 1, ascension = 1; int target, avatarId, level = 1, ascension = 1;
if (args.size() < 1) { if (args.size() < 1) {
@ -220,7 +236,8 @@ public final class PlayerCommands {
try { try {
target = Integer.parseInt(args.get(0)); target = Integer.parseInt(args.get(0));
if (Grasscutter.getGameServer().getPlayerByUid(target) == null) { if (Grasscutter.getGameServer().getPlayerByUid(target) == null) {
CommandHandler.sendMessage(player, "Invalid player ID."); return; CommandHandler.sendMessage(player, "Invalid player ID.");
return;
} }
avatarId = Integer.parseInt(args.get(1)); avatarId = Integer.parseInt(args.get(1));
@ -235,12 +252,14 @@ public final class PlayerCommands {
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(player, "Player not found."); return; CommandHandler.sendMessage(player, "Player not found.");
return;
} }
AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId); AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarId);
if (avatarData == null) { if (avatarData == null) {
CommandHandler.sendMessage(player, "Invalid avatar id."); return; CommandHandler.sendMessage(player, "Invalid avatar id.");
return;
} }
// Calculate ascension level. // Calculate ascension level.
@ -270,17 +289,21 @@ public final class PlayerCommands {
try { try {
int target = Integer.parseInt(args.get(0)); int target = Integer.parseInt(args.get(0));
int avatarID = Integer.parseInt(args.get(1)); int avatarID = Integer.parseInt(args.get(1));
int level = 1; if(args.size() > 2) level = Integer.parseInt(args.get(2)); int level = 1;
if (args.size() > 2)
level = Integer.parseInt(args.get(2));
int ascension; int ascension;
GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); GenshinPlayer targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target);
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, "Player not found."); return; CommandHandler.sendMessage(null, "Player not found.");
return;
} }
AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarID); AvatarData avatarData = GenshinData.getAvatarDataMap().get(avatarID);
if (avatarData == null) { if (avatarData == null) {
CommandHandler.sendMessage(null, "Invalid avatar id."); return; CommandHandler.sendMessage(null, "Invalid avatar id.");
return;
} }
// Calculate ascension level. // Calculate ascension level.
@ -304,8 +327,7 @@ public final class PlayerCommands {
} }
} }
@Command(label = "spawn", execution = Command.Execution.PLAYER, @Command(label = "spawn", execution = Command.Execution.PLAYER, usage = "Usage: spawn <entityId|entityName> [level] [amount]")
usage = "Usage: spawn <entityId|entityName> [level] [amount]")
public static class SpawnCommand implements CommandHandler { public static class SpawnCommand implements CommandHandler {
@Override @Override
@ -317,17 +339,23 @@ public final class PlayerCommands {
try { try {
int entity = Integer.parseInt(args.get(0)); int entity = Integer.parseInt(args.get(0));
int level = 1; if(args.size() > 1) level = Integer.parseInt(args.get(1)); int level = 1;
int amount = 1; if(args.size() > 2) amount = Integer.parseInt(args.get(2)); if (args.size() > 1)
level = Integer.parseInt(args.get(1));
int amount = 1;
if (args.size() > 2)
amount = Integer.parseInt(args.get(2));
MonsterData entityData = GenshinData.getMonsterDataMap().get(entity); MonsterData entityData = GenshinData.getMonsterDataMap().get(entity);
if (entityData == null) { if (entityData == null) {
CommandHandler.sendMessage(null, "Invalid entity id."); return; CommandHandler.sendMessage(null, "Invalid entity id.");
return;
} }
float range = (5f + (.1f * amount)); float range = (5f + (.1f * amount));
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f).addZ((float) (Math.random() * range) - (range / 2)); Position pos = player.getPos().clone().addX((float) (Math.random() * range) - (range / 2)).addY(3f)
.addZ((float) (Math.random() * range) - (range / 2));
EntityMonster monster = new EntityMonster(player.getScene(), entityData, pos, level); EntityMonster monster = new EntityMonster(player.getScene(), entityData, pos, level);
player.getScene().addEntity(monster); player.getScene().addEntity(monster);
} }
@ -337,8 +365,7 @@ public final class PlayerCommands {
} }
} }
@Command(label = "killall", @Command(label = "killall", usage = "Usage: killall [playerUid] [sceneId]")
usage = "Usage: killall [playerUid] [sceneId]")
public static class KillAllCommand implements CommandHandler { public static class KillAllCommand implements CommandHandler {
@Override @Override
@ -353,7 +380,8 @@ public final class PlayerCommands {
@Override @Override
public void execute(List<String> args) { public void execute(List<String> args) {
if (args.size() < 2) { if (args.size() < 2) {
CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]"); return; CommandHandler.sendMessage(null, "Usage: killall [playerUid] [sceneId]");
return;
} }
try { try {
@ -382,8 +410,8 @@ public final class PlayerCommands {
} }
} }
@Command(label = "resetconst", aliases = {"resetconstellation"}, @Command(label = "resetconst", aliases = {
usage = "Usage: resetconst [all]", execution = Command.Execution.PLAYER) "resetconstellation" }, usage = "Usage: resetconst [all]", execution = Command.Execution.PLAYER)
public static class ResetConstellationCommand implements CommandHandler { public static class ResetConstellationCommand implements CommandHandler {
@Override @Override
@ -399,7 +427,8 @@ public final class PlayerCommands {
GenshinAvatar avatar = entity.getAvatar(); GenshinAvatar avatar = entity.getAvatar();
this.resetConstellation(avatar); this.resetConstellation(avatar);
player.dropMessage("Constellations for " + avatar.getAvatarData().getName() + " have been reset. Please relog to see changes."); player.dropMessage("Constellations for " + avatar.getAvatarData().getName()
+ " have been reset. Please relog to see changes.");
} }
} }
@ -411,8 +440,7 @@ public final class PlayerCommands {
} }
} }
@Command(label = "godmode", @Command(label = "godmode", usage = "Usage: godmode", execution = Command.Execution.PLAYER)
usage = "Usage: godmode", execution = Command.Execution.PLAYER)
public static class GodModeCommand implements CommandHandler { public static class GodModeCommand implements CommandHandler {
@Override @Override
@ -422,14 +450,15 @@ public final class PlayerCommands {
} }
} }
@Command(label = "sethealth", aliases = {"sethp"}, @Command(label = "sethealth", aliases = {
usage = "Usage: sethealth <hp>", execution = Command.Execution.PLAYER) "sethp" }, usage = "Usage: sethealth <hp>", execution = Command.Execution.PLAYER)
public static class SetHealthCommand implements CommandHandler { public static class SetHealthCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(GenshinPlayer player, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(null, "Usage: sethealth <hp>"); return; CommandHandler.sendMessage(null, "Usage: sethealth <hp>");
return;
} }
try { try {
@ -439,7 +468,8 @@ public final class PlayerCommands {
return; return;
entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health); entity.setFightProperty(FightProperty.FIGHT_PROP_CUR_HP, health);
entity.getWorld().broadcastPacket(new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP)); entity.getWorld().broadcastPacket(
new PacketEntityFightPropUpdateNotify(entity, FightProperty.FIGHT_PROP_CUR_HP));
player.dropMessage("Health set to " + health + "."); player.dropMessage("Health set to " + health + ".");
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(null, "Invalid health value."); CommandHandler.sendMessage(null, "Invalid health value.");
@ -447,13 +477,14 @@ public final class PlayerCommands {
} }
} }
@Command(label = "setworldlevel", aliases = {"setworldlvl"}, @Command(label = "setworldlevel", aliases = {
usage = "Usage: setworldlevel <level>", execution = Command.Execution.PLAYER) "setworldlvl" }, usage = "Usage: setworldlevel <level>", execution = Command.Execution.PLAYER)
public static class SetWorldLevelCommand implements CommandHandler { public static class SetWorldLevelCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(GenshinPlayer player, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(player, "Usage: setworldlevel <level>"); return; CommandHandler.sendMessage(player, "Usage: setworldlevel <level>");
return;
} }
try { try {
@ -470,8 +501,8 @@ public final class PlayerCommands {
} }
} }
@Command(label = "clearartifacts", aliases = {"clearart"}, @Command(label = "clearartifacts", aliases = {
usage = "Usage: clearartifacts", execution = Command.Execution.PLAYER) "clearart" }, usage = "Usage: clearartifacts", execution = Command.Execution.PLAYER)
public static class ClearArtifactsCommand implements CommandHandler { public static class ClearArtifactsCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(GenshinPlayer player, List<String> args) {
@ -484,13 +515,14 @@ public final class PlayerCommands {
} }
} }
@Command(label = "changescene", aliases = {"scene"}, @Command(label = "changescene", aliases = {
usage = "Usage: changescene <scene id>", execution = Command.Execution.PLAYER) "scene" }, usage = "Usage: changescene <scene id>", execution = Command.Execution.PLAYER)
public static class ChangeSceneCommand implements CommandHandler { public static class ChangeSceneCommand implements CommandHandler {
@Override @Override
public void execute(GenshinPlayer player, List<String> args) { public void execute(GenshinPlayer player, List<String> args) {
if (args.size() < 1) { if (args.size() < 1) {
CommandHandler.sendMessage(player, "Usage: changescene <scene id>"); return; CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
return;
} }
try { try {
@ -501,8 +533,18 @@ public final class PlayerCommands {
CommandHandler.sendMessage(null, "Scene does not exist or you are already in it"); CommandHandler.sendMessage(null, "Scene does not exist or you are already in it");
} }
} catch (Exception e) { } catch (Exception e) {
CommandHandler.sendMessage(player, "Usage: changescene <scene id>"); return; CommandHandler.sendMessage(player, "Usage: changescene <scene id>");
return;
} }
} }
} }
@Command(label = "restart", usage = "Usage: restart - Restarts the current session", execution = Command.Execution.PLAYER)
public static class RestartCommand implements CommandHandler {
@Override
public void execute(GenshinPlayer player, List<String> args) {
player.getSession().close();
}
}
} }