SteamWar/SpigotCore
Archiviert
13
0
Dieser Commit ist enthalten in:
Chaoscaot 2021-02-02 18:02:15 +01:00
Ursprung 4b4d5f92bf
Commit 3efe00c16f
2 geänderte Dateien mit 32 neuen und 13 gelöschten Zeilen

Datei anzeigen

@ -20,15 +20,9 @@
package de.steamwar.sql;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.VersionedCallable;
import de.steamwar.core.VersionedRunnable;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

Datei anzeigen

@ -33,15 +33,12 @@ import java.util.*;
public class SchematicNode {
private static final String DIR_TYPE = "directory";
public static final int ROOT_DIR = 0;
public static SchematicNode createSchematic(int owner, String name, int parent) {
return createSchematicNode(owner, name, parent, SchematicType.Normal.toDB(), "");
}
public static SchematicNode createSchematicDirectory(int owner, String name, int parent) {
return createSchematicNode(owner, name, parent, DIR_TYPE, "");
return createSchematicNode(owner, name, parent, null, "");
}
public static SchematicNode createSchematicNode(int owner, String name, int parent, String type, String item) {
@ -222,6 +219,7 @@ public class SchematicNode {
private String type;
private boolean schemFormat;
private int rank;
private boolean isDir;
private SchematicNode(ResultSet set) throws SQLException {
id = set.getInt("NodeId");
@ -230,8 +228,13 @@ public class SchematicNode {
parent = set.getInt("ParentNode");
item = set.getString("NodeItem");
type = set.getString("NodeType");
if(type != null) {
isDir = false;
rank = set.getInt("NodeRank");
schemFormat = set.getBoolean("SchemFormat");
}else {
isDir = true;
}
}
public int getId() {
@ -270,27 +273,37 @@ public class SchematicNode {
}
public String getType() {
if(isDir)
throw new SecurityException("Node is Directory");
return type;
}
public void setType(String type) {
if(isDir)
throw new SecurityException("Node is Directory");
this.type = type;
updateDB();
}
public boolean isDir() {
return type.equals(DIR_TYPE);
return isDir;
}
public boolean getSchemFormat() {
if(isDir)
throw new SecurityException("Node is Directory");
return schemFormat;
}
public int getRank() {
if(isDir)
throw new SecurityException("Node is Directory");
return rank;
}
public void setRank(int rank) {
if(isDir)
throw new SecurityException("Node is Directory");
this.rank = rank;
}
@ -325,6 +338,8 @@ public class SchematicNode {
}
public Clipboard load() throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
ResultSet rs = SQL.select("SELECT NodeData FROM SchematicNode WHERE NodeId = ?", id);
try {
rs.next();
@ -340,6 +355,8 @@ public class SchematicNode {
}
public void loadToPlayer(Player player) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
ResultSet rs = SQL.select("SELECT NodeData FROM SchematicNode WHERE NodeId = ?", id);
try {
rs.next();
@ -355,14 +372,20 @@ public class SchematicNode {
}
public void saveOldFormatFromPlayer(Player player) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
saveFromPlayer(player, false);
}
public void saveFromPlayer(Player player) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
saveFromPlayer(player, true);
}
public void saveFromBytes(byte[] bytes, boolean newFormat) {
if(isDir)
throw new SecurityException("Node is Directory");
Blob blob = SQL.blob();
try {
blob.setBytes(1, bytes);
@ -373,6 +396,8 @@ public class SchematicNode {
}
private void saveFromPlayer(Player player, boolean newFormat) throws IOException, NoClipboardException {
if(isDir)
throw new SecurityException("Node is Directory");
Blob blob = SQL.blob();
VersionedRunnable.call(new VersionedRunnable(() -> {
try {