Paper/nms-patches/PlayerList.patch

984 lines
51 KiB
Diff
Raw Normal View History

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/PlayerList.java
+++ b/net/minecraft/server/PlayerList.java
2018-12-25 22:00:00 +01:00
@@ -18,6 +18,29 @@
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;
+import com.google.common.collect.Iterables;
+
+import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.chunkio.ChunkIOExecutor;
+
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.TravelAgent;
+import org.bukkit.craftbukkit.util.CraftChatMessage;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerChangedWorldEvent;
+import org.bukkit.event.player.PlayerPortalEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
+import org.bukkit.event.player.PlayerLoginEvent;
+import org.bukkit.event.player.PlayerQuitEvent;
+import org.bukkit.event.player.PlayerRespawnEvent;
+import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
+import org.bukkit.util.Vector;
+// CraftBukkit end
+
public abstract class PlayerList {
public static final File a = new File("banned-players.json");
2018-12-25 22:00:00 +01:00
@@ -27,14 +50,16 @@
2015-02-26 23:41:06 +01:00
private static final Logger f = LogManager.getLogger();
2018-12-06 00:00:00 +01:00
private static final SimpleDateFormat g = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
private final MinecraftServer server;
- public final List<EntityPlayer> players = Lists.newArrayList();
+ public final List<EntityPlayer> players = new java.util.concurrent.CopyOnWriteArrayList(); // CraftBukkit - ArrayList -> CopyOnWriteArrayList: Iterator safety
2015-02-26 23:41:06 +01:00
private final Map<UUID, EntityPlayer> j = Maps.newHashMap();
private final GameProfileBanList k;
private final IpBanList l;
2017-07-17 01:55:47 +02:00
private final OpList operators;
private final WhiteList whitelist;
- private final Map<UUID, ServerStatisticManager> o;
- private final Map<UUID, AdvancementDataPlayer> p;
+ // CraftBukkit start
+ // private final Map<UUID, ServerStatisticManager> o;
+ // private final Map<UUID, AdvancementDataPlayer> p;
+ // CraftBukkit end
public IPlayerFileData playerFileData;
private boolean hasWhitelist;
protected int maxPlayers;
2018-12-25 22:00:00 +01:00
@@ -43,13 +68,23 @@
2017-05-14 04:00:00 +02:00
private boolean u;
private int v;
+ // CraftBukkit start
+ private CraftServer cserver;
+
public PlayerList(MinecraftServer minecraftserver) {
+ this.cserver = minecraftserver.server = new CraftServer(minecraftserver, this);
+ minecraftserver.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance();
+ minecraftserver.reader.addCompleter(new org.bukkit.craftbukkit.command.ConsoleCommandCompleter(minecraftserver.server));
+ // CraftBukkit end
+
this.k = new GameProfileBanList(PlayerList.a);
this.l = new IpBanList(PlayerList.b);
this.operators = new OpList(PlayerList.c);
2017-07-17 01:55:47 +02:00
this.whitelist = new WhiteList(PlayerList.d);
- this.o = Maps.newHashMap();
- this.p = Maps.newHashMap();
+ // CraftBukkit start
+ // this.o = Maps.newHashMap();
+ // this.p = Maps.newHashMap();
+ // CraftBukkit end
this.server = minecraftserver;
2018-07-15 02:00:00 +02:00
this.getProfileBans().a(true);
this.getIPBans().a(true);
2018-12-25 22:00:00 +01:00
@@ -64,6 +99,12 @@
usercache.a(gameprofile);
NBTTagCompound nbttagcompound = this.a(entityplayer);
+ // CraftBukkit start - Better rename detection
2015-02-04 21:33:06 +01:00
+ if (nbttagcompound != null && nbttagcompound.hasKey("bukkit")) {
+ NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit");
+ s = bukkit.hasKeyOfType("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s;
+ }
+ // CraftBukkit end
entityplayer.spawnIn(this.server.getWorldServer(entityplayer.dimension));
entityplayer.playerInteractManager.a((WorldServer) entityplayer.world);
2018-12-25 22:00:00 +01:00
@@ -73,7 +114,8 @@
s1 = networkmanager.getSocketAddress().toString();
}
2018-12-06 00:00:00 +01:00
- PlayerList.f.info("{}[{}] logged in with entity id {} at ({}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.locX, entityplayer.locY, entityplayer.locZ);
+ // CraftBukkit - Moved message to after join
2018-12-06 00:00:00 +01:00
+ // PlayerList.f.info("{}[{}] logged in with entity id {} at ({}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.locX, entityplayer.locY, entityplayer.locZ);
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
WorldData worlddata = worldserver.getWorldData();
2016-11-17 02:41:03 +01:00
2018-12-25 22:00:00 +01:00
@@ -81,6 +123,7 @@
PlayerConnection playerconnection = new PlayerConnection(this.server, networkmanager, entityplayer);
2018-08-26 04:00:00 +02:00
playerconnection.sendPacket(new PacketPlayOutLogin(entityplayer.getId(), entityplayer.playerInteractManager.getGameMode(), worlddata.isHardcore(), worldserver.worldProvider.getDimensionManager(), worldserver.getDifficulty(), this.getMaxPlayers(), worlddata.getType(), worldserver.getGameRules().getBoolean("reducedDebugInfo")));
+ entityplayer.getBukkitEntity().sendSupportedChannels(); // CraftBukkit
2018-07-15 02:00:00 +02:00
playerconnection.sendPacket(new PacketPlayOutCustomPayload(PacketPlayOutCustomPayload.b, (new PacketDataSerializer(Unpooled.buffer())).a(this.getServer().getServerModName())));
2015-05-05 22:43:47 +02:00
playerconnection.sendPacket(new PacketPlayOutServerDifficulty(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
2016-11-17 02:41:03 +01:00
playerconnection.sendPacket(new PacketPlayOutAbilities(entityplayer.abilities));
2018-12-25 22:00:00 +01:00
@@ -100,8 +143,10 @@
2018-07-15 02:00:00 +02:00
chatmessage = new ChatMessage("multiplayer.player.joined.renamed", new Object[] { entityplayer.getScoreboardDisplayName(), s});
}
2018-07-15 02:00:00 +02:00
- this.sendMessage(chatmessage.a(EnumChatFormat.YELLOW));
- this.onPlayerJoin(entityplayer);
2018-07-15 02:00:00 +02:00
+ chatmessage.a(EnumChatFormat.YELLOW);
+ this.onPlayerJoin(entityplayer, CraftChatMessage.fromComponent(chatmessage));
+ // CraftBukkit end
+ worldserver = server.getWorldServer(entityplayer.dimension); // CraftBukkit - Update in case join event changed it
playerconnection.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
this.b(entityplayer, worldserver);
2016-02-29 22:32:46 +01:00
if (!this.server.getResourcePack().isEmpty()) {
2018-12-25 22:00:00 +01:00
@@ -153,6 +198,8 @@
}
2016-02-29 22:32:46 +01:00
entityplayer.syncInventory();
+ // CraftBukkit - Moved from above, added world
2018-12-06 00:00:00 +01:00
+ PlayerList.f.info("{}[{}] logged in with entity id {} at ([{}]{}, {}, {})", entityplayer.getDisplayName().getString(), s1, entityplayer.getId(), entityplayer.world.worldData.getName(), entityplayer.locX, entityplayer.locY, entityplayer.locZ);
}
public void sendScoreboard(ScoreboardServer scoreboardserver, EntityPlayer entityplayer) {
2018-12-25 22:00:00 +01:00
@@ -185,26 +232,27 @@
}
2018-08-26 04:00:00 +02:00
public void setPlayerFileData(WorldServer worldserver) {
+ if (playerFileData != null) return; // CraftBukkit
2018-08-26 04:00:00 +02:00
this.playerFileData = worldserver.getDataManager().getPlayerFileData();
worldserver.getWorldBorder().a(new IWorldBorderListener() {
2015-02-26 23:41:06 +01:00
public void a(WorldBorder worldborder, double d0) {
2016-02-29 22:32:46 +01:00
- PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_SIZE));
+ PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_SIZE), worldborder.world);
}
public void a(WorldBorder worldborder, double d0, double d1, long i) {
- PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.LERP_SIZE));
+ PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.LERP_SIZE), worldborder.world);
}
public void a(WorldBorder worldborder, double d0, double d1) {
- PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_CENTER));
+ PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_CENTER), worldborder.world);
}
public void a(WorldBorder worldborder, int i) {
- PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_TIME));
+ PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_TIME), worldborder.world);
}
public void b(WorldBorder worldborder, int i) {
- PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_BLOCKS));
+ PlayerList.this.sendAll(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_BLOCKS), worldborder.world);
}
public void b(WorldBorder worldborder, double d0) {}
2018-12-25 22:00:00 +01:00
@@ -252,14 +300,15 @@
}
2017-07-17 01:55:47 +02:00
protected void savePlayerFile(EntityPlayer entityplayer) {
+ if (!entityplayer.getBukkitEntity().isPersistent()) return; // CraftBukkit
2017-07-17 01:55:47 +02:00
this.playerFileData.save(entityplayer);
- ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) this.o.get(entityplayer.getUniqueID());
+ ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStatisticManager(); // CraftBukkit
if (serverstatisticmanager != null) {
2018-07-15 02:00:00 +02:00
serverstatisticmanager.a();
2017-07-17 01:55:47 +02:00
}
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.p.get(entityplayer.getUniqueID());
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit
if (advancementdataplayer != null) {
advancementdataplayer.c();
2018-12-25 22:00:00 +01:00
@@ -267,29 +316,80 @@
}
- public void onPlayerJoin(EntityPlayer entityplayer) {
+ public void onPlayerJoin(EntityPlayer entityplayer, String joinMessage) { // CraftBukkit added param
this.players.add(entityplayer);
2015-02-26 23:41:06 +01:00
this.j.put(entityplayer.getUniqueID(), entityplayer);
- 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
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
+ // CraftBukkit start
+ PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(cserver.getPlayer(entityplayer), joinMessage);
+ cserver.getPluginManager().callEvent(playerJoinEvent);
+
+ if (!entityplayer.playerConnection.networkManager.isConnected()) {
+ return;
+ }
+
+ joinMessage = playerJoinEvent.getJoinMessage();
+
+ if (joinMessage != null && joinMessage.length() > 0) {
+ for (IChatBaseComponent line : org.bukkit.craftbukkit.util.CraftChatMessage.fromString(joinMessage)) {
+ server.getPlayerList().sendAll(new PacketPlayOutChat(line));
+ }
+ }
+
+ ChunkIOExecutor.adjustPoolSize(getPlayerCount());
2015-02-26 23:41:06 +01:00
+ // CraftBukkit end
+
+ // CraftBukkit start - sendAll above replaced with this loop
2015-02-26 23:41:06 +01:00
+ PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityplayer);
2016-02-29 22:32:46 +01:00
+
for (int i = 0; i < this.players.size(); ++i) {
2016-02-29 22:32:46 +01:00
- entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { (EntityPlayer) this.players.get(i)}));
+ EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
+
+ if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) {
+ entityplayer1.playerConnection.sendPacket(packet);
+ }
+
+ if (!entityplayer.getBukkitEntity().canSee(entityplayer1.getBukkitEntity())) {
+ continue;
+ }
+
2016-02-29 22:32:46 +01:00
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, new EntityPlayer[] { entityplayer1}));
}
+ entityplayer.sentListPacket = true;
+ // CraftBukkit end
+
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutEntityMetadata(entityplayer.getId(), entityplayer.datawatcher, true)); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn
2016-02-29 22:32:46 +01:00
- worldserver.addEntity(entityplayer);
- this.a(entityplayer, (WorldServer) null);
2018-12-06 00:00:00 +01:00
- this.server.getBossBattleCustomData().a(entityplayer);
+ // CraftBukkit start - Only add if the player wasn't moved in the event
+ if (entityplayer.world == worldserver && !worldserver.players.contains(entityplayer)) {
+ worldserver.addEntity(entityplayer);
+ this.a(entityplayer, (WorldServer) null);
2018-12-06 00:00:00 +01:00
+ this.server.getBossBattleCustomData().a(entityplayer);
+ }
+ // CraftBukkit end
}
2018-10-22 21:00:00 +02:00
public void updateChunks(EntityPlayer entityplayer) {
2018-07-15 02:00:00 +02:00
entityplayer.getWorldServer().getPlayerChunkMap().movePlayer(entityplayer);
}
- 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);
+
+ // CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it
+ org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(entityplayer);
+
+ PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " left the game");
+ cserver.getPluginManager().callEvent(playerQuitEvent);
+ entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
+
2016-11-17 02:41:03 +01:00
+ entityplayer.playerTick();// SPIGOT-924
+ // CraftBukkit end
+
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();
2018-12-25 22:00:00 +01:00
@@ -320,18 +420,68 @@
2017-07-17 01:55:47 +02:00
if (entityplayer1 == entityplayer) {
this.j.remove(uuid);
- this.o.remove(uuid);
- this.p.remove(uuid);
+ // CraftBukkit start
+ // this.o.remove(uuid);
+ // this.p.remove(uuid);
+ // CraftBukkit end
}
- this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[] { entityplayer}));
+ // CraftBukkit start
+ // this.sendAll(new PacketPlayOutPlayerInfo(EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[] { entityplayer}));
2015-02-26 23:41:06 +01:00
+ PacketPlayOutPlayerInfo packet = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, entityplayer);
+ for (int i = 0; i < players.size(); i++) {
2015-02-26 23:41:06 +01:00
+ EntityPlayer entityplayer2 = (EntityPlayer) this.players.get(i);
+
2015-02-26 23:41:06 +01:00
+ if (entityplayer2.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) {
+ entityplayer2.playerConnection.sendPacket(packet);
+ } else {
2015-02-26 23:41:06 +01:00
+ entityplayer2.getBukkitEntity().removeDisconnectingPlayer(entityplayer.getBukkitEntity());
+ }
+ }
+ // This removes the scoreboard (and player reference) for the specific player in the manager
+ cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
+ // CraftBukkit end
+
+ ChunkIOExecutor.adjustPoolSize(this.getPlayerCount()); // CraftBukkit
+
+ return playerQuitEvent.getQuitMessage(); // CraftBukkit
}
2018-07-15 02:00:00 +02:00
- @Nullable
- public IChatBaseComponent attemptLogin(SocketAddress socketaddress, GameProfile gameprofile) {
+ // 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;
- if (this.k.isBanned(gameprofile)) {
+ // Moved from processLogin
+ UUID uuid = EntityHuman.a(gameprofile);
2018-12-25 22:00:00 +01:00
+ List<EntityPlayer> list = Lists.newArrayList();
+
+ 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);
+ }
+ }
+
2018-12-25 22:00:00 +01:00
+ Iterator iterator = list.iterator();
+
+ while (iterator.hasNext()) {
+ entityplayer = (EntityPlayer) iterator.next();
+ savePlayerFile(entityplayer); // CraftBukkit - Force the player's inventory to be saved
2017-05-30 13:25:59 +02:00
+ entityplayer.playerConnection.disconnect(new ChatMessage("multiplayer.disconnect.duplicate_login", new Object[0]));
+ }
2015-02-26 23:41:06 +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.
+ SocketAddress socketaddress = loginlistener.networkManager.getSocketAddress();
+
2018-08-26 04:00:00 +02:00
+ EntityPlayer entity = new EntityPlayer(this.server, this.server.getWorldServer(DimensionManager.OVERWORLD), gameprofile, new PlayerInteractManager(this.server.getWorldServer(DimensionManager.OVERWORLD)));
+ Player player = entity.getBukkitEntity();
+ PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, ((java.net.InetSocketAddress) socketaddress).getAddress());
2018-07-15 02:00:00 +02:00
+
+ if (getProfileBans().isBanned(gameprofile) && !getProfileBans().get(gameprofile).hasExpired()) {
GameProfileBanEntry gameprofilebanentry = (GameProfileBanEntry) this.k.get(gameprofile);
2018-07-15 02:00:00 +02:00
chatmessage = new ChatMessage("multiplayer.disconnect.banned.reason", new Object[] { gameprofilebanentry.getReason()});
2018-12-25 22:00:00 +01:00
@@ -339,10 +489,12 @@
2018-07-15 02:00:00 +02:00
chatmessage.addSibling(new ChatMessage("multiplayer.disconnect.banned.expiration", new Object[] { PlayerList.g.format(gameprofilebanentry.getExpires())}));
}
2018-07-15 02:00:00 +02:00
- return chatmessage;
+ // return chatmessage;
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
} else if (!this.isWhitelisted(gameprofile)) {
2018-07-15 02:00:00 +02:00
- return new ChatMessage("multiplayer.disconnect.not_whitelisted", new Object[0]);
- } else if (this.l.isBanned(socketaddress)) {
2018-07-15 02:00:00 +02:00
+ chatmessage = new ChatMessage("multiplayer.disconnect.not_whitelisted", new Object[0]);
+ event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, CraftChatMessage.fromComponent(chatmessage));
+ } else if (getIPBans().isBanned(socketaddress) && !getIPBans().get(socketaddress).hasExpired()) {
IpBanEntry ipbanentry = this.l.get(socketaddress);
2018-07-15 02:00:00 +02:00
chatmessage = new ChatMessage("multiplayer.disconnect.banned_ip.reason", new Object[] { ipbanentry.getReason()});
2018-12-25 22:00:00 +01:00
@@ -350,13 +502,25 @@
2018-07-15 02:00:00 +02:00
chatmessage.addSibling(new ChatMessage("multiplayer.disconnect.banned_ip.expiration", new Object[] { PlayerList.g.format(ipbanentry.getExpires())}));
}
2018-07-15 02:00:00 +02:00
- return chatmessage;
+ // return chatmessage;
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage));
} else {
2018-07-15 02:00:00 +02:00
- return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? new ChatMessage("multiplayer.disconnect.server_full", new Object[0]) : null;
+ // return this.players.size() >= this.maxPlayers && !this.f(gameprofile) ? new ChatMessage("multiplayer.disconnect.server_full", new Object[0]) : null;
2015-05-05 22:43:47 +02:00
+ if (this.players.size() >= this.maxPlayers && !this.f(gameprofile)) {
+ event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full");
+ }
2018-08-26 04:00:00 +02:00
}
+
+ cserver.getPluginManager().callEvent(event);
+ if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
+ loginlistener.disconnect(event.getKickMessage());
+ return null;
2018-08-26 04:00:00 +02:00
+ }
+ return entity;
}
- public EntityPlayer processLogin(GameProfile gameprofile) {
+ public EntityPlayer processLogin(GameProfile gameprofile, EntityPlayer player) { // CraftBukkit - added EntityPlayer
+ /* CraftBukkit startMoved up
UUID uuid = EntityHuman.a(gameprofile);
2018-12-25 22:00:00 +01:00
List<EntityPlayer> list = Lists.newArrayList();
2018-12-25 22:00:00 +01:00
@@ -391,17 +555,27 @@
}
2018-08-26 04:00:00 +02:00
return new EntityPlayer(this.server, this.server.getWorldServer(DimensionManager.OVERWORLD), gameprofile, (PlayerInteractManager) object);
2015-02-26 23:41:06 +01:00
+ */
+ return player;
+ // CraftBukkit end
}
+ // CraftBukkit start
2018-08-26 04:00:00 +02:00
public EntityPlayer moveToWorld(EntityPlayer entityplayer, DimensionManager dimensionmanager, boolean flag) {
+ return this.moveToWorld(entityplayer, dimensionmanager, flag, null, true);
+ }
+
2018-08-26 04:00:00 +02:00
+ public EntityPlayer moveToWorld(EntityPlayer entityplayer, DimensionManager dimensionmanager, boolean flag, Location location, boolean avoidSuffocation) {
+ entityplayer.stopRiding(); // CraftBukkit
2018-07-15 02:00:00 +02:00
entityplayer.getWorldServer().getTracker().untrackPlayer(entityplayer);
- entityplayer.getWorldServer().getTracker().untrackEntity(entityplayer);
+ // entityplayer.getWorldServer().getTracker().untrackEntity(entityplayer); // CraftBukkit
entityplayer.getWorldServer().getPlayerChunkMap().removePlayer(entityplayer);
this.players.remove(entityplayer);
this.server.getWorldServer(entityplayer.dimension).removeEntity(entityplayer);
BlockPosition blockposition = entityplayer.getBed();
boolean flag1 = entityplayer.isRespawnForced();
+ /* CraftBukkit start
2018-08-26 04:00:00 +02:00
entityplayer.dimension = dimensionmanager;
Object object;
2018-12-25 22:00:00 +01:00
@@ -412,6 +586,11 @@
}
EntityPlayer entityplayer1 = new EntityPlayer(this.server, this.server.getWorldServer(entityplayer.dimension), entityplayer.getProfile(), (PlayerInteractManager) object);
+ // */
+ EntityPlayer entityplayer1 = entityplayer;
+ org.bukkit.World fromWorld = entityplayer.getBukkitEntity().getWorld();
+ entityplayer.viewingCredits = false;
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
entityplayer1.playerConnection = entityplayer.playerConnection;
2017-05-14 04:00:00 +02:00
entityplayer1.copyFrom(entityplayer, flag);
2018-12-25 22:00:00 +01:00
@@ -425,43 +604,160 @@
2017-05-14 04:00:00 +02:00
entityplayer1.addScoreboardTag(s);
2016-02-29 22:32:46 +01:00
}
- WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
+ // WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension); // CraftBukkit - handled later
- this.a(entityplayer1, entityplayer, worldserver);
+ // this.a(entityplayer1, entityplayer, worldserver); // CraftBukkit - removed
BlockPosition blockposition1;
- if (blockposition != null) {
- blockposition1 = EntityHuman.getBed(this.server.getWorldServer(entityplayer.dimension), blockposition, flag1);
- if (blockposition1 != null) {
- entityplayer1.setPositionRotation((double) ((float) blockposition1.getX() + 0.5F), (double) ((float) blockposition1.getY() + 0.1F), (double) ((float) blockposition1.getZ() + 0.5F), 0.0F, 0.0F);
- entityplayer1.setRespawnPosition(blockposition, flag1);
- } else {
- entityplayer1.playerConnection.sendPacket(new PacketPlayOutGameStateChange(0, 0.0F));
+ // CraftBukkit start - fire PlayerRespawnEvent
+ if (location == null) {
+ boolean isBedSpawn = false;
+ CraftWorld cworld = (CraftWorld) this.server.server.getWorld(entityplayer.spawnWorld);
+ if (cworld != null && blockposition != null) {
+ blockposition1 = EntityHuman.getBed(cworld.getHandle(), blockposition, flag1);
+ if (blockposition1 != null) {
+ isBedSpawn = true;
+ location = new Location(cworld, (double) ((float) blockposition1.getX() + 0.5F), (double) ((float) blockposition1.getY() + 0.1F), (double) ((float) blockposition1.getZ() + 0.5F));
+ } else {
+ entityplayer1.setRespawnPosition(null, true);
+ entityplayer1.playerConnection.sendPacket(new PacketPlayOutGameStateChange(0, 0.0F));
+ }
2018-08-26 04:00:00 +02:00
}
+
+ if (location == null) {
+ cworld = (CraftWorld) this.server.server.getWorlds().get(0);
2018-07-15 02:00:00 +02:00
+ blockposition = entityplayer1.getSpawnPoint(cworld.getHandle());
+ location = new Location(cworld, (double) ((float) blockposition.getX() + 0.5F), (double) ((float) blockposition.getY() + 0.1F), (double) ((float) blockposition.getZ() + 0.5F));
2018-08-26 04:00:00 +02:00
+ }
+
+ Player respawnPlayer = cserver.getPlayer(entityplayer1);
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
+ cserver.getPluginManager().callEvent(respawnEvent);
+
+ location = respawnEvent.getRespawnLocation();
+ entityplayer.reset();
+ } else {
2018-08-26 04:00:00 +02:00
+ location.setWorld(server.getWorldServer(dimensionmanager).getWorld());
}
+ WorldServer worldserver = ((CraftWorld) location.getWorld()).getHandle();
+ entityplayer1.forceSetPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
+ // CraftBukkit end
2018-12-13 01:00:00 +01:00
worldserver.getChunkProvider().getChunkAt((int) entityplayer1.locX >> 4, (int) entityplayer1.locZ >> 4, true, true);
2018-07-15 02:00:00 +02:00
- while (!worldserver.getCubes(entityplayer1, entityplayer1.getBoundingBox()) && entityplayer1.locY < 256.0D) {
+ while (avoidSuffocation && !worldserver.getCubes(entityplayer1, entityplayer1.getBoundingBox()) && entityplayer1.locY < 256.0D) {
entityplayer1.setPosition(entityplayer1.locX, entityplayer1.locY + 1.0D, entityplayer1.locZ);
}
+ // CraftBukkit start
+ // Force the client to refresh their chunk cache
+ if (fromWorld.getEnvironment() == worldserver.getWorld().getEnvironment()) {
2018-08-26 04:00:00 +02:00
+ entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn(worldserver.worldProvider.getDimensionManager().getDimensionID() >= 0 ? DimensionManager.NETHER : DimensionManager.OVERWORLD, worldserver.getDifficulty(), worldserver.getWorldData().getType(), entityplayer.playerInteractManager.getGameMode()));
+ }
2016-06-09 03:43:49 +02:00
- entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn(entityplayer1.dimension, entityplayer1.world.getDifficulty(), entityplayer1.world.getWorldData().getType(), entityplayer1.playerInteractManager.getGameMode()));
2018-08-26 04:00:00 +02:00
+ entityplayer1.playerConnection.sendPacket(new PacketPlayOutRespawn(worldserver.worldProvider.getDimensionManager(), worldserver.getDifficulty(), worldserver.getWorldData().getType(), entityplayer1.playerInteractManager.getGameMode()));
+ entityplayer1.spawnIn(worldserver);
+ entityplayer1.dead = false;
+ entityplayer1.playerConnection.teleport(new Location(worldserver.getWorld(), entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch));
+ entityplayer1.setSneaking(false);
blockposition1 = worldserver.getSpawn();
- entityplayer1.playerConnection.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch);
+ // entityplayer1.playerConnection.a(entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch);
entityplayer1.playerConnection.sendPacket(new PacketPlayOutSpawnPosition(blockposition1));
entityplayer1.playerConnection.sendPacket(new PacketPlayOutExperience(entityplayer1.exp, entityplayer1.expTotal, entityplayer1.expLevel));
this.b(entityplayer1, worldserver);
this.f(entityplayer1);
- worldserver.getPlayerChunkMap().addPlayer(entityplayer1);
- worldserver.addEntity(entityplayer1);
- this.players.add(entityplayer1);
2015-02-26 23:41:06 +01:00
- this.j.put(entityplayer1.getUniqueID(), entityplayer1);
- entityplayer1.syncInventory();
+ if (!entityplayer.playerConnection.isDisconnected()) {
+ worldserver.getPlayerChunkMap().addPlayer(entityplayer1);
+ worldserver.addEntity(entityplayer1);
+ this.players.add(entityplayer1);
2015-02-26 23:41:06 +01:00
+ this.j.put(entityplayer1.getUniqueID(), entityplayer1);
+ }
+ // entityplayer1.syncInventory();
entityplayer1.setHealth(entityplayer1.getHealth());
+ // Added from changeDimension
+ updateClient(entityplayer); // Update health, etc...
+ entityplayer.updateAbilities();
+ for (Object o1 : entityplayer.getEffects()) {
+ MobEffect mobEffect = (MobEffect) o1;
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutEntityEffect(entityplayer.getId(), mobEffect));
+ }
+
2017-05-14 04:00:00 +02:00
+ // Fire advancement trigger
2018-07-15 02:00:00 +02:00
+ CriterionTriggers.v.a(entityplayer, ((CraftWorld) fromWorld).getHandle().worldProvider.getDimensionManager(), worldserver.worldProvider.getDimensionManager());
+ if (((CraftWorld) fromWorld).getHandle().worldProvider.getDimensionManager() == DimensionManager.NETHER && worldserver.worldProvider.getDimensionManager() == DimensionManager.OVERWORLD && entityplayer.M() != null) {
+ CriterionTriggers.C.a(entityplayer, entityplayer.M());
2017-05-14 04:00:00 +02:00
+ }
+
+ // Don't fire on respawn
+ if (fromWorld != location.getWorld()) {
+ PlayerChangedWorldEvent event = new PlayerChangedWorldEvent(entityplayer.getBukkitEntity(), fromWorld);
+ server.server.getPluginManager().callEvent(event);
+ }
+
+ // Save player file again if they were disconnected
+ if (entityplayer.playerConnection.isDisconnected()) {
+ this.savePlayerFile(entityplayer);
+ }
+ // CraftBukkit end
return entityplayer1;
}
+ // CraftBukkit start - Replaced the standard handling of portals with a more customised method.
2018-08-26 04:00:00 +02:00
+ public void changeDimension(EntityPlayer entityplayer, DimensionManager dimensionManager, TeleportCause cause) {
+ WorldServer exitWorld = null;
2018-08-26 04:00:00 +02:00
+ if (entityplayer.dimension.getDimensionID() < CraftWorld.CUSTOM_DIMENSION_OFFSET) { // plugins must specify exit from custom Bukkit worlds
+ exitWorld = server.getWorldServer(dimensionManager);
+ }
2016-02-29 22:32:46 +01:00
+
+ Location enter = entityplayer.getBukkitEntity().getLocation();
+ Location exit = null;
+ boolean useTravelAgent = false; // don't use agent for custom worlds or return from THE_END
+ if (exitWorld != null) {
2018-08-26 04:00:00 +02:00
+ if ((cause == TeleportCause.END_PORTAL) && (dimensionManager == DimensionManager.OVERWORLD)) {
+ // THE_END -> NORMAL; use bed if available, otherwise default spawn
+ exit = ((org.bukkit.craftbukkit.entity.CraftPlayer) entityplayer.getBukkitEntity()).getBedSpawnLocation();
2018-08-26 04:00:00 +02:00
+ if (exit == null || ((CraftWorld) exit.getWorld()).getHandle().dimension != DimensionManager.OVERWORLD) {
2018-07-15 02:00:00 +02:00
+ BlockPosition randomSpawn = entityplayer.getSpawnPoint(exitWorld);
+ exit = new Location(exitWorld.getWorld(), randomSpawn.getX(), randomSpawn.getY(), randomSpawn.getZ());
+ } else {
+ exit = exit.add(0.5F, 0.1F, 0.5F); // SPIGOT-3879
+ }
+ } else {
+ // NORMAL <-> NETHER or NORMAL -> THE_END
+ exit = this.calculateTarget(enter, exitWorld);
+ useTravelAgent = true;
+ }
+ }
2016-02-29 22:32:46 +01:00
+
+ TravelAgent agent = exit != null ? (TravelAgent) ((CraftWorld) exit.getWorld()).getHandle().getTravelAgent() : org.bukkit.craftbukkit.CraftTravelAgent.DEFAULT; // return arbitrary TA to compensate for implementation dependent plugins
+ PlayerPortalEvent event = new PlayerPortalEvent(entityplayer.getBukkitEntity(), enter, exit, agent, cause);
+ event.useTravelAgent(useTravelAgent);
+ Bukkit.getServer().getPluginManager().callEvent(event);
+ if (event.isCancelled() || event.getTo() == null) {
+ return;
+ }
2016-02-29 22:32:46 +01:00
+
+ exit = event.useTravelAgent() ? event.getPortalTravelAgent().findOrCreate(event.getTo()) : event.getTo();
+ if (exit == null) {
+ return;
+ }
+ exitWorld = ((CraftWorld) exit.getWorld()).getHandle();
2016-02-29 22:32:46 +01:00
+
+ org.bukkit.event.player.PlayerTeleportEvent tpEvent = new org.bukkit.event.player.PlayerTeleportEvent(entityplayer.getBukkitEntity(), enter, exit, cause);
+ Bukkit.getServer().getPluginManager().callEvent(tpEvent);
+ if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
+ return;
2016-02-29 22:32:46 +01:00
+ }
+
+ Vector velocity = entityplayer.getBukkitEntity().getVelocity();
+ exitWorld.getTravelAgent().adjustExit(entityplayer, exit, velocity);
+
2016-06-09 03:43:49 +02:00
+ entityplayer.worldChangeInvuln = true; // CraftBukkit - Set teleport invulnerability only if player changing worlds
+ this.moveToWorld(entityplayer, exitWorld.dimension, true, exit, false); // Vanilla doesn't check for suffocation when handling portals, so neither should we
+ if (entityplayer.motX != velocity.getX() || entityplayer.motY != velocity.getY() || entityplayer.motZ != velocity.getZ()) {
+ entityplayer.getBukkitEntity().setVelocity(velocity);
+ }
2016-02-29 22:32:46 +01:00
+ }
+
public void f(EntityPlayer entityplayer) {
GameProfile gameprofile = entityplayer.getProfile();
2018-07-22 04:00:00 +02:00
int i = this.server.a(gameprofile);
2018-12-25 22:00:00 +01:00
@@ -498,42 +794,69 @@
2015-02-26 23:41:06 +01:00
}
2018-08-26 04:00:00 +02:00
public void changeWorld(Entity entity, DimensionManager dimensionmanager, WorldServer worldserver, WorldServer worldserver1) {
+ // CraftBukkit start - Split into modular functions
+ Location exit = calculateTarget(entity.getBukkitEntity().getLocation(), worldserver1);
+ repositionEntity(entity, exit, true);
+ }
+
+ // Copy of original changeWorld(Entity, int, WorldServer, WorldServer) method with only location calculation logic
+ public Location calculateTarget(Location enter, World target) {
+ WorldServer worldserver = ((CraftWorld) enter.getWorld()).getHandle();
+ WorldServer worldserver1 = ((CraftWorld) target.getWorld()).getHandle();
2018-08-26 04:00:00 +02:00
+ DimensionManager dimensionmanager = worldserver.dimension;
+
+ double y = enter.getY();
+ float yaw = enter.getYaw();
+ float pitch = enter.getPitch();
+ double d0 = enter.getX();
+ double d1 = enter.getZ();
2018-08-26 04:00:00 +02:00
+ double d2 = 8.0D;
+ /*
2018-07-15 02:00:00 +02:00
double d0 = entity.locX;
double d1 = entity.locZ;
double d2 = 8.0D;
float f = entity.yaw;
+ */
2018-07-15 02:00:00 +02:00
2018-12-13 01:00:00 +01:00
worldserver.methodProfiler.enter("moving");
2018-08-26 04:00:00 +02:00
- if (entity.dimension == DimensionManager.NETHER) {
+ if (worldserver1.dimension == DimensionManager.NETHER) {
d0 = MathHelper.a(d0 / 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D);
d1 = MathHelper.a(d1 / 8.0D, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D);
+ /*
2018-08-26 04:00:00 +02:00
entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch);
if (entity.isAlive()) {
worldserver.entityJoinedWorld(entity, false);
}
- } else if (entity.dimension == DimensionManager.OVERWORLD) {
+ */
2018-08-26 04:00:00 +02:00
+ } else if (worldserver1.dimension == DimensionManager.OVERWORLD) {
d0 = MathHelper.a(d0 * 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D);
d1 = MathHelper.a(d1 * 8.0D, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D);
+ /*
2018-08-26 04:00:00 +02:00
entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch);
if (entity.isAlive()) {
worldserver.entityJoinedWorld(entity, false);
}
+ */
2018-08-26 04:00:00 +02:00
} else {
BlockPosition blockposition;
if (dimensionmanager == DimensionManager.THE_END) {
+ // use default NORMAL world spawn instead of target
2018-08-26 04:00:00 +02:00
+ worldserver1 = this.server.getWorldServer(DimensionManager.OVERWORLD);
blockposition = worldserver1.getSpawn();
} else {
blockposition = worldserver1.getDimensionSpawn();
}
d0 = (double) blockposition.getX();
- entity.locY = (double) blockposition.getY();
+ y = (double) blockposition.getY();
2018-08-26 04:00:00 +02:00
d1 = (double) blockposition.getZ();
+ /*
2018-08-26 04:00:00 +02:00
entity.setPositionRotation(d0, entity.locY, d1, 90.0F, 0.0F);
if (entity.isAlive()) {
worldserver.entityJoinedWorld(entity, false);
}
+ */
2018-08-26 04:00:00 +02:00
}
2018-12-13 01:00:00 +01:00
worldserver.methodProfiler.exit();
2018-12-25 22:00:00 +01:00
@@ -541,22 +864,119 @@
2018-12-13 01:00:00 +01:00
worldserver.methodProfiler.enter("placing");
2018-08-26 04:00:00 +02:00
d0 = (double) MathHelper.clamp((int) d0, -29999872, 29999872);
d1 = (double) MathHelper.clamp((int) d1, -29999872, 29999872);
+ /*
2018-08-26 04:00:00 +02:00
if (entity.isAlive()) {
entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch);
worldserver1.getTravelAgent().a(entity, f);
worldserver1.addEntity(entity);
worldserver1.entityJoinedWorld(entity, false);
}
+ */
2015-02-26 23:41:06 +01:00
+
2018-12-13 01:00:00 +01:00
+ worldserver.methodProfiler.exit();
2015-02-26 23:41:06 +01:00
+ }
+
+ // entity.spawnIn(worldserver1);
+ return new Location(worldserver1.getWorld(), d0, y, d1, yaw, pitch);
2015-02-26 23:41:06 +01:00
+ }
+
+ // copy of original a(Entity, int, WorldServer, WorldServer) method with only entity repositioning logic
+ public void repositionEntity(Entity entity, Location exit, boolean portal) {
+ WorldServer worldserver = (WorldServer) entity.world;
+ WorldServer worldserver1 = ((CraftWorld) exit.getWorld()).getHandle();
2018-08-26 04:00:00 +02:00
+ DimensionManager dimensionmanager = worldserver.dimension;
+
+ /*
2018-07-15 02:00:00 +02:00
+ double d0 = entity.locX;
+ double d1 = entity.locZ;
+ double d2 = 8.0D;
+ float f = entity.yaw;
+ */
2018-07-15 02:00:00 +02:00
+
2018-12-13 01:00:00 +01:00
+ worldserver.methodProfiler.enter("moving");
+ entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch());
+ if (entity.isAlive()) {
+ worldserver.entityJoinedWorld(entity, false);
+ }
+ /*
2018-08-26 04:00:00 +02:00
+ if (entity.dimension == DimensionManager.NETHER) {
+ d0 = MathHelper.a(d0 / 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D);
+ d1 = MathHelper.a(d1 / 8.0D, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D);
+ entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch);
+ if (entity.isAlive()) {
+ worldserver.entityJoinedWorld(entity, false);
+ }
+ } else if (entity.dimension == DimensionManager.OVERWORLD) {
+ d0 = MathHelper.a(d0 * 8.0D, worldserver1.getWorldBorder().b() + 16.0D, worldserver1.getWorldBorder().d() - 16.0D);
+ d1 = MathHelper.a(d1 * 8.0D, worldserver1.getWorldBorder().c() + 16.0D, worldserver1.getWorldBorder().e() - 16.0D);
+ entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch);
+ if (entity.isAlive()) {
+ worldserver.entityJoinedWorld(entity, false);
+ }
+ } else {
+ BlockPosition blockposition;
+
+ if (dimensionmanager == DimensionManager.THE_END) {
+ // use default NORMAL world spawn instead of target
+ worldserver1 = this.server.worlds.get(0);
2018-08-26 04:00:00 +02:00
+ blockposition = worldserver1.getSpawn();
+ } else {
+ blockposition = worldserver1.getDimensionSpawn();
+ }
+
+ d0 = (double) blockposition.getX();
+ entity.locY = (double) blockposition.getY();
+ d1 = (double) blockposition.getZ();
+ entity.setPositionRotation(d0, entity.locY, d1, 90.0F, 0.0F);
+ if (entity.isAlive()) {
+ worldserver.entityJoinedWorld(entity, false);
+ }
+ }
+ */
2018-08-26 04:00:00 +02:00
+
2018-12-13 01:00:00 +01:00
+ worldserver.methodProfiler.exit();
2018-08-26 04:00:00 +02:00
+ if (dimensionmanager != DimensionManager.THE_END) {
2018-12-13 01:00:00 +01:00
+ worldserver.methodProfiler.enter("placing");
+ /*
2018-08-26 04:00:00 +02:00
+ d0 = (double) MathHelper.clamp((int) d0, -29999872, 29999872);
+ d1 = (double) MathHelper.clamp((int) d1, -29999872, 29999872);
+ */
2018-08-26 04:00:00 +02:00
+ if (entity.isAlive()) {
+ // entity.setPositionRotation(d0, entity.locY, d1, entity.yaw, entity.pitch);
+ // worldserver1.getTravelAgent().a(entity, f);
+ if (portal) {
+ Vector velocity = entity.getBukkitEntity().getVelocity();
+ worldserver1.getTravelAgent().adjustExit(entity, exit, velocity);
+ entity.setPositionRotation(exit.getX(), exit.getY(), exit.getZ(), exit.getYaw(), exit.getPitch());
+ if (entity.motX != velocity.getX() || entity.motY != velocity.getY() || entity.motZ != velocity.getZ()) {
+ entity.getBukkitEntity().setVelocity(velocity);
+ }
+ }
+ // worldserver1.addEntity(entity);
2018-08-26 04:00:00 +02:00
+ worldserver1.entityJoinedWorld(entity, false);
+ }
2018-12-13 01:00:00 +01:00
worldserver.methodProfiler.exit();
}
entity.spawnIn(worldserver1);
+ // CraftBukkit end
}
public void tick() {
2017-05-14 04:00:00 +02:00
if (++this.v > 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);
+
+ target.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, Iterables.filter(this.players, new Predicate<EntityPlayer>() {
+ @Override
+ public boolean apply(EntityPlayer input) {
+ return target.getBukkitEntity().canSee(input.getBukkitEntity());
+ }
+ })));
+ }
+ // CraftBukkit end
2017-05-14 04:00:00 +02:00
this.v = 0;
2016-11-28 00:02:40 +01:00
}
2018-12-25 22:00:00 +01:00
@@ -569,6 +989,25 @@
}
+ // 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;
+ }
+ ((EntityPlayer) this.players.get(i)).playerConnection.sendPacket(packet);
+ }
+ }
+
+ public void sendAll(Packet packet, World world) {
+ for (int i = 0; i < world.players.size(); ++i) {
+ ((EntityPlayer) world.players.get(i)).playerConnection.sendPacket(packet);
+ }
+
+ }
+ // CraftBukkit end
+
2018-08-26 04:00:00 +02:00
public void a(Packet<?> packet, DimensionManager dimensionmanager) {
for (int i = 0; i < this.players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
2018-12-25 22:00:00 +01:00
@@ -669,6 +1108,7 @@
2018-07-15 02:00:00 +02:00
entityplayer.playerConnection.sendPacket(new PacketPlayOutEntityStatus(entityplayer, b0));
}
2018-07-15 02:00:00 +02:00
+ entityplayer.getBukkitEntity().recalculatePermissions(); // CraftBukkit
this.server.getCommandDispatcher().a(entityplayer);
}
2018-12-25 22:00:00 +01:00
@@ -701,6 +1141,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);
+ // 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
+
2018-08-26 04:00:00 +02:00
if (entityplayer != entityhuman && entityplayer.dimension == dimensionmanager) {
double d4 = d0 - entityplayer.locX;
double d5 = d1 - entityplayer.locY;
2018-12-25 22:00:00 +01:00
@@ -740,7 +1186,7 @@
public void reloadWhitelist() {}
public void b(EntityPlayer entityplayer, WorldServer worldserver) {
2018-08-26 04:00:00 +02:00
- WorldBorder worldborder = this.server.getWorldServer(DimensionManager.OVERWORLD).getWorldBorder();
2015-02-26 23:41:06 +01:00
+ WorldBorder worldborder = entityplayer.world.getWorldBorder(); // CraftBukkit
2015-02-26 23:41:06 +01:00
entityplayer.playerConnection.sendPacket(new PacketPlayOutWorldBorder(worldborder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE));
entityplayer.playerConnection.sendPacket(new PacketPlayOutUpdateTime(worldserver.getTime(), worldserver.getDayTime(), worldserver.getGameRules().getBoolean("doDaylightCycle")));
@@ -748,17 +1194,26 @@
2016-11-17 02:41:03 +01:00
entityplayer.playerConnection.sendPacket(new PacketPlayOutSpawnPosition(blockposition));
2017-05-19 13:00:13 +02:00
if (worldserver.isRaining()) {
- entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0.0F));
2018-07-15 02:00:00 +02:00
- entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, worldserver.i(1.0F)));
- entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, worldserver.g(1.0F)));
+ // CraftBukkit start - handle player weather
+ // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(1, 0.0F));
2018-07-15 02:00:00 +02:00
+ // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(7, worldserver.i(1.0F)));
+ // entityplayer.playerConnection.sendPacket(new PacketPlayOutGameStateChange(8, worldserver.g(1.0F)));
+ entityplayer.setPlayerWeather(org.bukkit.WeatherType.DOWNFALL, false);
2016-02-29 22:32:46 +01:00
+ entityplayer.updateWeather(-worldserver.o, worldserver.o, -worldserver.q, worldserver.q);
+ // CraftBukkit end
}
}
public void updateClient(EntityPlayer entityplayer) {
entityplayer.updateInventory(entityplayer.defaultContainer);
- entityplayer.triggerHealthUpdate();
+ // entityplayer.triggerHealthUpdate();
+ entityplayer.getBukkitEntity().updateScaledHealth(); // CraftBukkit - Update scaled health on respawn and worldchange
entityplayer.playerConnection.sendPacket(new PacketPlayOutHeldItemSlot(entityplayer.inventory.itemInHandIndex));
+ // CraftBukkit start - from GameRules
+ int i = entityplayer.world.getGameRules().get("reducedDebugInfo").b() ? 22 : 23;
+ entityplayer.playerConnection.sendPacket(new PacketPlayOutEntityStatus(entityplayer, (byte) i));
+ // CraftBukkit end
}
public int getPlayerCount() {
@@ -819,26 +1274,39 @@
}
2015-02-26 23:41:06 +01:00
public void u() {
- for (int i = 0; i < this.players.size(); ++i) {
2017-05-30 13:25:59 +02:00
- ((EntityPlayer) this.players.get(i)).playerConnection.disconnect(new ChatMessage("multiplayer.disconnect.server_shutdown", new Object[0]));
+ // CraftBukkit start - disconnect safely
+ for (EntityPlayer player : this.players) {
+ player.playerConnection.disconnect(this.server.server.getShutdownMessage()); // CraftBukkit - add custom shutdown message
}
+ // CraftBukkit end
2016-12-20 21:00:00 +01:00
}
+ // CraftBukkit start
+ public void sendMessage(IChatBaseComponent[] iChatBaseComponents) {
+ for (IChatBaseComponent component : iChatBaseComponents) {
+ sendMessage(component, true);
+ }
2016-12-20 21:00:00 +01:00
+ }
+ // CraftBukkit end
2016-12-20 21:00:00 +01:00
+
public void sendMessage(IChatBaseComponent ichatbasecomponent, boolean flag) {
this.server.sendMessage(ichatbasecomponent);
2017-05-14 04:00:00 +02:00
ChatMessageType chatmessagetype = flag ? ChatMessageType.SYSTEM : ChatMessageType.CHAT;
2017-05-14 04:00:00 +02:00
- this.sendAll(new PacketPlayOutChat(ichatbasecomponent, chatmessagetype));
+ // CraftBukkit start - we run this through our processor first so we can get web links etc
2017-05-14 04:00:00 +02:00
+ this.sendAll(new PacketPlayOutChat(CraftChatMessage.fixComponent(ichatbasecomponent), chatmessagetype));
+ // CraftBukkit end
}
public void sendMessage(IChatBaseComponent ichatbasecomponent) {
2017-07-17 01:55:47 +02:00
this.sendMessage(ichatbasecomponent, true);
}
2017-08-03 15:00:00 +02:00
- public ServerStatisticManager getStatisticManager(EntityHuman entityhuman) {
2017-07-17 01:55:47 +02:00
+ public ServerStatisticManager getStatisticManager(EntityPlayer entityhuman) {
UUID uuid = entityhuman.getUniqueID();
- ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) this.o.get(uuid);
+ ServerStatisticManager serverstatisticmanager = uuid == null ? null : (ServerStatisticManager) entityhuman.getStatisticManager();
+ // CraftBukkit end
if (serverstatisticmanager == null) {
2018-08-26 04:00:00 +02:00
File file = new File(this.server.getWorldServer(DimensionManager.OVERWORLD).getDataManager().getDirectory(), "stats");
@@ -853,7 +1321,7 @@
2018-07-15 02:00:00 +02:00
}
2017-07-17 01:55:47 +02:00
serverstatisticmanager = new ServerStatisticManager(this.server, file1);
- this.o.put(uuid, serverstatisticmanager);
+ // this.o.put(uuid, serverstatisticmanager); // CraftBukkit
}
return serverstatisticmanager;
@@ -861,14 +1329,14 @@
2017-07-17 01:55:47 +02:00
public AdvancementDataPlayer h(EntityPlayer entityplayer) {
UUID uuid = entityplayer.getUniqueID();
- AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) this.p.get(uuid);
+ AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) entityplayer.getAdvancementData(); // CraftBukkit
if (advancementdataplayer == null) {
2018-08-26 04:00:00 +02:00
File file = new File(this.server.getWorldServer(DimensionManager.OVERWORLD).getDataManager().getDirectory(), "advancements");
2017-07-17 01:55:47 +02:00
File file1 = new File(file, uuid + ".json");
advancementdataplayer = new AdvancementDataPlayer(this.server, file1, entityplayer);
- this.p.put(uuid, advancementdataplayer);
+ // this.p.put(uuid, advancementdataplayer); // CraftBukkit
}
advancementdataplayer.a(entityplayer);
@@ -904,13 +1372,20 @@
2017-07-17 01:55:47 +02:00
}
public void reload() {
- Iterator iterator = this.p.values().iterator();
+ // CraftBukkit start
+ /*Iterator iterator = this.p.values().iterator();
while (iterator.hasNext()) {
AdvancementDataPlayer advancementdataplayer = (AdvancementDataPlayer) iterator.next();
advancementdataplayer.b();
2017-07-17 01:55:47 +02:00
+ }*/
+
+ for (EntityPlayer player : players) {
2017-07-17 01:55:47 +02:00
+ player.getAdvancementData().b();
+ player.getAdvancementData().b(player); // CraftBukkit - trigger immediate flush of advancements
}
+ // CraftBukkit end
2018-07-15 02:00:00 +02:00
this.sendAll(new PacketPlayOutTags(this.server.getTagRegistry()));
PacketPlayOutRecipeUpdate packetplayoutrecipeupdate = new PacketPlayOutRecipeUpdate(this.server.getCraftingManager().b());