From 4339810ca379d2bd32acb938f64b36aa94010f3b Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 29 Apr 2022 17:53:42 +0800 Subject: [PATCH 1/4] Support Teleport from console --- README.md | 6 +-- README_zh-CN.md | 4 +- .../command/commands/TeleportCommand.java | 49 +++++++++++++------ 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 909aa6cc5..cbc09ea3e 100644 --- a/README.md +++ b/README.md @@ -114,8 +114,8 @@ There is a dummy user named "Server" in every player's friends list that you can | clearweapons | clearweapons | player.clearweapons | Client only | Deletes all unequipped and unlocked weapons, including 5-star rarity ones from your inventory. | clearwpns | | drop | drop [amount] | server.drop | Client only | Drops an item around you. | `d` `dropitem` | | give | give [player] [amount] [level] | player.give | Both side | Gives item(s) to you or the specified player. | `g` `item` `giveitem` | -| givechar | givechar | player.givechar | Both side | Gives the player a specified character. | givec | -| giveall | giveall [uid] [amount] | player.giveall | Both side | Gives all items. | givea | +| givechar | givechar | player.givechar | Both side | Gives the player a specified character. | givec | +| giveall | giveall [uid] [amount] | player.giveall | Both side | Gives all items. | givea | | godmode | godmode [uid] | player.godmode | Client only | Prevents you from taking damage. | | | heal | heal | player.heal | Client only | Heals all characters in your current team. | h | | help | help [command] | | Both side | Sends the help message or shows information about a specified command. | | @@ -134,7 +134,7 @@ There is a dummy user named "Server" in every player's friends list that you can | spawn | spanw [level] [amount] | server.spawn | Client only | Spawns an entity near you | | | stop | stop | server.stop | Both side | Stops the server | | | talent | talent | player.settalent | Client only | Sets talent level for your currently selected character | | -| teleport | teleport | player.teleport | Client only | Change the player's position. | tp | +| teleport | teleport [@player id] [scene id] | player.teleport | Both side | Change the player's position. | tp | | tpall | | player.tpall | Client only | Teleports all players in your world to your position | | | weather | weather | player.weather | Client only | Changes the weather | w | diff --git a/README_zh-CN.md b/README_zh-CN.md index 97f332f3a..1d19117e5 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -105,7 +105,7 @@ chmod +x gradlew 在每个玩家的朋友列表中都有一个名为“服务器”的虚拟用户,你可以通过发送消息来使用命令。命令也适用于其他聊天室,例如私人/团队聊天。 要在游戏中使用命令,需要添加 `/` 或 `!` 前缀,如 `/pos` -| 命令 | 用法 | 权限节点 | 可用性 | 注释 | 别名 | +| 命令 | 用法 | 权限节点 | 可用性 | 注释 | 别名 | | -------------- | -------------------------------------------- | ------------------------- | -------- | ------------------------------------------ | ----------------------------------------------- | | account | account <用户名> [uid] | | 仅服务端 | 通过指定用户名和uid增删账户 | | | broadcast | broadcast <消息内容> | server.broadcast | 均可使用 | 给所有玩家发送公告 | b | @@ -135,7 +135,7 @@ chmod +x gradlew | spawn | spanw <实体ID\|实体名称> [等级] [数量] | server.spawn | 仅客户端 | 在你周围生成实体 | | | stop | stop | server.stop | 均可使用 | 停止服务器 | | | talent | talent <天赋ID> <等级> | player.settalent | 仅客户端 | 设置当前角色的天赋等级 | | -| teleport | teleport | player.teleport | 仅客户端 | 传送玩家到指定坐标 | tp | +| teleport | teleport [@player id] [scene id] | player.teleport | 均可使用 | 传送玩家到指定坐标 | tp | | tpall | | player.tpall | 仅客户端 | 传送多人世界中所有的玩家到自身地点 | | | weather | weather <天气ID> <气候ID> | player.weather | 仅客户端 | 改变天气 | w | diff --git a/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java index c478118e3..238dccfa1 100644 --- a/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/TeleportCommand.java @@ -1,5 +1,6 @@ package emu.grasscutter.command.commands; +import emu.grasscutter.Grasscutter; import emu.grasscutter.command.Command; import emu.grasscutter.command.CommandHandler; import emu.grasscutter.game.player.Player; @@ -7,21 +8,39 @@ import emu.grasscutter.utils.Position; import java.util.List; -@Command(label = "teleport", usage = "teleport ", aliases = {"tp"}, +@Command(label = "teleport", usage = "teleport [@player id] [scene id]", aliases = {"tp"}, description = "Change the player's position.", permission = "player.teleport") public final class TeleportCommand implements CommandHandler { @Override public void execute(Player sender, List args) { - if (sender == null) { - CommandHandler.sendMessage(null, "Run this command in-game."); + int target; + if (args.size() < (sender == null ? 4 : 3)) { + CommandHandler.sendMessage(sender, sender == null ? "Usage: /tp @ [scene id]" : + "Usage: /tp [@] [scene id]"); return; } + if (args.get(0).startsWith("@")) { + try { + target = Integer.parseInt(args.get(0).substring(1)); + } catch (NumberFormatException e) { + CommandHandler.sendMessage(sender, "Invalid player id."); + return; + } + } else { + if (sender == null) { + CommandHandler.sendMessage(null, "You must specify a player id."); + return; + } + target = sender.getUid(); + } - if (args.size() < 3){ - CommandHandler.sendMessage(sender, "Usage: /tp [scene id]"); + Player targetPlayer = Grasscutter.getGameServer().getPlayerByUid(target); + if (targetPlayer == null) { + CommandHandler.sendMessage(sender, "Player not found or offline."); return; } + args = args.subList(args.get(0).startsWith("@") ? 1 : 0, args.size()); try { float x = 0f; @@ -29,39 +48,41 @@ public final class TeleportCommand implements CommandHandler { float z = 0f; if (args.get(0).contains("~")) { if (args.get(0).equals("~")) { - x = sender.getPos().getX(); + x = targetPlayer.getPos().getX(); } else { - x = Float.parseFloat(args.get(0).replace("~", "")) + sender.getPos().getX(); + x = Float.parseFloat(args.get(0).replace("~", "")) + targetPlayer.getPos().getX(); } } else { x = Float.parseFloat(args.get(0)); } if (args.get(1).contains("~")) { if (args.get(1).equals("~")) { - y = sender.getPos().getY(); + y = targetPlayer.getPos().getY(); } else { - y = Float.parseFloat(args.get(1).replace("~", "")) + sender.getPos().getY(); + y = Float.parseFloat(args.get(1).replace("~", "")) + targetPlayer.getPos().getY(); } } else { y = Float.parseFloat(args.get(1)); } if (args.get(2).contains("~")) { if (args.get(2).equals("~")) { - z = sender.getPos().getZ(); + z = targetPlayer.getPos().getZ(); } else { - z = Float.parseFloat(args.get(2).replace("~", "")) + sender.getPos().getZ(); + z = Float.parseFloat(args.get(2).replace("~", "")) + targetPlayer.getPos().getZ(); } } else { z = Float.parseFloat(args.get(2)); } - int sceneId = sender.getSceneId(); + int sceneId = targetPlayer.getSceneId(); if (args.size() == 4){ sceneId = Integer.parseInt(args.get(3)); } - Position target = new Position(x, y, z); - boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, target); + Position target_pos = new Position(x, y, z); + boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos); if (!result) { CommandHandler.sendMessage(sender, "Invalid position."); + } else { + CommandHandler.sendMessage(sender, "Teleported " + targetPlayer.getNickname() + " to " + x + "," + y + "," + z + " in scene " + sceneId); } } catch (NumberFormatException ignored) { CommandHandler.sendMessage(sender, "Invalid position."); From 2487e2af752275ac90bf8e8764adbbe285a0af98 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 29 Apr 2022 18:04:20 +0800 Subject: [PATCH 2/4] Support custom server avatar --- src/main/java/emu/grasscutter/Config.java | 1 + src/main/java/emu/grasscutter/GameConstants.java | 1 + .../server/packet/send/PacketGetPlayerFriendListRsp.java | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index 238ddb31c..56a1a0352 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -70,6 +70,7 @@ public final class Config { public int MaxAvatarsInTeamMultiplayer = 4; public int MaxEntityLimit = 1000; // Max entity limit per world. // TODO: Enforce later. public boolean WatchGacha = false; + public int ServerAvatarId = 10000007; public int[] WelcomeEmotes = {2007, 1002, 4010}; public String WelcomeMotd = "Welcome to Grasscutter emu"; public String WelcomeMailContent = "Hi there!\r\nFirst of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you! \r\n\r\nCheck out our:\r\n "; diff --git a/src/main/java/emu/grasscutter/GameConstants.java b/src/main/java/emu/grasscutter/GameConstants.java index dc07c32e1..ab48c01c7 100644 --- a/src/main/java/emu/grasscutter/GameConstants.java +++ b/src/main/java/emu/grasscutter/GameConstants.java @@ -11,6 +11,7 @@ public final class GameConstants { public static final int MAX_TEAMS = 4; public static final int MAIN_CHARACTER_MALE = 10000005; public static final int MAIN_CHARACTER_FEMALE = 10000007; + public static final int SERVER_AVATAR_ID = Grasscutter.getConfig().getGameServerOptions().ServerAvatarId; public static final Position START_POSITION = new Position(2747, 194, -1719); public static final int MAX_FRIENDS = 45; diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java index dbaa4b316..e085e6f6e 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java @@ -20,7 +20,7 @@ public class PacketGetPlayerFriendListRsp extends BasePacket { .setUid(GameConstants.SERVER_CONSOLE_UID) .setNickname("Server") .setLevel(1) - .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(GameConstants.MAIN_CHARACTER_FEMALE)) + .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(GameConstants.SERVER_AVATAR_ID)) .setWorldLevel(0) .setSignature("") .setLastActiveTime((int) (System.currentTimeMillis() / 1000f)) From c4bdfc26eb74fe43c31bcbf9c539cf474219b779 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 29 Apr 2022 18:59:24 +0800 Subject: [PATCH 3/4] Support custom server in-game nickname --- src/main/java/emu/grasscutter/Config.java | 1 + src/main/java/emu/grasscutter/GameConstants.java | 1 + .../server/packet/send/PacketGetPlayerFriendListRsp.java | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index 56a1a0352..c2d7850fd 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -51,6 +51,7 @@ public final class Config { public static class GameServerOptions { public String Name = "Test"; + public String NickName = "Server"; public String Ip = "0.0.0.0"; public String PublicIp = "127.0.0.1"; public int Port = 22102; diff --git a/src/main/java/emu/grasscutter/GameConstants.java b/src/main/java/emu/grasscutter/GameConstants.java index ab48c01c7..317221ec6 100644 --- a/src/main/java/emu/grasscutter/GameConstants.java +++ b/src/main/java/emu/grasscutter/GameConstants.java @@ -12,6 +12,7 @@ public final class GameConstants { public static final int MAIN_CHARACTER_MALE = 10000005; public static final int MAIN_CHARACTER_FEMALE = 10000007; public static final int SERVER_AVATAR_ID = Grasscutter.getConfig().getGameServerOptions().ServerAvatarId; + public static final String SERVER_AVATAR_NAME = Grasscutter.getConfig().getGameServerOptions().NickName; public static final Position START_POSITION = new Position(2747, 194, -1719); public static final int MAX_FRIENDS = 45; diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java index e085e6f6e..d7a9427b8 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketGetPlayerFriendListRsp.java @@ -18,7 +18,7 @@ public class PacketGetPlayerFriendListRsp extends BasePacket { FriendBrief serverFriend = FriendBrief.newBuilder() .setUid(GameConstants.SERVER_CONSOLE_UID) - .setNickname("Server") + .setNickname(GameConstants.SERVER_AVATAR_NAME) .setLevel(1) .setProfilePicture(ProfilePicture.newBuilder().setAvatarId(GameConstants.SERVER_AVATAR_ID)) .setWorldLevel(0) From 8c3333dbea5089ac4149140330c218c2f8f7c179 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 29 Apr 2022 19:37:51 +0800 Subject: [PATCH 4/4] Change NickName to ServerNickname --- src/main/java/emu/grasscutter/Config.java | 2 +- src/main/java/emu/grasscutter/GameConstants.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/emu/grasscutter/Config.java b/src/main/java/emu/grasscutter/Config.java index c2d7850fd..109c7b8ee 100644 --- a/src/main/java/emu/grasscutter/Config.java +++ b/src/main/java/emu/grasscutter/Config.java @@ -51,7 +51,6 @@ public final class Config { public static class GameServerOptions { public String Name = "Test"; - public String NickName = "Server"; public String Ip = "0.0.0.0"; public String PublicIp = "127.0.0.1"; public int Port = 22102; @@ -71,6 +70,7 @@ public final class Config { public int MaxAvatarsInTeamMultiplayer = 4; public int MaxEntityLimit = 1000; // Max entity limit per world. // TODO: Enforce later. public boolean WatchGacha = false; + public String ServerNickname = "Server"; public int ServerAvatarId = 10000007; public int[] WelcomeEmotes = {2007, 1002, 4010}; public String WelcomeMotd = "Welcome to Grasscutter emu"; diff --git a/src/main/java/emu/grasscutter/GameConstants.java b/src/main/java/emu/grasscutter/GameConstants.java index 317221ec6..39b28b736 100644 --- a/src/main/java/emu/grasscutter/GameConstants.java +++ b/src/main/java/emu/grasscutter/GameConstants.java @@ -11,8 +11,8 @@ public final class GameConstants { public static final int MAX_TEAMS = 4; public static final int MAIN_CHARACTER_MALE = 10000005; public static final int MAIN_CHARACTER_FEMALE = 10000007; + public static final String SERVER_AVATAR_NAME = Grasscutter.getConfig().getGameServerOptions().ServerNickname; public static final int SERVER_AVATAR_ID = Grasscutter.getConfig().getGameServerOptions().ServerAvatarId; - public static final String SERVER_AVATAR_NAME = Grasscutter.getConfig().getGameServerOptions().NickName; public static final Position START_POSITION = new Position(2747, 194, -1719); public static final int MAX_FRIENDS = 45;