SteamWar/SpigotCore
Archiviert
13
0

Merge branch 'master' into schematic_selector
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Dieser Commit ist enthalten in:
YoyoNow 2021-11-21 15:17:55 +01:00
Commit 7a78fa9d63

Datei anzeigen

@ -21,8 +21,6 @@ package de.steamwar.sql;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import de.steamwar.core.Core;
import de.steamwar.core.VersionedCallable;
import de.steamwar.core.VersionedRunnable;
import de.steamwar.core.WorldEditWrapper;
import org.bukkit.entity.Player;
@ -35,7 +33,6 @@ import java.sql.SQLException;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Predicate;
import java.util.zip.GZIPInputStream;
@ -309,6 +306,40 @@ public class SchematicNode {
}, node);
}
public static SchematicNode getNodeFromPath(SteamwarUser user, String s) {
if (s.startsWith("/")) {
s = s.substring(1);
}
if (s.isEmpty()) {
return null;
}
if (s.contains("/")) {
String[] layers = s.split("/");
SchematicNode currentNode = null;
for (int i = 0; i < layers.length; i++) {
int finalI = i;
Optional<SchematicNode> node;
if (currentNode == null) {
node = SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
} else {
node = SchematicNode.getSchematicNodeInNode(currentNode).stream().filter(node1 -> node1.getName().equals(layers[finalI])).findAny();
}
if (!node.isPresent()) {
return null;
} else {
currentNode = node.get();
if (!currentNode.isDir() && i != layers.length - 1) {
return null;
}
}
}
return currentNode;
} else {
String finalS = s;
return SchematicNode.getSchematicsAccessibleByUser(user.getId(), 0).stream().filter(node1 -> node1.getName().equals(finalS)).findAny().orElse(null);
}
}
private final int id;
private final int owner;
private String name;
@ -378,12 +409,14 @@ public class SchematicNode {
updateDB();
}
@Deprecated
public String getType() {
if(isDir)
throw new SecurityException("Node is Directory");
return type;
}
@Deprecated
public void setType(String type) {
if(isDir)
throw new SecurityException("Node is Directory");
@ -419,6 +452,13 @@ public class SchematicNode {
return SchematicType.fromDB(type);
}
public void setSchemtype(SchematicType type) {
if(isDir())
throw new RuntimeException("Is Directory");
this.type = type.toDB();
updateDB();
}
public SchematicNode getParentNode() {
if(parent == null) return null;
return SchematicNode.getSchematicNode(parent);