2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
2024-04-23 17:15:00 +02:00
@@ -103,6 +103,27 @@
2023-12-05 17:40:00 +01:00
import net.minecraft.world.scores.ScoreboardTeam;
2022-02-28 16:00:00 +01:00
import org.slf4j.Logger;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
2021-06-11 07:00:00 +02:00
+import java.util.stream.Collectors;
2021-03-15 23:00:00 +01:00
+import net.minecraft.server.dedicated.DedicatedServer;
+import net.minecraft.server.network.LoginListener;
2021-06-11 07:00:00 +02:00
+import org.bukkit.Location;
2014-11-25 22:32:16 +01:00
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
2021-06-20 01:27:32 +02:00
+import org.bukkit.craftbukkit.entity.CraftPlayer;
2014-12-12 08:20:42 +01:00
+import org.bukkit.craftbukkit.util.CraftChatMessage;
2023-04-19 11:59:19 +02:00
+import org.bukkit.craftbukkit.util.CraftLocation;
2014-11-25 22:32:16 +01:00
+import org.bukkit.entity.Player;
2024-02-21 10:55:34 +01:00
+import org.bukkit.event.entity.EntityRemoveEvent;
2014-11-25 22:32:16 +01:00
+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;
2023-04-10 00:26:45 +02:00
+import org.bukkit.event.player.PlayerRespawnEvent.RespawnReason;
2023-04-17 11:33:17 +02:00
+import org.bukkit.event.player.PlayerSpawnChangeEvent;
2014-11-25 22:32:16 +01:00
+// CraftBukkit end
+
public abstract class PlayerList {
2021-06-11 07:00:00 +02:00
public static final File USERBANLIST_FILE = new File("banned-players.json");
2024-04-23 17:15:00 +02:00
@@ -115,14 +136,16 @@
2021-06-11 07:00:00 +02:00
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");
2014-11-25 22:32:16 +01:00
private final MinecraftServer server;
2015-06-06 11:33:48 +02:00
- public final List<EntityPlayer> players = Lists.newArrayList();
+ public final List<EntityPlayer> players = new java.util.concurrent.CopyOnWriteArrayList(); // CraftBukkit - ArrayList -> CopyOnWriteArrayList: Iterator safety
2021-06-11 07:00:00 +02:00
private final Map<UUID, EntityPlayer> playersByUUID = Maps.newHashMap();
private final GameProfileBanList bans;
private final IpBanList ipBans;
private final OpList ops;
2017-07-17 01:55:47 +02:00
private final WhiteList whitelist;
2021-06-11 07:00:00 +02:00
- private final Map<UUID, ServerStatisticManager> stats;
- private final Map<UUID, AdvancementDataPlayer> advancements;
2017-07-17 01:55:47 +02:00
+ // CraftBukkit start
2021-06-20 01:27:32 +02:00
+ // private final Map<UUID, ServerStatisticManager> stats;
+ // private final Map<UUID, AdvancementDataPlayer> advancements;
2017-07-17 01:55:47 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
public final WorldNBTStorage playerIo;
private boolean doWhiteList;
2022-12-07 17:00:00 +01:00
private final LayeredRegistryAccess<RegistryLayer> registries;
2024-04-23 17:15:00 +02:00
@@ -133,13 +156,23 @@
2021-06-11 07:00:00 +02:00
private static final boolean ALLOW_LOGOUTIVATOR = false;
private int sendAllPlayerInfoIn;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ private CraftServer cserver;
+
2022-12-07 17:00:00 +01:00
public PlayerList(MinecraftServer minecraftserver, LayeredRegistryAccess<RegistryLayer> layeredregistryaccess, WorldNBTStorage worldnbtstorage, int i) {
2019-04-23 04:00:00 +02:00
+ this.cserver = minecraftserver.server = new CraftServer((DedicatedServer) minecraftserver, this);
2014-11-25 22:32:16 +01:00
+ minecraftserver.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance();
+ minecraftserver.reader.addCompleter(new org.bukkit.craftbukkit.command.ConsoleCommandCompleter(minecraftserver.server));
+ // CraftBukkit end
2016-06-25 12:38:13 +02:00
+
2021-06-11 07:00:00 +02:00
this.bans = new GameProfileBanList(PlayerList.USERBANLIST_FILE);
this.ipBans = new IpBanList(PlayerList.IPBANLIST_FILE);
this.ops = new OpList(PlayerList.OPLIST_FILE);
this.whitelist = new WhiteList(PlayerList.WHITELIST_FILE);
- this.stats = Maps.newHashMap();
- this.advancements = Maps.newHashMap();
2017-07-17 01:55:47 +02:00
+ // CraftBukkit start
2021-06-20 01:27:32 +02:00
+ // this.stats = Maps.newHashMap();
+ // this.advancements = Maps.newHashMap();
2017-07-17 01:55:47 +02:00
+ // CraftBukkit end
this.server = minecraftserver;
2022-12-07 17:00:00 +01:00
this.registries = layeredregistryaccess;
2023-09-21 18:40:00 +02:00
this.maxPlayers = i;
2024-04-23 17:15:00 +02:00
@@ -149,25 +182,34 @@
public void placeNewPlayer(NetworkManager networkmanager, EntityPlayer entityplayer, CommonListenerCookie commonlistenercookie) {
GameProfile gameprofile = entityplayer.getGameProfile();
UserCache usercache = this.server.getProfileCache();
- Optional optional;
+ // Optional optional; // CraftBukkit - decompile error
String s;
if (usercache != null) {
- optional = usercache.get(gameprofile.getId());
+ Optional<GameProfile> optional = usercache.get(gameprofile.getId()); // CraftBukkit - decompile error
s = (String) optional.map(GameProfile::getName).orElse(gameprofile.getName());
usercache.add(gameprofile);
} else {
s = gameprofile.getName();
}
2023-06-07 17:30:00 +02:00
2024-04-23 17:15:00 +02:00
- optional = this.load(entityplayer);
+ Optional<NBTTagCompound> optional = this.load(entityplayer); // CraftBukkit - decompile error
2015-02-04 20:29:07 +01:00
+ // CraftBukkit start - Better rename detection
2024-04-23 17:15:00 +02:00
+ if (optional.isPresent()) {
+ NBTTagCompound nbttagcompound = optional.get();
+ if (nbttagcompound.contains("bukkit")) {
+ NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit");
+ s = bukkit.contains("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s;
+ }
2015-02-04 20:29:07 +01:00
+ }
+ // CraftBukkit end
2024-04-23 17:15:00 +02:00
ResourceKey<World> resourcekey = (ResourceKey) optional.flatMap((nbttagcompound) -> {
2022-02-28 16:00:00 +01:00
- DataResult dataresult = DimensionManager.parseLegacy(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("Dimension")));
+ DataResult<ResourceKey<World>> dataresult = DimensionManager.parseLegacy(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("Dimension"))); // CraftBukkit - decompile error
Logger logger = PlayerList.LOGGER;
Objects.requireNonNull(logger);
2024-04-23 17:15:00 +02:00
return dataresult.resultOrPartial(logger::error);
- }).orElse(World.OVERWORLD);
+ }).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
WorldServer worldserver = this.server.getLevel(resourcekey);
WorldServer worldserver1;
2023-10-21 07:25:23 +02:00
2024-04-23 17:15:00 +02:00
@@ -181,10 +223,11 @@
2023-09-21 18:40:00 +02:00
entityplayer.setServerLevel(worldserver1);
String s1 = networkmanager.getLoggableAddress(this.server.logIPs());
2014-11-25 22:32:16 +01:00
2022-02-28 16:00:00 +01:00
- PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", new Object[]{entityplayer.getName().getString(), s1, entityplayer.getId(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ()});
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - Moved message to after join
2022-02-28 16:00:00 +01:00
+ // PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", new Object[]{entityplayer.getName().getString(), s1, entityplayer.getId(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ()});
2021-11-21 23:00:00 +01:00
WorldData worlddata = worldserver1.getLevelData();
2016-11-17 02:41:03 +01:00
2024-04-23 17:15:00 +02:00
- entityplayer.loadGameTypes((NBTTagCompound) optional.orElse((Object) null));
+ entityplayer.loadGameTypes((NBTTagCompound) optional.orElse(null)); // CraftBukkit - decompile error
PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer, commonlistenercookie);
networkmanager.setupInboundProtocol(GameProtocols.SERVERBOUND.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection);
@@ -194,6 +237,7 @@
2023-09-21 18:40:00 +02:00
boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING);
2014-11-25 22:32:16 +01:00
2024-04-23 17:15:00 +02:00
playerconnection.send(new PacketPlayOutLogin(entityplayer.getId(), worlddata.isHardcore(), this.server.levelKeys(), this.getMaxPlayers(), this.viewDistance, this.simulationDistance, flag1, !flag, flag2, entityplayer.createCommonSpawnInfo(worldserver1), this.server.enforceSecureProfile()));
2014-11-25 22:32:16 +01:00
+ entityplayer.getBukkitEntity().sendSupportedChannels(); // CraftBukkit
2021-11-21 23:00:00 +01:00
playerconnection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
2023-09-21 18:40:00 +02:00
playerconnection.send(new PacketPlayOutAbilities(entityplayer.getAbilities()));
playerconnection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected));
2024-04-23 17:15:00 +02:00
@@ -210,8 +254,10 @@
2019-04-23 04:00:00 +02:00
} else {
2022-06-07 18:00:00 +02:00
ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.player.joined.renamed", entityplayer.getDisplayName(), s);
2015-02-04 00:38:21 +01:00
}
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2022-06-07 18:00:00 +02:00
+ ichatmutablecomponent.withStyle(EnumChatFormat.YELLOW);
+ String joinMessage = CraftChatMessage.fromComponent(ichatmutablecomponent);
2014-11-25 22:32:16 +01:00
2022-07-27 20:00:00 +02:00
- this.broadcastSystemMessage(ichatmutablecomponent.withStyle(EnumChatFormat.YELLOW), false);
2021-11-21 23:00:00 +01:00
playerconnection.teleport(entityplayer.getX(), entityplayer.getY(), entityplayer.getZ(), entityplayer.getYRot(), entityplayer.getXRot());
2023-03-14 17:30:00 +01:00
ServerPing serverping = this.server.getStatus();
2024-04-23 17:15:00 +02:00
@@ -219,13 +265,64 @@
2023-06-09 00:24:31 +02:00
entityplayer.sendServerStatus(serverping);
}
- entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players));
+ // entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(this.players)); // CraftBukkit - replaced with loop below
2019-04-23 04:00:00 +02:00
this.players.add(entityplayer);
2021-11-21 23:00:00 +01:00
this.playersByUUID.put(entityplayer.getUUID(), entityplayer);
2022-12-07 17:00:00 +01:00
- this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer)));
+ // this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer))); // CraftBukkit - replaced with loop below
2019-04-23 04:00:00 +02:00
+
+ // CraftBukkit start
2021-06-20 01:27:32 +02:00
+ 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);
2019-04-23 04:00:00 +02:00
+ cserver.getPluginManager().callEvent(playerJoinEvent);
+
2023-03-14 17:30:00 +01:00
+ if (!entityplayer.connection.isAcceptingMessages()) {
2019-04-23 04:00:00 +02:00
+ return;
+ }
+
+ joinMessage = playerJoinEvent.getJoinMessage();
+
+ if (joinMessage != null && joinMessage.length() > 0) {
+ for (IChatBaseComponent line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) {
2022-07-27 20:00:00 +02:00
+ server.getPlayerList().broadcastSystemMessage(line, false);
2019-04-23 04:00:00 +02:00
+ }
+ }
+ // CraftBukkit end
+
+ // CraftBukkit start - sendAll above replaced with this loop
2022-12-07 17:00:00 +01:00
+ ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer));
+
+ for (int i = 0; i < this.players.size(); ++i) {
2019-04-23 04:00:00 +02:00
+ EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
+
2021-06-20 01:27:32 +02:00
+ if (entityplayer1.getBukkitEntity().canSee(bukkitPlayer)) {
2021-11-21 23:00:00 +01:00
+ entityplayer1.connection.send(packet);
2019-04-23 04:00:00 +02:00
+ }
+
2021-06-20 01:27:32 +02:00
+ if (!bukkitPlayer.canSee(entityplayer1.getBukkitEntity())) {
2019-04-23 04:00:00 +02:00
+ continue;
+ }
+
2022-12-07 17:00:00 +01:00
+ entityplayer.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer1)));
+ }
2019-04-23 04:00:00 +02:00
+ entityplayer.sentListPacket = true;
2015-02-04 00:38:21 +01:00
+ // CraftBukkit end
2022-12-07 17:00:00 +01:00
+
2024-04-23 17:15:00 +02:00
+ entityplayer.refreshEntityData(entityplayer); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn
2023-03-14 17:30:00 +01:00
+
this.sendLevelInfo(entityplayer, worldserver1);
- worldserver1.addNewPlayer(entityplayer);
- this.server.getCustomBossEvents().onPlayerConnect(entityplayer);
2019-04-23 04:00:00 +02:00
+
+ // CraftBukkit start - Only add if the player wasn't moved in the event
2023-06-07 17:30:00 +02:00
+ if (entityplayer.level() == worldserver1 && !worldserver1.players().contains(entityplayer)) {
2021-11-21 23:00:00 +01:00
+ worldserver1.addNewPlayer(entityplayer);
+ this.server.getCustomBossEvents().onPlayerConnect(entityplayer);
2021-06-20 01:27:32 +02:00
+ }
+
2023-06-07 17:30:00 +02:00
+ worldserver1 = entityplayer.serverLevel(); // CraftBukkit - Update in case join event changed it
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2023-09-21 18:40:00 +02:00
Iterator iterator = entityplayer.getActiveEffects().iterator();
while (iterator.hasNext()) {
2024-04-23 17:15:00 +02:00
@@ -236,8 +333,9 @@
2019-04-23 04:00:00 +02:00
2024-04-23 17:15:00 +02:00
if (optional.isPresent() && ((NBTTagCompound) optional.get()).contains("RootVehicle", 10)) {
NBTTagCompound nbttagcompound = ((NBTTagCompound) optional.get()).getCompound("RootVehicle");
+ WorldServer finalWorldServer = worldserver1; // CraftBukkit - decompile error
Entity entity = EntityTypes.loadEntityRecursive(nbttagcompound.getCompound("Entity"), worldserver1, (entity1) -> {
2021-11-21 23:00:00 +01:00
- return !worldserver1.addWithUUID(entity1) ? null : entity1;
2024-04-23 17:15:00 +02:00
+ return !finalWorldServer.addWithUUID(entity1) ? null : entity1; // CraftBukkit - decompile error
2019-04-23 04:00:00 +02:00
});
if (entity != null) {
2024-04-23 17:15:00 +02:00
@@ -268,18 +366,20 @@
2024-02-21 10:55:34 +01:00
if (!entityplayer.isPassenger()) {
PlayerList.LOGGER.warn("Couldn't reattach entity to player");
- entity.discard();
+ entity.discard(null); // CraftBukkit - add Bukkit remove cause
iterator1 = entity.getIndirectPassengers().iterator();
while (iterator1.hasNext()) {
entity1 = (Entity) iterator1.next();
- entity1.discard();
+ entity1.discard(null); // CraftBukkit - add Bukkit remove cause
}
}
}
2014-11-25 22:32:16 +01:00
}
2021-11-21 23:00:00 +01:00
entityplayer.initInventoryMenu();
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - Moved from above, added world
2021-11-21 23:00:00 +01:00
+ PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getName().getString(), s1, entityplayer.getId(), worldserver1.serverLevelData.getLevelName(), entityplayer.getX(), entityplayer.getY(), entityplayer.getZ());
2014-11-25 22:32:16 +01:00
}
2021-11-21 23:00:00 +01:00
public void updateEntireScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
2024-04-23 17:15:00 +02:00
@@ -316,30 +416,31 @@
2014-11-25 22:32:16 +01:00
}
2021-11-21 23:00:00 +01:00
public void addWorldborderListener(WorldServer worldserver) {
2021-06-11 07:00:00 +02:00
+ if (playerIo != null) return; // CraftBukkit
2021-11-21 23:00:00 +01:00
worldserver.getWorldBorder().addListener(new IWorldBorderListener() {
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void onBorderSizeSet(WorldBorder worldborder, double d0) {
- PlayerList.this.broadcastAll(new ClientboundSetBorderSizePacket(worldborder));
+ PlayerList.this.broadcastAll(new ClientboundSetBorderSizePacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void onBorderSizeLerping(WorldBorder worldborder, double d0, double d1, long i) {
- PlayerList.this.broadcastAll(new ClientboundSetBorderLerpSizePacket(worldborder));
+ PlayerList.this.broadcastAll(new ClientboundSetBorderLerpSizePacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void onBorderCenterSet(WorldBorder worldborder, double d0, double d1) {
- PlayerList.this.broadcastAll(new ClientboundSetBorderCenterPacket(worldborder));
+ PlayerList.this.broadcastAll(new ClientboundSetBorderCenterPacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void onBorderSetWarningTime(WorldBorder worldborder, int i) {
- PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDelayPacket(worldborder));
+ PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDelayPacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2021-11-21 23:00:00 +01:00
public void onBorderSetWarningBlocks(WorldBorder worldborder, int i) {
- PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDistancePacket(worldborder));
+ PlayerList.this.broadcastAll(new ClientboundSetBorderWarningDistancePacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2024-04-23 17:15:00 +02:00
@@ -366,14 +467,15 @@
2018-10-02 17:41:47 +02:00
}
2017-07-17 01:55:47 +02:00
2021-11-21 23:00:00 +01:00
protected void save(EntityPlayer entityplayer) {
2018-10-02 17:41:47 +02:00
+ if (!entityplayer.getBukkitEntity().isPersistent()) return; // CraftBukkit
2021-06-11 07:00:00 +02:00
this.playerIo.save(entityplayer);
2021-11-21 23:00:00 +01:00
- ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) this.stats.get(entityplayer.getUUID());
+ ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStats(); // CraftBukkit
2017-07-17 01:55:47 +02:00
if (serverstatisticmanager != null) {
2020-06-25 02:00:00 +02:00
serverstatisticmanager.save();
2017-07-17 01:55:47 +02:00
}
2021-11-21 23:00:00 +01:00
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.advancements.get(entityplayer.getUUID());
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancements(); // CraftBukkit
2017-07-17 01:55:47 +02:00
if (advancementdataplayer != null) {
2021-11-21 23:00:00 +01:00
advancementdataplayer.save();
2024-04-23 17:15:00 +02:00
@@ -381,10 +483,24 @@
2015-02-04 00:38:21 +01:00
}
2021-11-21 23:00:00 +01:00
- public void remove(EntityPlayer entityplayer) {
+ public String remove(EntityPlayer entityplayer) { // CraftBukkit - return string
2023-06-07 17:30:00 +02:00
WorldServer worldserver = entityplayer.serverLevel();
2016-02-29 22:32:46 +01:00
2021-11-21 23:00:00 +01:00
entityplayer.awardStat(StatisticList.LEAVE_GAME);
2014-11-25 22:32:16 +01:00
+
+ // CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it
2020-10-01 11:07:54 +02:00
+ // See SPIGOT-5799, SPIGOT-6145
2021-06-11 07:00:00 +02:00
+ if (entityplayer.containerMenu != entityplayer.inventoryMenu) {
2021-11-21 23:00:00 +01:00
+ entityplayer.closeContainer();
2020-10-01 11:07:54 +02:00
+ }
2014-11-25 22:32:16 +01:00
+
2022-03-16 09:49:07 +01:00
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), entityplayer.kickLeaveMessage != null ? entityplayer.kickLeaveMessage : "\u00A7e" + entityplayer.getScoreboardName() + " left the game");
2014-11-25 22:32:16 +01:00
+ cserver.getPluginManager().callEvent(playerQuitEvent);
+ entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
2016-06-25 12:38:13 +02:00
+
2021-11-21 23:00:00 +01:00
+ entityplayer.doTick(); // SPIGOT-924
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2016-06-25 12:38:13 +02:00
+
2021-11-21 23:00:00 +01:00
this.save(entityplayer);
2016-02-29 22:32:46 +01:00
if (entityplayer.isPassenger()) {
2018-07-15 02:00:00 +02:00
Entity entity = entityplayer.getRootVehicle();
2024-04-23 17:15:00 +02:00
@@ -393,7 +509,7 @@
2024-02-21 10:55:34 +01:00
PlayerList.LOGGER.debug("Removing player mount");
entityplayer.stopRiding();
entity.getPassengersAndSelf().forEach((entity1) -> {
- entity1.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER);
+ entity1.setRemoved(Entity.RemovalReason.UNLOADED_WITH_PLAYER, EntityRemoveEvent.Cause.PLAYER_QUIT); // CraftBukkit - add Bukkit remove cause
});
}
}
2024-04-23 17:15:00 +02:00
@@ -408,17 +524,66 @@
2017-07-17 01:55:47 +02:00
if (entityplayer1 == entityplayer) {
2021-06-11 07:00:00 +02:00
this.playersByUUID.remove(uuid);
- this.stats.remove(uuid);
- this.advancements.remove(uuid);
2017-07-17 01:55:47 +02:00
+ // CraftBukkit start
2021-06-20 01:27:32 +02:00
+ // this.stats.remove(uuid);
+ // this.advancements.remove(uuid);
2017-07-17 01:55:47 +02:00
+ // CraftBukkit end
2022-12-07 17:00:00 +01:00
}
- this.broadcastAll(new ClientboundPlayerInfoRemovePacket(List.of(entityplayer.getUUID())));
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2022-12-07 17:00:00 +01:00
+ // this.broadcastAll(new ClientboundPlayerInfoRemovePacket(List.of(entityplayer.getUUID())));
+ ClientboundPlayerInfoRemovePacket packet = new ClientboundPlayerInfoRemovePacket(List.of(entityplayer.getUUID()));
2014-11-25 22:32:16 +01:00
+ for (int i = 0; i < players.size(); i++) {
2015-02-26 23:41:06 +01:00
+ EntityPlayer entityplayer2 = (EntityPlayer) this.players.get(i);
2014-11-25 22:32:16 +01:00
+
2015-02-26 23:41:06 +01:00
+ if (entityplayer2.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) {
2021-11-21 23:00:00 +01:00
+ entityplayer2.connection.send(packet);
2014-11-25 22:32:16 +01:00
+ } else {
2021-12-03 22:23:26 +01:00
+ entityplayer2.getBukkitEntity().onEntityRemove(entityplayer);
2014-11-25 22:32:16 +01:00
+ }
2022-12-07 17:00:00 +01:00
+ }
2014-11-25 22:32:16 +01:00
+ // This removes the scoreboard (and player reference) for the specific player in the manager
+ cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
+ // CraftBukkit end
2022-12-07 17:00:00 +01:00
+
2014-11-25 22:32:16 +01:00
+ return playerQuitEvent.getQuitMessage(); // CraftBukkit
}
2018-07-15 02:00:00 +02:00
- @Nullable
2021-11-21 23:00:00 +01:00
- public IChatBaseComponent canPlayerLogin(SocketAddress socketaddress, GameProfile gameprofile) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
2022-12-07 17:00:00 +01:00
+ public EntityPlayer canPlayerLogin(LoginListener loginlistener, GameProfile gameprofile) {
2022-06-07 18:00:00 +02:00
IChatMutableComponent ichatmutablecomponent;
2018-07-15 02:00:00 +02:00
2014-12-06 21:53:57 +01:00
+ // Moved from processLogin
2023-09-21 18:40:00 +02:00
+ UUID uuid = gameprofile.getId();
2018-12-25 22:00:00 +01:00
+ List<EntityPlayer> list = Lists.newArrayList();
2014-12-06 21:53:57 +01:00
+
+ EntityPlayer entityplayer;
+
+ for (int i = 0; i < this.players.size(); ++i) {
+ entityplayer = (EntityPlayer) this.players.get(i);
2021-11-21 23:00:00 +01:00
+ if (entityplayer.getUUID().equals(uuid)) {
2018-12-25 22:00:00 +01:00
+ list.add(entityplayer);
2014-12-06 21:53:57 +01:00
+ }
+ }
+
2018-12-25 22:00:00 +01:00
+ Iterator iterator = list.iterator();
2014-12-06 21:53:57 +01:00
+
+ while (iterator.hasNext()) {
+ entityplayer = (EntityPlayer) iterator.next();
2021-11-21 23:00:00 +01:00
+ save(entityplayer); // CraftBukkit - Force the player's inventory to be saved
2022-06-07 18:00:00 +02:00
+ entityplayer.connection.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.duplicate_login"));
2014-12-06 21:53:57 +01:00
+ }
2015-02-26 23:41:06 +01:00
+
2014-11-25 22:32:16 +01:00
+ // 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.
2021-11-21 23:00:00 +01:00
+ SocketAddress socketaddress = loginlistener.connection.getRemoteAddress();
2014-11-25 22:32:16 +01:00
+
2023-09-21 18:40:00 +02:00
+ EntityPlayer entity = new EntityPlayer(this.server, this.server.getLevel(World.OVERWORLD), gameprofile, ClientInformation.createDefault());
2024-04-23 17:15:00 +02:00
+ entity.transferCookieConnection = loginlistener;
2014-11-25 22:32:16 +01:00
+ Player player = entity.getBukkitEntity();
2022-10-28 11:19:11 +02:00
+ PlayerLoginEvent event = new PlayerLoginEvent(player, loginlistener.connection.hostname, ((java.net.InetSocketAddress) socketaddress).getAddress());
2018-07-15 02:00:00 +02:00
+
2024-02-22 09:55:53 +01:00
if (this.bans.isBanned(gameprofile)) {
2021-06-11 07:00:00 +02:00
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile);
2014-11-25 22:32:16 +01:00
2024-04-23 17:15:00 +02:00
@@ -427,9 +592,11 @@
2022-06-07 18:00:00 +02:00
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())));
2014-11-25 22:32:16 +01:00
}
2022-06-07 18:00:00 +02:00
- return ichatmutablecomponent;
2018-07-15 02:00:00 +02:00
+ // return chatmessage;
2022-06-07 18:00:00 +02:00
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
2021-11-21 23:00:00 +01:00
} else if (!this.isWhiteListed(gameprofile)) {
2022-06-07 18:00:00 +02:00
- return IChatBaseComponent.translatable("multiplayer.disconnect.not_whitelisted");
+ ichatmutablecomponent = IChatBaseComponent.translatable("multiplayer.disconnect.not_whitelisted");
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, CraftChatMessage.fromComponent(ichatmutablecomponent));
2024-02-22 09:55:53 +01:00
} else if (this.ipBans.isBanned(socketaddress)) {
2021-06-11 07:00:00 +02:00
IpBanEntry ipbanentry = this.ipBans.get(socketaddress);
2014-11-25 22:32:16 +01:00
2024-04-23 17:15:00 +02:00
@@ -438,17 +605,32 @@
2022-06-07 18:00:00 +02:00
ichatmutablecomponent.append((IChatBaseComponent) IChatBaseComponent.translatable("multiplayer.disconnect.banned_ip.expiration", PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires())));
2014-11-25 22:32:16 +01:00
}
2022-06-07 18:00:00 +02:00
- return ichatmutablecomponent;
2018-07-15 02:00:00 +02:00
+ // return chatmessage;
2022-06-07 18:00:00 +02:00
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(ichatmutablecomponent));
2014-11-25 22:32:16 +01:00
} else {
2022-06-07 18:00:00 +02:00
- return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null;
+ // return this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile) ? IChatBaseComponent.translatable("multiplayer.disconnect.server_full") : null;
2021-11-21 23:00:00 +01:00
+ if (this.players.size() >= this.maxPlayers && !this.canBypassPlayerLimit(gameprofile)) {
2014-11-25 22:32:16 +01:00
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full");
+ }
2024-02-21 10:55:34 +01:00
+ }
2014-11-25 22:32:16 +01:00
+
+ cserver.getPluginManager().callEvent(event);
+ if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
+ loginlistener.disconnect(event.getKickMessage());
+ return null;
2024-02-21 10:55:34 +01:00
}
2014-11-25 22:32:16 +01:00
+ return entity;
}
2023-09-21 18:40:00 +02:00
- public EntityPlayer getPlayerForLogin(GameProfile gameprofile, ClientInformation clientinformation) {
- return new EntityPlayer(this.server, this.server.overworld(), gameprofile, clientinformation);
+ // CraftBukkit start - added EntityPlayer
+ public EntityPlayer getPlayerForLogin(GameProfile gameprofile, ClientInformation clientinformation, EntityPlayer player) {
+ player.updateOptions(clientinformation);
+ return player;
+ // CraftBukkit end
}
2014-11-25 22:32:16 +01:00
2023-09-21 18:40:00 +02:00
- public boolean disconnectAllPlayersWithProfile(GameProfile gameprofile) {
+ public boolean disconnectAllPlayersWithProfile(GameProfile gameprofile, EntityPlayer player) { // CraftBukkit - added EntityPlayer
+ /* CraftBukkit startMoved up
UUID uuid = gameprofile.getId();
Set<EntityPlayer> set = Sets.newIdentityHashSet();
Iterator iterator = this.players.iterator();
2024-04-23 17:15:00 +02:00
@@ -476,14 +658,24 @@
2014-11-25 22:32:16 +01:00
}
2023-09-21 18:40:00 +02:00
return !set.isEmpty();
2015-02-26 23:41:06 +01:00
+ */
2023-09-21 18:40:00 +02:00
+ return player == null;
2016-06-25 12:38:13 +02:00
+ // CraftBukkit end
2023-04-10 00:26:45 +02:00
}
- public EntityPlayer respawn(EntityPlayer entityplayer, boolean flag) {
2023-09-21 18:57:13 +02:00
+ // CraftBukkit start
+ public EntityPlayer respawn(EntityPlayer entityplayer, boolean flag, RespawnReason reason) {
+ return this.respawn(entityplayer, this.server.getLevel(entityplayer.getRespawnDimension()), flag, null, true, reason);
+ }
+
2023-04-10 00:26:45 +02:00
+ public EntityPlayer respawn(EntityPlayer entityplayer, WorldServer worldserver, boolean flag, Location location, boolean avoidSuffocation, RespawnReason reason) {
2017-04-21 06:56:41 +02:00
+ entityplayer.stopRiding(); // CraftBukkit
2014-11-25 22:32:16 +01:00
this.players.remove(entityplayer);
2023-06-07 17:30:00 +02:00
entityplayer.serverLevel().removePlayerImmediately(entityplayer, Entity.RemovalReason.DISCARDED);
2021-11-21 23:00:00 +01:00
BlockPosition blockposition = entityplayer.getRespawnPosition();
float f = entityplayer.getRespawnAngle();
boolean flag1 = entityplayer.isRespawnForced();
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start
2021-11-21 23:00:00 +01:00
WorldServer worldserver = this.server.getLevel(entityplayer.getRespawnDimension());
2020-06-25 02:00:00 +02:00
Optional optional;
2014-11-25 22:32:16 +01:00
2024-04-23 17:15:00 +02:00
@@ -495,6 +687,11 @@
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
WorldServer worldserver1 = worldserver != null && optional.isPresent() ? worldserver : this.server.overworld();
2023-09-21 18:40:00 +02:00
EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver1, entityplayer.getGameProfile(), entityplayer.clientInformation());
2014-11-25 22:32:16 +01:00
+ // */
+ EntityPlayer entityplayer1 = entityplayer;
+ org.bukkit.World fromWorld = entityplayer.getBukkitEntity().getWorld();
2021-06-11 07:00:00 +02:00
+ entityplayer.wonGame = false;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
2021-06-11 07:00:00 +02:00
entityplayer1.connection = entityplayer.connection;
2021-11-21 23:00:00 +01:00
entityplayer1.restoreFrom(entityplayer, flag);
2024-04-23 17:15:00 +02:00
@@ -510,28 +707,66 @@
2016-02-29 22:32:46 +01:00
2020-06-25 02:00:00 +02:00
boolean flag2 = false;
2019-04-25 04:00:00 +02:00
2020-06-25 02:00:00 +02:00
- if (optional.isPresent()) {
2021-11-21 23:00:00 +01:00
- IBlockData iblockdata = worldserver1.getBlockState(blockposition);
- boolean flag3 = iblockdata.is(Blocks.RESPAWN_ANCHOR);
2020-06-25 02:00:00 +02:00
- Vec3D vec3d = (Vec3D) optional.get();
2020-08-11 23:00:00 +02:00
- float f1;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - fire PlayerRespawnEvent
+ if (location == null) {
+ boolean isBedSpawn = false;
2021-11-21 23:00:00 +01:00
+ WorldServer worldserver1 = this.server.getLevel(entityplayer.getRespawnDimension());
2020-06-25 02:00:00 +02:00
+ if (worldserver1 != null) {
+ Optional optional;
2020-08-11 23:00:00 +02:00
2022-02-28 16:00:00 +01:00
- if (!iblockdata.is(TagsBlock.BEDS) && !flag3) {
2020-08-11 23:00:00 +02:00
- f1 = f;
- } else {
2021-11-21 23:00:00 +01:00
- Vec3D vec3d1 = Vec3D.atBottomCenterOf(blockposition).subtract(vec3d).normalize();
2020-06-25 02:00:00 +02:00
+ if (blockposition != null) {
2021-11-21 23:00:00 +01:00
+ optional = EntityHuman.findRespawnPositionAndUseSpawnBlock(worldserver1, blockposition, f, flag1, flag);
2020-06-25 02:00:00 +02:00
+ } else {
+ optional = Optional.empty();
+ }
2023-09-21 18:57:13 +02:00
- f1 = (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
2019-04-25 04:00:00 +02:00
+ if (optional.isPresent()) {
2021-11-21 23:00:00 +01:00
+ IBlockData iblockdata = worldserver1.getBlockState(blockposition);
+ boolean flag3 = iblockdata.is(Blocks.RESPAWN_ANCHOR);
2019-04-25 04:00:00 +02:00
+ Vec3D vec3d = (Vec3D) optional.get();
2020-08-11 23:00:00 +02:00
+ float f1;
+
2022-02-28 16:00:00 +01:00
+ if (!iblockdata.is(TagsBlock.BEDS) && !flag3) {
2020-08-11 23:00:00 +02:00
+ f1 = f;
+ } else {
2021-11-21 23:00:00 +01:00
+ Vec3D vec3d1 = Vec3D.atBottomCenterOf(blockposition).subtract(vec3d).normalize();
2022-12-07 17:00:00 +01:00
+
2021-11-21 23:00:00 +01:00
+ f1 = (float) MathHelper.wrapDegrees(MathHelper.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
2020-08-11 23:00:00 +02:00
+ }
2021-06-11 07:00:00 +02:00
+
2023-04-17 11:33:17 +02:00
+ // entityplayer1.setRespawnPosition(worldserver1.dimension(), blockposition, f, flag1, false); // CraftBukkit - not required, just copies old location into reused entity
2020-08-11 23:00:00 +02:00
+ flag2 = !flag && flag3;
2014-11-25 22:32:16 +01:00
+ isBedSpawn = true;
2023-04-19 11:59:19 +02:00
+ location = CraftLocation.toBukkit(vec3d, worldserver1.getWorld(), f1, 0.0F);
2020-06-25 02:00:00 +02:00
+ } else if (blockposition != null) {
2021-11-21 23:00:00 +01:00
+ entityplayer1.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
2023-04-17 11:33:17 +02:00
+ entityplayer1.setRespawnPosition(null, null, 0f, false, false, PlayerSpawnChangeEvent.Cause.RESET); // CraftBukkit - SPIGOT-5988: Clear respawn location when obstructed
2014-11-25 22:32:16 +01:00
+ }
2020-08-11 23:00:00 +02:00
}
2021-11-21 23:00:00 +01:00
- entityplayer1.moveTo(vec3d.x, vec3d.y, vec3d.z, f1, 0.0F);
- entityplayer1.setRespawnPosition(worldserver1.dimension(), blockposition, f, flag1, false);
2020-08-11 23:00:00 +02:00
- flag2 = !flag && flag3;
- } else if (blockposition != null) {
2021-11-21 23:00:00 +01:00
- entityplayer1.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
2023-09-21 18:57:13 +02:00
+ if (location == null) {
+ worldserver1 = this.server.getLevel(World.OVERWORLD);
+ blockposition = entityplayer1.getSpawnPoint(worldserver1);
+ location = CraftLocation.toBukkit(blockposition, worldserver1.getWorld()).add(0.5F, 0.1F, 0.5F);
+ }
+
2021-06-20 01:27:32 +02:00
+ Player respawnPlayer = entityplayer1.getBukkitEntity();
2023-04-10 00:26:45 +02:00
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn && !flag2, flag2, reason);
2014-11-25 22:32:16 +01:00
+ cserver.getPluginManager().callEvent(respawnEvent);
+
+ location = respawnEvent.getRespawnLocation();
2019-04-27 07:43:04 +02:00
+ if (!flag) entityplayer.reset(); // SPIGOT-4785
2014-11-25 22:32:16 +01:00
+ } else {
2020-06-25 02:00:00 +02:00
+ location.setWorld(worldserver.getWorld());
2014-11-25 22:32:16 +01:00
}
2020-06-25 02:00:00 +02:00
+ WorldServer worldserver1 = ((CraftWorld) location.getWorld()).getHandle();
2023-09-21 18:40:00 +02:00
+ entityplayer1.spawnIn(worldserver1);
+ entityplayer1.unsetRemoved();
+ entityplayer1.setShiftKeyDown(false);
2016-10-23 05:00:35 +02:00
+ entityplayer1.forceSetPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
- while (!worldserver1.noCollision((Entity) entityplayer1) && entityplayer1.getY() < (double) worldserver1.getMaxBuildHeight()) {
2022-02-28 16:00:00 +01:00
+ while (avoidSuffocation && !worldserver1.noCollision((Entity) entityplayer1) && entityplayer1.getY() < (double) worldserver1.getMaxBuildHeight()) {
2023-09-21 18:40:00 +02:00
+ // CraftBukkit end
2021-11-21 23:00:00 +01:00
entityplayer1.setPos(entityplayer1.getX(), entityplayer1.getY() + 1.0D, entityplayer1.getZ());
2014-11-25 22:32:16 +01:00
}
2022-12-07 17:00:00 +01:00
2024-04-23 17:15:00 +02:00
@@ -540,21 +775,43 @@
2023-09-21 18:40:00 +02:00
WorldData worlddata = worldserver2.getLevelData();
2019-04-23 04:00:00 +02:00
2023-09-21 18:40:00 +02:00
entityplayer1.connection.send(new PacketPlayOutRespawn(entityplayer1.createCommonSpawnInfo(worldserver2), (byte) i));
2021-11-21 23:00:00 +01:00
- entityplayer1.connection.teleport(entityplayer1.getX(), entityplayer1.getY(), entityplayer1.getZ(), entityplayer1.getYRot(), entityplayer1.getXRot());
2023-09-21 18:40:00 +02:00
+ entityplayer1.connection.teleport(CraftLocation.toBukkit(entityplayer1.position(), worldserver2.getWorld(), entityplayer1.getYRot(), entityplayer1.getXRot())); // CraftBukkit
2021-11-21 23:00:00 +01:00
entityplayer1.connection.send(new PacketPlayOutSpawnPosition(worldserver1.getSharedSpawnPos(), worldserver1.getSharedSpawnAngle()));
entityplayer1.connection.send(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
entityplayer1.connection.send(new PacketPlayOutExperience(entityplayer1.experienceProgress, entityplayer1.totalExperience, entityplayer1.experienceLevel));
this.sendLevelInfo(entityplayer1, worldserver1);
this.sendPlayerPermissionLevel(entityplayer1);
- worldserver1.addRespawnedPlayer(entityplayer1);
2014-11-25 22:32:16 +01:00
- this.players.add(entityplayer1);
2021-11-21 23:00:00 +01:00
- this.playersByUUID.put(entityplayer1.getUUID(), entityplayer1);
- entityplayer1.initInventoryMenu();
2021-06-11 07:00:00 +02:00
+ if (!entityplayer.connection.isDisconnected()) {
2021-11-21 23:00:00 +01:00
+ worldserver1.addRespawnedPlayer(entityplayer1);
2014-11-25 22:32:16 +01:00
+ this.players.add(entityplayer1);
2021-11-21 23:00:00 +01:00
+ this.playersByUUID.put(entityplayer1.getUUID(), entityplayer1);
2014-11-25 22:32:16 +01:00
+ }
2021-11-21 23:00:00 +01:00
+ // entityplayer1.initInventoryMenu();
2016-03-06 04:35:33 +01:00
entityplayer1.setHealth(entityplayer1.getHealth());
2020-06-25 02:00:00 +02:00
if (flag2) {
2022-06-07 18:00:00 +02:00
entityplayer1.connection.send(new PacketPlayOutNamedSoundEffect(SoundEffects.RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 1.0F, 1.0F, worldserver1.getRandom().nextLong()));
2020-06-25 02:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
+ // Added from changeDimension
2021-11-21 23:00:00 +01:00
+ sendAllPlayerInfo(entityplayer); // Update health, etc...
+ entityplayer.onUpdateAbilities();
+ for (MobEffect mobEffect : entityplayer.getActiveEffects()) {
2024-04-23 17:15:00 +02:00
+ entityplayer.connection.send(new PacketPlayOutEntityEffect(entityplayer.getId(), mobEffect, false)); // blend = false
2014-11-25 22:32:16 +01:00
+ }
2024-04-23 17:15:00 +02:00
+
2017-05-14 04:00:00 +02:00
+ // Fire advancement trigger
2021-11-21 23:00:00 +01:00
+ entityplayer.triggerDimensionChangeTriggers(((CraftWorld) fromWorld).getHandle());
2023-09-21 18:40:00 +02:00
+
2014-11-25 22:32:16 +01:00
+ // Don't fire on respawn
+ if (fromWorld != location.getWorld()) {
+ PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(entityplayer.getBukkitEntity(), fromWorld);
+ server.server.getPluginManager().callEvent(event);
+ }
2024-04-23 17:15:00 +02:00
2014-11-25 22:32:16 +01:00
+ // Save player file again if they were disconnected
2021-06-11 07:00:00 +02:00
+ if (entityplayer.connection.isDisconnected()) {
2021-11-21 23:00:00 +01:00
+ this.save(entityplayer);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
return entityplayer1;
}
2024-04-23 17:15:00 +02:00
@@ -567,7 +824,18 @@
2014-11-25 22:32:16 +01:00
public void tick() {
2021-06-11 07:00:00 +02:00
if (++this.sendAllPlayerInfoIn > 600) {
2022-12-07 17:00:00 +01:00
- this.broadcastAll(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.a.UPDATE_LATENCY), this.players));
2016-11-28 00:02:40 +01:00
+ // CraftBukkit start
+ for (int i = 0; i < this.players.size(); ++i) {
+ final EntityPlayer target = (EntityPlayer) this.players.get(i);
+
2022-12-07 17:00:00 +01:00
+ target.connection.send(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.a.UPDATE_LATENCY), this.players.stream().filter(new Predicate<EntityPlayer>() {
2016-11-28 00:02:40 +01:00
+ @Override
2022-07-27 20:00:00 +02:00
+ public boolean test(EntityPlayer input) {
2016-11-28 00:02:40 +01:00
+ return target.getBukkitEntity().canSee(input.getBukkitEntity());
+ }
2021-06-11 07:00:00 +02:00
+ }).collect(Collectors.toList())));
2016-11-28 00:02:40 +01:00
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.sendAllPlayerInfoIn = 0;
2016-11-28 00:02:40 +01:00
}
2024-04-23 17:15:00 +02:00
@@ -584,6 +852,25 @@
2014-12-10 20:16:37 +01:00
}
2015-06-07 22:04:28 +02:00
+ // CraftBukkit start - add a world/entity limited version
2021-11-21 23:00:00 +01:00
+ public void broadcastAll(Packet packet, EntityHuman entityhuman) {
2015-06-07 22:04:28 +02:00
+ for (int i = 0; i < this.players.size(); ++i) {
+ EntityPlayer entityplayer = this.players.get(i);
2021-11-28 23:18:52 +01:00
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
2015-06-07 22:04:28 +02:00
+ continue;
+ }
2021-11-21 23:00:00 +01:00
+ ((EntityPlayer) this.players.get(i)).connection.send(packet);
2015-06-07 22:04:28 +02:00
+ }
+ }
+
2021-11-21 23:00:00 +01:00
+ public void broadcastAll(Packet packet, World world) {
+ for (int i = 0; i < world.players().size(); ++i) {
+ ((EntityPlayer) world.players().get(i)).connection.send(packet);
2014-12-10 20:16:37 +01:00
+ }
+
+ }
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
public void broadcastAll(Packet<?> packet, ResourceKey<World> resourcekey) {
2021-06-11 07:00:00 +02:00
Iterator iterator = this.players.iterator();
2024-04-23 17:15:00 +02:00
@@ -662,7 +949,7 @@
2021-11-21 23:00:00 +01:00
}
public void deop(GameProfile gameprofile) {
- this.ops.remove((Object) gameprofile);
+ this.ops.remove(gameprofile); // CraftBukkit - decompile error
EntityPlayer entityplayer = this.getPlayer(gameprofile.getId());
if (entityplayer != null) {
2024-04-23 17:15:00 +02:00
@@ -686,6 +973,7 @@
2021-11-21 23:00:00 +01:00
entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, b0));
2018-07-15 02:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
2018-07-15 02:00:00 +02:00
+ entityplayer.getBukkitEntity().recalculatePermissions(); // CraftBukkit
2021-11-21 23:00:00 +01:00
this.server.getCommands().sendCommands(entityplayer);
2014-11-25 22:32:16 +01:00
}
2024-04-23 17:15:00 +02:00
@@ -716,6 +1004,12 @@
2018-08-26 04:00:00 +02:00
for (int i = 0; i < this.players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet
2021-11-28 23:18:52 +01:00
+ if (entityhuman != null && !entityplayer.getBukkitEntity().canSee(entityhuman.getBukkitEntity())) {
2014-11-25 22:32:16 +01:00
+ continue;
+ }
+ // CraftBukkit end
+
2023-06-07 17:30:00 +02:00
if (entityplayer != entityhuman && entityplayer.level().dimension() == resourcekey) {
2021-11-21 23:00:00 +01:00
double d4 = d0 - entityplayer.getX();
double d5 = d1 - entityplayer.getY();
2024-04-23 17:15:00 +02:00
@@ -755,15 +1049,19 @@
2021-11-21 23:00:00 +01:00
public void reloadWhiteList() {}
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
public void sendLevelInfo(EntityPlayer entityplayer, WorldServer worldserver) {
- WorldBorder worldborder = this.server.overworld().getWorldBorder();
2023-06-07 17:30:00 +02:00
+ WorldBorder worldborder = entityplayer.level().getWorldBorder(); // CraftBukkit
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
entityplayer.connection.send(new ClientboundInitializeBorderPacket(worldborder));
entityplayer.connection.send(new PacketPlayOutUpdateTime(worldserver.getGameTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
entityplayer.connection.send(new PacketPlayOutSpawnPosition(worldserver.getSharedSpawnPos(), worldserver.getSharedSpawnAngle()));
2017-05-19 13:00:13 +02:00
if (worldserver.isRaining()) {
2021-11-21 23:00:00 +01:00
- 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)));
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - handle player weather
2021-11-21 23:00:00 +01:00
+ // 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)));
2014-11-25 22:32:16 +01:00
+ entityplayer.setPlayerWeather(org.bukkit.WeatherType.DOWNFALL, false);
2019-05-14 02:00:00 +02:00
+ entityplayer.updateWeather(-worldserver.rainLevel, worldserver.rainLevel, -worldserver.thunderLevel, worldserver.thunderLevel);
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
}
2023-12-05 17:40:00 +01:00
entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.LEVEL_CHUNKS_LOAD_START, 0.0F));
2024-04-23 17:15:00 +02:00
@@ -772,8 +1070,16 @@
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
public void sendAllPlayerInfo(EntityPlayer entityplayer) {
entityplayer.inventoryMenu.sendAllDataToRemote();
- entityplayer.resetSentInfo();
+ // entityplayer.resetSentInfo();
2014-11-25 22:32:16 +01:00
+ entityplayer.getBukkitEntity().updateScaledHealth(); // CraftBukkit - Update scaled health on respawn and worldchange
2024-04-23 17:15:00 +02:00
+ entityplayer.refreshEntityData(entityplayer); // CraftBukkkit - SPIGOT-7218: sync metadata
2021-11-21 23:00:00 +01:00
entityplayer.connection.send(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected));
2019-01-02 00:57:47 +01:00
+ // CraftBukkit start - from GameRules
2023-06-07 17:30:00 +02:00
+ int i = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23;
2021-11-21 23:00:00 +01:00
+ entityplayer.connection.send(new PacketPlayOutEntityStatus(entityplayer, (byte) i));
2023-06-07 17:30:00 +02:00
+ float immediateRespawn = entityplayer.level().getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F;
2021-11-21 23:00:00 +01:00
+ entityplayer.connection.send(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.IMMEDIATE_RESPAWN, immediateRespawn));
2019-01-02 00:57:47 +01:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
2019-01-02 00:57:47 +01:00
public int getPlayerCount() {
2024-04-23 17:15:00 +02:00
@@ -829,12 +1135,22 @@
2016-08-23 06:02:48 +02:00
}
2014-11-25 22:32:16 +01:00
2021-11-21 23:00:00 +01:00
public void removeAll() {
2016-08-23 06:02:48 +02:00
- for (int i = 0; i < this.players.size(); ++i) {
2022-06-07 18:00:00 +02:00
- ((EntityPlayer) this.players.get(i)).connection.disconnect(IChatBaseComponent.translatable("multiplayer.disconnect.server_shutdown"));
2016-08-23 06:02:48 +02:00
+ // CraftBukkit start - disconnect safely
+ for (EntityPlayer player : this.players) {
2021-06-11 07:00:00 +02:00
+ player.connection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message
2014-11-25 22:32:16 +01:00
}
2016-08-23 06:02:48 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ public void broadcastMessage(IChatBaseComponent[] iChatBaseComponents) {
2014-11-25 22:32:16 +01:00
+ for (IChatBaseComponent component : iChatBaseComponents) {
2022-07-27 20:00:00 +02:00
+ broadcastSystemMessage(component, false);
2014-11-25 22:32:16 +01:00
+ }
2021-06-11 07:00:00 +02:00
+ }
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
+
2022-07-27 20:00:00 +02:00
public void broadcastSystemMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
2022-06-07 18:00:00 +02:00
this.broadcastSystemMessage(ichatbasecomponent, (entityplayer) -> {
return ichatbasecomponent;
2024-04-23 17:15:00 +02:00
@@ -892,16 +1208,23 @@
2022-12-07 17:00:00 +01:00
return playerchatmessage.hasSignature() && !playerchatmessage.hasExpiredServer(Instant.now());
2017-07-17 01:55:47 +02:00
}
2021-11-21 23:00:00 +01:00
- public ServerStatisticManager getPlayerStats(EntityHuman entityhuman) {
- UUID uuid = entityhuman.getUUID();
- ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) this.stats.get(uuid);
2020-04-05 07:58:43 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ public ServerStatisticManager getPlayerStats(EntityPlayer entityhuman) {
+ ServerStatisticManager serverstatisticmanager = entityhuman.getStats();
+ return serverstatisticmanager == null ? getPlayerStats(entityhuman.getUUID(), entityhuman.getDisplayName().getString()) : serverstatisticmanager;
2020-04-05 07:58:43 +02:00
+ }
+
2021-11-21 23:00:00 +01:00
+ public ServerStatisticManager getPlayerStats(UUID uuid, String displayName) {
2020-06-25 02:00:00 +02:00
+ EntityPlayer entityhuman = this.getPlayer(uuid);
2021-11-21 23:00:00 +01:00
+ ServerStatisticManager serverstatisticmanager = entityhuman == null ? null : (ServerStatisticManager) entityhuman.getStats();
2017-07-17 01:55:47 +02:00
+ // CraftBukkit end
if (serverstatisticmanager == null) {
2021-11-21 23:00:00 +01:00
File file = this.server.getWorldPath(SavedFile.PLAYER_STATS_DIR).toFile();
2024-04-23 17:15:00 +02:00
File file1 = new File(file, String.valueOf(uuid) + ".json");
2020-04-05 07:58:43 +02:00
if (!file1.exists()) {
2021-11-21 23:00:00 +01:00
- File file2 = new File(file, entityhuman.getName().getString() + ".json");
2020-04-05 07:58:43 +02:00
+ File file2 = new File(file, displayName + ".json"); // CraftBukkit
2021-07-06 16:00:00 +02:00
Path path = file2.toPath();
2020-04-05 07:58:43 +02:00
2021-11-21 23:00:00 +01:00
if (FileUtils.isPathNormalized(path) && FileUtils.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
2024-04-23 17:15:00 +02:00
@@ -910,7 +1233,7 @@
2018-07-15 02:00:00 +02:00
}
2017-07-17 01:55:47 +02:00
serverstatisticmanager = new ServerStatisticManager(this.server, file1);
2021-06-11 07:00:00 +02:00
- this.stats.put(uuid, serverstatisticmanager);
2021-06-20 01:27:32 +02:00
+ // this.stats.put(uuid, serverstatisticmanager); // CraftBukkit
2017-07-17 01:55:47 +02:00
}
return serverstatisticmanager;
2024-04-23 17:15:00 +02:00
@@ -918,13 +1241,13 @@
2017-07-17 01:55:47 +02:00
2021-11-21 23:00:00 +01:00
public AdvancementDataPlayer getPlayerAdvancements(EntityPlayer entityplayer) {
UUID uuid = entityplayer.getUUID();
2021-06-11 07:00:00 +02:00
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.advancements.get(uuid);
2021-11-21 23:00:00 +01:00
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancements(); // CraftBukkit
2017-07-17 01:55:47 +02:00
if (advancementdataplayer == null) {
2024-04-23 17:15:00 +02:00
Path path = this.server.getWorldPath(SavedFile.PLAYER_ADVANCEMENTS_DIR).resolve(String.valueOf(uuid) + ".json");
2017-07-17 01:55:47 +02:00
2023-03-14 17:30:00 +01:00
advancementdataplayer = new AdvancementDataPlayer(this.server.getFixerUpper(), this, this.server.getAdvancements(), path, entityplayer);
2021-06-11 07:00:00 +02:00
- this.advancements.put(uuid, advancementdataplayer);
2021-06-20 01:27:32 +02:00
+ // this.advancements.put(uuid, advancementdataplayer); // CraftBukkit
2017-07-17 01:55:47 +02:00
}
2021-11-21 23:00:00 +01:00
advancementdataplayer.setPlayer(entityplayer);
2024-04-23 17:15:00 +02:00
@@ -975,13 +1298,20 @@
2017-07-17 01:55:47 +02:00
}
2021-11-21 23:00:00 +01:00
public void reloadResources() {
2021-06-11 07:00:00 +02:00
- Iterator iterator = this.advancements.values().iterator();
2017-07-17 01:55:47 +02:00
+ // CraftBukkit start
2021-06-20 01:27:32 +02:00
+ /*Iterator iterator = this.advancements.values().iterator();
2017-07-17 01:55:47 +02:00
while (iterator.hasNext()) {
AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) iterator.next();
2017-05-16 13:22:07 +02:00
2021-11-21 23:00:00 +01:00
advancementdataplayer.reload(this.server.getAdvancements());
2017-07-17 01:55:47 +02:00
+ }*/
+
2017-05-16 13:22:07 +02:00
+ for (EntityPlayer player : players) {
2021-11-21 23:00:00 +01:00
+ player.getAdvancements().reload(this.server.getAdvancements());
+ player.getAdvancements().flushDirty(player); // CraftBukkit - trigger immediate flush of advancements
2017-07-17 01:55:47 +02:00
}
2017-05-16 13:22:07 +02:00
+ // CraftBukkit end
2023-09-21 18:40:00 +02:00
this.broadcastAll(new ClientboundUpdateTagsPacket(TagNetworkSerialization.serializeTagsToNetwork(this.registries)));
2024-04-23 17:15:00 +02:00
PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getRecipeManager().getOrderedRecipes());