Dieser Commit ist enthalten in:
Ursprung
865f5b0ff8
Commit
aa7fff46b4
@ -29,10 +29,9 @@ import com.sk89q.worldedit.world.registry.LegacyMapper;
|
|||||||
import de.steamwar.sql.NoClipboardException;
|
import de.steamwar.sql.NoClipboardException;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
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;
|
private static final ClipboardFormat SCHEM = BuiltInClipboardFormat.SPONGE_SCHEMATIC;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
|
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
|
||||||
ClipboardHolder clipboardHolder;
|
ClipboardHolder clipboardHolder;
|
||||||
try {
|
try {
|
||||||
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
||||||
@ -55,7 +54,15 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
|
|||||||
if(clipboard == null)
|
if(clipboard == null)
|
||||||
throw new NoClipboardException();
|
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{
|
try{
|
||||||
if(schemFormat){
|
if(schemFormat){
|
||||||
ClipboardWriter writer = SCHEM.getWriter(outputStream);
|
ClipboardWriter writer = SCHEM.getWriter(outputStream);
|
||||||
@ -64,12 +71,17 @@ public class WorldEditWrapper14 implements WorldEditWrapper.IWorldEditWrapper {
|
|||||||
}else{
|
}else{
|
||||||
SCHEMATIC.getWriter(outputStream).write(clipboard);
|
SCHEMATIC.getWriter(outputStream).write(clipboard);
|
||||||
}
|
}
|
||||||
}catch(NullPointerException e){
|
}catch(NullPointerException | IOException e) {
|
||||||
throw new RuntimeException(e.getMessage(), new IOException(e));
|
Core.getInstance().getLogger().log(Level.SEVERE, "Could not write schematic", e);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e.getMessage(), 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
|
@Override
|
||||||
|
@ -19,19 +19,18 @@ import com.sk89q.worldedit.world.registry.WorldData;
|
|||||||
import de.steamwar.sql.NoClipboardException;
|
import de.steamwar.sql.NoClipboardException;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
|
public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getPlayerClipboard(Player player, boolean schemFormat) {
|
public InputStream getPlayerClipboard(Player player, boolean schemFormat) {
|
||||||
ClipboardHolder clipboardHolder;
|
ClipboardHolder clipboardHolder;
|
||||||
try {
|
try {
|
||||||
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
clipboardHolder = WorldEditWrapper.getWorldEditPlugin().getSession(player).getClipboard();
|
||||||
@ -43,13 +42,28 @@ public class WorldEditWrapper8 implements WorldEditWrapper.IWorldEditWrapper {
|
|||||||
if(clipboard == null)
|
if(clipboard == null)
|
||||||
throw new NoClipboardException();
|
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 {
|
try {
|
||||||
ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
|
ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
|
||||||
} catch (IOException e) {
|
} 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
|
@Override
|
||||||
|
@ -14,7 +14,7 @@ public class WorldEditWrapper {
|
|||||||
public static final IWorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
|
public static final IWorldEditWrapper impl = VersionDependent.getVersionImpl(Core.getInstance());
|
||||||
|
|
||||||
public interface IWorldEditWrapper {
|
public interface IWorldEditWrapper {
|
||||||
byte[] getPlayerClipboard(Player player, boolean schemFormat);
|
InputStream getPlayerClipboard(Player player, boolean schemFormat);
|
||||||
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
|
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
|
||||||
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
|
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
|
||||||
|
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren