SteamWar/SpigotCore
Archiviert
13
0

Schematic Nodes #90

Zusammengeführt
Lixfel hat 48 Commits von schematic-node nach master 2021-11-20 13:12:32 +01:00 zusammengeführt
2 geänderte Dateien mit 32 neuen und 13 gelöschten Zeilen
Nur Änderungen aus Commit 3efe00c16f werden angezeigt - Alle Commits anzeigen

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) {
Chaoscaot markierte diese Unterhaltung als gelöst Veraltet
Veraltet
Review

Wenns ein Verzeichnis ist: NULL

Wenns ein Verzeichnis ist: NULL
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");
rank = set.getInt("NodeRank");
schemFormat = set.getBoolean("SchemFormat");
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 {