Fix sponge schematics not loading at startup.

This commit is contained in:
bloodshot 2019-12-01 00:43:25 -05:00
parent ef3659b33e
commit 29824075e2
2 changed files with 8 additions and 14 deletions

View File

@ -30,6 +30,7 @@
import com.griefdefender.api.claim.ClaimSchematic; import com.griefdefender.api.claim.ClaimSchematic;
import com.griefdefender.internal.util.VecHelper; import com.griefdefender.internal.util.VecHelper;
import org.spongepowered.api.data.DataContainer; 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.DataFormats;
import org.spongepowered.api.data.persistence.DataTranslators; import org.spongepowered.api.data.persistence.DataTranslators;
import org.spongepowered.api.world.BlockChangeFlags; import org.spongepowered.api.world.BlockChangeFlags;
@ -55,10 +56,10 @@ public class GDClaimSchematic implements ClaimSchematic {
private final Instant dateCreated; private final Instant dateCreated;
// Used during server startup to load schematic // 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.claim = claim;
this.schematic = schematic; this.schematic = schematic;
this.name = name; this.name = schematic.getMetadata().getString(DataQuery.of(".", Schematic.METADATA_NAME)).orElse(fileName);
this.origin = claim.getLesserBoundaryCorner(); this.origin = claim.getLesserBoundaryCorner();
this.dateCreated = Instant.now(); this.dateCreated = Instant.now();
} }
@ -169,7 +170,7 @@ public Optional<ClaimSchematic> build() {
} catch (IOException e1) { } catch (IOException e1) {
e1.printStackTrace(); e1.printStackTrace();
} }
File outputFile = schematicPath.resolve(name + ".schematic").toFile(); File outputFile = schematicPath.resolve(this.name + ".schematic").toFile();
try { try {
DataFormats.NBT.writeTo(new GZIPOutputStream(new FileOutputStream(outputFile)), schematicData); DataFormats.NBT.writeTo(new GZIPOutputStream(new FileOutputStream(outputFile)), schematicData);
} catch (Exception e) { } catch (Exception e) {

View File

@ -33,7 +33,6 @@
import com.griefdefender.api.claim.Claim; import com.griefdefender.api.claim.Claim;
import com.griefdefender.api.claim.ClaimResult; import com.griefdefender.api.claim.ClaimResult;
import com.griefdefender.api.claim.ClaimResultType; 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.api.permission.option.type.CreateModeTypes;
import com.griefdefender.cache.MessageCache; import com.griefdefender.cache.MessageCache;
import com.griefdefender.claim.GDClaim; 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.MultiSelectionGridEvent;
import com.griefdefender.internal.provider.worldedit.cui.event.MultiSelectionPointEvent; import com.griefdefender.internal.provider.worldedit.cui.event.MultiSelectionPointEvent;
import com.griefdefender.internal.util.BlockUtil; import com.griefdefender.internal.util.BlockUtil;
import com.griefdefender.storage.FileStorage;
import com.griefdefender.util.PlayerUtil; import com.griefdefender.util.PlayerUtil;
import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
@ -72,7 +70,6 @@
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.HashMap;
@ -331,18 +328,14 @@ public void loadSchematics(org.spongepowered.api.world.World world) {
for (Claim claim : claimWorldManager.getWorldClaims()) { for (Claim claim : claimWorldManager.getWorldClaims()) {
Path path = this.schematicWorldMap.get(claim.getWorldUniqueId()).resolve(claim.getUniqueId().toString()); Path path = this.schematicWorldMap.get(claim.getWorldUniqueId()).resolve(claim.getUniqueId().toString());
if (!Files.exists(path)) { if (!Files.exists(path)) {
try { continue;
Files.createDirectories(path);
} catch (IOException e) {
e.printStackTrace();
}
return;
} }
File files[] = path.toFile().listFiles(); File files[] = path.toFile().listFiles();
for (File file : files) { for (File file : files) {
DataContainer schematicData = null; DataContainer schematicData = null;
Schematic schematic = null; Schematic schematic = null;
final String fileName = file.getName().replaceFirst("[.][^.]+$", "");
try { try {
schematicData = DataFormats.NBT.readFrom(new GZIPInputStream(new FileInputStream(file))); schematicData = DataFormats.NBT.readFrom(new GZIPInputStream(new FileInputStream(file)));
schematic = DataTranslators.SCHEMATIC.translate(schematicData); schematic = DataTranslators.SCHEMATIC.translate(schematicData);
@ -350,8 +343,8 @@ public void loadSchematics(org.spongepowered.api.world.World world) {
e.printStackTrace(); e.printStackTrace();
continue; continue;
} }
GDClaimSchematic claimSchematic = new GDClaimSchematic(claim, schematic, schematic.METADATA_NAME); final GDClaimSchematic claimSchematic = new GDClaimSchematic(claim, schematic, fileName);
((GDClaim) claim).schematics.put(file.getName(), claimSchematic); ((GDClaim) claim).schematics.put(fileName, claimSchematic);
} }
} }
}); });