Skip to content

Commit

Permalink
Avoid reflection when using SportPaper
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
calcastor committed Feb 26, 2024
1 parent ef5d5a9 commit b20fb85
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 4 additions & 4 deletions util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacks1_8.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
11 changes: 11 additions & 0 deletions util/src/main/java/tc/oc/pgm/util/nms/v1_8/NMSHacksSportPaper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Material> materials) {
itemMeta.setCanDestroy(materials);
Expand Down

0 comments on commit b20fb85

Please sign in to comment.