Merge branch 'main' into MojMapReflections

# Conflicts:
#	SpigotCore/SpigotCore_8/src/de/steamwar/core/BountifulWrapper8.java
#	SpigotCore/SpigotCore_9/src/de/steamwar/core/BountifulWrapper9.java
#	SpigotCore/SpigotCore_Main/src/de/steamwar/core/events/PartialChunkFixer.java
This commit is contained in:
Lixfel
2025-01-06 10:06:28 +01:00
61 changed files with 426 additions and 467 deletions
@@ -70,15 +70,15 @@ public class BountifulWrapper8 implements BountifulWrapper.IBountifulWrapper {
Reflection.Field<Integer> posX = Reflection.getField(packetClass, int.class, fieldOffset);
Reflection.Field<Integer> posY = Reflection.getField(packetClass, int.class, fieldOffset +1);
Reflection.Field<Integer> posZ = Reflection.getField(packetClass, int.class, fieldOffset +2);
Reflection.Field<Byte> lookPitch = Reflection.getField(packetClass, byte.class, 0);
Reflection.Field<Byte> lookYaw = Reflection.getField(packetClass, byte.class, 1);
Reflection.Field<Byte> lookYaw = Reflection.getField(packetClass, byte.class, 0);
Reflection.Field<Byte> lookPitch = Reflection.getField(packetClass, byte.class, 1);
return (packet, x, y, z, pitch, yaw) -> {
posX.set(packet, MathHelper.floor(x * 32));
posY.set(packet, MathHelper.floor(y * 32));
posZ.set(packet, MathHelper.floor(z * 32));
lookPitch.set(packet, (byte)(pitch * 256 / 360));
lookYaw.set(packet, (byte)(yaw * 256 / 360));
lookPitch.set(packet, (byte)(pitch * 256 / 360));
};
}
@@ -37,6 +37,7 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.registry.WorldData;
import de.steamwar.sql.NodeData;
import org.bukkit.entity.Player;
import java.io.IOException;
@@ -50,13 +51,13 @@ import java.util.stream.Collectors;
public class WorldEditWrapper8 implements WorldEditWrapper {
@Override
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) ->
public InputStream getPlayerClipboard(Player player) {
return WorldEditWrapper.getPlayerClipboard(player, (outputStream, clipboard, clipboardHolder) ->
ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData()));
}
@Override
public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) {
public void setPlayerClipboard(Player player, InputStream is, NodeData.SchematicFormat schemFormat) {
WorldData world = new BukkitWorld(player.getWorld()).getWorldData();
Clipboard clipboard;
try {
@@ -70,11 +71,16 @@ public class WorldEditWrapper8 implements WorldEditWrapper {
}
@Override
public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
if(schemFormat)
return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
else
return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
public Clipboard getClipboard(InputStream is, NodeData.SchematicFormat schemFormat) throws IOException {
switch (schemFormat) {
case MCEDIT:
return new SchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
case SPONGE_V2:
case SPONGE_V3:
return new SpongeSchematicReader(new NBTInputStream(is)).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
default:
throw new IllegalArgumentException("Unsupported schematic format");
}
}
@Override
@@ -99,6 +105,11 @@ public class WorldEditWrapper8 implements WorldEditWrapper {
return new org.bukkit.util.Vector(v.getX(), v.getY(), v.getZ());
}
@Override
public NodeData.SchematicFormat getNativeFormat() {
return NodeData.SchematicFormat.MCEDIT;
}
private static class SpongeSchematicReader implements ClipboardReader {
private final NBTInputStream inputStream;
@@ -137,6 +148,13 @@ public class WorldEditWrapper8 implements WorldEditWrapper {
IDConverter8 ids = new IDConverter8();
Map<String, Tag> schematic = schematicTag.getValue();
boolean v3Mode = false;
if (schematic.size() == 1) {
schematic = (requireTag(schematic, "Schematic", CompoundTag.class)).getValue();
v3Mode = true;
}
int width = (requireTag(schematic, "Width", ShortTag.class)).getValue();
int height = (requireTag(schematic, "Height", ShortTag.class)).getValue();
int length = (requireTag(schematic, "Length", ShortTag.class)).getValue();
@@ -167,10 +185,13 @@ public class WorldEditWrapper8 implements WorldEditWrapper {
region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector.ONE));
}
IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class);
Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue();
if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue())
throw new IOException("Block palette size does not match expected size.");
Map<String, Tag> blockContainer = null;
if (v3Mode) {
blockContainer = getTag(schematic, "Blocks", CompoundTag.class).getValue();
}
Map<String, Tag> paletteObject = requireTag(v3Mode ? blockContainer : schematic, "Palette", CompoundTag.class).getValue();
Map<Integer, BaseBlock> palette = new HashMap<>();
ParserContext parserContext = new ParserContext();
@@ -182,11 +203,11 @@ public class WorldEditWrapper8 implements WorldEditWrapper {
palette.put(requireTag(paletteObject, palettePart, IntTag.class).getValue(), new BaseBlock(blockID.getBlockId(), blockID.getDataId()));
}
byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue();
byte[] blocks = requireTag(v3Mode ? blockContainer : schematic, v3Mode ? "Data" : "BlockData", ByteArrayTag.class).getValue();
Map<BlockVector, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
ListTag tileEntities = getTag(schematic, "BlockEntities", ListTag.class);
ListTag tileEntities = getTag(v3Mode ? blockContainer : schematic, "BlockEntities", ListTag.class);
if (tileEntities == null) {
tileEntities = getTag(schematic, "TileEntities", ListTag.class);
tileEntities = getTag(v3Mode ? blockContainer : schematic, "TileEntities", ListTag.class);
}
if (tileEntities != null) {