From b20fb850ac5ea824174bdd139b5237f526cb6150 Mon Sep 17 00:00:00 2001 From: "BT (calcastor/mame)" <43831917+calcastor@users.noreply.github.com> Date: Mon, 1 Jan 2024 08:59:01 -0800 Subject: [PATCH] Avoid reflection when using SportPaper The reflection used in NMSHacks1_8 breaks in modern Java versions, but we can modify SportPaper to avoid that here. Signed-off-by: BT (calcastor/mame) <43831917+calcastor@users.noreply.github.com> --- .../java/tc/oc/pgm/util/nms/v1_8/NMSHacks1_8.java | 8 ++++---- .../tc/oc/pgm/util/nms/v1_8/NMSHacksSportPaper.java | 11 +++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacks1_8.java b/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacks1_8.java index be896fc8b0..f5f401b629 100644 --- a/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacks1_8.java +++ b/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacks1_8.java @@ -837,12 +837,12 @@ public boolean canMineBlock(MaterialData blockMaterial, ItemStack tool) { || (nmsTool != null && nmsTool.canDestroySpecialBlock(nmsBlock))); } - Field worldServerField = ReflectionUtils.getField(CraftWorld.class, "world"); - Field dimensionField = ReflectionUtils.getField(WorldServer.class, "dimension"); - Field modifiersField = ReflectionUtils.getField(Field.class, "modifiers"); - @Override public void resetDimension(World world) { + Field worldServerField = ReflectionUtils.getField(CraftWorld.class, "world"); + Field dimensionField = ReflectionUtils.getField(WorldServer.class, "dimension"); + Field modifiersField = ReflectionUtils.getField(Field.class, "modifiers"); + try { modifiersField.setInt(dimensionField, dimensionField.getModifiers() & ~Modifier.FINAL); diff --git a/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacksSportPaper.java b/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacksSportPaper.java index 1221040eee..6cc8d9ffd9 100644 --- a/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacksSportPaper.java +++ b/util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacksSportPaper.java @@ -16,7 +16,9 @@ import org.bukkit.ChunkSnapshot; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.block.BlockState; +import org.bukkit.craftbukkit.v1_8_R3.CraftWorld; import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_8_R3.scoreboard.CraftTeam; import org.bukkit.entity.EntityType; @@ -185,6 +187,15 @@ public Skin getPlayerSkinForViewer(Player player, Player viewer) { : getPlayerSkin(player); } + @Override + public void resetDimension(World world) { + try { + ((CraftWorld) world).getHandle().dimension = 11; + } catch (IllegalAccessError e) { + super.resetDimension(world); + } + } + @Override public void setCanDestroy(ItemMeta itemMeta, Collection materials) { itemMeta.setCanDestroy(materials);