From 29824075e27d79df273257531108dc6da37c5e32 Mon Sep 17 00:00:00 2001 From: bloodshot Date: Sun, 1 Dec 2019 00:43:25 -0500 Subject: [PATCH] Fix sponge schematics not loading at startup. --- .../com/griefdefender/claim/GDClaimSchematic.java | 7 ++++--- .../internal/provider/WorldEditProvider.java | 15 ++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/sponge/src/main/java/com/griefdefender/claim/GDClaimSchematic.java b/sponge/src/main/java/com/griefdefender/claim/GDClaimSchematic.java index 388d58f..486e57c 100644 --- a/sponge/src/main/java/com/griefdefender/claim/GDClaimSchematic.java +++ b/sponge/src/main/java/com/griefdefender/claim/GDClaimSchematic.java @@ -30,6 +30,7 @@ import com.griefdefender.api.claim.ClaimSchematic; import com.griefdefender.internal.util.VecHelper; import org.spongepowered.api.data.DataContainer; +import org.spongepowered.api.data.DataQuery; import org.spongepowered.api.data.persistence.DataFormats; import org.spongepowered.api.data.persistence.DataTranslators; import org.spongepowered.api.world.BlockChangeFlags; @@ -55,10 +56,10 @@ public class GDClaimSchematic implements ClaimSchematic { private final Instant dateCreated; // Used during server startup to load schematic - public GDClaimSchematic(Claim claim, Schematic schematic, String name) { + public GDClaimSchematic(Claim claim, Schematic schematic, String fileName) { this.claim = claim; this.schematic = schematic; - this.name = name; + this.name = schematic.getMetadata().getString(DataQuery.of(".", Schematic.METADATA_NAME)).orElse(fileName); this.origin = claim.getLesserBoundaryCorner(); this.dateCreated = Instant.now(); } @@ -169,7 +170,7 @@ public Optional build() { } catch (IOException e1) { e1.printStackTrace(); } - File outputFile = schematicPath.resolve(name + ".schematic").toFile(); + File outputFile = schematicPath.resolve(this.name + ".schematic").toFile(); try { DataFormats.NBT.writeTo(new GZIPOutputStream(new FileOutputStream(outputFile)), schematicData); } catch (Exception e) { diff --git a/sponge/src/main/java/com/griefdefender/internal/provider/WorldEditProvider.java b/sponge/src/main/java/com/griefdefender/internal/provider/WorldEditProvider.java index 76ae676..74fe48b 100644 --- a/sponge/src/main/java/com/griefdefender/internal/provider/WorldEditProvider.java +++ b/sponge/src/main/java/com/griefdefender/internal/provider/WorldEditProvider.java @@ -33,7 +33,6 @@ import com.griefdefender.api.claim.Claim; import com.griefdefender.api.claim.ClaimResult; import com.griefdefender.api.claim.ClaimResultType; -import com.griefdefender.api.permission.option.type.CreateModeType; import com.griefdefender.api.permission.option.type.CreateModeTypes; import com.griefdefender.cache.MessageCache; import com.griefdefender.claim.GDClaim; @@ -49,7 +48,6 @@ import com.griefdefender.internal.provider.worldedit.cui.event.MultiSelectionGridEvent; import com.griefdefender.internal.provider.worldedit.cui.event.MultiSelectionPointEvent; import com.griefdefender.internal.util.BlockUtil; -import com.griefdefender.storage.FileStorage; import com.griefdefender.util.PlayerUtil; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; @@ -72,7 +70,6 @@ import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -331,18 +328,14 @@ public void loadSchematics(org.spongepowered.api.world.World world) { for (Claim claim : claimWorldManager.getWorldClaims()) { Path path = this.schematicWorldMap.get(claim.getWorldUniqueId()).resolve(claim.getUniqueId().toString()); if (!Files.exists(path)) { - try { - Files.createDirectories(path); - } catch (IOException e) { - e.printStackTrace(); - } - return; + continue; } File files[] = path.toFile().listFiles(); for (File file : files) { DataContainer schematicData = null; Schematic schematic = null; + final String fileName = file.getName().replaceFirst("[.][^.]+$", ""); try { schematicData = DataFormats.NBT.readFrom(new GZIPInputStream(new FileInputStream(file))); schematic = DataTranslators.SCHEMATIC.translate(schematicData); @@ -350,8 +343,8 @@ public void loadSchematics(org.spongepowered.api.world.World world) { e.printStackTrace(); continue; } - GDClaimSchematic claimSchematic = new GDClaimSchematic(claim, schematic, schematic.METADATA_NAME); - ((GDClaim) claim).schematics.put(file.getName(), claimSchematic); + final GDClaimSchematic claimSchematic = new GDClaimSchematic(claim, schematic, fileName); + ((GDClaim) claim).schematics.put(fileName, claimSchematic); } } });