Fix Version construction
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
Lixfel 2023-09-15 16:37:03 +02:00
Ursprung 610ba248ea
Commit 028448be8d
3 geänderte Dateien mit 31 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -4,6 +4,7 @@ import com.moulberry.axiom.integration.PaperFailMoveListener;
import com.moulberry.axiom.packet.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.papermc.paper.event.player.PlayerFailMoveEvent;
import net.minecraft.core.BlockPos;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
@ -90,6 +91,7 @@ public class AxiomPaper extends JavaPlugin implements Listener {
instance = this;
try {
PlayerFailMoveEvent.class.getName(); //Try load class
Bukkit.getPluginManager().registerEvents(new PaperFailMoveListener(), this);
} catch (NoClassDefFoundError e) {
getLogger().log(java.util.logging.Level.WARNING, "Axiom players may move too quickly according to the server. Use a current Paper version or increase the 'moved-too-quickly-multiplier' in spigot.yml.");

Datei anzeigen

@ -126,6 +126,28 @@ public class Reflection {
}
public interface Constructor<T> {
T newInstance(Object... arguments);
}
public static <T> Constructor<T> getConstructor(Class<T> clazz, Class<?>... params) {
try {
java.lang.reflect.Constructor<T> constructor = clazz.getDeclaredConstructor(params);
constructor.setAccessible(true);
return arguments -> {
try {
return constructor.newInstance(arguments);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new IllegalArgumentException("Cannot invoke constructor " + constructor, e);
}
};
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Cannot find matching constructor");
}
}
private static final String ORG_BUKKIT_CRAFTBUKKIT = Bukkit.getServer().getClass().getPackage().getName();
public static final int VERSION; // Format: 2 digit minor version, 2 digit CraftBukkit revision: eg. 2001 for v1_20_R1
static {

Datei anzeigen

@ -13,6 +13,7 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.chunk.LevelChunk;
import org.bukkit.Chunk;
import java.util.BitSet;
import java.util.Set;
public class Version19R2 implements VersionWrapper {
@ -25,6 +26,11 @@ public class Version19R2 implements VersionWrapper {
return getLightBlock.invoke(old, chunk, pos) != getLightBlock.invoke(state, chunk, pos) || lightEmission.get(old) != lightEmission.get(state) || useShapeForLightOcclusion.get(old) || useShapeForLightOcclusion.get(state);
}
private static final Class<?> LevelLightEngine = Reflection.getClass("net.minecraft.world.level.lighting.LightEngine");
private static final Reflection.Constructor<ClientboundLevelChunkWithLightPacket> newClientboundLevelChunkWithLightPacket = Reflection.getConstructor(
ClientboundLevelChunkWithLightPacket.class,
LevelChunk.class, LevelLightEngine, BitSet.class, BitSet.class, boolean.class
);
@Override
public void publishBiomeChange(ServerLevel level, Set<Chunk> chunks) {
ThreadedLevelLightEngine lightEngine = AxiomPaper.getLightEngine(AxiomPaper.getChunkSource(level));
@ -32,7 +38,7 @@ public class Version19R2 implements VersionWrapper {
for (Chunk chunk : chunks) {
ChunkPos chunkPos = new ChunkPos(chunk.getX(), chunk.getZ());
LevelChunk nativeChunk = AxiomPaper.getChunk(level, chunk.getX(), chunk.getZ());
ClientboundLevelChunkWithLightPacket packet = new ClientboundLevelChunkWithLightPacket(nativeChunk, lightEngine, null, null, true);
ClientboundLevelChunkWithLightPacket packet = newClientboundLevelChunkWithLightPacket.newInstance(nativeChunk, lightEngine, null, null, true);
for (ServerPlayer player : AxiomPaper.getPlayersSeeingChunk(level, chunkPos)) {
AxiomPaper.sendPacket(player, packet);
}