mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 02:25:28 +01:00
8c5b837e05
Firstly, the old methods all routed to the CompletableFuture method. However, the CF method could not guarantee that if the caller was off-main that the future would be "completed" on-main. Since the callback methods used the CF one, this meant that the callback methods did not guarantee that the callbacks were to be called on the main thread. Now, all methods route to getChunkAtAsync(x, z, gen, urgent, cb) so that the methods with the callback are guaranteed to invoke the callback on the main thread. The CF behavior remains unchanged; it may still appear to complete on main if invoked off-main. Secondly, remove the scheduleOnMain invocation in the async chunk completion. This unnecessarily delays the callback by 1 tick. Thirdly, add getChunksAtAsync(minX, minZ, maxX, maxZ, ...) which will load chunks within an area. This method is provided as a helper as keeping all chunks loaded within an area can be complicated to implement for plugins (due to the lacking ticket API), and is already implemented internally anyways. Fourthly, remove the ticket addition that occured with getChunkAt and getChunkAtAsync. The ticket addition may delay the unloading of the chunk unnecessarily. It also fixes a very rare timing bug where the future/callback would be completed after the chunk unloads.
62 lines
4.0 KiB
Diff
62 lines
4.0 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: SamB440 <sam@islandearth.net>
|
|
Date: Mon, 15 Nov 2021 18:10:10 +0000
|
|
Subject: [PATCH] Add PlayerItemFrameChangeEvent
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
|
|
index c0deabf9d86d086fbd8cbaac5a02badf5c01c870..30af4cbb17148c247a46c0346419d6c838dbc9d2 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/decoration/ItemFrame.java
|
|
@@ -1,6 +1,7 @@
|
|
package net.minecraft.world.entity.decoration;
|
|
|
|
import javax.annotation.Nullable;
|
|
+import io.papermc.paper.event.player.PlayerItemFrameChangeEvent; // Paper - Add PlayerItemFrameChangeEvent
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.core.component.DataComponents;
|
|
@@ -166,6 +167,13 @@ public class ItemFrame extends HangingEntity {
|
|
return true;
|
|
}
|
|
// CraftBukkit end
|
|
+ // Paper start - Add PlayerItemFrameChangeEvent
|
|
+ if (source.getEntity() instanceof Player player) {
|
|
+ var event = new PlayerItemFrameChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.ItemFrame) this.getBukkitEntity(), this.getItem().asBukkitCopy(), PlayerItemFrameChangeEvent.ItemFrameChangeAction.REMOVE);
|
|
+ if (!event.callEvent()) return true; // return true here because you aren't cancelling the damage, just the change
|
|
+ this.setItem(ItemStack.fromBukkitCopy(event.getItemStack()), false);
|
|
+ }
|
|
+ // Paper end - Add PlayerItemFrameChangeEvent
|
|
this.dropItem(world, source.getEntity(), false);
|
|
this.gameEvent(GameEvent.BLOCK_CHANGE, source.getEntity());
|
|
this.playSound(this.getRemoveItemSound(), 1.0F, 1.0F);
|
|
@@ -403,7 +411,13 @@ public class ItemFrame extends HangingEntity {
|
|
if (worldmap != null && worldmap.isTrackedCountOverLimit(256)) {
|
|
return InteractionResult.FAIL;
|
|
} else {
|
|
- this.setItem(itemstack);
|
|
+ // Paper start - Add PlayerItemFrameChangeEvent
|
|
+ PlayerItemFrameChangeEvent event = new PlayerItemFrameChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.ItemFrame) this.getBukkitEntity(), itemstack.asBukkitCopy(), PlayerItemFrameChangeEvent.ItemFrameChangeAction.PLACE);
|
|
+ if (!event.callEvent()) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ this.setItem(ItemStack.fromBukkitCopy(event.getItemStack()));
|
|
+ // Paper end - Add PlayerItemFrameChangeEvent
|
|
this.gameEvent(GameEvent.BLOCK_CHANGE, player);
|
|
itemstack.consume(1, player);
|
|
return InteractionResult.SUCCESS;
|
|
@@ -412,6 +426,13 @@ public class ItemFrame extends HangingEntity {
|
|
return InteractionResult.PASS;
|
|
}
|
|
} else {
|
|
+ // Paper start - Add PlayerItemFrameChangeEvent
|
|
+ PlayerItemFrameChangeEvent event = new PlayerItemFrameChangeEvent((org.bukkit.entity.Player) player.getBukkitEntity(), (org.bukkit.entity.ItemFrame) this.getBukkitEntity(), this.getItem().asBukkitCopy(), PlayerItemFrameChangeEvent.ItemFrameChangeAction.ROTATE);
|
|
+ if (!event.callEvent()) {
|
|
+ return InteractionResult.FAIL;
|
|
+ }
|
|
+ setItem(ItemStack.fromBukkitCopy(event.getItemStack()), false, false);
|
|
+ // Paper end - Add PlayerItemFrameChangeEvent
|
|
this.playSound(this.getRotateItemSound(), 1.0F, 1.0F);
|
|
this.setRotation(this.getRotation() + 1);
|
|
this.gameEvent(GameEvent.BLOCK_CHANGE, player);
|