diff options
Diffstat (limited to 'patch-remap/mache-vineflower-stripped/net/minecraft/server/players/PlayerList.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower-stripped/net/minecraft/server/players/PlayerList.java.patch | 968 |
1 files changed, 968 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower-stripped/net/minecraft/server/players/PlayerList.java.patch b/patch-remap/mache-vineflower-stripped/net/minecraft/server/players/PlayerList.java.patch new file mode 100644 index 0000000000..8555b90bc5 --- /dev/null +++ b/patch-remap/mache-vineflower-stripped/net/minecraft/server/players/PlayerList.java.patch @@ -0,0 +1,968 @@ +--- a/net/minecraft/server/players/PlayerList.java ++++ b/net/minecraft/server/players/PlayerList.java +@@ -98,6 +101,25 @@ + import net.minecraft.world.scores.Team; + import org.slf4j.Logger; + ++// CraftBukkit start ++import java.util.stream.Collectors; ++import net.minecraft.server.dedicated.DedicatedServer; ++import org.bukkit.Location; ++import org.bukkit.craftbukkit.CraftServer; ++import org.bukkit.craftbukkit.CraftWorld; ++import org.bukkit.craftbukkit.entity.CraftPlayer; ++import org.bukkit.craftbukkit.util.CraftChatMessage; ++import org.bukkit.craftbukkit.util.CraftLocation; ++import org.bukkit.entity.Player; ++import org.bukkit.event.player.PlayerChangedWorldEvent; ++import org.bukkit.event.player.PlayerJoinEvent; ++import org.bukkit.event.player.PlayerLoginEvent; ++import org.bukkit.event.player.PlayerQuitEvent; ++import org.bukkit.event.player.PlayerRespawnEvent; ++import org.bukkit.event.player.PlayerRespawnEvent.RespawnReason; ++import org.bukkit.event.player.PlayerSpawnChangeEvent; ++// CraftBukkit end ++ + public abstract class PlayerList { + public static final File USERBANLIST_FILE = new File("banned-players.json"); + public static final File IPBANLIST_FILE = new File("banned-ips.json"); +@@ -109,15 +132,17 @@ + private static final int SEND_PLAYER_INFO_INTERVAL = 600; + private static final SimpleDateFormat BAN_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); + private final MinecraftServer server; +- private final List<ServerPlayer> players = Lists.newArrayList(); ++ public final List<ServerPlayer> players = new java.util.concurrent.CopyOnWriteArrayList(); // CraftBukkit - ArrayList -> CopyOnWriteArrayList: Iterator safety + private final Map<UUID, ServerPlayer> playersByUUID = Maps.newHashMap(); +- private final UserBanList bans = new UserBanList(USERBANLIST_FILE); +- private final IpBanList ipBans = new IpBanList(IPBANLIST_FILE); +- private final ServerOpList ops = new ServerOpList(OPLIST_FILE); +- private final UserWhiteList whitelist = new UserWhiteList(WHITELIST_FILE); +- private final Map<UUID, ServerStatsCounter> stats = Maps.newHashMap(); +- private final Map<UUID, PlayerAdvancements> advancements = Maps.newHashMap(); +- private final PlayerDataStorage playerIo; ++ private final UserBanList bans; ++ private final IpBanList ipBans; ++ private final ServerOpList ops; ++ private final UserWhiteList whitelist; ++ // CraftBukkit start ++ // private final Map<UUID, ServerStatisticManager> stats; ++ // private final Map<UUID, AdvancementDataPlayer> advancements; ++ // CraftBukkit end ++ public final PlayerDataStorage playerIo; + private boolean doWhiteList; + private final LayeredRegistryAccess<RegistryLayer> registries; + protected final int maxPlayers; +@@ -127,7 +152,23 @@ + private static final boolean ALLOW_LOGOUTIVATOR = false; + private int sendAllPlayerInfoIn; + ++ // CraftBukkit start ++ private CraftServer cserver; ++ + public PlayerList(MinecraftServer server, LayeredRegistryAccess<RegistryLayer> registries, PlayerDataStorage playerIo, int maxPlayers) { ++ this.cserver = server.server = new CraftServer((DedicatedServer) server, this); ++ server.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance(); ++ server.reader.addCompleter(new org.bukkit.craftbukkit.command.ConsoleCommandCompleter(server.server)); ++ // CraftBukkit end ++ ++ this.bans = new UserBanList(PlayerList.USERBANLIST_FILE); ++ this.ipBans = new IpBanList(PlayerList.IPBANLIST_FILE); ++ this.ops = new ServerOpList(PlayerList.OPLIST_FILE); ++ this.whitelist = new UserWhiteList(PlayerList.WHITELIST_FILE); ++ // CraftBukkit start ++ // this.stats = Maps.newHashMap(); ++ // this.advancements = Maps.newHashMap(); ++ // CraftBukkit end + this.server = server; + this.registries = registries; + this.maxPlayers = maxPlayers; +@@ -146,61 +189,60 @@ + string = gameProfile.getName(); + } + +- CompoundTag compoundTag = this.load(serverPlayer); +- ResourceKey<Level> resourceKey = compoundTag != null +- ? DimensionType.parseLegacy(new Dynamic<>(NbtOps.INSTANCE, compoundTag.get("Dimension"))).resultOrPartial(LOGGER::error).orElse(Level.OVERWORLD) +- : Level.OVERWORLD; +- ServerLevel level = this.server.getLevel(resourceKey); +- ServerLevel serverLevel; +- if (level == null) { +- LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", resourceKey); +- serverLevel = this.server.overworld(); ++ CompoundTag nbttagcompound = this.load(entityplayer); ++ ResourceKey resourcekey; ++ // CraftBukkit start - Better rename detection ++ if (nbttagcompound != null && nbttagcompound.contains("bukkit")) { ++ CompoundTag bukkit = nbttagcompound.getCompound("bukkit"); ++ s = bukkit.contains("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s; ++ } ++ // CraftBukkit end ++ ++ if (nbttagcompound != null) { ++ DataResult<ResourceKey<Level>> dataresult = DimensionType.parseLegacy(new Dynamic(NbtOps.INSTANCE, nbttagcompound.get("Dimension"))); // CraftBukkit - decompile error ++ Logger logger = PlayerList.LOGGER; ++ ++ Objects.requireNonNull(logger); ++ resourcekey = (ResourceKey) dataresult.resultOrPartial(logger::error).orElse(entityplayer.serverLevel().dimension()); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD + } else { +- serverLevel = level; ++ resourcekey = entityplayer.serverLevel().dimension(); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD + } + +- serverPlayer.setServerLevel(serverLevel); +- String loggableAddress = connection.getLoggableAddress(this.server.logIPs()); +- LOGGER.info( +- "{}[{}] logged in with entity id {} at ({}, {}, {})", +- serverPlayer.getName().getString(), +- loggableAddress, +- serverPlayer.getId(), +- serverPlayer.getX(), +- serverPlayer.getY(), +- serverPlayer.getZ() +- ); +- LevelData levelData = serverLevel.getLevelData(); +- serverPlayer.loadGameTypes(compoundTag); +- ServerGamePacketListenerImpl serverGamePacketListenerImpl = new ServerGamePacketListenerImpl( +- this.server, connection, serverPlayer, commonListenerCookie +- ); +- GameRules gameRules = serverLevel.getGameRules(); +- boolean _boolean = gameRules.getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN); +- boolean _boolean1 = gameRules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO); +- boolean _boolean2 = gameRules.getBoolean(GameRules.RULE_LIMITED_CRAFTING); +- serverGamePacketListenerImpl.send( +- new ClientboundLoginPacket( +- serverPlayer.getId(), +- levelData.isHardcore(), +- this.server.levelKeys(), +- this.getMaxPlayers(), +- this.viewDistance, +- this.simulationDistance, +- _boolean1, +- !_boolean, +- _boolean2, +- serverPlayer.createCommonSpawnInfo(serverLevel) +- ) +- ); +- serverGamePacketListenerImpl.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked())); +- serverGamePacketListenerImpl.send(new ClientboundPlayerAbilitiesPacket(serverPlayer.getAbilities())); +- serverGamePacketListenerImpl.send(new ClientboundSetCarriedItemPacket(serverPlayer.getInventory().selected)); +- serverGamePacketListenerImpl.send(new ClientboundUpdateRecipesPacket(this.server.getRecipeManager().getRecipes())); +- this.sendPlayerPermissionLevel(serverPlayer); +- serverPlayer.getStats().markAllDirty(); +- serverPlayer.getRecipeBook().sendInitialRecipeBook(serverPlayer); +- this.updateEntireScoreboard(serverLevel.getScoreboard(), serverPlayer); ++ ResourceKey<Level> resourcekey1 = resourcekey; ++ ServerLevel worldserver = this.server.getLevel(resourcekey1); ++ ServerLevel worldserver1; ++ ++ if (worldserver == null) { ++ PlayerList.LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", resourcekey1); ++ worldserver1 = this.server.overworld(); ++ } else { ++ worldserver1 = worldserver; ++ } ++ ++ entityplayer.setServerLevel(worldserver1); ++ String s1 = networkmanager.getLoggableAddress(this.server.logIPs()); ++ ++ // CraftBukkit - Moved message to after join ++ // PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", new Object[]{entityplayer.getName().getString(), s1, entityplayer.getId(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ()}); ++ LevelData worlddata = worldserver1.getLevelData(); ++ ++ entityplayer.loadGameTypes(nbttagcompound); ++ ServerGamePacketListenerImpl playerconnection = new ServerGamePacketListenerImpl(this.server, networkmanager, entityplayer, commonlistenercookie); ++ GameRules gamerules = worldserver1.getGameRules(); ++ boolean flag = gamerules.getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN); ++ boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO); ++ boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING); ++ ++ playerconnection.send(new ClientboundLoginPacket(entityplayer.getId(), worlddata.isHardcore(), this.server.levelKeys(), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, flag2, entityplayer.createCommonSpawnInfo(worldserver1))); ++ entityplayer.getBukkitEntity().sendSupportedChannels(); // CraftBukkit ++ playerconnection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); ++ playerconnection.send(new ClientboundPlayerAbilitiesPacket(entityplayer.getAbilities())); ++ playerconnection.send(new ClientboundSetCarriedItemPacket(entityplayer.getInventory().selected)); ++ playerconnection.send(new ClientboundUpdateRecipesPacket(this.server.getRecipeManager().getRecipes())); ++ this.sendPlayerPermissionLevel(entityplayer); ++ entityplayer.getStats().markAllDirty(); ++ entityplayer.getRecipeBook().sendInitialRecipeBook(entityplayer); ++ this.updateEntireScoreboard(worldserver1.getScoreboard(), entityplayer); + this.server.invalidateStatus(); + MutableComponent mutableComponent; + if (serverPlayer.getGameProfile().getName().equalsIgnoreCase(string)) { +@@ -208,6 +251,9 @@ + } else { + mutableComponent = Component.translatable("multiplayer.player.joined.renamed", serverPlayer.getDisplayName(), string); + } ++ // CraftBukkit start ++ ichatmutablecomponent.withStyle(ChatFormatting.YELLOW); ++ String joinMessage = CraftChatMessage.fromComponent(ichatmutablecomponent); + + this.broadcastSystemMessage(mutableComponent.withStyle(ChatFormatting.YELLOW), false); + serverGamePacketListenerImpl.teleport(serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), serverPlayer.getYRot(), serverPlayer.getXRot()); +@@ -216,23 +262,81 @@ + serverPlayer.sendServerStatus(status); + } + +- serverPlayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players)); +- this.players.add(serverPlayer); +- this.playersByUUID.put(serverPlayer.getUUID(), serverPlayer); +- this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(serverPlayer))); +- this.sendLevelInfo(serverPlayer, serverLevel); +- serverLevel.addNewPlayer(serverPlayer); +- this.server.getCustomBossEvents().onPlayerConnect(serverPlayer); ++ // entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players)); // CraftBukkit - replaced with loop below ++ this.players.add(entityplayer); ++ this.playersByUUID.put(entityplayer.getUUID(), entityplayer); ++ // this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer))); // CraftBukkit - replaced with loop below + +- for (MobEffectInstance mobEffectInstance : serverPlayer.getActiveEffects()) { +- serverGamePacketListenerImpl.send(new ClientboundUpdateMobEffectPacket(serverPlayer.getId(), mobEffectInstance)); ++ // CraftBukkit start ++ CraftPlayer bukkitPlayer = entityplayer.getBukkitEntity(); ++ ++ // Ensure that player inventory is populated with its viewer ++ entityplayer.containerMenu.transferTo(entityplayer.containerMenu, bukkitPlayer); ++ ++ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(bukkitPlayer, joinMessage); ++ cserver.getPluginManager().callEvent(playerJoinEvent); ++ ++ if (!entityplayer.connection.isAcceptingMessages()) { ++ return; + } + +- if (compoundTag != null && compoundTag.contains("RootVehicle", 10)) { +- CompoundTag compound = compoundTag.getCompound("RootVehicle"); +- Entity entity = EntityType.loadEntityRecursive( +- compound.getCompound("Entity"), serverLevel, entity2 -> !serverLevel.addWithUUID(entity2) ? null : entity2 +- ); ++ joinMessage = playerJoinEvent.getJoinMessage(); ++ ++ if (joinMessage != null && joinMessage.length() > 0) { ++ for (Component line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) { ++ server.getPlayerList().broadcastSystemMessage(line, false); ++ } ++ } ++ // CraftBukkit end ++ ++ // CraftBukkit start - sendAll above replaced with this loop ++ ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer)); ++ ++ for (int i = 0; i < this.players.size(); ++i) { ++ ServerPlayer entityplayer1 = (ServerPlayer) this.players.get(i); ++ ++ if (entityplayer1.getBukkitEntity().canSee(bukkitPlayer)) { ++ entityplayer1.connection.send(packet); ++ } ++ ++ if (!bukkitPlayer.canSee(entityplayer1.getBukkitEntity())) { ++ continue; ++ } ++ ++ entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer1))); ++ } ++ entityplayer.sentListPacket = true; ++ // CraftBukkit end ++ ++ entityplayer.getEntityData().refresh(entityplayer); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn ++ ++ this.sendLevelInfo(entityplayer, worldserver1); ++ ++ // CraftBukkit start - Only add if the player wasn't moved in the event ++ if (entityplayer.level() == worldserver1 && !worldserver1.players().contains(entityplayer)) { ++ worldserver1.addNewPlayer(entityplayer); ++ this.server.getCustomBossEvents().onPlayerConnect(entityplayer); ++ } ++ ++ worldserver1 = entityplayer.serverLevel(); // CraftBukkit - Update in case join event changed it ++ // CraftBukkit end ++ Iterator iterator = entityplayer.getActiveEffects().iterator(); ++ ++ while (iterator.hasNext()) { ++ MobEffectInstance mobeffect = (MobEffectInstance) iterator.next(); ++ ++ playerconnection.send(new ClientboundUpdateMobEffectPacket(entityplayer.getId(), mobeffect)); ++ } ++ ++ if (nbttagcompound != null && nbttagcompound.contains("RootVehicle", 10)) { ++ CompoundTag nbttagcompound1 = nbttagcompound.getCompound("RootVehicle"); ++ // CraftBukkit start ++ ServerLevel finalWorldServer = worldserver1; ++ Entity entity = EntityType.loadEntityRecursive(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> { ++ return !finalWorldServer.addWithUUID(entity1) ? null : entity1; ++ // CraftBukkit end ++ }); ++ + if (entity != null) { + UUID uUID; + if (compound.hasUUID("Attach")) { +@@ -263,7 +376,9 @@ + } + } + +- serverPlayer.initInventoryMenu(); ++ entityplayer.initInventoryMenu(); ++ // CraftBukkit - Moved from above, added world ++ PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getName().getString(), s1, entityplayer.getId(), worldserver1.serverLevelData.getLevelName(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ()); + } + + protected void updateEntireScoreboard(ServerScoreboard scoreboard, ServerPlayer player) { +@@ -286,30 +415,31 @@ + } + + public void addWorldborderListener(ServerLevel level) { ++ if (playerIo != null) return; // CraftBukkit + level.getWorldBorder().addListener(new BorderChangeListener() { + @Override + public void onBorderSizeSet(WorldBorder border, double size) { +- PlayerList.this.broadcastAll(new ClientboundSetBorderSizePacket(border)); ++ PlayerList.this.broadcastAll(new ClientboundSetBorderSizePacket(border), border.world); // CraftBukkit + } + + @Override +- public void onBorderSizeLerping(WorldBorder border, double oldSize, double newSize, long time) { +- PlayerList.this.broadcastAll(new ClientboundSetBorderLerpSizePacket(border)); ++ public void onBorderSizeLerping(WorldBorder border, double oldSize, double d1, long newSize) { ++ PlayerList.this.broadcastAll(new ClientboundSetBorderLerpSizePacket(border), border.world); // CraftBukkit + } + + @Override +- public void onBorderCenterSet(WorldBorder border, double x, double z) { +- PlayerList.this.broadcastAll(new ClientboundSetBorderCenterPacket(border)); ++ public void onBorderCenterSet(WorldBorder border, double x, double d1) { ++ PlayerList.this.broadcastAll(new ClientboundSetBorderCenterPacket(border), border.world); // CraftBukkit + } + + @Override + public void onBorderSetWarningTime(WorldBorder border, int warningTime) { +- PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDelayPacket(border)); ++ PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDelayPacket(border), border.world); // CraftBukkit + } + + @Override + public void onBorderSetWarningBlocks(WorldBorder border, int warningBlocks) { +- PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDistancePacket(border)); ++ PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDistancePacket(border), border.world); // CraftBukkit + } + + @Override +@@ -338,68 +467,126 @@ + } + + protected void save(ServerPlayer player) { ++ if (!player.getBukkitEntity().isPersistent()) return; // CraftBukkit + this.playerIo.save(player); +- ServerStatsCounter serverStatsCounter = this.stats.get(player.getUUID()); +- if (serverStatsCounter != null) { +- serverStatsCounter.save(); ++ ServerStatsCounter serverstatisticmanager = (ServerStatsCounter) player.getStats(); // CraftBukkit ++ ++ if (serverstatisticmanager != null) { ++ serverstatisticmanager.save(); + } + +- PlayerAdvancements playerAdvancements = this.advancements.get(player.getUUID()); +- if (playerAdvancements != null) { +- playerAdvancements.save(); ++ PlayerAdvancements advancementdataplayer = (PlayerAdvancements) player.getAdvancements(); // CraftBukkit ++ ++ if (advancementdataplayer != null) { ++ advancementdataplayer.save(); + } + } + +- public void remove(ServerPlayer player) { +- ServerLevel serverLevel = player.serverLevel(); +- player.awardStat(Stats.LEAVE_GAME); +- this.save(player); +- if (player.isPassenger()) { +- Entity rootVehicle = player.getRootVehicle(); +- if (rootVehicle.hasExactlyOnePlayerPassenger()) { +- LOGGER.debug("Removing player mount"); +- player.stopRiding(); +- rootVehicle.getPassengersAndSelf().forEach(entity -> entity.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER)); ++ public String remove(ServerPlayer entityplayer) { // CraftBukkit - return string ++ ServerLevel worldserver = entityplayer.serverLevel(); ++ ++ entityplayer.awardStat(Stats.LEAVE_GAME); ++ ++ // CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it ++ // See SPIGOT-5799, SPIGOT-6145 ++ if (entityplayer.containerMenu != entityplayer.inventoryMenu) { ++ entityplayer.closeContainer(); ++ } ++ ++ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), entityplayer.kickLeaveMessage != null ? entityplayer.kickLeaveMessage : "\u00A7e" + entityplayer.getScoreboardName() + " left the game"); ++ cserver.getPluginManager().callEvent(playerQuitEvent); ++ entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); ++ ++ entityplayer.doTick(); // SPIGOT-924 ++ // CraftBukkit end ++ ++ this.save(entityplayer); ++ if (entityplayer.isPassenger()) { ++ Entity entity = entityplayer.getRootVehicle(); ++ ++ if (entity.hasExactlyOnePlayerPassenger()) { ++ PlayerList.LOGGER.debug("Removing player mount"); ++ entityplayer.stopRiding(); ++ entity.getPassengersAndSelf().forEach((entity1) -> { ++ entity1.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER); ++ }); + } + } + +- player.unRide(); +- serverLevel.removePlayerImmediately(player, Entity.RemovalReason.UNLOADED_WITH_PLAYER); +- player.getAdvancements().stopListening(); +- this.players.remove(player); +- this.server.getCustomBossEvents().onPlayerDisconnect(player); +- UUID uUID = player.getUUID(); +- ServerPlayer serverPlayer = this.playersByUUID.get(uUID); +- if (serverPlayer == player) { +- this.playersByUUID.remove(uUID); +- this.stats.remove(uUID); +- this.advancements.remove(uUID); ++ entityplayer.unRide(); ++ worldserver.removePlayerImmediately(entityplayer, Entity.RemovalReason.UNLOADED_WITH_PLAYER); ++ entityplayer.getAdvancements().stopListening(); ++ this.players.remove(entityplayer); ++ this.server.getCustomBossEvents().onPlayerDisconnect(entityplayer); ++ UUID uuid = entityplayer.getUUID(); ++ ServerPlayer entityplayer1 = (ServerPlayer) this.playersByUUID.get(uuid); ++ ++ if (entityplayer1 == entityplayer) { ++ this.playersByUUID.remove(uuid); ++ // CraftBukkit start ++ // this.stats.remove(uuid); ++ // this.advancements.remove(uuid); ++ // CraftBukkit end + } + +- this.broadcastAll(new ClientboundPlayerInfoRemovePacket(List.of(player.getUUID()))); ++ // CraftBukkit start ++ // this.broadcastAll(new ClientboundPlayerInfoRemovePacket(List.of(entityplayer.getUUID()))); ++ ClientboundPlayerInfoRemovePacket packet = new ClientboundPlayerInfoRemovePacket(List.of(entityplayer.getUUID())); ++ for (int i = 0; i < players.size(); i++) { ++ ServerPlayer entityplayer2 = (ServerPlayer) this.players.get(i); ++ ++ if (entityplayer2.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) { ++ entityplayer2.connection.send(packet); ++ } else { ++ entityplayer2.getBukkitEntity().onEntityRemove(entityplayer); ++ } ++ } ++ // This removes the scoreboard (and player reference) for the specific player in the manager ++ cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity()); ++ // CraftBukkit end ++ ++ return playerQuitEvent.getQuitMessage(); // CraftBukkit + } + +- @Nullable +- public Component canPlayerLogin(SocketAddress socketAddress, GameProfile gameProfile) { +- if (this.bans.isBanned(gameProfile)) { +- UserBanListEntry userBanListEntry = this.bans.get(gameProfile); +- MutableComponent mutableComponent = Component.translatable("multiplayer.disconnect.banned.reason", userBanListEntry.getReason()); +- if (userBanListEntry.getExpires() != null) { +- mutableComponent.append( +- Component.translatable("multiplayer.disconnect.banned.expiration", BAN_DATE_FORMAT.format(userBanListEntry.getExpires())) +- ); ++ // CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer ++ public ServerPlayer canPlayerLogin(ServerLoginPacketListenerImpl loginlistener, GameProfile gameprofile) { ++ MutableComponent ichatmutablecomponent; ++ ++ // Moved from processLogin ++ UUID uuid = gameprofile.getId(); ++ List<ServerPlayer> list = Lists.newArrayList(); ++ ++ ServerPlayer entityplayer; ++ ++ for (int i = 0; i < this.players.size(); ++i) { ++ entityplayer = (ServerPlayer) this.players.get(i); ++ if (entityplayer.getUUID().equals(uuid)) { ++ list.add(entityplayer); + } + +- return mutableComponent; +- } else if (!this.isWhiteListed(gameProfile)) { +- return Component.translatable("multiplayer.disconnect.not_whitelisted"); +- } else if (this.ipBans.isBanned(socketAddress)) { +- IpBanListEntry ipBanListEntry = this.ipBans.get(socketAddress); +- MutableComponent mutableComponent = Component.translatable("multiplayer.disconnect.banned_ip.reason", ipBanListEntry.getReason()); +- if (ipBanListEntry.getExpires() != null) { +- mutableComponent.append( +- Component.translatable("multiplayer.disconnect.banned_ip.expiration", BAN_DATE_FORMAT.format(ipBanListEntry.getExpires())) +- ); ++ Iterator iterator = list.iterator(); ++ ++ while (iterator.hasNext()) { ++ entityplayer = (ServerPlayer) iterator.next(); ++ save(entityplayer); // CraftBukkit - Force the player's inventory to be saved ++ entityplayer.connection.disconnect(Component.translatable("multiplayer.disconnect.duplicate_login")); ++ } ++ ++ // Instead of kicking then returning, we need to store the kick reason ++ // in the event, check with plugins to see if it's ok, and THEN kick ++ // depending on the outcome. ++ SocketAddress socketaddress = loginlistener.connection.getRemoteAddress(); ++ ++ ServerPlayer entity = new ServerPlayer(this.server, this.server.getLevel(Level.OVERWORLD), gameprofile, ClientInformation.createDefault()); ++ Player player = entity.getBukkitEntity(); ++ PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress()); ++ ++ if (getBans().isBanned(gameprofile) && !getBans().get(gameprofile).hasExpired()) { ++ UserBanListEntry gameprofilebanentry = (UserBanListEntry) this.bans.get(gameprofile); ++ ++ ichatmutablecomponent = Component.translatable("multiplayer.disconnect.banned.reason", gameprofilebanentry.getReason()); ++ if (gameprofilebanentry.getExpires() != null) { ++ ichatmutablecomponent.append((Component) Component.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires()))); + } + + return mutableComponent; +@@ -410,13 +621,18 @@ + } + } + +- public ServerPlayer getPlayerForLogin(GameProfile gameProfile, ClientInformation clientInformation) { +- return new ServerPlayer(this.server, this.server.overworld(), gameProfile, clientInformation); ++ // CraftBukkit start - added EntityPlayer ++ public ServerPlayer getPlayerForLogin(GameProfile gameprofile, ClientInformation clientinformation, ServerPlayer player) { ++ player.updateOptions(clientinformation); ++ return player; ++ // CraftBukkit end + } + +- public boolean disconnectAllPlayersWithProfile(GameProfile gameProfile) { +- UUID id = gameProfile.getId(); +- Set<ServerPlayer> set = Sets.newIdentityHashSet(); ++ public boolean disconnectAllPlayersWithProfile(GameProfile gameprofile, ServerPlayer player) { // CraftBukkit - added EntityPlayer ++ /* CraftBukkit startMoved up ++ UUID uuid = gameprofile.getId(); ++ Set<EntityPlayer> set = Sets.newIdentityHashSet(); ++ Iterator iterator = this.players.iterator(); + + for (ServerPlayer serverPlayer : this.players) { + if (serverPlayer.getUUID().equals(id)) { +@@ -434,44 +657,82 @@ + } + + return !set.isEmpty(); ++ */ ++ return player == null; ++ // CraftBukkit end + } + +- public ServerPlayer respawn(ServerPlayer player, boolean keepEverything) { +- this.players.remove(player); +- player.serverLevel().removePlayerImmediately(player, Entity.RemovalReason.DISCARDED); +- BlockPos respawnPosition = player.getRespawnPosition(); +- float respawnAngle = player.getRespawnAngle(); +- boolean isRespawnForced = player.isRespawnForced(); +- ServerLevel level = this.server.getLevel(player.getRespawnDimension()); +- Optional<Vec3> optional; +- if (level != null && respawnPosition != null) { +- optional = Player.findRespawnPositionAndUseSpawnBlock(level, respawnPosition, respawnAngle, isRespawnForced, keepEverything); ++ // CraftBukkit start ++ public ServerPlayer respawn(ServerPlayer entityplayer, boolean flag, RespawnReason reason) { ++ return this.respawn(entityplayer, this.server.getLevel(entityplayer.getRespawnDimension()), flag, null, true, reason); ++ } ++ ++ public ServerPlayer respawn(ServerPlayer entityplayer, ServerLevel worldserver, boolean flag, Location location, boolean avoidSuffocation, RespawnReason reason) { ++ entityplayer.stopRiding(); // CraftBukkit ++ this.players.remove(entityplayer); ++ entityplayer.serverLevel().removePlayerImmediately(entityplayer, Entity.RemovalReason.DISCARDED); ++ BlockPos blockposition = entityplayer.getRespawnPosition(); ++ float f = entityplayer.getRespawnAngle(); ++ boolean flag1 = entityplayer.isRespawnForced(); ++ /* CraftBukkit start ++ WorldServer worldserver = this.server.getLevel(entityplayer.getRespawnDimension()); ++ Optional optional; ++ ++ if (worldserver != null && blockposition != null) { ++ optional = EntityHuman.findRespawnPositionAndUseSpawnBlock(worldserver, blockposition, f, flag1, flag); + } else { + optional = Optional.empty(); + } + +- ServerLevel serverLevel = level != null && optional.isPresent() ? level : this.server.overworld(); +- ServerPlayer serverPlayer = new ServerPlayer(this.server, serverLevel, player.getGameProfile(), player.clientInformation()); +- serverPlayer.connection = player.connection; +- serverPlayer.restoreFrom(player, keepEverything); +- serverPlayer.setId(player.getId()); +- serverPlayer.setMainArm(player.getMainArm()); ++ WorldServer worldserver1 = worldserver != null && optional.isPresent() ? worldserver : this.server.overworld(); ++ EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver1, entityplayer.getGameProfile(), entityplayer.clientInformation()); ++ // */ ++ ServerPlayer entityplayer1 = entityplayer; ++ org.bukkit.World fromWorld = entityplayer.getBukkitEntity().getWorld(); ++ entityplayer.wonGame = false; ++ // CraftBukkit end + + for (String string : player.getTags()) { + serverPlayer.addTag(string); + } + +- boolean flag = false; +- if (optional.isPresent()) { +- BlockState blockState = serverLevel.getBlockState(respawnPosition); +- boolean isRespawnAnchor = blockState.is(Blocks.RESPAWN_ANCHOR); +- Vec3 vec3 = optional.get(); +- float f; +- if (!blockState.is(BlockTags.BEDS) && !isRespawnAnchor) { +- f = respawnAngle; +- } else { +- Vec3 vec31 = Vec3.atBottomCenterOf(respawnPosition).subtract(vec3).normalize(); +- f = (float)Mth.wrapDegrees(Mth.atan2(vec31.z, vec31.x) * 180.0F / (float)Math.PI - 90.0); ++ boolean flag2 = false; ++ ++ // CraftBukkit start - fire PlayerRespawnEvent ++ if (location == null) { ++ boolean isBedSpawn = false; ++ ServerLevel worldserver1 = this.server.getLevel(entityplayer.getRespawnDimension()); ++ if (worldserver1 != null) { ++ Optional optional; ++ ++ if (blockposition != null) { ++ optional = net.minecraft.world.entity.player.Player.findRespawnPositionAndUseSpawnBlock(worldserver1, blockposition, f, flag1, flag); ++ } else { ++ optional = Optional.empty(); ++ } ++ ++ if (optional.isPresent()) { ++ IBlockData iblockdata = worldserver1.getBlockState(blockposition); ++ boolean flag3 = iblockdata.is(Blocks.RESPAWN_ANCHOR); ++ Vec3 vec3d = (Vec3) optional.get(); ++ float f1; ++ ++ if (!iblockdata.is(BlockTags.BEDS) && !flag3) { ++ f1 = f; ++ } else { ++ Vec3 vec3d1 = Vec3.atBottomCenterOf(blockposition).subtract(vec3d).normalize(); ++ ++ f1 = (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); ++ } ++ ++ // entityplayer1.setRespawnPosition(worldserver1.dimension(), blockposition, f, flag1, false); // CraftBukkit - not required, just copies old location into reused entity ++ flag2 = !flag && flag3; ++ isBedSpawn = true; ++ location = CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), f1, 0.0F); ++ } else if (blockposition != null) { ++ entityplayer1.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F)); ++ entityplayer1.setRespawnPosition(null, null, 0f, false, false, PlayerSpawnChangeEvent.Cause.RESET); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed ++ } + } + + serverPlayer.moveTo(vec3.x, vec3.y, vec3.z, f, 0.0F); +@@ -481,43 +764,43 @@ + serverPlayer.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F)); + } + +- while (!serverLevel.noCollision(serverPlayer) && serverPlayer.getY() < (double)serverLevel.getMaxBuildHeight()) { +- serverPlayer.setPos(serverPlayer.getX(), serverPlayer.getY() + 1.0, serverPlayer.getZ()); ++ while (avoidSuffocation && !worldserver1.noCollision((Entity) entityplayer1) && entityplayer1.getY() < (double) worldserver1.getMaxBuildHeight()) { ++ // CraftBukkit end ++ entityplayer1.setPos(entityplayer1.getX(), entityplayer1.getY() + 1.0D, entityplayer1.getZ()); + } + +- byte b = (byte)(keepEverything ? 1 : 0); +- ServerLevel serverLevel1 = serverPlayer.serverLevel(); +- LevelData levelData = serverLevel1.getLevelData(); +- serverPlayer.connection.send(new ClientboundRespawnPacket(serverPlayer.createCommonSpawnInfo(serverLevel1), b)); +- serverPlayer.connection.teleport(serverPlayer.getX(), serverPlayer.getY(), serverPlayer.getZ(), serverPlayer.getYRot(), serverPlayer.getXRot()); +- serverPlayer.connection.send(new ClientboundSetDefaultSpawnPositionPacket(serverLevel.getSharedSpawnPos(), serverLevel.getSharedSpawnAngle())); +- serverPlayer.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked())); +- serverPlayer.connection +- .send(new ClientboundSetExperiencePacket(serverPlayer.experienceProgress, serverPlayer.totalExperience, serverPlayer.experienceLevel)); +- this.sendLevelInfo(serverPlayer, serverLevel); +- this.sendPlayerPermissionLevel(serverPlayer); +- serverLevel.addRespawnedPlayer(serverPlayer); +- this.players.add(serverPlayer); +- this.playersByUUID.put(serverPlayer.getUUID(), serverPlayer); +- serverPlayer.initInventoryMenu(); +- serverPlayer.setHealth(serverPlayer.getHealth()); +- if (flag) { +- serverPlayer.connection +- .send( +- new ClientboundSoundPacket( +- SoundEvents.RESPAWN_ANCHOR_DEPLETE, +- SoundSource.BLOCKS, +- (double)respawnPosition.getX(), +- (double)respawnPosition.getY(), +- (double)respawnPosition.getZ(), +- 1.0F, +- 1.0F, +- serverLevel.getRandom().nextLong() +- ) +- ); ++ int i = flag ? 1 : 0; ++ ServerLevel worldserver2 = entityplayer1.serverLevel(); ++ LevelData worlddata = worldserver2.getLevelData(); ++ ++ entityplayer1.connection.send(new ClientboundRespawnPacket(entityplayer1.createCommonSpawnInfo(worldserver2), (byte) i)); ++ entityplayer1.connection.teleport(CraftLocation.toBukkit(entityplayer1.position(), worldserver2.getWorld(), entityplayer1.getYRot(), entityplayer1.getXRot())); // CraftBukkit ++ entityplayer1.connection.send(new ClientboundSetDefaultSpawnPositionPacket(worldserver1.getSharedSpawnPos(), worldserver1.getSharedSpawnAngle())); ++ entityplayer1.connection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked())); ++ entityplayer1.connection.send(new ClientboundSetExperiencePacket(entityplayer1.experienceProgress, entityplayer1.totalExperience, entityplayer1.experienceLevel)); ++ this.sendLevelInfo(entityplayer1, worldserver1); ++ this.sendPlayerPermissionLevel(entityplayer1); ++ if (!entityplayer.connection.isDisconnected()) { ++ worldserver1.addRespawnedPlayer(entityplayer1); ++ this.players.add(entityplayer1); ++ this.playersByUUID.put(entityplayer1.getUUID(), entityplayer1); + } + +- return serverPlayer; ++ // Fire advancement trigger ++ entityplayer.triggerDimensionChangeTriggers(((CraftWorld) fromWorld).getHandle()); ++ ++ // Don't fire on respawn ++ if (fromWorld != location.getWorld()) { ++ PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(entityplayer.getBukkitEntity(), fromWorld); ++ server.server.getPluginManager().callEvent(event); ++ } ++ ++ // Save player file again if they were disconnected ++ if (entityplayer.connection.isDisconnected()) { ++ this.save(entityplayer); ++ } ++ // CraftBukkit end ++ return entityplayer1; + } + + public void sendPlayerPermissionLevel(ServerPlayer player) { +@@ -528,7 +823,18 @@ + + public void tick() { + if (++this.sendAllPlayerInfoIn > 600) { +- this.broadcastAll(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY), this.players)); ++ // CraftBukkit start ++ for (int i = 0; i < this.players.size(); ++i) { ++ final ServerPlayer target = (ServerPlayer) this.players.get(i); ++ ++ target.connection.send(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY), this.players.stream().filter(new Predicate<ServerPlayer>() { ++ @Override ++ public boolean test(ServerPlayer input) { ++ return target.getBukkitEntity().canSee(input.getBukkitEntity()); ++ } ++ }).collect(Collectors.toList()))); ++ } ++ // CraftBukkit end + this.sendAllPlayerInfoIn = 0; + } + } +@@ -539,6 +851,25 @@ + } + } + ++ // CraftBukkit start - add a world/entity limited version ++ public void broadcastAll(Packet packet, net.minecraft.world.entity.player.Player entityhuman) { ++ for (int i = 0; i < this.players.size(); ++i) { ++ ServerPlayer entityplayer = this.players.get(i); ++ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) { ++ continue; ++ } ++ ((ServerPlayer) this.players.get(i)).connection.send(packet); ++ } ++ } ++ ++ public void broadcastAll(Packet packet, Level world) { ++ for (int i = 0; i < world.players().size(); ++i) { ++ ((ServerPlayer) world.players().get(i)).connection.send(packet); ++ } ++ ++ } ++ // CraftBukkit end ++ + public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) { + for (ServerPlayer serverPlayer : this.players) { + if (serverPlayer.level().dimension() == dimension) { +@@ -621,6 +972,7 @@ + player.connection.send(new ClientboundEntityEventPacket(player, b)); + } + ++ player.getBukkitEntity().recalculatePermissions(); // CraftBukkit + this.server.getCommands().sendCommands(player); + } + +@@ -648,15 +999,23 @@ + return null; + } + +- public void broadcast(@Nullable Player except, double x, double y, double z, double radius, ResourceKey<Level> dimension, Packet<?> packet) { +- for (int i = 0; i < this.players.size(); i++) { +- ServerPlayer serverPlayer = this.players.get(i); +- if (serverPlayer != except && serverPlayer.level().dimension() == dimension) { +- double d = x - serverPlayer.getX(); +- double d1 = y - serverPlayer.getY(); +- double d2 = z - serverPlayer.getZ(); +- if (d * d + d1 * d1 + d2 * d2 < radius * radius) { +- serverPlayer.connection.send(packet); ++ public void broadcast(@Nullable net.minecraft.world.entity.player.Player except, double x, double d1, double y, double d3, ResourceKey<Level> z, Packet<?> packet) { ++ for (int i = 0; i < this.players.size(); ++i) { ++ ServerPlayer entityplayer = (ServerPlayer) this.players.get(i); ++ ++ // CraftBukkit start - Test if player receiving packet can see the source of the packet ++ if (except != null && !entityplayer.getBukkitEntity().canSee(except.getBukkitEntity())) { ++ continue; ++ } ++ // CraftBukkit end ++ ++ if (entityplayer != except && entityplayer.level().dimension() == z) { ++ double d4 = x - entityplayer.getX(); ++ double d5 = d1 - entityplayer.getY(); ++ double d6 = y - entityplayer.getZ(); ++ ++ if (d4 * d4 + d5 * d5 + d6 * d6 < d3 * d3) { ++ entityplayer.connection.send(packet); + } + } + } +@@ -688,14 +1048,19 @@ + } + + public void sendLevelInfo(ServerPlayer player, ServerLevel level) { +- WorldBorder worldBorder = this.server.overworld().getWorldBorder(); +- player.connection.send(new ClientboundInitializeBorderPacket(worldBorder)); ++ WorldBorder worldborder = player.level().getWorldBorder(); // CraftBukkit ++ ++ player.connection.send(new ClientboundInitializeBorderPacket(worldborder)); + player.connection.send(new ClientboundSetTimePacket(level.getGameTime(), level.getDayTime(), level.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT))); + player.connection.send(new ClientboundSetDefaultSpawnPositionPacket(level.getSharedSpawnPos(), level.getSharedSpawnAngle())); + if (level.isRaining()) { +- player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0.0F)); +- player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.RAIN_LEVEL_CHANGE, level.getRainLevel(1.0F))); +- player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE, level.getThunderLevel(1.0F))); ++ // CraftBukkit start - handle player weather ++ // entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.START_RAINING, 0.0F)); ++ // entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, worldserver.getRainLevel(1.0F))); ++ // entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, worldserver.getThunderLevel(1.0F))); ++ player.setPlayerWeather(org.bukkit.WeatherType.DOWNFALL, false); ++ player.updateWeather(-level.rainLevel, level.rainLevel, -level.thunderLevel, level.thunderLevel); ++ // CraftBukkit end + } + + player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F)); +@@ -704,8 +1069,16 @@ + + public void sendAllPlayerInfo(ServerPlayer player) { + player.inventoryMenu.sendAllDataToRemote(); +- player.resetSentInfo(); ++ // entityplayer.resetSentInfo(); ++ player.getBukkitEntity().updateScaledHealth(); // CraftBukkit - Update scaled health on respawn and worldchange ++ player.getEntityData().refresh(player); // CraftBukkkit - SPIGOT-7218: sync metadata + player.connection.send(new ClientboundSetCarriedItemPacket(player.getInventory().selected)); ++ // CraftBukkit start - from GameRules ++ int i = player.level().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23; ++ player.connection.send(new ClientboundEntityEventPacket(player, (byte) i)); ++ float immediateRespawn = player.level().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F; ++ player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.IMMEDIATE_RESPAWN, immediateRespawn)); ++ // CraftBukkit end + } + + public int getPlayerCount() { +@@ -758,11 +1134,22 @@ + } + + public void removeAll() { +- for (int i = 0; i < this.players.size(); i++) { +- this.players.get(i).connection.disconnect(Component.translatable("multiplayer.disconnect.server_shutdown")); ++ // CraftBukkit start - disconnect safely ++ for (ServerPlayer player : this.players) { ++ player.connection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message + } ++ // CraftBukkit end ++ + } + ++ // CraftBukkit start ++ public void broadcastMessage(Component[] iChatBaseComponents) { ++ for (Component component : iChatBaseComponents) { ++ broadcastSystemMessage(component, false); ++ } ++ } ++ // CraftBukkit end ++ + public void broadcastSystemMessage(Component message, boolean bypassHiddenChat) { + this.broadcastSystemMessage(message, serverPlayer -> message, bypassHiddenChat); + } +@@ -809,34 +1207,44 @@ + return message.hasSignature() && !message.hasExpiredServer(Instant.now()); + } + +- public ServerStatsCounter getPlayerStats(Player player) { +- UUID uUID = player.getUUID(); +- ServerStatsCounter serverStatsCounter = this.stats.get(uUID); +- if (serverStatsCounter == null) { ++ // CraftBukkit start ++ public ServerStatsCounter getPlayerStats(ServerPlayer entityhuman) { ++ ServerStatsCounter serverstatisticmanager = entityhuman.getStats(); ++ return serverstatisticmanager == null ? getPlayerStats(entityhuman.getUUID(), entityhuman.getDisplayName().getString()) : serverstatisticmanager; ++ } ++ ++ public ServerStatsCounter getPlayerStats(UUID uuid, String displayName) { ++ ServerPlayer entityhuman = this.getPlayer(uuid); ++ ServerStatsCounter serverstatisticmanager = entityhuman == null ? null : (ServerStatsCounter) entityhuman.getStats(); ++ // CraftBukkit end ++ ++ if (serverstatisticmanager == null) { + File file = this.server.getWorldPath(LevelResource.PLAYER_STATS_DIR).toFile(); + File file1 = new File(file, uUID + ".json"); + if (!file1.exists()) { +- File file2 = new File(file, player.getName().getString() + ".json"); ++ File file2 = new File(file, displayName + ".json"); // CraftBukkit + Path path = file2.toPath(); + if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) { + file2.renameTo(file1); + } + } + +- serverStatsCounter = new ServerStatsCounter(this.server, file1); +- this.stats.put(uUID, serverStatsCounter); ++ serverstatisticmanager = new ServerStatsCounter(this.server, file1); ++ // this.stats.put(uuid, serverstatisticmanager); // CraftBukkit + } + + return serverStatsCounter; + } + + public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) { +- UUID uUID = player.getUUID(); +- PlayerAdvancements playerAdvancements = this.advancements.get(uUID); +- if (playerAdvancements == null) { +- Path path = this.server.getWorldPath(LevelResource.PLAYER_ADVANCEMENTS_DIR).resolve(uUID + ".json"); +- playerAdvancements = new PlayerAdvancements(this.server.getFixerUpper(), this, this.server.getAdvancements(), path, player); +- this.advancements.put(uUID, playerAdvancements); ++ UUID uuid = player.getUUID(); ++ PlayerAdvancements advancementdataplayer = (PlayerAdvancements) player.getAdvancements(); // CraftBukkit ++ ++ if (advancementdataplayer == null) { ++ Path path = this.server.getWorldPath(LevelResource.PLAYER_ADVANCEMENTS_DIR).resolve(uuid + ".json"); ++ ++ advancementdataplayer = new PlayerAdvancements(this.server.getFixerUpper(), this, this.server.getAdvancements(), path, player); ++ // this.advancements.put(uuid, advancementdataplayer); // CraftBukkit + } + + playerAdvancements.setPlayer(player); +@@ -879,9 +1297,20 @@ + } + + public void reloadResources() { +- for (PlayerAdvancements playerAdvancements : this.advancements.values()) { +- playerAdvancements.reload(this.server.getAdvancements()); ++ // CraftBukkit start ++ /*Iterator iterator = this.advancements.values().iterator(); ++ ++ while (iterator.hasNext()) { ++ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) iterator.next(); ++ ++ advancementdataplayer.reload(this.server.getAdvancements()); ++ }*/ ++ ++ for (ServerPlayer player : players) { ++ player.getAdvancements().reload(this.server.getAdvancements()); ++ player.getAdvancements().flushDirty(player); // CraftBukkit - trigger immediate flush of advancements + } ++ // CraftBukkit end + + this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries))); + ClientboundUpdateRecipesPacket clientboundUpdateRecipesPacket = new ClientboundUpdateRecipesPacket(this.server.getRecipeManager().getRecipes()); |