Update WorldEditWrapper21

This commit is contained in:
2024-11-28 23:28:44 +01:00
parent edd3524b41
commit e088e9794b
9 changed files with 171 additions and 93 deletions
@@ -23,6 +23,10 @@ plugins {
dependencies {
compileOnly(project(":SpigotCore:SpigotCore_Main", "default"))
compileOnly(project(":SpigotCore:SpigotCore_18", "default"))
compileOnly(project(":SpigotCore:SpigotCore_14", "default"))
compileOnly(libs.fawe21)
compileOnly(libs.paperapi21) {
attributes {
@@ -0,0 +1,97 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2024 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.core;
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV2;
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReaderV3;
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriterV3;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader;
import com.sk89q.worldedit.extent.clipboard.io.sponge.SpongeSchematicV1Reader;
import com.sk89q.worldedit.session.ClipboardHolder;
import org.bukkit.entity.Player;
import org.enginehub.linbus.stream.LinBinaryIO;
import org.enginehub.linbus.stream.LinStream;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinRootEntry;
import org.enginehub.linbus.tree.LinTagType;
import java.io.*;
public class WorldEditWrapper21 implements WorldEditWrapper.IWorldEditWrapper {
@Override
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> {
try {
new FastSchematicWriterV3(new NBTOutputStream(outputStream)).write(clipboard);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
@Override
public void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) {
Clipboard clipboard = null;
try {
clipboard = getClipboard(is, schemFormat);
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
if (clipboard == null)
throw new SecurityException("Clipboard is null");
Actor actor = WorldEditWrapper.getWorldEditPlugin().wrapCommandSender(player);
WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard));
}
@Override
public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
if (!schemFormat) {
return new MCEditSchematicReader(new NBTInputStream(is)).read();
} else {
BufferedInputStream bis = new BufferedInputStream(is);
bis.mark(Integer.MAX_VALUE);
LinStream linStream = LinBinaryIO.read(new DataInputStream(bis));
LinCompoundTag entry = LinRootEntry.readFrom(linStream).value();
bis.reset();
switch (entry.getTag("Version", LinTagType.intTag()).valueAsInt()) {
case 1:
return new SpongeSchematicV1Reader(entry.linStream()).read();
case 2:
return new FastSchematicReaderV2(new NBTInputStream(bis)).read();
case 3:
return new FastSchematicReaderV3(bis).read();
default:
throw new IOException("Unknown schematic version");
}
}
}
}