SteamWar/SpigotCore
Archiviert
13
0

Making Schematics 1.14+ vanilla-WE compatible

Dieser Commit ist enthalten in:
Lixfel 2019-12-23 13:36:37 +01:00
Ursprung dc6e785d72
Commit 34c759949f
2 geänderte Dateien mit 21 neuen und 23 gelöschten Zeilen

Datei anzeigen

@ -35,8 +35,8 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>steamwar</groupId> <groupId>steamwar</groupId>
<artifactId>FAWE</artifactId> <artifactId>WorldEdit</artifactId>
<version>1.14</version> <version>1.15</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

Datei anzeigen

@ -4,6 +4,7 @@ import com.sk89q.worldedit.EmptyClipboardException;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -16,28 +17,30 @@ import java.io.InputStream;
class Schematic_14 { class Schematic_14 {
private Schematic_14(){} private Schematic_14(){}
private static final String SCHEM = "schem"; private static final ClipboardFormat SCHEMATIC = ClipboardFormats.findByAlias("schematic");
private static final String SCHEMATIC = "schematic"; private static final ClipboardFormat SCHEM = ClipboardFormats.findByAlias("schem");
static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException { static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException {
ClipboardHolder clipboardHolder; ClipboardHolder clipboardHolder;
try { try {
clipboardHolder = WorldEditPlugin.getInstance().getSession(player).getClipboard(); clipboardHolder = getWorldEditPlugin().getSession(player).getClipboard();
} catch (EmptyClipboardException e) { } catch (EmptyClipboardException e) {
throw new NoClipboardException(); throw new NoClipboardException();
} }
@SuppressWarnings("deprecation")
Clipboard clipboard = clipboardHolder.getClipboard(); Clipboard clipboard = clipboardHolder.getClipboard();
if(clipboard == null) if(clipboard == null)
throw new NoClipboardException(); throw new NoClipboardException();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try{ try{
if(schemFormat) if(schemFormat){
ClipboardFormats.findByExtension(SCHEM).getWriter(outputStream).write(clipboard); assert SCHEM != null;
else SCHEM.getWriter(outputStream).write(clipboard);
ClipboardFormats.findByExtension(SCHEMATIC).getWriter(outputStream).write(clipboard); }else{
assert SCHEMATIC != null;
SCHEMATIC.getWriter(outputStream).write(clipboard);
}
}catch(NullPointerException e){ }catch(NullPointerException e){
throw new IOException(e); throw new IOException(e);
} }
@ -45,15 +48,7 @@ class Schematic_14 {
} }
static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) throws IOException, NoClipboardException { static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) throws IOException, NoClipboardException {
Clipboard clipboard; Clipboard clipboard = getClipboard(is, schemFormat);
try {
if (schemFormat)
clipboard = ClipboardFormats.findByExtension(SCHEM).getReader(is).read();
else
clipboard = ClipboardFormats.findByExtension(SCHEMATIC).getReader(is).read();
}catch(NullPointerException e){
throw new IOException(e);
}
if (clipboard == null) if (clipboard == null)
throw new NoClipboardException(); throw new NoClipboardException();
@ -64,10 +59,13 @@ class Schematic_14 {
static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException, NoClipboardException { static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException, NoClipboardException {
try { try {
if(schemFormat) if(schemFormat){
return ClipboardFormats.findByExtension(SCHEM).getReader(is).read(); assert SCHEM != null;
else return SCHEM.getReader(is).read();
return ClipboardFormats.findByExtension(SCHEMATIC).getReader(is).read(); }else{
assert SCHEMATIC != null;
return SCHEMATIC.getReader(is).read();
}
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new NoClipboardException(); throw new NoClipboardException();
} }