Prevent opening inventories when frozen

This commit is contained in:
Shane Freeder 2020-04-13 07:31:44 +01:00
parent ee1fd0844d
commit 6b7013458d
2 changed files with 30 additions and 29 deletions

View file

@ -114,7 +114,7 @@
@Nullable @Nullable
private Vec3 startingToFallPosition; private Vec3 startingToFallPosition;
@Nullable @Nullable
@@ -258,7 +293,33 @@ @@ -258,6 +293,32 @@
private final CommandSource commandSource; private final CommandSource commandSource;
private int containerCounter; private int containerCounter;
public boolean wonGame; public boolean wonGame;
@ -125,7 +125,7 @@
+ public boolean queueHealthUpdatePacket; + public boolean queueHealthUpdatePacket;
+ public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket; + public net.minecraft.network.protocol.game.ClientboundSetHealthPacket queuedHealthUpdatePacket;
+ // Paper end - cancellable death event + // Paper end - cancellable death event
+
+ // CraftBukkit start + // CraftBukkit start
+ public CraftPlayer.TransferCookieConnection transferCookieConnection; + public CraftPlayer.TransferCookieConnection transferCookieConnection;
+ public String displayName; + public String displayName;
@ -144,10 +144,9 @@
+ // CraftBukkit end + // CraftBukkit end
+ public boolean isRealPlayer; // Paper + public boolean isRealPlayer; // Paper
+ public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent + public com.destroystokyo.paper.event.entity.PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper - PlayerNaturallySpawnCreaturesEvent
+
public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) { public ServerPlayer(MinecraftServer server, ServerLevel world, GameProfile profile, ClientInformation clientOptions) {
super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile); super(world, world.getSharedSpawnPos(), world.getSharedSpawnAngle(), profile);
this.chatVisibility = ChatVisiblity.FULL;
@@ -266,7 +327,7 @@ @@ -266,7 +327,7 @@
this.canChatColor = true; this.canChatColor = true;
this.lastActionTime = Util.getMillis(); this.lastActionTime = Util.getMillis();
@ -185,8 +184,8 @@
+ this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper + this.adventure$displayName = net.kyori.adventure.text.Component.text(this.getScoreboardName()); // Paper
+ this.bukkitPickUpLoot = true; + this.bukkitPickUpLoot = true;
+ this.maxHealthCache = this.getMaxHealth(); + this.maxHealthCache = this.getMaxHealth();
+ } }
+
+ // Use method to resend items in hands in case of client desync, because the item use got cancelled. + // 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 + // For example, when cancelling the leash event
+ public void resendItemInHands() { + public void resendItemInHands() {
@ -232,9 +231,9 @@
+ } + }
+ +
+ return blockposition; + return blockposition;
} + }
+ // CraftBukkit end + // CraftBukkit end
+
@Override @Override
public BlockPos adjustSpawnLocation(ServerLevel world, BlockPos basePos) { public BlockPos adjustSpawnLocation(ServerLevel world, BlockPos basePos) {
AABB axisalignedbb = this.getDimensions(Pose.STANDING).makeBoundingBox(Vec3.ZERO); AABB axisalignedbb = this.getDimensions(Pose.STANDING).makeBoundingBox(Vec3.ZERO);
@ -285,16 +284,16 @@
if (this.isSleeping()) { if (this.isSleeping()) {
this.stopSleeping(); this.stopSleeping();
+ } }
+
+ // CraftBukkit start + // CraftBukkit start
+ String spawnWorld = nbt.getString("SpawnWorld"); + String spawnWorld = nbt.getString("SpawnWorld");
+ CraftWorld oldWorld = (CraftWorld) Bukkit.getWorld(spawnWorld); + CraftWorld oldWorld = (CraftWorld) Bukkit.getWorld(spawnWorld);
+ if (oldWorld != null) { + if (oldWorld != null) {
+ this.respawnDimension = oldWorld.getHandle().dimension(); + this.respawnDimension = oldWorld.getHandle().dimension();
} + }
+ // CraftBukkit end + // CraftBukkit end
+
if (nbt.contains("SpawnX", 99) && nbt.contains("SpawnY", 99) && nbt.contains("SpawnZ", 99)) { if (nbt.contains("SpawnX", 99) && nbt.contains("SpawnY", 99) && nbt.contains("SpawnZ", 99)) {
this.respawnPosition = new BlockPos(nbt.getInt("SpawnX"), nbt.getInt("SpawnY"), nbt.getInt("SpawnZ")); this.respawnPosition = new BlockPos(nbt.getInt("SpawnX"), nbt.getInt("SpawnY"), nbt.getInt("SpawnZ"));
this.respawnForced = nbt.getBoolean("SpawnForced"); this.respawnForced = nbt.getBoolean("SpawnForced");
@ -442,13 +441,14 @@
} }
- this.containerMenu.broadcastChanges(); - this.containerMenu.broadcastChanges();
- if (!this.containerMenu.stillValid(this)) {
- this.closeContainer();
+ if (--this.containerUpdateDelay <= 0) { + if (--this.containerUpdateDelay <= 0) {
+ this.containerMenu.broadcastChanges(); + this.containerMenu.broadcastChanges();
+ this.containerUpdateDelay = this.level().paperConfig().tickRates.containerUpdate; + this.containerUpdateDelay = this.level().paperConfig().tickRates.containerUpdate;
+ } + }
+ // Paper end - Configurable container update tick rate + // Paper end - Configurable container update tick rate
if (!this.containerMenu.stillValid(this)) { + if (this.containerMenu != this.inventoryMenu && (this.isImmobile() || !this.containerMenu.stillValid(this))) { // Paper - Prevent opening inventories when frozen
- this.closeContainer();
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper - Inventory close reason + this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper - Inventory close reason
this.containerMenu = this.inventoryMenu; this.containerMenu = this.inventoryMenu;
} }
@ -484,10 +484,12 @@
if (this.experienceLevel != this.lastRecordedLevel) { if (this.experienceLevel != this.lastRecordedLevel) {
this.lastRecordedLevel = this.experienceLevel; this.lastRecordedLevel = this.experienceLevel;
this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel)); this.updateScoreForCriteria(ObjectiveCriteria.LEVEL, Mth.ceil((float) this.lastRecordedLevel));
@@ -865,6 +1054,20 @@ @@ -863,8 +1052,22 @@
CriteriaTriggers.LOCATION.trigger(this);
}
if (this.tickCount % 20 == 0) {
CriteriaTriggers.LOCATION.trigger(this);
+ }
+
+ // CraftBukkit start - initialize oldLevel, fire PlayerLevelChangeEvent, and tick client-sided world border + // CraftBukkit start - initialize oldLevel, fire PlayerLevelChangeEvent, and tick client-sided world border
+ if (this.oldLevel == -1) { + if (this.oldLevel == -1) {
+ this.oldLevel = this.experienceLevel; + this.oldLevel = this.experienceLevel;
@ -496,8 +498,8 @@
+ if (this.oldLevel != this.experienceLevel) { + if (this.oldLevel != this.experienceLevel) {
+ CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel); + CraftEventFactory.callPlayerLevelChangeEvent(this.getBukkitEntity(), this.oldLevel, this.experienceLevel);
+ this.oldLevel = this.experienceLevel; + this.oldLevel = this.experienceLevel;
+ } }
+
+ if (this.getBukkitEntity().hasClientWorldBorder()) { + if (this.getBukkitEntity().hasClientWorldBorder()) {
+ ((CraftWorldBorder) this.getBukkitEntity().getWorldBorder()).getHandle().tick(); + ((CraftWorldBorder) this.getBukkitEntity().getWorldBorder()).getHandle().tick();
+ } + }
@ -1137,7 +1139,7 @@
- this.initMenu(container); - this.initMenu(container);
+ // CraftBukkit start + // CraftBukkit start
this.containerMenu = container; this.containerMenu = container;
+ this.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), container.getTitle())); + if (!this.isImmobile()) this.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), container.getTitle())); // Paper - Prevent opening inventories when frozen
+ // CraftBukkit end + // CraftBukkit end
+ this.initMenu(container); + this.initMenu(container);
return OptionalInt.of(this.containerCounter); return OptionalInt.of(this.containerCounter);
@ -1533,7 +1535,7 @@
if (entity instanceof LivingEntity entityliving) { if (entity instanceof LivingEntity entityliving) {
Iterator iterator = entityliving.getActiveEffects().iterator(); Iterator iterator = entityliving.getActiveEffects().iterator();
@@ -2375,16 +2966,161 @@ @@ -2375,10 +2966,12 @@
return TicketType.ENDER_PEARL.timeout(); return TicketType.ENDER_PEARL.timeout();
} }
@ -1549,11 +1551,10 @@
} }
private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) { private static float calculateLookAtYaw(Vec3 respawnPos, BlockPos currentPos) {
Vec3 vec3d1 = Vec3.atBottomCenterOf(currentPos).subtract(respawnPos).normalize(); @@ -2387,4 +2980,147 @@
return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D); return (float) Mth.wrapDegrees(Mth.atan2(vec3d1.z, vec3d1.x) * 57.2957763671875D - 90.0D);
+ } }
+ } }
+ +
+ // CraftBukkit start - Add per-player time and weather. + // CraftBukkit start - Add per-player time and weather.
+ public long timeOffset = 0; + public long timeOffset = 0;
@ -1578,7 +1579,7 @@
+ public void setPlayerWeather(WeatherType type, boolean plugin) { + public void setPlayerWeather(WeatherType type, boolean plugin) {
+ if (!plugin && this.weather != null) { + if (!plugin && this.weather != null) {
+ return; + return;
} + }
+ +
+ if (plugin) { + if (plugin) {
+ this.weather = type; + this.weather = type;
@ -1589,7 +1590,7 @@
+ } else { + } else {
+ this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0)); + this.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.START_RAINING, 0));
+ } + }
} + }
+ +
+ private float pluginRainPosition; + private float pluginRainPosition;
+ private float pluginRainPositionPrevious; + private float pluginRainPositionPrevious;

View file

@ -335,7 +335,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(container.getBukkitView().getTitle()); // Paper if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(container.getBukkitView().getTitle()); // Paper
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper if (!player.isImmobile()) player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper - Prevent opening inventories when frozen
player.containerMenu = container; player.containerMenu = container;
player.initMenu(container); player.initMenu(container);
} }
@ -410,7 +410,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(inventory.getTitle()); // Paper if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(inventory.getTitle()); // Paper
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper if (!player.isImmobile()) player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper - Prevent opening inventories when frozen
player.containerMenu = container; player.containerMenu = container;
player.initMenu(container); player.initMenu(container);
} }