Remove reflection from BauSystem

This commit is contained in:
2026-06-11 13:45:49 +02:00
parent 961331f029
commit eb866125ea
6 changed files with 62 additions and 20 deletions
+44
View File
@@ -30,6 +30,45 @@ java {
targetCompatibility = JavaVersion.VERSION_21
}
// ─── Collect all .accesswidener files from this plugin's resources ────────────
val accessWidenerFiles: FileCollection = fileTree("src/") {
include("**/*.accesswidener")
}
val paperJarProvider: Provider<File> = provider {
val dep = libs.nms.get()
configurations["compileClasspath"].resolvedConfiguration.resolvedArtifacts.first { artifact ->
artifact.moduleVersion.id.module.group == dep.module.group && artifact.moduleVersion.id.module.name == dep.module.name
}.file
}
// ─── Widen the Paper dev JAR so the IDE / javac see the patched access ────────
val widenedJar by tasks.registering(JavaExec::class) {
description = "Produces a widened copy of the Paper dev JAR for compile-time use."
group = "widener"
// Re-run whenever the .accesswidener files change
inputs.file(paperJarProvider)
inputs.files(accessWidenerFiles)
val output = layout.buildDirectory.file("widened/paper-widened.jar")
outputs.file(output)
classpath = project(":AccessWidener").tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar").get().outputs.files
mainClass.set("de.steamwar.Main")
doFirst {
args = buildList {
add(paperJarProvider.get().absolutePath)
add(output.get().asFile.absolutePath)
addAll(accessWidenerFiles.map { it.absolutePath })
}
}
dependsOn(":AccessWidener:shadowJar")
}
dependencies {
compileOnly(libs.classindex)
annotationProcessor(libs.classindex)
@@ -40,6 +79,7 @@ dependencies {
compileOnly(libs.paperapi)
compileOnly(libs.nms)
compileOnly(files(widenedJar))
compileOnly(libs.fawe)
compileOnly(libs.netty)
@@ -47,3 +87,7 @@ dependencies {
implementation(libs.luaj)
implementation(files("$projectDir/../libs/YAPION-SNAPSHOT.jar"))
}
tasks.compileJava {
dependsOn(widenedJar)
}
@@ -1,3 +1,8 @@
accessWidener v2 named
accessible field net/minecraft/server/level/ServerPlayerGameMode gameModeForPlayer Lnet/minecraft/world/level/GameType;
accessible field org/bukkit/craftbukkit/block/CraftBlockState position Lnet/minecraft/core/BlockPos;
accessible field org/bukkit/craftbukkit/block/CraftBlockState world Lorg/bukkit/craftbukkit/CraftWorld;
mutable field org/bukkit/craftbukkit/block/CraftBlockState position Lnet/minecraft/core/BlockPos;
mutable field org/bukkit/craftbukkit/block/CraftBlockState world Lorg/bukkit/craftbukkit/CraftWorld;
accessible field net/minecraft/server/ServerTickRateManager remainingSprintTicks J
@@ -102,7 +102,7 @@ public class NoClipCommand extends SWCommand implements Listener {
}
private void setInternalGameMode(Player player, GameMode gameMode) {
// ((CraftPlayer) player).getHandle().gameMode.gameModeForPlayer = GameType.byId(gameMode.getValue());
((CraftPlayer) player).getHandle().gameMode.gameModeForPlayer = GameType.byId(gameMode.getValue());
}
@Register(help = true)
@@ -19,7 +19,6 @@
package de.steamwar.bausystem.utils;
import de.steamwar.Reflection;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.experimental.UtilityClass;
@@ -86,9 +85,6 @@ public class PlaceItemUtils {
.collect(Collectors.toSet());
}
private static final Reflection.Field<?> positionAccessor = Reflection.getField(CraftBlockState.class, BlockPos.class, 0);
private static final Reflection.Field<?> worldAccessor = Reflection.getField(CraftBlockState.class, CraftWorld.class, 0);
/**
* Attempt to place an {@link ItemStack} the {@link Player} is holding against a {@link Block} inside the World.
* This can be easily used inside the {@link org.bukkit.event.player.PlayerInteractEvent} to mimik placing a
@@ -288,8 +284,9 @@ public class PlaceItemUtils {
} else {
// If a BlockState is present set the Position and World to the Block you want to place
Location blockLocation = block.getLocation();
positionAccessor.set(blockState, new BlockPos(blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ()));
worldAccessor.set(blockState, blockLocation.getWorld());
CraftBlockState craftBlockState = (CraftBlockState) blockState;
craftBlockState.position = new BlockPos(blockLocation.getBlockX(), blockLocation.getBlockY(), blockLocation.getBlockZ());
craftBlockState.world = (CraftWorld) blockLocation.getWorld();
}
if (blockData.getMaterial().isSolid()) {
@@ -20,7 +20,6 @@
package de.steamwar.bausystem.utils;
import com.comphenix.tinyprotocol.TinyProtocol;
import de.steamwar.Reflection;
import de.steamwar.bausystem.BauSystem;
import net.minecraft.network.protocol.game.ClientboundTickingStatePacket;
import net.minecraft.server.MinecraftServer;
@@ -33,7 +32,6 @@ public class TickManager implements Listener {
public static final TickManager impl = new TickManager();
private static final ServerTickRateManager manager = MinecraftServer.getServer().tickRateManager();
private static final Reflection.Field<Long> remainingSprintTicks = Reflection.getField(ServerTickRateManager.class, long.class, 0);
private boolean blockTpsPacket = true;
private int totalSteps;
@@ -121,7 +119,7 @@ public class TickManager implements Listener {
public long getRemainingTicks() {
if (isSprinting()) {
return remainingSprintTicks.get(manager);
return manager.remainingSprintTicks;
} else {
return manager.frozenTicksToRun();
}