9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-23 17:09:26 +00:00

New FakePlayer (#337)

---------

Co-authored-by: Lumine1909 <133463833+Lumine1909@users.noreply.github.com>
This commit is contained in:
violetc
2024-09-16 13:11:32 +08:00
committed by GitHub
parent 3436062db6
commit c33b54733c
20 changed files with 2927 additions and 1703 deletions

View File

@@ -108,10 +108,10 @@ index c8d39e6e1c570c9219f6066da273dc0130920519..96a074281d16a7f64058619da4b102f3
if (((List) object).size() >= i) {
return (List) object;
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 9e5e89aa5220dcfa278931bc891b055ae4ef0ad8..49e5749d838883a9a292c283daba136b9629b8eb 100644
index dc3972dd9340febc7540cc32160291c4945dec85..7ad8f7cbcf4238ba2d6771ef51fb09a42d0cdb96 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1690,7 +1690,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1692,7 +1692,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
private ServerStatus.Players buildPlayerStatus() {
@@ -169,7 +169,7 @@ index 64b63fe65f12d21e589c946c76e54f8f9fc8aeef..04d8c32316814d31e4216215c4c84cc7
}
// Leaves end - skip
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf628052eb 100644
index 103d9c9132fc8ed8fe590cd66a348c048432de34..47c4eefe1dd006a26b011182ccf659f943e9be60 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -124,6 +124,7 @@ import org.bukkit.event.player.PlayerSpawnChangeEvent;
@@ -188,7 +188,7 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
// CraftBukkit start
private CraftServer cserver;
@@ -182,6 +184,120 @@ public abstract class PlayerList {
@@ -182,6 +184,118 @@ public abstract class PlayerList {
}
abstract public void loadAndSaveFiles(); // Paper - fix converting txt to json file; moved from DedicatedPlayerList constructor
@@ -250,13 +250,11 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
+
+ // Leaves start - bot support
+ if (org.leavesmc.leaves.LeavesConfig.fakeplayerSupport) {
+ ServerBot bot = ServerBot.getBot(player.getScoreboardName().toLowerCase(java.util.Locale.ROOT));
+ ServerBot bot = this.server.getBotList().getBotByName(player.getScoreboardName());
+ if (bot != null) {
+ bot.die(bot.damageSources().fellOutOfWorld()); // Leaves - remove bot with the same name
+ this.playersByName.put(player.getScoreboardName().toLowerCase(java.util.Locale.ROOT), player);
+ this.playersByUUID.put(player.getUUID(), player);
+ this.server.getBotList().removeBot(bot, org.leavesmc.leaves.event.bot.BotRemoveEvent.RemoveReason.INTERNAL, player.getBukkitEntity(), false);
+ }
+ ServerBot.getBots().forEach(bot1 -> {
+ this.server.getBotList().bots.forEach(bot1 -> {
+ bot1.sendPlayerInfo(player);
+ bot1.sendFakeDataIfNeed(player, true);
+ }); // Leaves - render bot
@@ -309,7 +307,7 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
public void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie clientData) {
player.isRealPlayer = true; // Paper
player.loginTime = System.currentTimeMillis(); // Paper - Replace OfflinePlayer#getLastPlayed
@@ -328,6 +444,7 @@ public abstract class PlayerList {
@@ -328,6 +442,7 @@ public abstract class PlayerList {
// entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players)); // CraftBukkit - replaced with loop below
this.players.add(player);
@@ -317,7 +315,7 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
this.playersByName.put(player.getScoreboardName().toLowerCase(java.util.Locale.ROOT), player); // Spigot
this.playersByUUID.put(player.getUUID(), player);
// this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer))); // CraftBukkit - replaced with loop below
@@ -399,6 +516,12 @@ public abstract class PlayerList {
@@ -397,6 +512,12 @@ public abstract class PlayerList {
continue;
}
@@ -330,7 +328,7 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
onlinePlayers.add(entityplayer1); // Paper - Use single player info update packet on join
}
// Paper start - Use single player info update packet on join
@@ -603,6 +726,43 @@ public abstract class PlayerList {
@@ -601,6 +722,43 @@ public abstract class PlayerList {
}
@@ -374,7 +372,7 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
public net.kyori.adventure.text.Component remove(ServerPlayer entityplayer) { // CraftBukkit - return string // Paper - return Component
// Paper start - Fix kick event leave message not being sent
return this.remove(entityplayer, net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName())));
@@ -671,6 +831,7 @@ public abstract class PlayerList {
@@ -669,6 +827,7 @@ public abstract class PlayerList {
entityplayer.retireScheduler(); // Paper - Folia schedulers
entityplayer.getAdvancements().stopListening();
this.players.remove(entityplayer);
@@ -382,7 +380,7 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
this.playersByName.remove(entityplayer.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
this.server.getCustomBossEvents().onPlayerDisconnect(entityplayer);
UUID uuid = entityplayer.getUUID();
@@ -765,7 +926,7 @@ public abstract class PlayerList {
@@ -763,7 +922,7 @@ public abstract class PlayerList {
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, io.papermc.paper.adventure.PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
} else {
// return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null;
@@ -392,13 +390,13 @@ index 6e68ad42d4fff62e38f45fd09de26da3363dcdd9..d04ebc381ba3f52954b647bc76ccc9cf
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 59cdcf7b25c17705b613c83dea107934b683af28..b759025019120a0029c46506f1eede4eb85d7550 100644
index 97d09246b5bab3fe85491d06c7b16f932bcd1cb2..d4b4b4a4baf2321fa682d26885e07186375b53e7 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -311,6 +311,7 @@ public final class CraftServer implements Server {
private final io.papermc.paper.potion.PaperPotionBrewer potionBrewer; // Paper - Custom Potion Mixes
public final io.papermc.paper.SparksFly spark; // Paper - spark
private final org.leavesmc.leaves.entity.CraftBotManager botManager = new org.leavesmc.leaves.entity.CraftBotManager(); // Leaves
private final org.leavesmc.leaves.entity.CraftBotManager botManager; // Leaves
+ private final org.leavesmc.leaves.entity.CraftPhotographerManager photographerManager = new org.leavesmc.leaves.entity.CraftPhotographerManager(); // Leaves
// Paper start - Folia region threading API
@@ -412,7 +410,7 @@ index 59cdcf7b25c17705b613c83dea107934b683af28..b759025019120a0029c46506f1eede4e
@Override
public CraftPlayer apply(ServerPlayer player) {
return player.getBukkitEntity();
@@ -3237,4 +3238,11 @@ public final class CraftServer implements Server {
@@ -3238,4 +3239,11 @@ public final class CraftServer implements Server {
return botManager;
}
// Leaves end - Bot API