Support reloading, better error handling

This commit is contained in:
Norbi Peti 2020-09-22 20:15:32 +02:00
parent 2a7a968825
commit ad3a9202b2
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 95 additions and 85 deletions

View file

@ -6,7 +6,7 @@
<groupId>com.github.TBMCPlugins</groupId>
<artifactId>CustomDimensions</artifactId>
<version>1.2</version>
<version>1.3</version>
<build>
<plugins>
<plugin>

View file

@ -13,12 +13,12 @@ import org.bukkit.event.world.WorldLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.IOException;
import java.util.*;
public class CustomDimensions extends JavaPlugin implements Listener {
@Override
public void onEnable() {
//Bukkit.getPluginManager().registerEvents(this, this);
getLogger().info("Loading custom dimensions...");
try {
load();
@ -36,23 +36,34 @@ public class CustomDimensions extends JavaPlugin implements Listener {
GeneratorSettings mainGenSettings = saveData.getGeneratorSettings();
RegistryMaterials<WorldDimension> dimensionRegistry = mainGenSettings.d();
var dimIterator = dimensionRegistry.d().iterator();
var mainWorld = Bukkit.getWorlds().get(0);
var convertable = Convertable.a(Bukkit.getWorldContainer().toPath());
while (dimIterator.hasNext()) {
Map.Entry<ResourceKey<WorldDimension>, WorldDimension> dimEntry = dimIterator.next();
ResourceKey<WorldDimension> dimKey = dimEntry.getKey();
for (var dimEntry : dimensionRegistry.d()) {
try {
loadDimension(dimEntry.getKey(), dimEntry.getValue(), convertable, console, mainWorld);
} catch (Exception e) {
getLogger().warning("Failed to load dimension " + dimEntry.getKey());
e.printStackTrace();
}
}
}
if (dimKey != WorldDimension.OVERWORLD //The default dimensions are already loaded
&& dimKey != WorldDimension.THE_NETHER
&& dimKey != WorldDimension.THE_END) {
private void loadDimension(ResourceKey<WorldDimension> dimKey, WorldDimension dimension,
Convertable convertable, DedicatedServer console, org.bukkit.World mainWorld) throws IOException {
if (dimKey == WorldDimension.OVERWORLD //The default dimensions are already loaded
|| dimKey == WorldDimension.THE_NETHER
|| dimKey == WorldDimension.THE_END)
return;
ResourceKey<World> worldKey = ResourceKey.a(IRegistry.L, dimKey.a());
DimensionManager dimensionmanager = dimEntry.getValue().b();
ChunkGenerator chunkgenerator = dimEntry.getValue().c();
DimensionManager dimensionmanager = dimension.b();
ChunkGenerator chunkgenerator = dimension.c();
var name = dimKey.a().getKey();
if (Bukkit.getWorld(name) != null) {
getLogger().info(name + " already loaded");
return;
}
getLogger().info("Loading " + name);
var session = convertable.new ConversionSession(name, dimKey) { //The original session isn't prepared for custom dimensions
@Override
@ -96,7 +107,8 @@ public class CustomDimensions extends JavaPlugin implements Listener {
var key = dimRegistry.getKey(dimensionmanager);
if (key != null) { //The loaded manager is the same
getLogger().warning("Dimension manager already loaded with key " + key + "! Skipping");
continue;
session.close();
return;
}
}
//Replace existing dimension manager, correctly setting the ID up (which is -1 for default worlds...)
@ -124,5 +136,3 @@ public class CustomDimensions extends JavaPlugin implements Listener {
}
}
}
}
}

View file

@ -1,6 +1,6 @@
name: CustomDimensions
main: buttondevteam.customdimensions.CustomDimensions
version: '1.2'
version: '1.3'
api-version: '1.16'
loadbefore:
- Multiverse-Core