SteamWar/SpigotCore
Archiviert
13
0

Early prototype of SpongeSchemLoader in 1.12-

Dieser Commit ist enthalten in:
Lixfel 2020-01-17 16:52:40 +01:00
Ursprung 2e54f56ab0
Commit 0fedaec64f
5 geänderte Dateien mit 124 neuen und 124 gelöschten Zeilen

Datei anzeigen

@ -13,11 +13,11 @@ class Schematic_10 {
return Schematic_8.getPlayerClipboard(player); return Schematic_8.getPlayerClipboard(player);
} }
static void setPlayerClipboard(Player player, InputStream is) throws IOException { static void setPlayerClipboard(Player player, InputStream is, boolean schemVersion) throws IOException {
Schematic_8.setPlayerClipboard(player, is); Schematic_8.setPlayerClipboard(player, is, schemVersion);
} }
static Clipboard getClipboard(InputStream is) throws IOException { static Clipboard getClipboard(InputStream is, boolean schemVersion) throws IOException {
return Schematic_8.getClipboard(is); return Schematic_8.getClipboard(is, schemVersion);
} }
} }

Datei anzeigen

@ -32,11 +32,11 @@ class Schematic_12 {
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
static void setPlayerClipboard(Player player, InputStream is) throws IOException { static void setPlayerClipboard(Player player, InputStream is, boolean schemVersion) throws IOException {
Schematic_8.setPlayerClipboard(player, is); Schematic_8.setPlayerClipboard(player, is, schemVersion);
} }
static Clipboard getClipboard(InputStream is) throws IOException { static Clipboard getClipboard(InputStream is, boolean schemVersion) throws IOException {
return Schematic_8.getClipboard(is); return Schematic_8.getClipboard(is, schemVersion);
} }
} }

Datei anzeigen

@ -7,7 +7,6 @@ import com.sk89q.worldedit.*;
import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitWorld; import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
@ -18,6 +17,7 @@ import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.world.registry.WorldData; import com.sk89q.worldedit.world.registry.WorldData;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -29,6 +29,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
class Schematic_8 { class Schematic_8 {
private Schematic_8(){} private Schematic_8(){}
@ -50,15 +51,18 @@ class Schematic_8 {
return outputStream.toByteArray(); return outputStream.toByteArray();
} }
static void setPlayerClipboard(Player player, InputStream is) throws IOException { static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) throws IOException {
WorldData world = new BukkitWorld(player.getWorld()).getWorldData(); WorldData world = new BukkitWorld(player.getWorld()).getWorldData();
Clipboard clipboard = getClipboard(is); Clipboard clipboard = getClipboard(is, schemFormat);
Actor actor = getWorldEditPlugin().wrapCommandSender(player); Actor actor = getWorldEditPlugin().wrapCommandSender(player);
getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard, world)); getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard, world));
} }
static Clipboard getClipboard(InputStream is) throws IOException { static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException {
if(schemFormat)
return new SpongeSchematicReader(new NBTInputStream(new GZIPInputStream(is))).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
else
return ClipboardFormat.SCHEMATIC.getReader(is).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData()); return ClipboardFormat.SCHEMATIC.getReader(is).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
} }
@ -70,7 +74,7 @@ class Schematic_8 {
private final NBTInputStream inputStream; private final NBTInputStream inputStream;
private int schematicVersion = -1; private int schematicVersion = -1;
public SpongeSchematicReader(NBTInputStream inputStream) { SpongeSchematicReader(NBTInputStream inputStream) {
Preconditions.checkNotNull(inputStream); Preconditions.checkNotNull(inputStream);
this.inputStream = inputStream; this.inputStream = inputStream;
} }
@ -79,9 +83,9 @@ class Schematic_8 {
public Clipboard read(WorldData worldData) throws IOException { public Clipboard read(WorldData worldData) throws IOException {
CompoundTag schematicTag = this.getBaseTag(); CompoundTag schematicTag = this.getBaseTag();
if (this.schematicVersion == 1) { if (this.schematicVersion == 1) {
return this.readVersion1(schematicTag); return this.readSchematic(schematicTag);
} else if (this.schematicVersion == 2) { } else if (this.schematicVersion == 2) {
return this.readVersion1(schematicTag); return this.readSchematic(schematicTag);
} else { } else {
throw new IOException("This schematic version is currently not supported"); throw new IOException("This schematic version is currently not supported");
} }
@ -99,7 +103,8 @@ class Schematic_8 {
} }
} }
private BlockArrayClipboard readVersion1(CompoundTag schematicTag) throws IOException { @SuppressWarnings("deprecation")
private BlockArrayClipboard readSchematic(CompoundTag schematicTag) throws IOException {
Map<String, Tag> schematic = schematicTag.getValue(); Map<String, Tag> schematic = schematicTag.getValue();
int width = (requireTag(schematic, "Width", ShortTag.class)).getValue(); int width = (requireTag(schematic, "Width", ShortTag.class)).getValue();
int height = (requireTag(schematic, "Height", ShortTag.class)).getValue(); int height = (requireTag(schematic, "Height", ShortTag.class)).getValue();
@ -108,9 +113,8 @@ class Schematic_8 {
int[] offsetParts; int[] offsetParts;
if (offsetTag != null) { if (offsetTag != null) {
offsetParts = offsetTag.getValue(); offsetParts = offsetTag.getValue();
if (offsetParts.length != 3) { if (offsetParts.length != 3)
throw new IOException("Invalid offset specified in schematic."); throw new IOException("Invalid offset specified in schematic.");
}
} else { } else {
offsetParts = new int[]{0, 0, 0}; offsetParts = new int[]{0, 0, 0};
} }
@ -134,26 +138,28 @@ class Schematic_8 {
IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class); IntTag paletteMaxTag = getTag(schematic, "PaletteMax", IntTag.class);
Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue(); Map<String, Tag> paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue();
if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue()) { if (paletteMaxTag != null && paletteObject.size() != paletteMaxTag.getValue())
throw new IOException("Block palette size does not match expected size."); throw new IOException("Block palette size does not match expected size.");
} else {
Map<Integer, BaseBlock> palette = new HashMap<>(); //TODO not base blocks Map<Integer, BaseBlock> palette = new HashMap<>();
ParserContext parserContext = new ParserContext(); ParserContext parserContext = new ParserContext();
parserContext.setRestricted(false); parserContext.setRestricted(false);
parserContext.setPreferringWildcard(false); parserContext.setPreferringWildcard(false);
int id; int id;
BaseBlock state; BaseBlock state;
for(Iterator var36 = paletteObject.keySet().iterator(); var36.hasNext(); palette.put(id, state)) { for(Iterator iterator = paletteObject.keySet().iterator(); iterator.hasNext(); palette.put(id, state)) {
String palettePart = (String)var36.next(); String palettePart = (String)iterator.next();
id = requireTag(paletteObject, palettePart, IntTag.class).getValue(); id = requireTag(paletteObject, palettePart, IntTag.class).getValue();
try { String matName = palettePart.split(":")[1].split("\\[")[0];
//TODO Parse id to base block Material material = Material.getMaterial(matName);
throw new InputParseException("TODO"); if(material == null){
} catch (InputParseException var31) {
state = new BaseBlock(0); //AIR state = new BaseBlock(0); //AIR
continue;
} }
state = new BaseBlock(material.getId());
} }
byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue();
@ -226,7 +232,6 @@ class Schematic_8 {
return clipboard; return clipboard;
} }
}
private static <T extends Tag> T requireTag(Map<String, Tag> items, String key, Class<T> expected) throws IOException { private static <T extends Tag> T requireTag(Map<String, Tag> items, String key, Class<T> expected) throws IOException {
if (!items.containsKey(key)) { if (!items.containsKey(key)) {

Datei anzeigen

@ -13,11 +13,11 @@ class Schematic_9 {
return Schematic_8.getPlayerClipboard(player); return Schematic_8.getPlayerClipboard(player);
} }
static void setPlayerClipboard(Player player, InputStream is) throws IOException { static void setPlayerClipboard(Player player, InputStream is, boolean schemVersion) throws IOException {
Schematic_8.setPlayerClipboard(player, is); Schematic_8.setPlayerClipboard(player, is, schemVersion);
} }
static Clipboard getClipboard(InputStream is) throws IOException { static Clipboard getClipboard(InputStream is, boolean schemVersion) throws IOException {
return Schematic_8.getClipboard(is); return Schematic_8.getClipboard(is, schemVersion);
} }
} }

Datei anzeigen

@ -152,10 +152,7 @@ public class Schematic {
return Core.getVersion() > 12 || !schemFormat; return Core.getVersion() > 12 || !schemFormat;
} }
public Clipboard load() throws WrongVersionException, IOException, NoClipboardException { public Clipboard load() throws IOException, NoClipboardException {
if(Core.getVersion() <= 12 && schemFormat)
throw new WrongVersionException();
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID); ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID);
try { try {
rs.next(); rs.next();
@ -165,26 +162,24 @@ public class Schematic {
InputStream is = schemData.getBinaryStream(); InputStream is = schemData.getBinaryStream();
switch(Core.getVersion()){ switch(Core.getVersion()){
case 8: case 8:
return Schematic_8.getClipboard(is); return Schematic_8.getClipboard(is, schemFormat);
case 9: case 9:
return Schematic_9.getClipboard(is); return Schematic_9.getClipboard(is, schemFormat);
case 10: case 10:
return Schematic_10.getClipboard(is); return Schematic_10.getClipboard(is, schemFormat);
case 14: case 14:
return Schematic_14.getClipboard(is, schemFormat); return Schematic_14.getClipboard(is, schemFormat);
case 15: case 15:
return Schematic_15.getClipboard(is, schemFormat); return Schematic_15.getClipboard(is, schemFormat);
default: default:
return Schematic_12.getClipboard(is); return Schematic_12.getClipboard(is, schemFormat);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new IOException(e); throw new IOException(e);
} }
} }
public void loadToPlayer(Player player) throws IOException, NoClipboardException, WrongVersionException { public void loadToPlayer(Player player) throws IOException, NoClipboardException {
if(Core.getVersion() <= 12 && schemFormat)
throw new WrongVersionException();
ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID); ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID);
try { try {
@ -192,13 +187,13 @@ public class Schematic {
InputStream is = rs.getBlob("SchemData").getBinaryStream(); InputStream is = rs.getBlob("SchemData").getBinaryStream();
switch(Core.getVersion()){ switch(Core.getVersion()){
case 8: case 8:
Schematic_8.setPlayerClipboard(player, is); Schematic_8.setPlayerClipboard(player, is, schemFormat);
break; break;
case 9: case 9:
Schematic_9.setPlayerClipboard(player, is); Schematic_9.setPlayerClipboard(player, is, schemFormat);
break; break;
case 10: case 10:
Schematic_10.setPlayerClipboard(player, is); Schematic_10.setPlayerClipboard(player, is, schemFormat);
break; break;
case 14: case 14:
Schematic_14.setPlayerClipboard(player, is, schemFormat); Schematic_14.setPlayerClipboard(player, is, schemFormat);
@ -207,7 +202,7 @@ public class Schematic {
Schematic_15.setPlayerClipboard(player, is, schemFormat); Schematic_15.setPlayerClipboard(player, is, schemFormat);
break; break;
default: default:
Schematic_12.setPlayerClipboard(player, is); Schematic_12.setPlayerClipboard(player, is, schemFormat);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new IOException(e); throw new IOException(e);