SteamWar/SpigotCore
Archiviert
13
0

Implement Streaming
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: Chaoscaot <chaoscaot444@gmail.com>
Dieser Commit ist enthalten in:
Chaoscaot 2021-11-03 16:28:01 +01:00
Ursprung 1e3d387ff8
Commit de6d8bbb10
4 geänderte Dateien mit 56 neuen und 39 gelöschten Zeilen

Datei anzeigen

@ -29,10 +29,9 @@ import com.sk89q.worldedit.world.registry.LegacyMapper;
import de.steamwar.sql.NoClipboardException;
import org.bukkit.entity.Player;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.*;
import java.util.logging.Level;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkNotNull;
@ -43,7 +42,7 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
@Override
public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
ClipboardHolder clipboardHolder;
try {
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
@ -55,7 +54,17 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
if(clipboard == null)
throw new NoClipboardException();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
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{
if(schemFormat){
ClipboardWriter writer = SCHEM.getWriter(outputStream);
@ -64,12 +73,17 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
}else{
SCHEMATIC.getWriter(outputStream).write(clipboard);
}
}catch(NullPointerException e){
throw new RuntimeException(e.getMessage(), new IOException(e));
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}catch(NullPointerException | IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
}
return outputStream.toByteArray();
try {
outputStream.close();
} catch (IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
}
}, "SchemWriter").start();
return inputStream;
}
@Override

Datei anzeigen

@ -19,19 +19,18 @@ import com.sk89q.worldedit.world.registry.WorldData;
import de.steamwar.sql.NoClipboardException;
import org.bukkit.entity.Player;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.stream.Collectors;
public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
@Override
public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
ClipboardHolder clipboardHolder;
try {
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
@ -43,13 +42,28 @@ public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
if(clipboard == null)
throw new NoClipboardException();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
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 {
ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
}
return outputStream.toByteArray();
try {
outputStream.close();
} catch (IOException e) {
Core.getInstance().getLogger().log(Level.SEVERE, "Could not close schem writer", e);
}
}, "SchemWriter").start();
return inputStream;
}
@Override

Datei anzeigen

@ -14,7 +14,7 @@ public class WorldEditWrapper {
public static final IWorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
public interface IWorldEditWrapper {
byte[] getPlayerClipboard(Player player, boolean schemFormat);
InputStream getPlayerClipboard(Player player, boolean schemFormat);
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;

Datei anzeigen

@ -25,6 +25,7 @@ import de.steamwar.core.VersionedRunnable;
import de.steamwar.core.WorldEditWrapper;
import org.bukkit.entity.Player;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
@ -476,28 +477,16 @@ public class SchematicNode {
public void saveFromBytes(byte[] bytes, boolean newFormat) {
if(isDir)
throw new SecurityException("Node is Directory");
Blob blob = SQL.blob();
try {
blob.setBytes(1, bytes);
updateDatabase(blob, newFormat);
} catch (SQLException e) {
throw new SecurityException(e);
}
updateDatabase(new ByteArrayInputStream(bytes), newFormat);
}
private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
Blob blob = SQL.blob();
try {
blob.setBytes(1, WorldEditWrapper.impl.getPlayerClipboard(player, newFormat));
} catch (SQLException exception) {
throw new RuntimeException(exception.getMessage(), exception);
}
updateDatabase(blob, newFormat);
updateDatabase(WorldEditWrapper.impl.getPlayerClipboard(player, newFormat), newFormat);
}
private void updateDatabase(Blob blob, boolean newFormat) {
private void updateDatabase(InputStream blob, boolean newFormat) {
SQL.update("UPDATE SchematicNode SET NodeData = ?, NodeFormat = ? WHERE NodeId = ?", blob, newFormat, id);
schemFormat = newFormat;
}