Prevent Ghost Players Caused by Plugins

Check if the player is still connected after firing event. Fixes BUKKIT-4327

By: Alex Ciuba <alexciuba@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2013-06-11 15:23:03 -04:00
parent b934e29ae6
commit a702945c70
2 changed files with 71 additions and 62 deletions

View File

@@ -112,10 +112,11 @@
@Nullable
private Vec3 startingToFallPosition;
@Nullable
@@ -259,6 +292,22 @@
@@ -258,6 +291,22 @@
private final CommandSource commandSource;
private int containerCounter;
public boolean wonGame;
+
+ // CraftBukkit start
+ public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName;
@@ -131,10 +132,9 @@
+ public boolean sentListPacket = false;
+ public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
+ // CraftBukkit end
+
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
@@ -340,6 +389,13 @@
public void sendSystemMessage(Component message) {
ServerPlayer.this.sendSystemMessage(message);
@@ -158,8 +158,8 @@
+ this.displayName = this.getScoreboardName();
+ this.bukkitPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth();
}
+ }
+
+ // Use method to resend items in hands in case of client desync, because the item use got cancelled.
+ // For example, when cancelling the leash event
+ public void resendItemInHands() {
@@ -205,9 +205,9 @@
+ }
+
+ return blockposition;
+ }
}
+ // CraftBukkit end
+
@Override
public BlockPos adjustSpawnLocation(ServerLevel world, BlockPos basePos) {
AABB axisalignedbb = this.getDimensions(Pose.STANDING).makeBoundingBox(Vec3.ZERO);
@@ -588,7 +588,7 @@
if (!this.canHarmPlayer(entityhuman1)) {
return false;
@@ -1088,33 +1322,58 @@
@@ -1088,33 +1322,63 @@
}
@Override
@@ -646,6 +646,11 @@
+
+ PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn, isAnchorSpawn, reason);
+ this.level().getCraftServer().getPluginManager().callEvent(respawnEvent);
+ // Spigot Start
+ if (this.connection.isDisconnected()) {
+ return null;
+ }
+ // Spigot End
+
+ location = respawnEvent.getRespawnLocation();
+
@@ -654,7 +659,7 @@
}
public static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel world, BlockPos pos, float spawnAngle, boolean spawnForced, boolean alive) {
@@ -1129,11 +1388,11 @@
@@ -1129,11 +1393,11 @@
}
return optional.map((vec3d) -> {
@@ -668,7 +673,7 @@
});
} else if (!spawnForced) {
return Optional.empty();
@@ -1142,7 +1401,7 @@
@@ -1142,7 +1406,7 @@
BlockState iblockdata1 = world.getBlockState(pos.above());
boolean flag3 = iblockdata1.getBlock().isPossibleToRespawnInThis(iblockdata1);
@@ -677,7 +682,7 @@
}
}
@@ -1160,6 +1419,7 @@
@@ -1160,6 +1424,7 @@
@Nullable
@Override
public ServerPlayer teleport(TeleportTransition teleportTarget) {
@@ -685,7 +690,7 @@
if (this.isRemoved()) {
return null;
} else {
@@ -1169,39 +1429,73 @@
@@ -1169,39 +1434,73 @@
ServerLevel worldserver = teleportTarget.newLevel();
ServerLevel worldserver1 = this.serverLevel();
@@ -767,7 +772,7 @@
this.connection.resetPosition();
worldserver.addDuringTeleport(this);
gameprofilerfiller.pop();
@@ -1215,12 +1509,30 @@
@@ -1215,12 +1514,30 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -798,7 +803,7 @@
public void forceSetRotation(float yaw, float pitch) {
this.connection.send(new ClientboundPlayerRotationPacket(yaw, pitch));
}
@@ -1228,13 +1540,21 @@
@@ -1228,13 +1545,21 @@
public void triggerDimensionChangeTriggers(ServerLevel origin) {
ResourceKey<Level> resourcekey = origin.dimension();
ResourceKey<Level> resourcekey1 = this.level().dimension();
@@ -823,7 +828,7 @@
this.enteredNetherPosition = null;
}
@@ -1251,36 +1571,63 @@
@@ -1251,36 +1576,63 @@
this.containerMenu.broadcastChanges();
}
@@ -902,7 +907,7 @@
this.awardStat(Stats.SLEEP_IN_BED);
CriteriaTriggers.SLEPT_IN_BED.trigger(this);
});
@@ -1293,9 +1640,8 @@
@@ -1293,9 +1645,8 @@
return either;
}
}
@@ -913,7 +918,7 @@
}
@Override
@@ -1322,13 +1668,31 @@
@@ -1322,13 +1673,31 @@
@Override
public void stopSleepInBed(boolean skipSleepTimer, boolean updateSleepingPlayers) {
@@ -946,7 +951,7 @@
}
}
@@ -1387,8 +1751,9 @@
@@ -1387,8 +1756,9 @@
this.connection.send(new ClientboundOpenSignEditorPacket(sign.getBlockPos(), front));
}
@@ -957,7 +962,7 @@
}
@Override
@@ -1396,13 +1761,35 @@
@@ -1396,13 +1766,35 @@
if (factory == null) {
return OptionalInt.empty();
} else {
@@ -993,7 +998,7 @@
if (container == null) {
if (this.isSpectator()) {
this.displayClientMessage(Component.translatable("container.spectatorCantOpen").withStyle(ChatFormatting.RED), true);
@@ -1410,9 +1797,11 @@
@@ -1410,9 +1802,11 @@
return OptionalInt.empty();
} else {
@@ -1007,7 +1012,7 @@
return OptionalInt.of(this.containerCounter);
}
}
@@ -1425,15 +1814,26 @@
@@ -1425,15 +1819,26 @@
@Override
public void openHorseInventory(AbstractHorse horse, Container inventory) {
@@ -1036,7 +1041,7 @@
this.initMenu(this.containerMenu);
}
@@ -1456,6 +1856,7 @@
@@ -1456,6 +1861,7 @@
@Override
public void closeContainer() {
@@ -1044,7 +1049,7 @@
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
this.doCloseContainer();
}
@@ -1485,19 +1886,19 @@
@@ -1485,19 +1891,19 @@
i = Math.round((float) Math.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) * 100.0F);
if (i > 0) {
this.awardStat(Stats.SWIM_ONE_CM, i);
@@ -1067,7 +1072,7 @@
}
} else if (this.onClimbable()) {
if (deltaY > 0.0D) {
@@ -1508,13 +1909,13 @@
@@ -1508,13 +1914,13 @@
if (i > 0) {
if (this.isSprinting()) {
this.awardStat(Stats.SPRINT_ONE_CM, i);
@@ -1084,7 +1089,7 @@
}
}
} else if (this.isFallFlying()) {
@@ -1557,7 +1958,7 @@
@@ -1557,7 +1963,7 @@
@Override
public void awardStat(Stat<?> stat, int amount) {
this.stats.increment(this, stat, amount);
@@ -1093,7 +1098,7 @@
scoreaccess.add(amount);
});
}
@@ -1565,7 +1966,7 @@
@@ -1565,7 +1971,7 @@
@Override
public void resetStat(Stat<?> stat) {
this.stats.setValue(this, stat, 0);
@@ -1102,7 +1107,7 @@
}
@Override
@@ -1597,9 +1998,9 @@
@@ -1597,9 +2003,9 @@
super.jumpFromGround();
this.awardStat(Stats.JUMP);
if (this.isSprinting()) {
@@ -1114,7 +1119,7 @@
}
}
@@ -1625,6 +2026,7 @@
@@ -1625,6 +2031,7 @@
public void resetSentInfo() {
this.lastSentHealth = -1.0E8F;
@@ -1122,7 +1127,7 @@
}
@Override
@@ -1661,7 +2063,7 @@
@@ -1661,7 +2068,7 @@
this.onUpdateAbilities();
if (alive) {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@@ -1131,7 +1136,7 @@
this.setHealth(oldPlayer.getHealth());
this.foodData = oldPlayer.foodData;
Iterator iterator = oldPlayer.getActiveEffects().iterator();
@@ -1669,7 +2071,7 @@
@@ -1669,7 +2076,7 @@
while (iterator.hasNext()) {
MobEffectInstance mobeffect = (MobEffectInstance) iterator.next();
@@ -1140,7 +1145,7 @@
}
this.getInventory().replaceWith(oldPlayer.getInventory());
@@ -1680,7 +2082,7 @@
@@ -1680,7 +2087,7 @@
this.portalProcess = oldPlayer.portalProcess;
} else {
this.getAttributes().assignBaseValues(oldPlayer.getAttributes());
@@ -1149,7 +1154,7 @@
if (this.serverLevel().getGameRules().getBoolean(GameRules.RULE_KEEPINVENTORY) || oldPlayer.isSpectator()) {
this.getInventory().replaceWith(oldPlayer.getInventory());
this.experienceLevel = oldPlayer.experienceLevel;
@@ -1696,7 +2098,7 @@
@@ -1696,7 +2103,7 @@
this.lastSentExp = -1;
this.lastSentHealth = -1.0F;
this.lastSentFood = -1;
@@ -1158,7 +1163,7 @@
this.seenCredits = oldPlayer.seenCredits;
this.enteredNetherPosition = oldPlayer.enteredNetherPosition;
this.chunkTrackingView = oldPlayer.chunkTrackingView;
@@ -1752,19 +2154,19 @@
@@ -1752,19 +2159,19 @@
}
@Override
@@ -1182,7 +1187,7 @@
}
return flag1;
@@ -1878,6 +2280,16 @@
@@ -1878,6 +2285,16 @@
}
public void updateOptions(ClientInformation clientOptions) {
@@ -1199,7 +1204,7 @@
this.language = clientOptions.language();
this.requestedViewDistance = clientOptions.viewDistance();
this.chatVisibility = clientOptions.chatVisibility();
@@ -1962,7 +2374,7 @@
@@ -1962,7 +2379,7 @@
if (world instanceof ServerLevel) {
ServerLevel worldserver = (ServerLevel) world;
@@ -1208,7 +1213,7 @@
}
if (entity != null) {
@@ -1999,11 +2411,11 @@
@@ -1999,11 +2416,11 @@
@Nullable
public Component getTabListDisplayName() {
@@ -1222,7 +1227,7 @@
}
@Override
@@ -2046,17 +2458,43 @@
@@ -2046,17 +2463,43 @@
}
public void setRespawnPosition(ResourceKey<Level> dimension, @Nullable BlockPos pos, float angle, boolean forced, boolean sendMessage) {
@@ -1273,7 +1278,7 @@
} else {
this.respawnPosition = null;
this.respawnDimension = Level.OVERWORLD;
@@ -2088,18 +2526,44 @@
@@ -2088,18 +2531,44 @@
}
@Override
@@ -1322,7 +1327,7 @@
}
this.awardStat(Stats.DROP);
@@ -2375,16 +2839,160 @@
@@ -2375,16 +2844,160 @@
return TicketType.ENDER_PEARL.timeout();
}
@@ -1355,8 +1360,8 @@
+ } else {
+ // Adds timeOffset to the beginning of this day.
+ return this.level().getDayTime() - (this.level().getDayTime() % 24000) + this.timeOffset;
+ }
+ }
}
}
+
+ public WeatherType weather = null;
+
@@ -1394,7 +1399,7 @@
+ if (this.pluginRainPositionPrevious != this.pluginRainPosition) {
+ this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.RAIN_LEVEL_CHANGE, this.pluginRainPosition));
+ }
}
+ }
+
+ if (oldThunder != newThunder) {
+ if (this.weather == WeatherType.DOWNFALL || this.weather == null) {
@@ -1403,7 +1408,7 @@
+ this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.THUNDER_LEVEL_CHANGE, 0));
+ }
+ }
}
+ }
+
+ public void tickWeather() {
+ if (this.weather == null) return;