Skip to content

Commit

Permalink
fix terrascript loading logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dfsek committed Jan 2, 2021
1 parent a51727b commit 6bac82d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class StructureScript {
private final String id;
private final LinkedHashMap<Location, StructureBuffer> cache;

public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, CheckCache cache) {
public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry registry, LootRegistry lootRegistry, CheckCache cache) throws ParseException {
Parser parser;
try {
parser = new Parser(IOUtils.toString(inputStream));
Expand All @@ -53,11 +53,7 @@ public StructureScript(InputStream inputStream, TerraPlugin main, ScriptRegistry
.addFunction("loot", new LootFunctionBuilder(main, lootRegistry))
.addFunction("entity", new EntityFunctionBuilder(main));

try {
block = parser.parse();
} catch(ParseException e) {
throw new RuntimeException(e);
}
block = parser.parse();
this.id = parser.getID();
this.cache = new LinkedHashMap<Location, StructureBuffer>() {
@Override
Expand Down
16 changes: 11 additions & 5 deletions common/src/main/java/com/dfsek/terra/config/base/ConfigPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,21 @@ private void load(Loader loader, long start, TerraPlugin main) throws ConfigExce
varScope.create(var.getKey()).setValue(var.getValue());
}

loader.open("structures/data", ".tesf").then(streams -> streams.forEach(stream -> {
StructureScript structureScript = new StructureScript(stream, main, scriptRegistry, lootRegistry, checkCache);
scriptRegistry.add(structureScript.getId(), structureScript);
})).close().open("structures/loot", ".json").thenEntries(entries -> {
loader.open("structures/data", ".tesf").thenEntries(entries -> {
for(Map.Entry<String, InputStream> entry : entries) {
try {
StructureScript structureScript = new StructureScript(entry.getValue(), main, scriptRegistry, lootRegistry, checkCache);
scriptRegistry.add(structureScript.getId(), structureScript);
} catch(com.dfsek.terra.api.structures.parser.exceptions.ParseException e) {
throw new LoadException("Unable to load script \"" + entry.getKey() + "\"", e);
}
}
}).close().open("structures/loot", ".json").thenEntries(entries -> {
for(Map.Entry<String, InputStream> entry : entries) {
try {
lootRegistry.add(entry.getKey(), new LootTable(IOUtils.toString(entry.getValue(), StandardCharsets.UTF_8), main));
} catch(ParseException | IOException | NullPointerException e) {
throw new LoadException("Unable to load loot", e);
throw new LoadException("Unable to load loot table \"" + entry.getKey() + "\"", e);
}
}
}).close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ protected void load(String directory, String extension) {
try(Stream<Path> paths = Files.walk(newPath.toPath())) {
paths.filter(Files::isRegularFile).filter(file -> file.toString().toLowerCase().endsWith(extension)).forEach(file -> {
try {
streams.put(newPath.toURI().relativize(file.toUri()).getPath(), new FileInputStream(file.toFile()));
String rel = newPath.toPath().relativize(file).toString();
streams.put(rel, new FileInputStream(file.toFile()));
} catch(FileNotFoundException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected void load(String directory, String extension) {
ZipEntry entry = entries.nextElement();
if(!entry.isDirectory() && entry.getName().startsWith(directory) && entry.getName().endsWith(extension)) {
try {
streams.put(entry.getName(), file.getInputStream(entry));
String rel = entry.getName().substring(directory.length() + 1);
streams.put(rel, file.getInputStream(entry));
} catch(IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dfsek.terra.bukkit.generator;

import com.dfsek.terra.TerraWorld;
import com.dfsek.terra.api.platform.TerraPlugin;
import com.dfsek.terra.api.platform.generator.GeneratorWrapper;
import com.dfsek.terra.api.platform.world.Chunk;
Expand All @@ -9,7 +10,6 @@
import com.dfsek.terra.bukkit.world.BukkitBiomeGrid;
import com.dfsek.terra.config.lang.LangUtil;
import com.dfsek.terra.debug.Debug;
import com.dfsek.terra.generation.MasterChunkGenerator;
import com.dfsek.terra.population.CavePopulator;
import com.dfsek.terra.population.FloraPopulator;
import com.dfsek.terra.population.OrePopulator;
Expand Down Expand Up @@ -64,7 +64,7 @@ public static synchronized void saveAll() {
}

public static synchronized void fixChunk(Chunk c) {
if(!(c.getWorld().getGenerator() instanceof MasterChunkGenerator)) throw new IllegalArgumentException();
if(!TerraWorld.isTerraWorld(c.getWorld())) throw new IllegalArgumentException();
popMap.get(c.getWorld()).checkNeighbors(c.getX(), c.getZ(), c.getWorld());
}

Expand Down

0 comments on commit 6bac82d

Please sign in to comment.