forked from SteamWar/SteamWar
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:
+7
-4
@@ -27,9 +27,7 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
|||||||
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
import com.sk89q.worldedit.bukkit.BukkitWorld;
|
||||||
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
import com.sk89q.worldedit.extent.clipboard.io.*;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
|
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.SpongeSchematicReader;
|
|
||||||
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
|
||||||
import com.sk89q.worldedit.function.operation.Operations;
|
import com.sk89q.worldedit.function.operation.Operations;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
@@ -120,7 +118,12 @@ public class WorldeditWrapper14 implements WorldeditWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Clipboard loadChar(String charName) throws IOException {
|
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
|
@Override
|
||||||
|
|||||||
@@ -203,13 +203,23 @@ public class FightSchematic extends StateDependent {
|
|||||||
for(int i = 0; i < chars.length; i++){
|
for(int i = 0; i < chars.length; i++){
|
||||||
Clipboard character;
|
Clipboard character;
|
||||||
try {
|
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) {
|
} catch (IOException e) {
|
||||||
Bukkit.getLogger().log(Level.WARNING, "Could not display character {} due to missing file!", chars[i]);
|
|
||||||
try {
|
try {
|
||||||
character = WorldeditWrapper.impl.loadChar("");
|
character = WorldeditWrapper.impl.loadChar(chars[i] == '/' ? "slash" : String.valueOf(chars[i]));
|
||||||
}catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
throw new SecurityException("Could not load text", 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,18 @@ tasks.register<FightServer>("WarGear20") {
|
|||||||
config = "WarGear20.yml"
|
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") {
|
tasks.register<FightServer>("WarGear21") {
|
||||||
group = "run"
|
group = "run"
|
||||||
description = "Run a WarGear 1.21 Fight Server"
|
description = "Run a WarGear 1.21 Fight Server"
|
||||||
|
|||||||
@@ -300,10 +300,10 @@ public class FlatteningWrapper14 implements FlatteningWrapper.IFlatteningWrapper
|
|||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Class<?> entityPose = Reflection.getClass("net.minecraft.world.entity.Pose");
|
protected static final Class<?> entityPose = Reflection.getClass("net.minecraft.world.entity.Pose");
|
||||||
private static final Object standing = entityPose.getEnumConstants()[0];
|
protected static final Object standing = entityPose.getEnumConstants()[0];
|
||||||
private static final Object swimming = entityPose.getEnumConstants()[3];
|
protected static final Object swimming = entityPose.getEnumConstants()[3];
|
||||||
private static final Object sneaking = entityPose.getEnumConstants()[5];
|
protected static final Object sneaking = entityPose.getEnumConstants()[5];
|
||||||
@Override
|
@Override
|
||||||
public Object getPose(FlatteningWrapper.EntityPose pose) {
|
public Object getPose(FlatteningWrapper.EntityPose pose) {
|
||||||
switch (pose) {
|
switch (pose) {
|
||||||
|
|||||||
@@ -43,4 +43,11 @@ public class FlatteningWrapper21 extends FlatteningWrapper14 implements Flatteni
|
|||||||
});
|
});
|
||||||
return head;
|
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.authlib.GameProfile;
|
||||||
import com.mojang.datafixers.util.Pair;
|
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.ClientboundPlayerInfoRemovePacket;
|
||||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
|
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
|
||||||
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
import net.minecraft.network.protocol.game.ClientboundSetEquipmentPacket;
|
||||||
@@ -33,8 +31,6 @@ import org.bukkit.GameMode;
|
|||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.LongSupplier;
|
|
||||||
|
|
||||||
public class ProtocolWrapper21 implements ProtocolWrapper {
|
public class ProtocolWrapper21 implements ProtocolWrapper {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
package de.steamwar.core;
|
package de.steamwar.core;
|
||||||
|
|
||||||
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV2;
|
|
||||||
import com.sk89q.jnbt.NBTInputStream;
|
import com.sk89q.jnbt.NBTInputStream;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
@@ -37,7 +36,11 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
import org.enginehub.linbus.stream.LinBinaryIO;
|
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 {
|
public class WorldEditWrapper21 implements WorldEditWrapper {
|
||||||
|
|
||||||
@@ -68,12 +71,58 @@ public class WorldEditWrapper21 implements WorldEditWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("removal")
|
@SuppressWarnings("removal")
|
||||||
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException {
|
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat ignored) throws IOException {
|
||||||
return switch (schemFormat) {
|
ResetableInputStream ris = new ResetableInputStream(is);
|
||||||
case MCEDIT -> new MCEditSchematicReader(new NBTInputStream(is)).read();
|
for (NodeData.SchematicFormat schemFormat : NodeData.SchematicFormat.values()) {
|
||||||
case SPONGE_V2 -> new SpongeSchematicV2Reader(LinBinaryIO.read(new DataInputStream(is))).read();
|
try {
|
||||||
case SPONGE_V3 -> new SpongeSchematicV3Reader(LinBinaryIO.read(new DataInputStream(is))).read();
|
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
|
@Override
|
||||||
|
|||||||
@@ -56,6 +56,8 @@ public class FlatteningWrapper {
|
|||||||
public enum EntityPose {
|
public enum EntityPose {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
SNEAKING,
|
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 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 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 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);
|
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) {
|
public void setBowDrawn(boolean drawn, boolean offHand) {
|
||||||
bowDrawn = drawn;
|
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))));
|
server.updateEntity(this, getDataWatcherPacket(bowDrawnWatcher, (byte) ((drawn ? 1 : 0) + (offHand ? 2 : 0))));
|
||||||
}else{
|
}else{
|
||||||
server.updateEntity(this, getDataWatcherPacket(entityStatusWatcher, getEntityStatus()));
|
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<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");
|
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 static final Reflection.Method asNMSCopy = Reflection.getTypedMethod(REntity.craftItemStack, "asNMSCopy", ProtocolWrapper.itemStack, ItemStack.class);
|
||||||
protected Object getEquipmentPacket(Object slot, ItemStack stack){
|
protected Object getEquipmentPacket(Object slot, ItemStack stack){
|
||||||
Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket);
|
Object packet = Reflection.newInstance(ProtocolWrapper.equipmentPacket);
|
||||||
equipmentEntity.set(packet, entityId);
|
equipmentEntity.set(packet, entityId);
|
||||||
|
equipmentSlots.set(packet, new ArrayList<>());
|
||||||
ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack));
|
ProtocolWrapper.impl.setEquipmentPacketStack(packet, slot, asNMSCopy.invoke(null, stack));
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user