Merge remote-tracking branch 'refs/remotes/origin/ReflectionReduction' into Refactor/remove-old-dependencies

# Conflicts:
#	MissileWars/build.gradle.kts
This commit is contained in:
2026-05-16 13:53:29 +02:00
30 changed files with 180 additions and 251 deletions
@@ -20,15 +20,19 @@
package de.steamwar.misslewars;
import de.steamwar.core.CraftbukkitWrapper;
import net.minecraft.world.level.chunk.Chunk;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.LevelChunkSection;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.WorldCreator;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.Set;
import java.util.function.ObjIntConsumer;
public class FightWorld {
@@ -71,10 +75,14 @@ public class FightWorld {
}
private static void resetChunk(World world, World backup, int x, int z) {
Chunk chunk = ((CraftWorld) world).getHandle().d(x, z);
Chunk backupChunk = ((CraftWorld) backup).getHandle().d(x, z);
System.arraycopy(backupChunk.d(), 0, chunk.d(), 0, chunk.d().length);
LevelChunk worldChunk = ((CraftWorld) world).getHandle().getChunk(x, z);
LevelChunk backupChunk = ((CraftWorld) backup).getHandle().getChunk(x, z);
LevelChunkSection[] sections = worldChunk.getSections();
System.arraycopy(backupChunk.getSections(), 0, sections, 0, sections.length);
Set<BlockPos> blocks = new HashSet<>(worldChunk.blockEntities.keySet());
blocks.stream().filter(key -> !backupChunk.blockEntities.containsKey(key)).forEach(worldChunk::removeBlockEntity);
worldChunk.heightmaps.clear();
worldChunk.heightmaps.putAll(backupChunk.heightmaps);
for(Player p : Bukkit.getOnlinePlayers())
CraftbukkitWrapper.impl.sendChunk(p, x, z);
@@ -19,9 +19,10 @@
package de.steamwar.misslewars.slowmo;
import de.steamwar.Reflection;
import net.minecraft.server.level.ServerLevel;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.CraftWorld;
import java.lang.reflect.Field;
@@ -30,7 +31,6 @@ public class SlowMoUtils {
private static final Field field;
public static final boolean freezeEnabled;
private static final Reflection.Method getWorldHandle = Reflection.getTypedMethod(Reflection.getClass("org.bukkit.craftbukkit.CraftWorld"), "getHandle", null);
private static boolean frozen = false;
private static final World world;
@@ -38,7 +38,7 @@ public class SlowMoUtils {
static {
Field temp;
try {
temp = Reflection.getClass("net.minecraft.server.level.ServerLevel").getField("freezed");
temp = ServerLevel.class.getField("freezed");
} catch (NoSuchFieldException e) {
temp = null;
}
@@ -64,7 +64,7 @@ public class SlowMoUtils {
if (freezeEnabled) {
if (frozen == state) return;
try {
field.set(getWorldHandle.invoke(world), state);
field.set(((CraftWorld) world).getHandle(), state);
frozen = state;
} catch (IllegalAccessException e) {
// Ignored;