forked from SteamWar/SteamWar
Introduce support for Minecraft 1.21: Add ReflectionWrapper21, ChunkHider21, and enhance version compatibility across systems.
This commit is contained in:
@@ -157,7 +157,16 @@ public final class Reflection {
|
||||
} else if(MAJOR_VERSION < 21 || MINOR_VERSION < 4) {
|
||||
return Class.forName(spigotClassnames.getOrDefault(name, name));
|
||||
} else {
|
||||
return Class.forName(name);
|
||||
Class<?> clazz = Class.forName(name);
|
||||
if (clazz.getName().equals(name)) {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
try {
|
||||
return Core.class.getClassLoader().getParent().loadClass(name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new IllegalArgumentException("Cannot find " + name, e);
|
||||
|
||||
@@ -53,6 +53,7 @@ public interface ChunkHider {
|
||||
|
||||
private boolean paletted;
|
||||
private int bitsPerBlock;
|
||||
private int blockCount;
|
||||
private int air;
|
||||
private int target;
|
||||
private Set<Integer> obfuscate;
|
||||
@@ -86,7 +87,8 @@ public interface ChunkHider {
|
||||
}
|
||||
|
||||
public void copyBlockCount() {
|
||||
out.writeShort(in.readShort());
|
||||
this.blockCount = in.readShort();
|
||||
out.writeShort(blockCount);
|
||||
}
|
||||
|
||||
public void copyBitsPerBlock() {
|
||||
@@ -140,6 +142,15 @@ public interface ChunkHider {
|
||||
out.writeBytes(in, dataArrayLength*8);
|
||||
}
|
||||
|
||||
public void skipNewDataArray(int entries) {
|
||||
if (bitsPerBlock == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
int longs = (int) (((long) entries * bitsPerBlock + 63) >> 6);
|
||||
out.writeBytes(in, longs * Long.BYTES);
|
||||
}
|
||||
|
||||
public long[] readDataArray() {
|
||||
long[] array = new long[copyVarInt()];
|
||||
for(int i = 0; i < array.length; i++)
|
||||
@@ -148,6 +159,19 @@ public interface ChunkHider {
|
||||
return array;
|
||||
}
|
||||
|
||||
public long[] readNewDataArray(int entries) {
|
||||
if (bitsPerBlock == 0) {
|
||||
return new long[entries];
|
||||
}
|
||||
|
||||
int longs = (int) (((long) entries * bitsPerBlock + 63) >> 6);
|
||||
long[] array = new long[longs];
|
||||
for(int i = 0; i < longs; i++)
|
||||
array[i] = in.readLong();
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
public void writeDataArray(long[] array) {
|
||||
for(long l : array)
|
||||
out.writeLong(l);
|
||||
|
||||
@@ -58,6 +58,16 @@ public class ProtocolUtils {
|
||||
};
|
||||
}
|
||||
|
||||
public static <T> UnaryOperator<T> shallowTypedCloneGenerator(Class<T> clazz) {
|
||||
BiConsumer<Object, Object> filler = shallowFill(clazz);
|
||||
|
||||
return source -> {
|
||||
Object clone = Reflection.newInstance(clazz);
|
||||
filler.accept(source, clone);
|
||||
return (T) clone;
|
||||
};
|
||||
}
|
||||
|
||||
private static BiConsumer<Object, Object> shallowFill(Class<?> clazz) {
|
||||
if(clazz == null)
|
||||
return (source, clone) -> {};
|
||||
|
||||
@@ -79,6 +79,7 @@ public class TechHider {
|
||||
techhiders.put(blockChangePacket, this::blockChangeHider);
|
||||
techhiders.put(tileEntityDataPacket, this::tileEntityDataHider);
|
||||
techhiders.put(multiBlockChangePacket, ProtocolWrapper.impl.multiBlockChangeGenerator(this));
|
||||
System.out.println(ChunkHider.impl.mapChunkPacket().getName());
|
||||
techhiders.put(ChunkHider.impl.mapChunkPacket(), ChunkHider.impl.chunkHiderGenerator(this));
|
||||
|
||||
if(Core.getVersion() > 12 && Core.getVersion() < 19) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: SpigotCore
|
||||
version: "2.0"
|
||||
author: Lixfel
|
||||
api-version: "1.13"
|
||||
api-version: "1.21"
|
||||
load: STARTUP
|
||||
softdepend:
|
||||
- WorldEdit
|
||||
|
||||
Reference in New Issue
Block a user