Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid reflection when using SportPaper #1288

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<repository>
<id>sportpaper-github</id>
<url>https://maven.pkg.github.com/Electroid/SportPaper</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jitpack-io</id>
Expand Down
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
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
Loading