Merge pull request 'Fix replay in 1.21 -> RPlayer needs fixing before' (#199) from FightSystem/ReplayFix21 into main

Reviewed-on: SteamWar/SteamWar#199
This commit is contained in:
2025-12-03 10:05:03 +01:00
9 changed files with 111 additions and 28 deletions
@@ -27,9 +27,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader;
import com.sk89q.worldedit.extent.clipboard.io.*;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.BlockVector3;
@@ -120,7 +118,12 @@ public class WorldeditWrapper14 implements WorldeditWrapper {
@Override
public Clipboard loadChar(String charName) throws IOException {
return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(new FileInputStream(new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schem"))))).read();
File file = new File(FightSystem.getPlugin().getDataFolder(), "text/" + charName + ".schem");
Clipboard clipboard;
try (ClipboardReader reader = Objects.requireNonNull(ClipboardFormats.findByFile(file)).getReader(new FileInputStream(file))) {
clipboard = reader.read();
}
return clipboard;
}
@Override
@@ -203,13 +203,23 @@ public class FightSchematic extends StateDependent {
for(int i = 0; i < chars.length; i++){
Clipboard character;
try {
character = WorldeditWrapper.impl.loadChar(chars[i] == '/' ? "slash" : String.valueOf(chars[i]));
if (Character.isLowerCase(chars[i])) {
character = WorldeditWrapper.impl.loadChar("lower/" + chars[i]);
} else if (Character.isUpperCase(chars[i])) {
character = WorldeditWrapper.impl.loadChar("upper/" + chars[i]);
} else {
character = WorldeditWrapper.impl.loadChar(chars[i] == '/' ? "slash" : String.valueOf(chars[i]));
}
} catch (IOException e) {
Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", chars[i]);
try {
character = WorldeditWrapper.impl.loadChar("");
}catch (IOException ex) {
throw new SecurityException("Could not load text", ex);
character = WorldeditWrapper.impl.loadChar(chars[i] == '/' ? "slash" : String.valueOf(chars[i]));
} catch (IOException ex) {
Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", chars[i]);
try {
character = WorldeditWrapper.impl.loadChar("");
}catch (IOException exc) {
throw new SecurityException("Could not load text", exc);
}
}
}
+12
View File
@@ -50,6 +50,18 @@ tasks.register<FightServer>("WarGear20") {
config = "WarGear20.yml"
}
tasks.register<FightServer>("HalloweenWS") {
group = "run"
description = "Run a Halloween 1.21 Fight Replay Server"
dependsOn(":SpigotCore:shadowJar")
dependsOn(":FightSystem:shadowJar")
template = "HalloweenWS"
worldName = "arenas/Lucifus"
config = "HalloweenWS.yml"
replay = 179786
jar = "/jars/paper-1.21.6.jar"
}
tasks.register<FightServer>("WarGear21") {
group = "run"
description = "Run a WarGear 1.21 Fight Server"
@@ -300,10 +300,10 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
return head;
}
private static final Class<?> entityPose = Reflection.getClass("net.minecraft.world.entity.Pose");
private static final Object standing = entityPose.getEnumConstants()[0];
private static final Object swimming = entityPose.getEnumConstants()[3];
private static final Object sneaking = entityPose.getEnumConstants()[5];
protected static final Class<?> entityPose = Reflection.getClass("net.minecraft.world.entity.Pose");
protected static final Object standing = entityPose.getEnumConstants()[0];
protected static final Object swimming = entityPose.getEnumConstants()[3];
protected static final Object sneaking = entityPose.getEnumConstants()[5];
@Override
public Object getPose(FlatteningWrapper.EntityPose pose) {
switch (pose) {
@@ -43,4 +43,11 @@ public class FlatteningWrapper21 extends FlatteningWrapper14 implements Flatteni
});
return head;
}
protected static final Object shooting = entityPose.getEnumConstants()[16];
@Override
public Object getPose(FlatteningWrapper.EntityPose pose) {
if (pose == FlatteningWrapper.EntityPose.SHOOTING) return shooting;
return super.getPose(pose);
}
}
@@ -21,8 +21,6 @@ package de.steamwar.core;
import com.mojang.authlib.GameProfile;
import com.mojang.datafixers.util.Pair;
import de.steamwar.Reflection;
import net.minecraft.Util;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoRemovePacket;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
@@ -33,8 +31,6 @@ import org.bukkit.GameMode;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.function.LongSupplier;
public class ProtocolWrapper21 implements ProtocolWrapper {
@Override
@@ -19,7 +19,6 @@
package de.steamwar.core;
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV2;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@@ -37,7 +36,11 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import org.enginehub.linbus.stream.LinBinaryIO;
import java.io.*;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
public class WorldEditWrapper21 implements WorldEditWrapper {
@@ -68,12 +71,58 @@ public class WorldEditWrapper21 implements WorldEditWrapper {
@Override
@SuppressWarnings("removal")
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException {
return switch (schemFormat) {
case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read();
case SPONGE_V2 -> new SpongeSchematicV2Reader(LinBinaryIO.read(new DataInputStream(is))).read();
case SPONGE_V3 -> new SpongeSchematicV3Reader(LinBinaryIO.read(new DataInputStream(is))).read();
};
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat ignored) throws IOException {
ResetableInputStream ris = new ResetableInputStream(is);
for (NodeData.SchematicFormat schemFormat : NodeData.SchematicFormat.values()) {
try {
Clipboard clipboard = switch (schemFormat) {
case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(ris)).read();
case SPONGE_V2 -> new SpongeSchematicV2Reader(LinBinaryIO.read(new DataInputStream(ris))).read();
case SPONGE_V3 -> new SpongeSchematicV3Reader(LinBinaryIO.read(new DataInputStream(ris))).read();
};
ris.close();
return clipboard;
} catch (Exception e) {
// Ignore
}
ris.reset();
}
throw new IOException("No clipboard found");
}
private class ResetableInputStream extends InputStream {
private InputStream inputStream;
private int pointer = 0;
private List<Integer> list = new ArrayList<>();
public ResetableInputStream(InputStream in) {
this.inputStream = in;
}
@Override
public int read() throws IOException {
if (pointer >= list.size()) {
int data = inputStream.read();
list.add(data);
pointer++;
return data;
}
int data = list.get(pointer);
pointer++;
return data;
}
@Override
public void reset() throws IOException {
pointer = 0;
}
@Override
public void close() throws IOException {
list.clear();
pointer = -1;
}
}
@Override
@@ -56,6 +56,8 @@ public class FlatteningWrapper {
public enum EntityPose {
NORMAL,
SNEAKING,
SWIMMING;
SWIMMING,
SHOOTING,
;
}
}
@@ -36,7 +36,7 @@ public class REntity {
private static final Object entityStatusWatcher = BountifulWrapper.impl.getDataWatcherObject(0, Byte.class);
private static final Object sneakingDataWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 6 : 0, FlatteningWrapper.impl.getPose(FlatteningWrapper.EntityPose.NORMAL).getClass());
private static final Object bowDrawnWatcher = BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 7 : 6, Byte.class);
private static final Object bowDrawnWatcher = Core.getVersion() >= 21 ? BountifulWrapper.impl.getDataWatcherObject(6, FlatteningWrapper.impl.getPose(FlatteningWrapper.EntityPose.NORMAL).getClass()) : BountifulWrapper.impl.getDataWatcherObject(Core.getVersion() > 12 ? 7 : 6, Byte.class);
private static final Object nameWatcher = BountifulWrapper.impl.getDataWatcherObject(2, Core.getVersion() > 12 ? Optional.class : String.class); // Optional<IChatBaseComponent>
private static final Object nameVisibleWatcher = BountifulWrapper.impl.getDataWatcherObject(3, Boolean.class);
@@ -219,7 +219,9 @@ public class REntity {
public void setBowDrawn(boolean drawn, boolean offHand) {
bowDrawn = drawn;
if(Core.getVersion() > 8){
if (Core.getVersion() >= 21) {
server.updateEntity(this, getDataWatcherPacket(bowDrawnWatcher, FlatteningWrapper.impl.getPose(FlatteningWrapper.EntityPose.SHOOTING)));
} else if(Core.getVersion() > 8){
server.updateEntity(this, getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
}else{
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
@@ -443,12 +445,14 @@ public class REntity {
}
private static final Reflection.Field<Integer> equipmentEntity = Reflection.getField(ProtocolWrapper.equipmentPacket, int.class, 0);
private static final Reflection.Field<List> equipmentSlots = Reflection.getField(ProtocolWrapper.equipmentPacket, List.class, 0);
private static final Class<?> craftItemStack = Reflection.getClass("org.bukkit.craftbukkit.inventory.CraftItemStack");
protected static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class);
protected Object getEquipmentPacket(Object slot, ItemStack stack){
Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket);
equipmentEntity.set(packet, entityId);
equipmentSlots.set(packet, new ArrayList<>());
ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack));
return packet;
}