mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
2f34301581
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 7361a62e SPIGOT-5641: Add Block.getDrops(ItemStack, Entity) 1dc91b15 Add specific notes about what is not API 2b05ef88 #484: Allow statistics to be accessed for offline players CraftBukkit Changes:f7d6ad53
SPIGOT-5603: Use LootContext#lootingModifier in CraftLootTable5838285d
SPIGOT-5657: BlockPlaceEvent not cancelling for tripwire hooksf325b9be
SPIGOT-5641: Add Block.getDrops(ItemStack, Entity)e25a2272
Fix some formatting in CraftHumanEntity498540e0
Add Merchant slot delegateb2de47d5
SPIGOT-5621: Add missing container types for opening InventoryViewaa3a2f27
#645: Allow statistics to be accessed for offline players2122c0b1
#649: CraftBell should implement Bell
136 lines
5.3 KiB
Diff
136 lines
5.3 KiB
Diff
From a14f5b0c6cc0718f0811156f67ed304439a657cc Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Mon, 6 Nov 2017 21:08:22 -0500
|
|
Subject: [PATCH] API to get a BlockState without a snapshot
|
|
|
|
This allows you to get a BlockState without creating a snapshot, operating
|
|
on the real tile entity.
|
|
|
|
This is useful for where performance is needed
|
|
|
|
also Avoid NPE during CraftBlockEntityState load if could not get TE
|
|
|
|
If Tile Entity was null, correct Sign to return empty lines instead of null
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
|
|
index 630b279158..958279249f 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntity.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntity.java
|
|
@@ -231,7 +231,12 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
}
|
|
|
|
// CraftBukkit start - add method
|
|
+ // Paper start
|
|
public InventoryHolder getOwner() {
|
|
+ return getOwner(true);
|
|
+ }
|
|
+ public InventoryHolder getOwner(boolean useSnapshot) {
|
|
+ // Paper end
|
|
if (world == null) return null;
|
|
// Spigot start
|
|
org.bukkit.block.Block block = world.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
|
|
@@ -240,7 +245,7 @@ public abstract class TileEntity implements KeyedObject { // Paper
|
|
return null;
|
|
}
|
|
// Spigot end
|
|
- org.bukkit.block.BlockState state = block.getState();
|
|
+ org.bukkit.block.BlockState state = block.getState(useSnapshot); // Paper
|
|
if (state instanceof InventoryHolder) return (InventoryHolder) state;
|
|
return null;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
index eb0201ebe1..1354d949c1 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
|
|
@@ -311,6 +311,20 @@ public class CraftBlock implements Block {
|
|
|
|
@Override
|
|
public BlockState getState() {
|
|
+ // Paper start - allow disabling the use of snapshots
|
|
+ return getState(true);
|
|
+ }
|
|
+ public BlockState getState(boolean useSnapshot) {
|
|
+ boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
|
|
+ try {
|
|
+ return getState0();
|
|
+ } finally {
|
|
+ CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
|
|
+ }
|
|
+ }
|
|
+ public BlockState getState0() {
|
|
+ // Paper end
|
|
Material material = getType();
|
|
|
|
switch (material) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
index 17d80b5c6e..f6401e2cde 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
|
|
@@ -26,20 +26,40 @@ public class CraftBlockEntityState<T extends TileEntity> extends CraftBlockState
|
|
this.tileEntity = tileEntityClass.cast(world.getHandle().getTileEntity(this.getPosition()));
|
|
Preconditions.checkState(this.tileEntity != null, "Tile is null, asynchronous access? " + block);
|
|
|
|
+ // Paper start
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
+ if (DISABLE_SNAPSHOT) {
|
|
+ this.snapshot = this.tileEntity;
|
|
+ } else {
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity);
|
|
+ }
|
|
// copy tile entity data:
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
|
- this.load(snapshot);
|
|
+ if(this.snapshot != null) {
|
|
+ this.load(this.snapshot);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
+ public final boolean snapshotDisabled; // Paper
|
|
+ public static boolean DISABLE_SNAPSHOT = false; // Paper
|
|
+
|
|
public CraftBlockEntityState(Material material, T tileEntity) {
|
|
super(material);
|
|
|
|
this.tileEntityClass = (Class<T>) tileEntity.getClass();
|
|
this.tileEntity = tileEntity;
|
|
-
|
|
+ // Paper start
|
|
+ this.snapshotDisabled = DISABLE_SNAPSHOT;
|
|
+ if (DISABLE_SNAPSHOT) {
|
|
+ this.snapshot = this.tileEntity;
|
|
+ } else {
|
|
+ this.snapshot = this.createSnapshot(this.tileEntity);
|
|
+ }
|
|
// copy tile entity data:
|
|
- this.snapshot = this.createSnapshot(tileEntity);
|
|
- this.load(snapshot);
|
|
+ if(this.snapshot != null) {
|
|
+ this.load(this.snapshot);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
private T createSnapshot(T tileEntity) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
index 15022ada0c..af15656cc4 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSign.java
|
|
@@ -17,10 +17,12 @@ public class CraftSign extends CraftBlockEntityState<TileEntitySign> implements
|
|
|
|
public CraftSign(final Block block) {
|
|
super(block, TileEntitySign.class);
|
|
+ if (lines == null) { lines = new String[]{"", "", "", ""}; } // Paper
|
|
}
|
|
|
|
public CraftSign(final Material material, final TileEntitySign te) {
|
|
super(material, te);
|
|
+ if (lines == null) { lines = new String[]{"", "", "", ""}; } // Paper
|
|
}
|
|
|
|
@Override
|
|
--
|
|
2.25.1
|
|
|