Skip to content

Commit e3a9427

Browse files
authored
Paper fixes (#2719)
* Some Paper fixes * Minor cleanup * Bump Paper API
1 parent 28d325c commit e3a9427

File tree

7 files changed

+20
-44
lines changed

7 files changed

+20
-44
lines changed

paper/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<dependency>
2626
<groupId>io.papermc.paper</groupId>
2727
<artifactId>paper-api</artifactId>
28-
<version>1.21.4-R0.1-SNAPSHOT</version>
28+
<version>1.21.5-R0.1-SNAPSHOT</version>
2929
<scope>provided</scope>
3030
</dependency>
3131
<dependency>

paper/src/main/java/com/denizenscript/denizen/paper/events/EntityKnocksbackEntityScriptEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ObjectTag getContext(String name) {
9696
case "entity" -> entity.getDenizenObject();
9797
case "damager" -> hitBy.getDenizenObject();
9898
case "acceleration" -> new LocationTag(event.getAcceleration());
99-
case "cause" -> new ElementTag(event.getCause());
99+
case "cause" -> new ElementTag(event.getCause().name(), true); // TODO: once 1.20 is the minimum supported version, use the enum constructor
100100
default -> super.getContext(name);
101101
};
102102
}

plugin/src/main/java/com/denizenscript/denizen/nms/interfaces/BlockHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ default BlockData parseBlockData(String text) {
6565
return Material.matchMaterial(material).createBlockData(otherData);
6666
}
6767

68-
void makeBlockStateRaw(BlockState state);
68+
default void makeBlockStateRaw(BlockState state) {} // TODO: once 1.19 is the minimum supported version, remove this
6969

7070
void doRandomTick(Location location);
7171

plugin/src/main/java/com/denizenscript/denizen/objects/LocationTag.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5252,20 +5252,21 @@ else if (state instanceof Dropper) {
52525252
// <LocationTag.jukebox_record>
52535253
// -->
52545254
if (mechanism.matches("jukebox_record")) {
5255-
BlockState state = getBlockState();
5256-
if (state instanceof Jukebox) {
5257-
if (mechanism.hasValue() && mechanism.requireObject(ItemTag.class)) {
5258-
((Jukebox) state).setRecord(mechanism.valueAsType(ItemTag.class).getItemStack());
5259-
}
5260-
else {
5261-
NMSHandler.blockHelper.makeBlockStateRaw(state);
5262-
((Jukebox) state).setRecord(null);
5255+
if (!(getBlockState() instanceof Jukebox jukebox)) {
5256+
mechanism.echoError("'jukebox_record' mechanism can only be called on a jukebox block.");
5257+
return;
5258+
}
5259+
if (mechanism.hasValue()) {
5260+
if (!mechanism.requireObject(ItemTag.class)) {
5261+
return;
52635262
}
5264-
state.update();
5263+
jukebox.setRecord(mechanism.valueAsType(ItemTag.class).getItemStack());
52655264
}
52665265
else {
5267-
mechanism.echoError("'jukebox_record' mechanism can only be called on a jukebox block.");
5266+
NMSHandler.blockHelper.makeBlockStateRaw(jukebox);
5267+
jukebox.setRecord(null);
52685268
}
5269+
jukebox.update();
52695270
}
52705271

52715272
// <--[mechanism]

v1_19/src/main/java/com/denizenscript/denizen/nms/v1_19/helpers/BlockHelperImpl.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import net.minecraft.world.level.material.PushReaction;
3939
import org.bukkit.*;
4040
import org.bukkit.block.Block;
41-
import org.bukkit.block.BlockState;
4241
import org.bukkit.block.CreatureSpawner;
4342
import org.bukkit.block.Skull;
4443
import org.bukkit.craftbukkit.v1_19_R3.CraftChunk;
@@ -66,16 +65,6 @@ public class BlockHelperImpl implements BlockHelper {
6665
public static final Field craftBlockEntityState_snapshot = ReflectionHelper.getFields(CraftBlockEntityState.class).get("snapshot");
6766
public static final Field craftSkull_profile = ReflectionHelper.getFields(CraftSkull.class).get("profile");
6867

69-
@Override
70-
public void makeBlockStateRaw(BlockState state) {
71-
try {
72-
craftBlockEntityState_snapshot.set(state, craftBlockEntityState_tileEntity.get(state));
73-
}
74-
catch (Throwable ex) {
75-
Debug.echoError(ex);
76-
}
77-
}
78-
7968
@Override
8069
public void applyPhysics(Location location) {
8170
BlockPos pos = new BlockPos(location.getBlockX(), location.getBlockY(), location.getBlockZ());

v1_20/src/main/java/com/denizenscript/denizen/nms/v1_20/helpers/BlockHelperImpl.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import net.minecraft.world.level.material.PushReaction;
3838
import org.bukkit.*;
3939
import org.bukkit.block.Block;
40-
import org.bukkit.block.BlockState;
4140
import org.bukkit.block.CreatureSpawner;
4241
import org.bukkit.block.Skull;
4342
import org.bukkit.craftbukkit.v1_20_R4.CraftChunk;
@@ -66,16 +65,6 @@ public class BlockHelperImpl implements BlockHelper {
6665
public static final Field craftBlockEntityState_snapshot = ReflectionHelper.getFields(CraftBlockEntityState.class).get("snapshot");
6766
public static final Field craftSkull_profile = ReflectionHelper.getFields(CraftSkull.class).get("profile");
6867

69-
@Override
70-
public void makeBlockStateRaw(BlockState state) {
71-
try {
72-
craftBlockEntityState_snapshot.set(state, craftBlockEntityState_tileEntity.get(state));
73-
}
74-
catch (Throwable ex) {
75-
Debug.echoError(ex);
76-
}
77-
}
78-
7968
@Override
8069
public void applyPhysics(Location location) {
8170
((CraftWorld) location.getWorld()).getHandle().updateNeighborsAt(CraftLocation.toBlockPosition(location), CraftMagicNumbers.getBlock(location.getBlock().getType()));

v1_21/src/main/java/com/denizenscript/denizen/nms/v1_21/helpers/BlockHelperImpl.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.bukkit.Location;
3333
import org.bukkit.Material;
3434
import org.bukkit.block.Block;
35-
import org.bukkit.block.BlockState;
3635
import org.bukkit.block.CreatureSpawner;
3736
import org.bukkit.block.Skull;
3837
import org.bukkit.craftbukkit.v1_21_R4.CraftChunk;
@@ -53,18 +52,16 @@
5352

5453
public class BlockHelperImpl implements BlockHelper {
5554

56-
public static final Field craftBlockEntityState_tileEntity = ReflectionHelper.getFields(CraftBlockEntityState.class).get("tileEntity");
55+
public static final Field craftBlockEntityState_tileEntity;
5756
public static final Field craftBlockEntityState_snapshot = ReflectionHelper.getFields(CraftBlockEntityState.class).get("snapshot");
5857
public static final Field craftSkull_profile = ReflectionHelper.getFields(CraftSkull.class).get("profile");
5958

60-
@Override
61-
public void makeBlockStateRaw(BlockState state) {
62-
try {
63-
craftBlockEntityState_snapshot.set(state, craftBlockEntityState_tileEntity.get(state));
64-
}
65-
catch (Throwable ex) {
66-
Debug.echoError(ex);
59+
static {
60+
Field blockEntityField = ReflectionHelper.getFields(CraftBlockEntityState.class).getNoCheck("blockEntity");
61+
if (blockEntityField == null) {
62+
blockEntityField = ReflectionHelper.getFields(CraftBlockEntityState.class).get("tileEntity");
6763
}
64+
craftBlockEntityState_tileEntity = blockEntityField;
6865
}
6966

7067
@Override

0 commit comments

Comments
 (0)