2021-03-15 23:00:00 +01:00
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
2021-06-11 07:00:00 +02:00
@@ -93,6 +93,25 @@
2014-11-25 22:32:16 +01:00
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// CraftBukkit start
2016-11-28 00:02:40 +01:00
+import com.google.common.base.Predicate;
2021-06-11 07:00:00 +02:00
+import java.util.stream.Collectors;
+import net.minecraft.network.protocol.game.PacketPlayOutChat;
2021-03-15 23:00:00 +01:00
+import net.minecraft.network.protocol.game.PacketPlayOutEntityMetadata;
+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;
2014-12-12 08:20:42 +01:00
+import org.bukkit.craftbukkit.util.CraftChatMessage;
2014-11-25 22:32:16 +01:00
+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;
+// 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");
@@ -103,14 +122,16 @@
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
+ // private final Map<UUID, ServerStatisticManager> o;
+ // private final Map<UUID, AdvancementDataPlayer> p;
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
public final WorldNBTStorage playerIo;
private boolean doWhiteList;
private final IRegistryCustom.Dimension registryHolder;
@@ -120,13 +141,23 @@
private static final boolean ALLOW_LOGOUTIVATOR = false;
private int sendAllPlayerInfoIn;
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ private CraftServer cserver;
+
2020-06-25 02:00:00 +02:00
public PlayerList(MinecraftServer minecraftserver, IRegistryCustom.Dimension iregistrycustom_dimension, 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
+ // this.o = Maps.newHashMap();
+ // this.p = Maps.newHashMap();
+ // CraftBukkit end
this.server = minecraftserver;
2021-06-11 07:00:00 +02:00
this.registryHolder = iregistrycustom_dimension;
2019-04-23 04:00:00 +02:00
this.maxPlayers = i;
2021-06-11 07:00:00 +02:00
@@ -142,6 +173,12 @@
2015-02-04 20:29:07 +01:00
usercache.a(gameprofile);
NBTTagCompound nbttagcompound = this.a(entityplayer);
2020-06-25 02:00:00 +02:00
ResourceKey resourcekey;
2015-02-04 20:29:07 +01:00
+ // CraftBukkit start - Better rename detection
2015-02-04 21:33:06 +01:00
+ if (nbttagcompound != null && nbttagcompound.hasKey("bukkit")) {
2015-02-04 20:29:07 +01:00
+ NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit");
+ s = bukkit.hasKeyOfType("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s;
+ }
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
if (nbttagcompound != null) {
2021-06-11 07:00:00 +02:00
DataResult dataresult = DimensionManager.a(new Dynamic(DynamicOpsNBT.INSTANCE, nbttagcompound.get("Dimension")));
@@ -171,7 +208,8 @@
2014-11-25 22:32:16 +01:00
s1 = networkmanager.getSocketAddress().toString();
}
2019-12-10 23:00:00 +01:00
- PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.locX(), entityplayer.locY(), entityplayer.locZ());
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - Moved message to after join
2019-12-10 23:00:00 +01:00
+ // PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ({}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.locX(), entityplayer.locY(), entityplayer.locZ());
2020-06-25 02:00:00 +02:00
WorldData worlddata = worldserver1.getWorldData();
2016-11-17 02:41:03 +01:00
2021-06-11 07:00:00 +02:00
entityplayer.c(nbttagcompound);
@@ -181,6 +219,7 @@
boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO);
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
playerconnection.sendPacket(new PacketPlayOutLogin(entityplayer.getId(), entityplayer.gameMode.getGameMode(), entityplayer.gameMode.c(), BiomeManager.a(worldserver1.getSeed()), worlddata.isHardcore(), this.server.G(), this.registryHolder, worldserver1.getDimensionManager(), worldserver1.getDimensionKey(), this.getMaxPlayers(), this.viewDistance, flag1, !flag, worldserver1.isDebugWorld(), worldserver1.isFlatWorld()));
2014-11-25 22:32:16 +01:00
+ entityplayer.getBukkitEntity().sendSupportedChannels(); // CraftBukkit
2021-06-11 07:00:00 +02:00
playerconnection.sendPacket(new PacketPlayOutCustomPayload(PacketPlayOutCustomPayload.BRAND, (new PacketDataSerializer(Unpooled.buffer())).a(this.getServer().getServerModName())));
2015-05-05 22:43:47 +02:00
playerconnection.sendPacket(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
2021-06-11 07:00:00 +02:00
playerconnection.sendPacket(new PacketPlayOutAbilities(entityplayer.getAbilities()));
@@ -199,19 +238,61 @@
2019-04-23 04:00:00 +02:00
} else {
2019-05-27 22:30:00 +02:00
chatmessage = new ChatMessage("multiplayer.player.joined.renamed", new Object[]{entityplayer.getScoreboardDisplayName(), s});
2015-02-04 00:38:21 +01:00
}
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
+ chatmessage.a(EnumChatFormat.YELLOW);
+ String joinMessage = CraftChatMessage.fromComponent(chatmessage);
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
- this.sendMessage(chatmessage.a(EnumChatFormat.YELLOW), ChatMessageType.SYSTEM, SystemUtils.NIL_UUID);
playerconnection.b(entityplayer.locX(), entityplayer.locY(), entityplayer.locZ(), entityplayer.getYRot(), entityplayer.getXRot());
2019-04-23 04:00:00 +02:00
this.players.add(entityplayer);
2021-06-11 07:00:00 +02:00
this.playersByUUID.put(entityplayer.getUniqueID(), entityplayer);
2019-05-27 22:30:00 +02:00
- this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[]{entityplayer}));
+ // this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[]{entityplayer})); // CraftBukkit - replaced with loop below
2019-04-23 04:00:00 +02:00
+
+ // CraftBukkit start
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(cserver.getPlayer(entityplayer), joinMessage);
+ cserver.getPluginManager().callEvent(playerJoinEvent);
+
2021-06-11 07:00:00 +02:00
+ if (!entityplayer.connection.connection.isConnected()) {
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)) {
2021-06-11 07:00:00 +02:00
+ server.getPlayerList().sendAll(new PacketPlayOutChat(line, ChatMessageType.SYSTEM, SystemUtils.NIL_UUID));
2019-04-23 04:00:00 +02:00
+ }
+ }
+ // CraftBukkit end
+
+ // CraftBukkit start - sendAll above replaced with this loop
+ PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityplayer);
for (int i = 0; i < this.players.size(); ++i) {
2021-06-11 07:00:00 +02:00
- entityplayer.connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[]{(EntityPlayer) this.players.get(i)}));
2019-04-23 04:00:00 +02:00
+ EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
+
+ if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) {
2021-06-11 07:00:00 +02:00
+ entityplayer1.connection.sendPacket(packet);
2019-04-23 04:00:00 +02:00
+ }
+
+ if (!entityplayer.getBukkitEntity().canSee(entityplayer1.getBukkitEntity())) {
+ continue;
+ }
+
2021-06-11 07:00:00 +02:00
+ entityplayer.connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { entityplayer1}));
2019-04-23 04:00:00 +02:00
+ }
+ entityplayer.sentListPacket = true;
2015-02-04 00:38:21 +01:00
+ // CraftBukkit end
2019-04-23 04:00:00 +02:00
+
2021-06-11 07:00:00 +02:00
+ entityplayer.connection.sendPacket(new PacketPlayOutEntityMetadata(entityplayer.getId(), entityplayer.getDataWatcher(), true)); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn
2019-04-23 04:00:00 +02:00
+
+ // CraftBukkit start - Only add if the player wasn't moved in the event
2021-06-11 07:00:00 +02:00
+ if (entityplayer.level == worldserver1 && !worldserver1.getPlayers().contains(entityplayer)) {
2020-06-25 02:00:00 +02:00
+ worldserver1.addPlayerJoin(entityplayer);
2019-04-23 04:00:00 +02:00
+ this.server.getBossBattleCustomData().a(entityplayer);
}
2020-06-25 02:00:00 +02:00
- worldserver1.addPlayerJoin(entityplayer);
2019-04-23 04:00:00 +02:00
- this.server.getBossBattleCustomData().a(entityplayer);
2020-06-25 02:00:00 +02:00
+ worldserver1 = entityplayer.getWorldServer(); // CraftBukkit - Update in case join event changed it
2019-04-23 04:00:00 +02:00
+ // CraftBukkit end
2020-06-25 02:00:00 +02:00
this.a(entityplayer, worldserver1);
2016-02-29 22:32:46 +01:00
if (!this.server.getResourcePack().isEmpty()) {
2021-06-11 07:00:00 +02:00
entityplayer.setResourcePack(this.server.getResourcePack(), this.server.getResourcePackHash(), this.server.aY(), this.server.bb());
@@ -227,8 +308,11 @@
2019-04-23 04:00:00 +02:00
if (nbttagcompound != null && nbttagcompound.hasKeyOfType("RootVehicle", 10)) {
NBTTagCompound nbttagcompound1 = nbttagcompound.getCompound("RootVehicle");
2020-06-25 02:00:00 +02:00
- Entity entity = EntityTypes.a(nbttagcompound1.getCompound("Entity"), worldserver1, (entity1) -> {
- return !worldserver1.addEntitySerialized(entity1) ? null : entity1;
2019-04-23 04:00:00 +02:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ WorldServer finalWorldServer = worldserver1;
2019-04-23 04:00:00 +02:00
+ Entity entity = EntityTypes.a(nbttagcompound1.getCompound("Entity"), finalWorldServer, (entity1) -> {
+ return !finalWorldServer.addEntitySerialized(entity1) ? null : entity1;
+ // CraftBukkit end
});
if (entity != null) {
2021-06-11 07:00:00 +02:00
@@ -271,6 +355,8 @@
2014-11-25 22:32:16 +01:00
}
2016-02-29 22:32:46 +01:00
entityplayer.syncInventory();
2014-11-25 22:32:16 +01:00
+ // CraftBukkit - Moved from above, added world
2021-06-11 07:00:00 +02:00
+ PlayerList.LOGGER.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), worldserver1.serverLevelData.getName(), entityplayer.locX(), entityplayer.locY(), entityplayer.locZ());
2014-11-25 22:32:16 +01:00
}
2015-06-06 11:33:48 +02:00
public void sendScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
2021-06-11 07:00:00 +02:00
@@ -303,30 +389,31 @@
2014-11-25 22:32:16 +01:00
}
2018-08-26 04:00:00 +02:00
public void setPlayerFileData(WorldServer worldserver) {
2021-06-11 07:00:00 +02:00
+ if (playerIo != null) return; // CraftBukkit
2018-08-26 04:00:00 +02:00
worldserver.getWorldBorder().a(new IWorldBorderListener() {
2019-04-23 04:00:00 +02:00
@Override
2015-02-26 23:41:06 +01:00
public void a(WorldBorder worldborder, double d0) {
2021-06-11 07:00:00 +02:00
- PlayerList.this.sendAll(new ClientboundSetBorderSizePacket(worldborder));
+ PlayerList.this.sendAll(new ClientboundSetBorderSizePacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2016-02-29 22:32:46 +01:00
public void a(WorldBorder worldborder, double d0, double d1, long i) {
2021-06-11 07:00:00 +02:00
- PlayerList.this.sendAll(new ClientboundSetBorderLerpSizePacket(worldborder));
+ PlayerList.this.sendAll(new ClientboundSetBorderLerpSizePacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2016-02-29 22:32:46 +01:00
public void a(WorldBorder worldborder, double d0, double d1) {
2021-06-11 07:00:00 +02:00
- PlayerList.this.sendAll(new ClientboundSetBorderCenterPacket(worldborder));
+ PlayerList.this.sendAll(new ClientboundSetBorderCenterPacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2016-02-29 22:32:46 +01:00
public void a(WorldBorder worldborder, int i) {
2021-06-11 07:00:00 +02:00
- PlayerList.this.sendAll(new ClientboundSetBorderWarningDelayPacket(worldborder));
+ PlayerList.this.sendAll(new ClientboundSetBorderWarningDelayPacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2016-02-29 22:32:46 +01:00
public void b(WorldBorder worldborder, int i) {
2021-06-11 07:00:00 +02:00
- PlayerList.this.sendAll(new ClientboundSetBorderWarningDistancePacket(worldborder));
+ PlayerList.this.sendAll(new ClientboundSetBorderWarningDistancePacket(worldborder), worldborder.world); // CraftBukkit
2016-02-29 22:32:46 +01:00
}
2019-04-23 04:00:00 +02:00
@Override
2021-06-11 07:00:00 +02:00
@@ -354,14 +441,15 @@
2018-10-02 17:41:47 +02:00
}
2017-07-17 01:55:47 +02:00
protected void savePlayerFile(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);
- ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) this.stats.get(entityplayer.getUniqueID());
2017-07-17 01:55:47 +02:00
+ ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStatisticManager(); // CraftBukkit
if (serverstatisticmanager != null) {
2020-06-25 02:00:00 +02:00
serverstatisticmanager.save();
2017-07-17 01:55:47 +02:00
}
2021-06-11 07:00:00 +02:00
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.advancements.get(entityplayer.getUniqueID());
2017-07-17 01:55:47 +02:00
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit
if (advancementdataplayer != null) {
2020-06-25 02:00:00 +02:00
advancementdataplayer.b();
2021-06-11 07:00:00 +02:00
@@ -369,10 +457,24 @@
2015-02-04 00:38:21 +01:00
}
2014-11-25 22:32:16 +01:00
- public void disconnect(EntityPlayer entityplayer) {
+ public String disconnect(EntityPlayer entityplayer) { // CraftBukkit - return string
2018-07-15 02:00:00 +02:00
WorldServer worldserver = entityplayer.getWorldServer();
2016-02-29 22:32:46 +01:00
2018-07-15 02:00:00 +02:00
entityplayer.a(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) {
2020-10-01 11:07:54 +02:00
+ entityplayer.closeInventory();
+ }
2014-11-25 22:32:16 +01:00
+
2016-07-07 02:43:49 +02:00
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " 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
+
2020-06-24 01:54:59 +02:00
+ entityplayer.playerTick(); // SPIGOT-924
2014-11-25 22:32:16 +01:00
+ // CraftBukkit end
2016-06-25 12:38:13 +02:00
+
2014-11-25 22:32:16 +01:00
this.savePlayerFile(entityplayer);
2016-02-29 22:32:46 +01:00
if (entityplayer.isPassenger()) {
2018-07-15 02:00:00 +02:00
Entity entity = entityplayer.getRootVehicle();
2021-06-11 07:00:00 +02:00
@@ -396,18 +498,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
+ // this.o.remove(uuid);
+ // this.p.remove(uuid);
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
+ }
+
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ // this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[]{entityplayer}));
2015-02-26 23:41:06 +01:00
+ PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entityplayer);
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-06-11 07:00:00 +02:00
+ entityplayer2.connection.sendPacket(packet);
2014-11-25 22:32:16 +01:00
+ } else {
2015-02-26 23:41:06 +01:00
+ entityplayer2.getBukkitEntity().removeDisconnectingPlayer(entityplayer.getBukkitEntity());
2014-11-25 22:32:16 +01:00
+ }
2021-06-11 07:00:00 +02: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
2021-06-11 07:00:00 +02:00
- this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[]{entityplayer}));
2014-11-25 22:32:16 +01:00
+ return playerQuitEvent.getQuitMessage(); // CraftBukkit
}
2018-07-15 02:00:00 +02:00
- @Nullable
- public IChatBaseComponent attemptLogin(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
+ public EntityPlayer attemptLogin(LoginListener loginlistener, GameProfile gameprofile, String hostname) {
2018-07-15 02:00:00 +02:00
ChatMessage chatmessage;
2021-06-11 07:00:00 +02:00
- if (this.bans.isBanned(gameprofile)) {
2014-12-06 21:53:57 +01:00
+ // Moved from processLogin
+ UUID uuid = EntityHuman.a(gameprofile);
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);
+ if (entityplayer.getUniqueID().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();
+ savePlayerFile(entityplayer); // CraftBukkit - Force the player's inventory to be saved
2021-06-11 07:00:00 +02:00
+ entityplayer.connection.disconnect(new ChatMessage("multiplayer.disconnect.duplicate_login", new Object[0]));
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-06-11 07:00:00 +02:00
+ SocketAddress socketaddress = loginlistener.connection.getSocketAddress();
2014-11-25 22:32:16 +01:00
+
2021-06-11 07:00:00 +02:00
+ EntityPlayer entity = new EntityPlayer(this.server, this.server.getWorldServer(World.OVERWORLD), gameprofile);
2014-11-25 22:32:16 +01:00
+ Player player = entity.getBukkitEntity();
+ PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) socketaddress).getAddress());
2018-07-15 02:00:00 +02:00
+
2014-11-25 22:32:16 +01:00
+ if (getProfileBans().isBanned(gameprofile) && !getProfileBans().get(gameprofile).hasExpired()) {
2021-06-11 07:00:00 +02:00
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.bans.get(gameprofile);
2014-11-25 22:32:16 +01:00
2019-05-27 22:30:00 +02:00
chatmessage = new ChatMessage("multiplayer.disconnect.banned.reason", new Object[]{gameprofilebanentry.getReason()});
2021-06-11 07:00:00 +02:00
@@ -415,10 +565,12 @@
chatmessage.addSibling(new ChatMessage("multiplayer.disconnect.banned.expiration", new Object[]{PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())}));
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
- return chatmessage;
+ // return chatmessage;
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
2014-11-25 22:32:16 +01:00
} else if (!this.isWhitelisted(gameprofile)) {
2020-06-25 02:00:00 +02:00
- return new ChatMessage("multiplayer.disconnect.not_whitelisted");
2021-06-11 07:00:00 +02:00
- } else if (this.ipBans.isBanned(socketaddress)) {
2020-06-25 02:00:00 +02:00
+ chatmessage = new ChatMessage("multiplayer.disconnect.not_whitelisted");
2018-07-15 02:00:00 +02:00
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, CraftChatMessage.fromComponent(chatmessage));
2014-11-25 22:32:16 +01:00
+ } else if (getIPBans().isBanned(socketaddress) && !getIPBans().get(socketaddress).hasExpired()) {
2021-06-11 07:00:00 +02:00
IpBanEntry ipbanentry = this.ipBans.get(socketaddress);
2014-11-25 22:32:16 +01:00
2019-05-27 22:30:00 +02:00
chatmessage = new ChatMessage("multiplayer.disconnect.banned_ip.reason", new Object[]{ipbanentry.getReason()});
2021-06-11 07:00:00 +02:00
@@ -426,13 +578,25 @@
chatmessage.addSibling(new ChatMessage("multiplayer.disconnect.banned_ip.expiration", new Object[]{PlayerList.BAN_DATE_FORMAT.format(ipbanentry.getExpires())}));
2014-11-25 22:32:16 +01:00
}
2018-07-15 02:00:00 +02:00
- return chatmessage;
+ // return chatmessage;
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
2014-11-25 22:32:16 +01:00
} else {
2021-06-11 07:00:00 +02:00
- return this.players.size() >= this.maxPlayers && !this.d(gameprofile) ? new ChatMessage("multiplayer.disconnect.server_full") : null;
+ // return this.players.size() >= this.maxPlayers && !this.d(gameprofile) ? new ChatMessage("multiplayer.disconnect.server_full") : null;
+ if (this.players.size() >= this.maxPlayers && !this.d(gameprofile)) {
2014-11-25 22:32:16 +01:00
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full");
+ }
2021-06-11 07:00:00 +02: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;
2021-06-11 07:00:00 +02:00
+ }
2014-11-25 22:32:16 +01:00
+ return entity;
}
- public EntityPlayer processLogin(GameProfile gameprofile) {
+ public EntityPlayer processLogin(GameProfile gameprofile, EntityPlayer player) { // CraftBukkit - added EntityPlayer
2014-12-06 21:53:57 +01:00
+ /* CraftBukkit startMoved up
2014-11-25 22:32:16 +01:00
UUID uuid = EntityHuman.a(gameprofile);
2018-12-25 22:00:00 +01:00
List<EntityPlayer> list = Lists.newArrayList();
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
@@ -459,14 +623,24 @@
2014-11-25 22:32:16 +01:00
}
2021-06-11 07:00:00 +02:00
return new EntityPlayer(this.server, this.server.F(), gameprofile);
2015-02-26 23:41:06 +01:00
+ */
2014-11-25 22:32:16 +01:00
+ return player;
2016-06-25 12:38:13 +02:00
+ // CraftBukkit end
2014-11-25 22:32:16 +01:00
}
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
public EntityPlayer moveToWorld(EntityPlayer entityplayer, boolean flag) {
+ return this.moveToWorld(entityplayer, this.server.getWorldServer(entityplayer.getSpawnDimension()), flag, null, true);
2014-11-25 22:32:16 +01:00
+ }
2016-03-06 04:35:33 +01:00
+
2020-06-25 02:00:00 +02:00
+ public EntityPlayer moveToWorld(EntityPlayer entityplayer, WorldServer worldserver, boolean flag, Location location, boolean avoidSuffocation) {
2017-04-21 06:56:41 +02:00
+ entityplayer.stopRiding(); // CraftBukkit
2014-11-25 22:32:16 +01:00
this.players.remove(entityplayer);
2021-06-11 07:00:00 +02:00
entityplayer.getWorldServer().a(entityplayer, Entity.RemovalReason.DISCARDED);
2020-06-25 02:00:00 +02:00
BlockPosition blockposition = entityplayer.getSpawn();
2020-08-11 23:00:00 +02:00
float f = entityplayer.getSpawnAngle();
2020-06-25 02:00:00 +02:00
boolean flag1 = entityplayer.isSpawnForced();
2014-11-25 22:32:16 +01:00
+ /* CraftBukkit start
2020-06-25 02:00:00 +02:00
WorldServer worldserver = this.server.getWorldServer(entityplayer.getSpawnDimension());
Optional optional;
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
@@ -478,6 +652,11 @@
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
WorldServer worldserver1 = worldserver != null && optional.isPresent() ? worldserver : this.server.F();
EntityPlayer entityplayer1 = new EntityPlayer(this.server, worldserver1, entityplayer.getProfile());
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;
2017-05-14 04:00:00 +02:00
entityplayer1.copyFrom(entityplayer, flag);
2021-06-11 07:00:00 +02:00
@@ -493,49 +672,110 @@
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()) {
2020-08-11 23:00:00 +02:00
- IBlockData iblockdata = worldserver1.getType(blockposition);
- boolean flag3 = iblockdata.a(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;
2020-06-25 02:00:00 +02:00
+ WorldServer worldserver1 = this.server.getWorldServer(entityplayer.getSpawnDimension());
+ if (worldserver1 != null) {
+ Optional optional;
2020-08-11 23:00:00 +02:00
- if (!iblockdata.a((Tag) TagsBlock.BEDS) && !flag3) {
- f1 = f;
- } else {
- Vec3D vec3d1 = Vec3D.c((BaseBlockPosition) blockposition).d(vec3d).d();
2020-06-25 02:00:00 +02:00
+ if (blockposition != null) {
2020-08-11 23:00:00 +02:00
+ optional = EntityHuman.getBed(worldserver1, blockposition, f, flag1, flag);
2020-06-25 02:00:00 +02:00
+ } else {
+ optional = Optional.empty();
+ }
2020-08-11 23:00:00 +02:00
+
2019-04-25 04:00:00 +02:00
+ if (optional.isPresent()) {
2020-08-11 23:00:00 +02:00
+ IBlockData iblockdata = worldserver1.getType(blockposition);
+ boolean flag3 = iblockdata.a(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;
+
+ if (!iblockdata.a((Tag) TagsBlock.BEDS) && !flag3) {
+ f1 = f;
+ } else {
+ Vec3D vec3d1 = Vec3D.c((BaseBlockPosition) blockposition).d(vec3d).d();
2019-04-25 04:00:00 +02:00
+
2021-06-11 07:00:00 +02:00
+ f1 = (float) MathHelper.f(MathHelper.d(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
2020-08-11 23:00:00 +02:00
+ }
2021-06-11 07:00:00 +02:00
+
2020-08-11 23:00:00 +02:00
+ entityplayer1.setRespawnPosition(worldserver1.getDimensionKey(), blockposition, f, flag1, false);
+ flag2 = !flag && flag3;
2014-11-25 22:32:16 +01:00
+ isBedSpawn = true;
2020-11-17 22:13:56 +01:00
+ location = new Location(worldserver1.getWorld(), vec3d.x, vec3d.y, vec3d.z, f1, 0.0F);
2020-06-25 02:00:00 +02:00
+ } else if (blockposition != null) {
2021-06-11 07:00:00 +02:00
+ entityplayer1.connection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
2014-11-25 22:32:16 +01:00
+ }
2021-06-11 07:00:00 +02:00
+ }
- f1 = (float) MathHelper.f(MathHelper.d(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
+ if (location == null) {
+ worldserver1 = this.server.getWorldServer(World.OVERWORLD);
+ blockposition = entityplayer1.getSpawnPoint(worldserver1);
+ location = new Location(worldserver1.getWorld(), (double) ((float) blockposition.getX() + 0.5F), (double) ((float) blockposition.getY() + 0.1F), (double) ((float) blockposition.getZ() + 0.5F));
2020-08-11 23:00:00 +02:00
}
- entityplayer1.setPositionRotation(vec3d.x, vec3d.y, vec3d.z, f1, 0.0F);
- entityplayer1.setRespawnPosition(worldserver1.getDimensionKey(), blockposition, f, flag1, false);
- flag2 = !flag && flag3;
- } else if (blockposition != null) {
2021-06-11 07:00:00 +02:00
- entityplayer1.connection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.NO_RESPAWN_BLOCK_AVAILABLE, 0.0F));
2014-11-25 22:32:16 +01:00
+ Player respawnPlayer = cserver.getPlayer(entityplayer1);
2020-07-03 01:54:05 +02:00
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn && !flag2, flag2);
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();
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
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
- while (!worldserver1.getCubes(entityplayer1) && entityplayer1.locY() < (double) worldserver1.getMaxBuildHeight()) {
+ while (avoidSuffocation && !worldserver1.getCubes(entityplayer1) && entityplayer1.locY() < (double) worldserver1.getMaxBuildHeight()) {
2019-12-10 23:00:00 +01:00
entityplayer1.setPosition(entityplayer1.locX(), entityplayer1.locY() + 1.0D, entityplayer1.locZ());
2014-11-25 22:32:16 +01:00
}
+ // CraftBukkit start
2020-06-25 02:00:00 +02:00
+ WorldData worlddata = worldserver1.getWorldData();
2021-06-11 07:00:00 +02:00
+ entityplayer1.connection.sendPacket(new PacketPlayOutRespawn(worldserver1.getDimensionManager(), worldserver1.getDimensionKey(), BiomeManager.a(worldserver1.getSeed()), entityplayer1.gameMode.getGameMode(), entityplayer1.gameMode.c(), worldserver1.isDebugWorld(), worldserver1.isFlatWorld(), flag));
2020-06-25 02:00:00 +02:00
+ entityplayer1.spawnIn(worldserver1);
2021-06-11 07:00:00 +02:00
+ entityplayer1.unsetRemoved();
+ entityplayer1.connection.teleport(new Location(worldserver1.getWorld(), entityplayer1.locX(), entityplayer1.locY(), entityplayer1.locZ(), entityplayer1.getYRot(), entityplayer1.getXRot()));
2014-11-25 22:32:16 +01:00
+ entityplayer1.setSneaking(false);
2019-04-23 04:00:00 +02:00
2021-06-11 07:00:00 +02:00
- WorldData worlddata = entityplayer1.level.getWorldData();
2020-06-25 02:00:00 +02:00
-
2021-06-11 07:00:00 +02:00
- entityplayer1.connection.sendPacket(new PacketPlayOutRespawn(entityplayer1.level.getDimensionManager(), entityplayer1.level.getDimensionKey(), BiomeManager.a(entityplayer1.getWorldServer().getSeed()), entityplayer1.gameMode.getGameMode(), entityplayer1.gameMode.c(), entityplayer1.getWorldServer().isDebugWorld(), entityplayer1.getWorldServer().isFlatWorld(), flag));
- entityplayer1.connection.b(entityplayer1.locX(), entityplayer1.locY(), entityplayer1.locZ(), entityplayer1.getYRot(), entityplayer1.getXRot());
+ // entityplayer1.connection.b(entityplayer1.locX(), entityplayer1.locY(), entityplayer1.locZ(), entityplayer1.getYRot(), entityplayer1.getXRot());
entityplayer1.connection.sendPacket(new PacketPlayOutSpawnPosition(worldserver1.getSpawn(), worldserver1.x()));
entityplayer1.connection.sendPacket(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
entityplayer1.connection.sendPacket(new PacketPlayOutExperience(entityplayer1.experienceProgress, entityplayer1.totalExperience, entityplayer1.experienceLevel));
2020-06-25 02:00:00 +02:00
this.a(entityplayer1, worldserver1);
2019-04-23 04:00:00 +02:00
this.d(entityplayer1);
2020-06-25 02:00:00 +02:00
- worldserver1.addPlayerRespawn(entityplayer1);
2014-11-25 22:32:16 +01:00
- this.players.add(entityplayer1);
2021-06-11 07:00:00 +02:00
- this.playersByUUID.put(entityplayer1.getUniqueID(), entityplayer1);
2016-03-06 06:25:50 +01:00
- entityplayer1.syncInventory();
2021-06-11 07:00:00 +02:00
+ if (!entityplayer.connection.isDisconnected()) {
2020-06-25 02:00:00 +02:00
+ worldserver1.addPlayerRespawn(entityplayer1);
2014-11-25 22:32:16 +01:00
+ this.players.add(entityplayer1);
2021-06-11 07:00:00 +02:00
+ this.playersByUUID.put(entityplayer1.getUniqueID(), entityplayer1);
2014-11-25 22:32:16 +01:00
+ }
2016-03-06 06:25:50 +01:00
+ // entityplayer1.syncInventory();
2016-03-06 04:35:33 +01:00
entityplayer1.setHealth(entityplayer1.getHealth());
2020-06-25 02:00:00 +02:00
if (flag2) {
2021-06-11 07:00:00 +02:00
entityplayer1.connection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 1.0F, 1.0F));
2020-06-25 02:00:00 +02:00
}
2014-11-25 22:32:16 +01:00
+ // Added from changeDimension
+ updateClient(entityplayer); // Update health, etc...
+ entityplayer.updateAbilities();
+ for (Object o1 : entityplayer.getEffects()) {
+ MobEffect mobEffect = (MobEffect) o1;
2021-06-11 07:00:00 +02:00
+ entityplayer.connection.sendPacket(new PacketPlayOutEntityEffect(entityplayer.getId(), mobEffect));
2014-11-25 22:32:16 +01:00
+ }
+
2017-05-14 04:00:00 +02:00
+ // Fire advancement trigger
2019-12-10 23:00:00 +01:00
+ entityplayer.triggerDimensionAdvancements(((CraftWorld) fromWorld).getHandle());
2017-05-14 04:00: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);
+ }
2020-06-25 02:00: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()) {
2014-11-25 22:32:16 +01:00
+ this.savePlayerFile(entityplayer);
+ }
+ // CraftBukkit end
return entityplayer1;
}
2021-06-11 07:00:00 +02:00
@@ -548,7 +788,18 @@
2014-11-25 22:32:16 +01:00
public void tick() {
2021-06-11 07:00:00 +02:00
if (++this.sendAllPlayerInfoIn > 600) {
2016-11-28 00:02:40 +01:00
- this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, this.players));
+ // CraftBukkit start
+ for (int i = 0; i < this.players.size(); ++i) {
+ final EntityPlayer target = (EntityPlayer) this.players.get(i);
+
2021-06-11 07:00:00 +02:00
+ target.connection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, this.players.stream().filter(new Predicate<EntityPlayer>() {
2016-11-28 00:02:40 +01:00
+ @Override
+ public boolean apply(EntityPlayer input) {
+ 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
}
2021-06-11 07:00:00 +02:00
@@ -565,6 +816,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
+ public void sendAll(Packet packet, EntityHuman entityhuman) {
+ for (int i = 0; i < this.players.size(); ++i) {
+ EntityPlayer entityplayer = this.players.get(i);
+ if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
+ continue;
+ }
2021-06-11 07:00:00 +02:00
+ ((EntityPlayer) this.players.get(i)).connection.sendPacket(packet);
2015-06-07 22:04:28 +02:00
+ }
+ }
+
2014-12-10 20:16:37 +01:00
+ public void sendAll(Packet packet, World world) {
2019-04-23 04:00:00 +02:00
+ for (int i = 0; i < world.getPlayers().size(); ++i) {
2021-06-11 07:00:00 +02:00
+ ((EntityPlayer) world.getPlayers().get(i)).connection.sendPacket(packet);
2014-12-10 20:16:37 +01:00
+ }
+
+ }
+ // CraftBukkit end
+
2020-06-25 02:00:00 +02:00
public void a(Packet<?> packet, ResourceKey<World> resourcekey) {
2021-06-11 07:00:00 +02:00
Iterator iterator = this.players.iterator();
@@ -667,6 +937,7 @@
entityplayer.connection.sendPacket(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
this.server.getCommandDispatcher().a(entityplayer);
2014-11-25 22:32:16 +01:00
}
2021-06-11 07:00:00 +02:00
@@ -699,6 +970,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
+ if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
+ continue;
+ }
+ // CraftBukkit end
+
2021-06-11 07:00:00 +02:00
if (entityplayer != entityhuman && entityplayer.level.getDimensionKey() == resourcekey) {
2019-12-10 23:00:00 +01:00
double d4 = d0 - entityplayer.locX();
double d5 = d1 - entityplayer.locY();
2021-06-11 07:00:00 +02:00
@@ -738,23 +1015,34 @@
2014-11-25 22:32:16 +01:00
public void reloadWhitelist() {}
2019-04-23 04:00:00 +02:00
public void a(EntityPlayer entityplayer, WorldServer worldserver) {
2021-06-11 07:00:00 +02:00
- WorldBorder worldborder = this.server.F().getWorldBorder();
+ WorldBorder worldborder = entityplayer.level.getWorldBorder(); // CraftBukkit
2014-11-25 22:32:16 +01:00
2021-06-11 07:00:00 +02:00
entityplayer.connection.sendPacket(new ClientboundInitializeBorderPacket(worldborder));
entityplayer.connection.sendPacket(new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT)));
entityplayer.connection.sendPacket(new PacketPlayOutSpawnPosition(worldserver.getSpawn(), worldserver.x()));
2017-05-19 13:00:13 +02:00
if (worldserver.isRaining()) {
2021-06-11 07:00:00 +02:00
- entityplayer.connection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.START_RAINING, 0.0F));
- entityplayer.connection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.RAIN_LEVEL_CHANGE, worldserver.d(1.0F)));
- entityplayer.connection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.THUNDER_LEVEL_CHANGE, worldserver.b(1.0F)));
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start - handle player weather
2020-06-25 02:00:00 +02:00
+ // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.b, 0.0F));
+ // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.h, worldserver.d(1.0F)));
+ // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(PacketPlayOutGameStateChange.i, worldserver.b(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
}
}
public void updateClient(EntityPlayer entityplayer) {
2021-06-11 07:00:00 +02:00
entityplayer.inventoryMenu.updateInventory();
2014-11-25 22:32:16 +01:00
- entityplayer.triggerHealthUpdate();
+ // entityplayer.triggerHealthUpdate();
+ entityplayer.getBukkitEntity().updateScaledHealth(); // CraftBukkit - Update scaled health on respawn and worldchange
2021-06-11 07:00:00 +02:00
entityplayer.connection.sendPacket(new PacketPlayOutHeldItemSlot(entityplayer.getInventory().selected));
2019-01-02 00:57:47 +01:00
+ // CraftBukkit start - from GameRules
2021-06-11 07:00:00 +02:00
+ int i = entityplayer.level.getGameRules().getBoolean(GameRules.RULE_REDUCEDDEBUGINFO) ? 22 : 23;
+ entityplayer.connection.sendPacket(new PacketPlayOutEntityStatus(entityplayer, (byte) i));
+ float immediateRespawn = entityplayer.level.getGameRules().getBoolean(GameRules.RULE_DO_IMMEDIATE_RESPAWN) ? 1.0F: 0.0F;
+ entityplayer.connection.sendPacket(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() {
2021-06-11 07:00:00 +02:00
@@ -805,12 +1093,22 @@
2016-08-23 06:02:48 +02:00
}
2014-11-25 22:32:16 +01:00
2019-04-23 04:00:00 +02:00
public void shutdown() {
2016-08-23 06:02:48 +02:00
- for (int i = 0; i < this.players.size(); ++i) {
2021-06-11 07:00:00 +02:00
- ((EntityPlayer) this.players.get(i)).connection.disconnect(new ChatMessage("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
+ public void sendMessage(IChatBaseComponent[] iChatBaseComponents) {
+ for (IChatBaseComponent component : iChatBaseComponents) {
2021-06-11 07:00:00 +02:00
+ sendMessage(component, ChatMessageType.SYSTEM, SystemUtils.NIL_UUID);
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
+
2020-06-25 02:00:00 +02:00
public void sendMessage(IChatBaseComponent ichatbasecomponent, ChatMessageType chatmessagetype, UUID uuid) {
this.server.sendMessage(ichatbasecomponent, uuid);
2021-06-11 07:00:00 +02:00
Iterator iterator = this.players.iterator();
@@ -838,16 +1136,23 @@
2017-07-17 01:55:47 +02:00
}
2017-08-03 15:00:00 +02:00
- public ServerStatisticManager getStatisticManager(EntityHuman entityhuman) {
2020-04-05 07:58:43 +02:00
- UUID uuid = entityhuman.getUniqueID();
2021-06-11 07:00:00 +02:00
- ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) this.stats.get(uuid);
2020-04-05 07:58:43 +02:00
+ // CraftBukkit start
+ public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) {
+ ServerStatisticManager serverstatisticmanager = entityhuman.getStatisticManager();
+ return serverstatisticmanager == null ? getStatisticManager(entityhuman.getUniqueID(), entityhuman.getDisplayName().getString()) : serverstatisticmanager;
+ }
+
+ public ServerStatisticManager getStatisticManager(UUID uuid, String displayName) {
2020-06-25 02:00:00 +02:00
+ EntityPlayer entityhuman = this.getPlayer(uuid);
+ ServerStatisticManager serverstatisticmanager = entityhuman == null ? null : (ServerStatisticManager) entityhuman.getStatisticManager();
2017-07-17 01:55:47 +02:00
+ // CraftBukkit end
if (serverstatisticmanager == null) {
2021-06-11 07:00:00 +02:00
File file = this.server.a(SavedFile.PLAYER_STATS_DIR).toFile();
2020-04-05 07:58:43 +02:00
File file1 = new File(file, uuid + ".json");
if (!file1.exists()) {
- File file2 = new File(file, entityhuman.getDisplayName().getString() + ".json");
+ File file2 = new File(file, displayName + ".json"); // CraftBukkit
if (file2.exists() && file2.isFile()) {
file2.renameTo(file1);
2021-06-11 07:00:00 +02:00
@@ -855,7 +1160,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);
2017-07-17 01:55:47 +02:00
+ // this.o.put(uuid, serverstatisticmanager); // CraftBukkit
}
return serverstatisticmanager;
2021-06-11 07:00:00 +02:00
@@ -863,14 +1168,14 @@
2017-07-17 01:55:47 +02:00
2019-04-23 04:00:00 +02:00
public AdvancementDataPlayer f(EntityPlayer entityplayer) {
2017-07-17 01:55:47 +02:00
UUID uuid = entityplayer.getUniqueID();
2021-06-11 07:00:00 +02:00
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.advancements.get(uuid);
2017-07-17 01:55:47 +02:00
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit
if (advancementdataplayer == null) {
2021-06-11 07:00:00 +02:00
File file = this.server.a(SavedFile.PLAYER_ADVANCEMENTS_DIR).toFile();
2017-07-17 01:55:47 +02:00
File file1 = new File(file, uuid + ".json");
2020-06-25 02:00:00 +02:00
advancementdataplayer = new AdvancementDataPlayer(this.server.getDataFixer(), this, this.server.getAdvancementData(), file1, entityplayer);
2021-06-11 07:00:00 +02:00
- this.advancements.put(uuid, advancementdataplayer);
2017-07-17 01:55:47 +02:00
+ // this.p.put(uuid, advancementdataplayer); // CraftBukkit
}
advancementdataplayer.a(entityplayer);
2021-06-11 07:00:00 +02:00
@@ -906,13 +1211,20 @@
2017-07-17 01:55:47 +02:00
}
public void reload() {
2021-06-11 07:00:00 +02:00
- Iterator iterator = this.advancements.values().iterator();
2017-07-17 01:55:47 +02:00
+ // CraftBukkit start
+ /*Iterator iterator = this.p.values().iterator();
while (iterator.hasNext()) {
AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) iterator.next();
2017-05-16 13:22:07 +02:00
2020-06-25 02:00:00 +02:00
advancementdataplayer.a(this.server.getAdvancementData());
2017-07-17 01:55:47 +02:00
+ }*/
+
2017-05-16 13:22:07 +02:00
+ for (EntityPlayer player : players) {
2020-06-25 02:00:00 +02:00
+ player.getAdvancementData().a(this.server.getAdvancementData());
2017-07-17 01:55:47 +02:00
+ player.getAdvancementData().b(player); // CraftBukkit - trigger immediate flush of advancements
}
2017-05-16 13:22:07 +02:00
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
this.sendAll(new PacketPlayOutTags(this.server.getTagRegistry().a((IRegistryCustom) this.registryHolder)));
2018-07-15 02:00:00 +02:00
PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getCraftingManager().b());