diff --git a/SpigotCore_12/pom.xml b/SpigotCore_12/pom.xml
index eb4680f..0959553 100644
--- a/SpigotCore_12/pom.xml
+++ b/SpigotCore_12/pom.xml
@@ -33,5 +33,27 @@
1.12
provided
+
+ steamwar
+ FAWE
+ 1.0
+ provided
+
+
+ steamwar
+ WorldEdit
+ 1.0
+ provided
+
+
+ steamwar
+ SpigotCore_API
+ 2.0
+
+
+ steamwar
+ SpigotCore_8
+ 2.0
+
\ No newline at end of file
diff --git a/SpigotCore_12/src/de/steamwar/sql/Schematic_12.java b/SpigotCore_12/src/de/steamwar/sql/Schematic_12.java
new file mode 100644
index 0000000..ef79b28
--- /dev/null
+++ b/SpigotCore_12/src/de/steamwar/sql/Schematic_12.java
@@ -0,0 +1,42 @@
+package de.steamwar.sql;
+
+import com.boydti.fawe.FaweAPI;
+import com.sk89q.worldedit.EmptyClipboardException;
+import com.sk89q.worldedit.extent.clipboard.Clipboard;
+import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
+import com.sk89q.worldedit.session.ClipboardHolder;
+import org.bukkit.entity.Player;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+class Schematic_12 {
+ private Schematic_12(){}
+
+ static byte[] getPlayerClipboard(Player player) throws IOException, NoClipboardException {
+ ClipboardHolder clipboardHolder;
+ try {
+ clipboardHolder = FaweAPI.wrapPlayer(player).getSession().getClipboard();
+ } catch (EmptyClipboardException e) {
+ throw new NoClipboardException();
+ }
+
+ @SuppressWarnings("deprecation")
+ Clipboard clipboard = clipboardHolder.getClipboard();
+ if(clipboard == null)
+ throw new NoClipboardException();
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
+ return outputStream.toByteArray();
+ }
+
+ static void setPlayerClipboard(Player player, InputStream is) throws IOException {
+ Schematic_8.setPlayerClipboard(player, is);
+ }
+
+ static Clipboard getClipboard(InputStream is) throws IOException {
+ return Schematic_8.getClipboard(is);
+ }
+}
diff --git a/SpigotCore_14/pom.xml b/SpigotCore_14/pom.xml
index 9b030de..cf128c3 100644
--- a/SpigotCore_14/pom.xml
+++ b/SpigotCore_14/pom.xml
@@ -33,5 +33,16 @@
1.14
provided
+
+ steamwar
+ FAWE
+ 1.14
+ provided
+
+
+ steamwar
+ SpigotCore_API
+ 2.0
+
\ No newline at end of file
diff --git a/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java
new file mode 100644
index 0000000..8320c36
--- /dev/null
+++ b/SpigotCore_14/src/de/steamwar/sql/Schematic_14.java
@@ -0,0 +1,80 @@
+package de.steamwar.sql;
+
+import com.boydti.fawe.FaweAPI;
+import com.sk89q.worldedit.EmptyClipboardException;
+import com.sk89q.worldedit.bukkit.WorldEditPlugin;
+import com.sk89q.worldedit.extension.platform.Actor;
+import com.sk89q.worldedit.extent.clipboard.Clipboard;
+import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
+import com.sk89q.worldedit.session.ClipboardHolder;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+class Schematic_14 {
+ private Schematic_14(){}
+
+ private static final String SCHEM = "schem";
+ private static final String SCHEMATIC = "schematic";
+
+ static byte[] getPlayerClipboard(Player player, boolean schemFormat) throws IOException, NoClipboardException {
+ ClipboardHolder clipboardHolder;
+ try {
+ clipboardHolder = FaweAPI.wrapPlayer(player).getSession().getClipboard();
+ } catch (EmptyClipboardException e) {
+ throw new NoClipboardException();
+ }
+
+ @SuppressWarnings("deprecation")
+ Clipboard clipboard = clipboardHolder.getClipboard();
+ if(clipboard == null)
+ throw new NoClipboardException();
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ try{
+ if(schemFormat)
+ ClipboardFormats.findByExtension(SCHEM).getWriter(outputStream).write(clipboard);
+ else
+ ClipboardFormats.findByExtension(SCHEMATIC).getWriter(outputStream).write(clipboard);
+ }catch(NullPointerException e){
+ throw new IOException(e);
+ }
+ return outputStream.toByteArray();
+ }
+
+ static void setPlayerClipboard(Player player, InputStream is, boolean schemFormat) throws IOException, NoClipboardException {
+ Clipboard clipboard;
+ 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)
+ throw new NoClipboardException();
+
+ Actor actor = getWorldEditPlugin().wrapCommandSender(player);
+ getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard));
+ }
+
+ static Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException, NoClipboardException {
+ try {
+ if(schemFormat)
+ return ClipboardFormats.findByExtension(SCHEM).getReader(is).read();
+ else
+ return ClipboardFormats.findByExtension(SCHEMATIC).getReader(is).read();
+ } catch (NullPointerException e) {
+ throw new NoClipboardException();
+ }
+ }
+
+ private static WorldEditPlugin getWorldEditPlugin() {
+ return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
+ }
+}
diff --git a/SpigotCore_8/pom.xml b/SpigotCore_8/pom.xml
index 5f39805..80681bb 100644
--- a/SpigotCore_8/pom.xml
+++ b/SpigotCore_8/pom.xml
@@ -33,5 +33,16 @@
1.8
provided
+
+ steamwar
+ WorldEdit
+ 1.0
+ provided
+
+
+ steamwar
+ SpigotCore_API
+ 2.0
+
\ No newline at end of file
diff --git a/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java
new file mode 100644
index 0000000..baf66ae
--- /dev/null
+++ b/SpigotCore_8/src/de/steamwar/sql/Schematic_8.java
@@ -0,0 +1,54 @@
+package de.steamwar.sql;
+
+import com.sk89q.worldedit.EmptyClipboardException;
+import com.sk89q.worldedit.WorldEdit;
+import com.sk89q.worldedit.bukkit.BukkitWorld;
+import com.sk89q.worldedit.bukkit.WorldEditPlugin;
+import com.sk89q.worldedit.extension.platform.Actor;
+import com.sk89q.worldedit.extent.clipboard.Clipboard;
+import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
+import com.sk89q.worldedit.session.ClipboardHolder;
+import com.sk89q.worldedit.world.registry.WorldData;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+class Schematic_8 {
+ private Schematic_8(){}
+
+ static byte[] getPlayerClipboard(Player player) throws IOException, NoClipboardException {
+ ClipboardHolder clipboardHolder;
+ try {
+ clipboardHolder = getWorldEditPlugin().getSession(player).getClipboard();
+ } catch (EmptyClipboardException e) {
+ throw new NoClipboardException();
+ }
+
+ Clipboard clipboard = clipboardHolder.getClipboard();
+ if(clipboard == null)
+ throw new NoClipboardException();
+
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ ClipboardFormat.SCHEMATIC.getWriter(outputStream).write(clipboard, clipboardHolder.getWorldData());
+ return outputStream.toByteArray();
+ }
+
+ static void setPlayerClipboard(Player player, InputStream is) throws IOException {
+ WorldData world = new BukkitWorld(player.getWorld()).getWorldData();
+ Clipboard clipboard = getClipboard(is);
+
+ Actor actor = getWorldEditPlugin().wrapCommandSender(player);
+ getWorldEditPlugin().getWorldEdit().getSessionManager().get(actor).setClipboard(new ClipboardHolder(clipboard, world));
+ }
+
+ static Clipboard getClipboard(InputStream is) throws IOException {
+ return ClipboardFormat.findByAlias("mcedit").getReader(is).read(WorldEdit.getInstance().getServer().getWorlds().get(0).getWorldData());
+ }
+
+ private static WorldEditPlugin getWorldEditPlugin() {
+ return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
+ }
+}
diff --git a/SpigotCore_API/pom.xml b/SpigotCore_API/pom.xml
new file mode 100644
index 0000000..26c1621
--- /dev/null
+++ b/SpigotCore_API/pom.xml
@@ -0,0 +1,28 @@
+
+
+ 4.0.0
+
+
+ steamwar
+ SpigotCore
+ 2.0
+
+
+ SpigotCore_API
+ 2.0
+
+
+ src
+
+
+ src
+
+ **/*.java
+ **/*.kt
+
+
+
+
+
\ No newline at end of file
diff --git a/SpigotCore_API/src/de/steamwar/sql/NoClipboardException.java b/SpigotCore_API/src/de/steamwar/sql/NoClipboardException.java
new file mode 100644
index 0000000..f8b6e02
--- /dev/null
+++ b/SpigotCore_API/src/de/steamwar/sql/NoClipboardException.java
@@ -0,0 +1,4 @@
+package de.steamwar.sql;
+
+public class NoClipboardException extends Exception {
+}
diff --git a/SpigotCore_Main/pom.xml b/SpigotCore_Main/pom.xml
index c05ee63..10c1151 100644
--- a/SpigotCore_Main/pom.xml
+++ b/SpigotCore_Main/pom.xml
@@ -50,6 +50,18 @@
1.12
provided
+
+ steamwar
+ WorldEdit
+ 1.0
+ provided
+
+
+ steamwar
+ SpigotCore_API
+ 2.0
+ compile
+
steamwar
SpigotCore_8
diff --git a/SpigotCore_Main/src/de/steamwar/sql/SQL.java b/SpigotCore_Main/src/de/steamwar/sql/SQL.java
index fd243d6..8375a99 100644
--- a/SpigotCore_Main/src/de/steamwar/sql/SQL.java
+++ b/SpigotCore_Main/src/de/steamwar/sql/SQL.java
@@ -48,6 +48,10 @@ public class SQL {
throw new SecurityException("Could not close connection", e);
}
}
+
+ static Connection getCon(){
+ return con;
+ }
static void update(String qry) {
try {
diff --git a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java
index 340252e..7fd5946 100644
--- a/SpigotCore_Main/src/de/steamwar/sql/Schematic.java
+++ b/SpigotCore_Main/src/de/steamwar/sql/Schematic.java
@@ -1,5 +1,13 @@
package de.steamwar.sql;
+import com.sk89q.worldedit.extent.clipboard.Clipboard;
+import de.steamwar.core.Core;
+import org.bukkit.entity.Player;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -8,38 +16,31 @@ import java.util.UUID;
public class Schematic {
+ private final int schemID;
private final String schemName;
private final int schemOwner;
+ private boolean schemFormat;
private String item;
private SchematicType schemType;
private Schematic(ResultSet rs) throws SQLException {
- this(
- rs.getString("SchemName"),
- rs.getInt("SchemOwner"),
- rs.getString("Item"),
- SchematicType.fromDB(rs.getString("SchemType")),
- false);
- }
-
- private Schematic(String schemName, int schemOwner, String item, SchematicType schemType, boolean updateDB){
- this.schemName = schemName;
- this.schemOwner = schemOwner;
- this.item = item;
- this.schemType = schemType;
- if(updateDB)
- updateDB();
- }
-
- public Schematic(String schemName, int schemOwner, String item, SchematicType schemType){
- this(schemName, schemOwner, item, schemType, true);
- }
-
- public Schematic(String schemName, UUID schemOwner, String item, SchematicType schemType){
- this(schemName, SteamwarUser.get(schemOwner).getId(), item, schemType, true);
+ this.schemID = rs.getInt("SchemID");
+ this.schemName = rs.getString("SchemName");
+ this.schemOwner = rs.getInt("SchemOwner");
+ this.item = rs.getString("Item");
+ this.schemType = SchematicType.fromDB(rs.getString("SchemType"));
+ this.schemFormat = rs.getBoolean("SchemFormat");
}
private void updateDB(){
+ createSchem(schemName, schemOwner, item, schemType);
+ }
+
+ public static void createSchem(String schemName, UUID schemOwner, String item, SchematicType schemType){
+ createSchem(schemName, SteamwarUser.get(schemOwner).getId(), item, schemType);
+ }
+
+ public static void createSchem(String schemName, int schemOwner, String item, SchematicType schemType){
SQL.update("INSERT INTO Schematic" +
" (SchemName, SchemOwner, Item, SchemType)" +
" VALUES" +
@@ -65,9 +66,8 @@ public class Schematic {
}
return new Schematic(schematic);
} catch (SQLException e) {
- e.printStackTrace();
+ throw new SecurityException("Failed loading schematic", e);
}
- return null;
}
public static List getSchemsAccessibleByUser(UUID schemOwner){
@@ -87,9 +87,8 @@ public class Schematic {
}
return schematics;
}catch(SQLException e){
- e.printStackTrace();
+ throw new SecurityException("Failed listing schematics", e);
}
- return null;
}
public static List getSchemsOfType(UUID schemOwner, SchematicType schemType){
@@ -99,10 +98,9 @@ public class Schematic {
public static List getSchemsOfType(int schemOwner, SchematicType schemType){
//Unsauber, dafür auch geaddede Schematics dabei
List schems = getSchemsAccessibleByUser(schemOwner);
- if(schems != null)
- for(int i = schems.size()-1; i >= 0; i--)
- if(!schems.get(i).getSchemType().equals(schemType))
- schems.remove(i);
+ for(int i = schems.size()-1; i >= 0; i--)
+ if(!schems.get(i).getSchemType().equals(schemType))
+ schems.remove(i);
return schems;
}
@@ -115,9 +113,12 @@ public class Schematic {
}
return schematics;
}catch(SQLException e){
- e.printStackTrace();
+ throw new SecurityException("Failed loading all schems of type", e);
}
- return null;
+ }
+
+ public int getSchemID() {
+ return schemID;
}
public String getSchemName() {
@@ -146,8 +147,91 @@ public class Schematic {
updateDB();
}
+ public boolean availible(){
+ return Core.getVersion() > 12 || !schemFormat;
+ }
+
+ public Clipboard load() throws WrongVersionException, IOException, NoClipboardException {
+ if(Core.getVersion() <= 12 && schemFormat)
+ throw new WrongVersionException();
+
+ ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID);
+ try {
+ rs.next();
+ InputStream is = rs.getBlob("SchemData").getBinaryStream();
+ switch(Core.getVersion()){
+ case 8:
+ return Schematic_8.getClipboard(is);
+ case 14:
+ return Schematic_14.getClipboard(is, schemFormat);
+ default:
+ return Schematic_12.getClipboard(is);
+ }
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void loadToPlayer(Player player) throws IOException, NoClipboardException, WrongVersionException {
+ if(Core.getVersion() <= 12 && schemFormat)
+ throw new WrongVersionException();
+
+ ResultSet rs = SQL.select("SELECT SchemData FROM Schematic WHERE SchemID = " + schemID);
+ try {
+ rs.next();
+ InputStream is = rs.getBlob("SchemData").getBinaryStream();
+ switch(Core.getVersion()){
+ case 8:
+ Schematic_8.setPlayerClipboard(player, is);
+ break;
+ case 14:
+ Schematic_14.setPlayerClipboard(player, is, schemFormat);
+ break;
+ default:
+ Schematic_12.setPlayerClipboard(player, is);
+ }
+ } catch (SQLException e) {
+ throw new IOException(e);
+ }
+ }
+
+ public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {
+ saveFromPlayer(player, false);
+ }
+
+ public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
+ saveFromPlayer(player, true);
+ }
+
+ private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
+ try{
+ PreparedStatement st = SQL.getCon().prepareStatement("UPDATE Schematic SET SchemData = ?, SchemFormat = ? WHERE SchemID = " + schemID);
+ byte[] data;
+ switch(Core.getVersion()){
+ case 8:
+ newFormat = false;
+ data = Schematic_8.getPlayerClipboard(player);
+ break;
+ case 14:
+ data = Schematic_14.getPlayerClipboard(player, newFormat);
+ break;
+ default:
+ newFormat = false;
+ data = Schematic_12.getPlayerClipboard(player);
+ }
+ st.setBlob(1, new ByteArrayInputStream(data));
+ st.setBoolean(2, newFormat);
+ st.executeUpdate();
+ schemFormat = newFormat;
+ }catch(SQLException e){
+ throw new IOException(e);
+ }
+ }
+
public void remove(){
SQL.update("DELETE FROM Schematic WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'");
SQL.update("DELETE FROM SchemMember WHERE SchemOwner = " + schemOwner + " AND SchemName = '" + schemName + "'");
}
+
+ public static class WrongVersionException extends Exception{}
}
diff --git a/pom.xml b/pom.xml
index dbc56a3..f403dc5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -37,6 +37,7 @@
+ SpigotCore_API
SpigotCore_8
SpigotCore_12
SpigotCore_14