From 94b985d754a8f568bf831ef13c1549a7cdeeaba9 Mon Sep 17 00:00:00 2001 From: violetc <58360096+s-yh-china@users.noreply.github.com> Date: Sat, 28 Jan 2023 17:13:24 +0800 Subject: [PATCH] Update fakeplayer bukkit support --- patches/server/0010-Fakeplayer-support.patch | 55 ++++++++++++++++++-- patches/server/0018-No-chat-sign.patch | 4 +- patches/server/0047-BBOR-Protocol.patch | 4 +- patches/server/0059-Xaero-Map-Protocol.patch | 4 +- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/patches/server/0010-Fakeplayer-support.patch b/patches/server/0010-Fakeplayer-support.patch index c57d5f2d..6f963923 100644 --- a/patches/server/0010-Fakeplayer-support.patch +++ b/patches/server/0010-Fakeplayer-support.patch @@ -83,7 +83,7 @@ index 7d6d3c8556033d289fdadc489e73fba478fce41a..2bdd75f4e48a232d2cc7c24475caafa2 PlayerChangedWorldEvent changeEvent = new PlayerChangedWorldEvent(this.getBukkitEntity(), worldserver1.getWorld()); this.level.getCraftServer().getPluginManager().callEvent(changeEvent); diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 4b754f6eae683248d7fe11d6d6cb168d5dd696a2..9ecc6e12cea85e96f55705ff5ee831732c614c91 100644 +index 4b754f6eae683248d7fe11d6d6cb168d5dd696a2..5a5a3f84138b2f9a55f0a7c17004194dd324ebb4 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -80,6 +80,7 @@ import net.minecraft.server.ServerScoreboard; @@ -129,6 +129,41 @@ index 4b754f6eae683248d7fe11d6d6cb168d5dd696a2..9ecc6e12cea85e96f55705ff5ee83173 final net.kyori.adventure.text.Component jm = playerJoinEvent.joinMessage(); if (jm != null && !jm.equals(net.kyori.adventure.text.Component.empty())) { // Paper - Adventure +@@ -1063,11 +1076,16 @@ public abstract class PlayerList { + } + + public String[] getPlayerNamesArray() { +- String[] astring = new String[this.players.size()]; ++ String[] astring = new String[this.players.size() + ServerBot.getBots().size()]; // Leaves - fakeplayer support + + for (int i = 0; i < this.players.size(); ++i) { + astring[i] = ((ServerPlayer) this.players.get(i)).getGameProfile().getName(); + } ++ // Leaves start - fakeplayer support ++ for (int i = 0; i < ServerBot.getBots().size(); ++i) { ++ astring[i] = ((ServerPlayer) ServerBot.getBots().get(i)).getGameProfile().getName(); ++ } ++ // Leaves end - fakeplayer support + + return astring; + } +@@ -1532,4 +1550,16 @@ public abstract class PlayerList { + public boolean isAllowCheatsForAllPlayers() { + return this.allowCheatsForAllPlayers; + } ++ ++ // Leaves start - fakeplayer support ++ public void addNewBot(ServerBot bot) { ++ playersByName.put(bot.getScoreboardName().toLowerCase(java.util.Locale.ROOT), bot); ++ playersByUUID.put(bot.getUUID(), bot); ++ } ++ ++ public void removeBot(ServerBot bot) { ++ playersByName.remove(bot.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); ++ playersByUUID.remove(bot.getUUID()); ++ } ++ // Leaves end - fakeplayer support + } diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java index 61597ebe2f9faff43994c475074b87d11905e582..179d49336ec6ff0ac345a9df1c1236afa096af4c 100644 --- a/src/main/java/net/minecraft/world/entity/player/Player.java @@ -572,10 +607,10 @@ index 0000000000000000000000000000000000000000..d6466ee4db637106e1394bb462d875e5 +} diff --git a/src/main/java/top/leavesmc/leaves/bot/ServerBot.java b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java new file mode 100644 -index 0000000000000000000000000000000000000000..2ea8875e702dbec3df1019d2c789b6864d955ef9 +index 0000000000000000000000000000000000000000..4cd3b2ff3e0d1f0ba8358e8ba9b11cc0ac1e1a7f --- /dev/null +++ b/src/main/java/top/leavesmc/leaves/bot/ServerBot.java -@@ -0,0 +1,739 @@ +@@ -0,0 +1,749 @@ +package top.leavesmc.leaves.bot; + +import com.google.common.collect.Lists; @@ -601,6 +636,7 @@ index 0000000000000000000000000000000000000000..2ea8875e702dbec3df1019d2c789b686 +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.server.network.ServerGamePacketListenerImpl; +import net.minecraft.server.network.ServerPlayerConnection; ++import net.minecraft.stats.ServerStatsCounter; +import net.minecraft.util.Mth; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.damagesource.DamageSource; @@ -663,8 +699,9 @@ index 0000000000000000000000000000000000000000..2ea8875e702dbec3df1019d2c789b686 + private int doActionNumber; + + private final ItemStack defaultItem; ++ private final ServerStatsCounter stats; + -+ private static final Set bots = new HashSet<>(); ++ private static final List bots = new ArrayList<>(); + private static final Plugin MINECRAFT_PLUGIN = new MinecraftInternalPlugin(); + + private ServerBot(MinecraftServer server, ServerLevel world, GameProfile profile) { @@ -679,6 +716,8 @@ index 0000000000000000000000000000000000000000..2ea8875e702dbec3df1019d2c789b686 + this.doActionNumber = -1; + this.defaultItem = new ItemStack(Material.AIR); + this.removeOnDeath = true; ++ this.stats = new ServerStatsCounter(server, null); ++ server.getPlayerList().addNewBot(this); + } + + public static void createBot(Location loc, String name , String skinName) { @@ -805,6 +844,7 @@ index 0000000000000000000000000000000000000000..2ea8875e702dbec3df1019d2c789b686 + private void dieCheck() { + if (removeOnDeath) { + bots.remove(this); ++ server.getPlayerList().removeBot(this); + remove(RemovalReason.KILLED); + this.setDead(); + this.removeTab(); @@ -1265,6 +1305,11 @@ index 0000000000000000000000000000000000000000..2ea8875e702dbec3df1019d2c789b686 + this.newAction = botAction; + } + ++ @Override ++ public ServerStatsCounter getStats() { ++ return stats; ++ } ++ + public static ServerBot getBot(ServerPlayer player) { + ServerBot bot = null; + for (ServerBot b : bots) { @@ -1297,7 +1342,7 @@ index 0000000000000000000000000000000000000000..2ea8875e702dbec3df1019d2c789b686 + return true; + } + -+ public static Set getBots() { // It needs unmodifiable ++ public static List getBots() { // It needs unmodifiable + return bots; + } + diff --git a/patches/server/0018-No-chat-sign.patch b/patches/server/0018-No-chat-sign.patch index 402e40e7..69f77f7e 100644 --- a/patches/server/0018-No-chat-sign.patch +++ b/patches/server/0018-No-chat-sign.patch @@ -195,10 +195,10 @@ index 3472f7f9b98d6d9c9f6465872803ef17fa67486d..af8d49e22ee3447ea6acc4b64fcb5713 if (packet == null || this.processedDisconnect) { // Spigot return; diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 9ecc6e12cea85e96f55705ff5ee831732c614c91..f6c1dbde282e51322d655302340704e4a8af766f 100644 +index 5a5a3f84138b2f9a55f0a7c17004194dd324ebb4..04885ae3016559e2f1cb6359ad8b558e19c3595a 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java -@@ -1420,7 +1420,7 @@ public abstract class PlayerList { +@@ -1425,7 +1425,7 @@ public abstract class PlayerList { } public boolean verifyChatTrusted(PlayerChatMessage message) { // Paper - private -> public diff --git a/patches/server/0047-BBOR-Protocol.patch b/patches/server/0047-BBOR-Protocol.patch index 10a57412..30a9e550 100644 --- a/patches/server/0047-BBOR-Protocol.patch +++ b/patches/server/0047-BBOR-Protocol.patch @@ -32,7 +32,7 @@ index 78f112575c2f8973e8aa66fb0fc44a18ec4758b5..308879d9b04aa95a83926ba795da53ce ServerGamePacketListenerImpl.LOGGER.error("Couldn\'t dispatch custom payload", ex); this.disconnect("Invalid custom payload!", org.bukkit.event.player.PlayerKickEvent.Cause.INVALID_PAYLOAD); diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 7b309f0fd34ca1071f221d5b97288f400b69c00a..7ee442a40b1e658d87faeefa08b2b08dee25b692 100644 +index 4ea3a0ad550b95a6355d476760ec4a5db76f9b16..c93d74705bd0e3cc26674b1dad69f42adfb21439 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -335,6 +335,7 @@ public abstract class PlayerList { @@ -51,7 +51,7 @@ index 7b309f0fd34ca1071f221d5b97288f400b69c00a..7ee442a40b1e658d87faeefa08b2b08d // Paper end ServerLevel worldserver = entityplayer.getLevel(); -@@ -1540,7 +1542,7 @@ public abstract class PlayerList { +@@ -1545,7 +1547,7 @@ public abstract class PlayerList { entityplayer.connection.send(packetplayoutrecipeupdate); entityplayer.getRecipeBook().sendInitialRecipeBook(entityplayer); } diff --git a/patches/server/0059-Xaero-Map-Protocol.patch b/patches/server/0059-Xaero-Map-Protocol.patch index 47823b17..66f8efa8 100644 --- a/patches/server/0059-Xaero-Map-Protocol.patch +++ b/patches/server/0059-Xaero-Map-Protocol.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Xaero Map Protocol diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java -index 67c6d95e81f0df600916d797af4af552d6e77604..290807a539909f95e7a75b8ec7e21316eb3ecd57 100644 +index ebf9894e216b8f30ded5134c683ad68efd9c4ccd..e485b48158d65b4d47da83226f3a4ebe66dd78c3 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java -@@ -1264,6 +1264,7 @@ public abstract class PlayerList { +@@ -1269,6 +1269,7 @@ public abstract class PlayerList { player.connection.send(new ClientboundInitializeBorderPacket(worldborder)); player.connection.send(new ClientboundSetTimePacket(world.getGameTime(), world.getDayTime(), world.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); player.connection.send(new ClientboundSetDefaultSpawnPositionPacket(world.getSharedSpawnPos(), world.getSharedSpawnAngle()));