SteamWar/SpigotCore
Archiviert
13
0

refactor(standalone): Move WorldEdit Directory to StandaloneProvider
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

feat(standalone): Add Creating Nodes
Dieser Commit ist enthalten in:
Chaos 2022-02-11 21:58:44 +01:00
Ursprung bc1f268022
Commit 5cc6ab2145
2 geänderte Dateien mit 35 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -18,12 +18,9 @@ public class WorldEditWrapper {
InputStream getPlayerClipboard(Player player, boolean schemFormat);
void setPlayerClipboard(Player player, InputStream is, boolean schemFormat);
Clipboard getClipboard(InputStream is, boolean schemFormat) throws IOException;
default File getWorldEditSchematicFolder() {
return WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getWorkingDirectoryFile(WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getConfiguration().saveDir);
}
}
static WorldEditPlugin getWorldEditPlugin() {
public static WorldEditPlugin getWorldEditPlugin() {
return (WorldEditPlugin) Bukkit.getPluginManager().getPlugin("WorldEdit");
}
}

Datei anzeigen

@ -203,7 +203,7 @@ public class StandaloneProvider implements Provider {
}
private int nodeId = 1;
private final File schematicDir = WorldEditWrapper.impl.getWorldEditSchematicFolder();
private final File schematicDir = WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getWorkingDirectoryFile(WorldEditWrapper.getWorldEditPlugin().getWorldEdit().getConfiguration().saveDir);
private final Map<Integer, SchematicNode> nodeById = new HashMap<>();
private final Map<Integer, List<SchematicNode>> nodesByParent = new HashMap<>();
private final Map<Integer, Path> nodesToPath = new HashMap<>();
@ -215,7 +215,7 @@ public class StandaloneProvider implements Provider {
SchematicNode node = new SchematicNode(
nodeId++,
0,
file.getName().substring(file.getName().lastIndexOf(".")),
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
null,
"",
"normal",
@ -237,7 +237,35 @@ public class StandaloneProvider implements Provider {
@Override
public void createSchematicNode(int owner, String name, Integer parent, String type, String item) {
boolean isDir = type == null;
Path p = null;
try {
if(isDir) {
p = Files.createDirectory(new File(nodesToPath.get(parent == null?-1:parent).toFile(), name).toPath());
} else {
p = Files.createFile(new File(nodesToPath.get(parent == null?-1:parent).toFile(), name + ".schem").toPath());
}
} catch (IOException e) {
throw new SecurityException(e);
}
File file = p.toFile();
int id = nodeId++;
nodesToPath.put(id, p);
SchematicNode node = new SchematicNode(
nodeId++,
0,
file.isDirectory()?file.getName():file.getName().substring(file.getName().lastIndexOf(".")),
null,
"",
"normal",
file.isDirectory(),
0,
Timestamp.from(Instant.now()),
file.getName().endsWith(".schem")
);
nodeById.put(id, node);
nodesByParent.get(parent == null?-1:parent).add(node);
}
@Override
@ -352,6 +380,10 @@ public class StandaloneProvider implements Provider {
while((nReadBytes = blob.read(bucket, 0, bucket.length)) !=-1){
stream.write(bucket, 0, nReadBytes);
}
if(newFormat != node.getSchemFormat()) {
nodesToPath.get(node.getId()).toFile().renameTo(new File(nodesToPath.get(node.getId()).toFile().getParentFile(), node.getName() + "." + (newFormat?".schem":"schematic")));
}
} catch (IOException e) {
throw new SecurityException(e);
}