forked from SteamWar/SteamWar
Update WorldEditWrapper21
This commit is contained in:
@@ -32,10 +32,12 @@ import net.minecraft.network.protocol.game.PacketPlayOutExplosion;
|
||||
import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
|
||||
import net.minecraft.server.level.EntityPlayer;
|
||||
import net.minecraft.server.level.PlayerInteractManager;
|
||||
import net.minecraft.world.entity.player.EntityHuman;
|
||||
import net.minecraft.world.entity.player.PlayerAbilities;
|
||||
import net.minecraft.world.item.component.CustomData;
|
||||
import net.minecraft.world.level.EnumGamemode;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.phys.Vec3D;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.craftbukkit.v1_21_R2.entity.CraftPlayer;
|
||||
@@ -44,6 +46,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class NMSWrapper21 implements NMSWrapper {
|
||||
|
||||
@@ -77,11 +80,13 @@ public class NMSWrapper21 implements NMSWrapper {
|
||||
gameStateChangeReason.set(packet, PacketPlayOutGameStateChange.d);
|
||||
}
|
||||
|
||||
private static final Reflection.FieldAccessor<PlayerAbilities> playerAbilities = Reflection.getField(EntityHuman.class, null, PlayerAbilities.class);
|
||||
|
||||
@Override
|
||||
public void setPlayerBuildAbilities(Player player) {
|
||||
PlayerAbilities abilities = ((CraftPlayer) player).getHandle().;
|
||||
((CraftPlayer) player).getHandle().().d = true;
|
||||
((CraftPlayer) player).getHandle().fZ().e = true;
|
||||
PlayerAbilities abilities = playerAbilities.get(((CraftPlayer) player).getHandle());
|
||||
abilities.d = true;
|
||||
abilities.e = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,30 +133,11 @@ public class NMSWrapper21 implements NMSWrapper {
|
||||
}
|
||||
|
||||
private final Class<?> explosionPacket = Reflection.getClass("{nms.network.protocol.game}.PacketPlayOutExplosion");
|
||||
private final Reflection.FieldAccessor<Double> a = Reflection.getField(explosionPacket, double.class, 0);
|
||||
private final Reflection.FieldAccessor<Double> b = Reflection.getField(explosionPacket, double.class, 1);
|
||||
private final Reflection.FieldAccessor<Double> c = Reflection.getField(explosionPacket, double.class, 2);
|
||||
private final Reflection.FieldAccessor<Float> d = Reflection.getField(explosionPacket, float.class, 0);
|
||||
private final Reflection.FieldAccessor<List> e = Reflection.getField(explosionPacket, List.class, 0);
|
||||
private final Reflection.FieldAccessor<Explosion.Effect> f = Reflection.getField(explosionPacket, Explosion.Effect.class, 0);
|
||||
private final Reflection.FieldAccessor<ParticleParam> g = Reflection.getField(explosionPacket, ParticleParam.class, 0);
|
||||
private final Reflection.FieldAccessor<ParticleParam> h = Reflection.getField(explosionPacket, ParticleParam.class, 1);
|
||||
private final Reflection.FieldAccessor<Holder> i = Reflection.getField(explosionPacket, Holder.class, 0);
|
||||
private final Reflection.FieldAccessor<Optional> explosionKnockback = Reflection.getField(explosionPacket, Optional.class, 0);
|
||||
|
||||
@Override
|
||||
public Object resetExplosionKnockback(Object packet) {
|
||||
PacketPlayOutExplosion packetPlayOutExplosion = (PacketPlayOutExplosion) packet;
|
||||
return new PacketPlayOutExplosion(
|
||||
a.get(packetPlayOutExplosion),
|
||||
b.get(packetPlayOutExplosion),
|
||||
c.get(packetPlayOutExplosion),
|
||||
d.get(packetPlayOutExplosion),
|
||||
e.get(packetPlayOutExplosion),
|
||||
null,
|
||||
f.get(packetPlayOutExplosion),
|
||||
g.get(packetPlayOutExplosion),
|
||||
h.get(packetPlayOutExplosion),
|
||||
i.get(packetPlayOutExplosion)
|
||||
);
|
||||
explosionKnockback.set(packet, Optional.empty());
|
||||
return packet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class NodeData {
|
||||
if(rs.wasNull() || schemData.available() == 0) {
|
||||
throw new SecurityException("SchemData is null");
|
||||
}
|
||||
return schemData;
|
||||
return new GZIPInputStream(schemData);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("SchemData is wrong", e);
|
||||
}
|
||||
|
||||
@@ -59,29 +59,8 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
|
||||
@Override
|
||||
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
|
||||
ClipboardHolder clipboardHolder;
|
||||
try {
|
||||
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
||||
} catch (EmptyClipboardException e) {
|
||||
throw new NoClipboardException();
|
||||
}
|
||||
|
||||
Clipboard clipboard = clipboardHolder.getClipboard();
|
||||
if(clipboard == null)
|
||||
throw new NoClipboardException();
|
||||
|
||||
PipedOutputStream outputStream = new PipedOutputStream();
|
||||
PipedInputStream inputStream;
|
||||
try {
|
||||
inputStream = new PipedInputStream(outputStream, 4096);
|
||||
}catch(NullPointerException e){
|
||||
throw new RuntimeException(e.getMessage(), new IOException(e));
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not init piped input stream", e);
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
try{
|
||||
return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) -> {
|
||||
try {
|
||||
if(schemFormat){
|
||||
ClipboardWriter writer = SCHEM.getWriter(outputStream);
|
||||
writer.write(clipboard);
|
||||
@@ -89,17 +68,10 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
}else{
|
||||
SCHEMATIC.getWriter(outputStream).write(clipboard);
|
||||
}
|
||||
}catch(NullPointerException | IOException e) {
|
||||
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
|
||||
}
|
||||
}, "SchemWriter").start();
|
||||
|
||||
return inputStream;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,8 +19,9 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.sk89q.jnbt.NBTInputStream;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.*;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -31,9 +32,10 @@ public class WorldEditWrapper18 extends WorldEditWrapper14 {
|
||||
@Override
|
||||
@SuppressWarnings("removal")
|
||||
public Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
|
||||
NBTInputStream nbtStream = new NBTInputStream(is);
|
||||
//Use FAWE reader due to FAWE capability of reading corrupt FAWE schems
|
||||
try {
|
||||
return (schemFormat ? BuiltInClipboardFormat.FAST.getReader(is) : BuiltInClipboardFormat.MCEDIT_SCHEMATIC.getReader(is)).read();
|
||||
return (schemFormat ? new SpongeSchematicReader(nbtStream) : new MCEditSchematicReader(nbtStream)).read();
|
||||
} catch (NullPointerException e) {
|
||||
throw new NoClipboardException();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,39 +49,14 @@ public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
|
||||
@Override
|
||||
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
|
||||
ClipboardHolder clipboardHolder;
|
||||
try {
|
||||
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
||||
} catch (EmptyClipboardException e) {
|
||||
throw new NoClipboardException();
|
||||
}
|
||||
|
||||
Clipboard clipboard = clipboardHolder.getClipboard();
|
||||
if(clipboard == null)
|
||||
throw new NoClipboardException();
|
||||
|
||||
PipedOutputStream outputStream = new PipedOutputStream();
|
||||
PipedInputStream inputStream;
|
||||
try {
|
||||
inputStream = new PipedInputStream(outputStream, 4096);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not init piped input stream", e);
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
return WorldEditWrapper.getPlayerClipboard(player, schemFormat, (outputStream, clipboard, clipboardHolder) ->
|
||||
{
|
||||
try {
|
||||
ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
|
||||
} catch (IOException e) {
|
||||
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
|
||||
}
|
||||
}, "SchemWriter").start();
|
||||
|
||||
return inputStream;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,7 +64,7 @@ public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
|
||||
WorldData world = new BukkitWorld(player.getWorld()).getWorldData();
|
||||
Clipboard clipboard;
|
||||
try {
|
||||
clipboard = getClipboard(new GZIPInputStream(is), schemFormat);
|
||||
clipboard = getClipboard(is, schemFormat);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -19,13 +19,18 @@
|
||||
|
||||
package de.steamwar.core;
|
||||
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import de.steamwar.sql.NoClipboardException;
|
||||
import org.apache.logging.log4j.util.TriConsumer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WorldEditWrapper {
|
||||
private WorldEditWrapper() {}
|
||||
@@ -41,4 +46,40 @@ public class WorldEditWrapper {
|
||||
public static WorldEditPlugin getWorldEditPlugin() {
|
||||
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
|
||||
}
|
||||
|
||||
public static InputStream getPlayerClipboard(Player player, boolean schemFormat, TriConsumer<OutputStream, Clipboard, ClipboardHolder> consumer) {
|
||||
ClipboardHolder clipboardHolder;
|
||||
try {
|
||||
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
||||
} catch (EmptyClipboardException e) {
|
||||
throw new NoClipboardException();
|
||||
}
|
||||
|
||||
Clipboard clipboard = clipboardHolder.getClipboard();
|
||||
if(clipboard == null)
|
||||
throw new NoClipboardException();
|
||||
|
||||
PipedOutputStream outputStream = new PipedOutputStream();
|
||||
PipedInputStream inputStream;
|
||||
try {
|
||||
inputStream = new PipedInputStream(outputStream, 4096);
|
||||
} catch (IOException e) {
|
||||
throw new SecurityException("Could not init piped input stream", e);
|
||||
}
|
||||
|
||||
new Thread(() -> {
|
||||
try {
|
||||
consumer.accept(outputStream, clipboard, clipboardHolder);
|
||||
} catch (Exception e) {
|
||||
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
|
||||
}
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
|
||||
}
|
||||
}, "SchemWriter").start();
|
||||
|
||||
return inputStream;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ dependencyResolutionManagement {
|
||||
library("worldedit12", "de.steamwar:worldedit:1.12")
|
||||
library("worldedit15", "de.steamwar:worldedit:1.15")
|
||||
library("fawe18", "de.steamwar:fastasyncworldedit:1.18")
|
||||
library("fawe21", "de.steamwar:fastasyncworldedit:1.21")
|
||||
|
||||
library("velocity", "de.steamwar:velocity:RELEASE")
|
||||
library("velocityapi", "com.velocitypowered:velocity-api:3.3.0-SNAPSHOT")
|
||||
|
||||
Reference in New Issue
Block a user