Skip to content

Commit

Permalink
Support world provider loading late
Browse files Browse the repository at this point in the history
  • Loading branch information
Jikoo committed Mar 13, 2024
1 parent db99afe commit 2e6e7ee
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 32 deletions.
18 changes: 10 additions & 8 deletions src/main/java/com/github/jikoo/regionerator/Regionerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ public void onEnable() {
saveConfig();
}

miscData.checkWorldValidity();

chunkFlagger = new ChunkFlagger(this);
debugListener = new DebugListener(this);

Expand All @@ -98,19 +96,23 @@ public void onEnable() {
this.setPaused(true);
}

// Don't load features if there are no worlds configured
if (config.enabledWorlds().isEmpty()) {
getLogger().severe("No worlds are enabled. There's nothing to do!");
return;
}

/*
* Load features after server has finished boot.
* While softdepend should take care of this for us, as soon as another plugin causes
* a circular dependency Bukkit makes no attempt to resolve soft dependencies at all.
* To combat this, we load features after the server boots.
*/
getServer().getScheduler().runTask(this, () -> {
// Reconsider world validity after plugins have enabled in case world provider also loads late.
config.reconsiderWorldValidity();
miscData.checkWorldValidity();

// Don't load features if there are no worlds configured
if (config.enabledWorlds().isEmpty()) {
getLogger().severe("No worlds are enabled. There's nothing to do!");
return;
}

reloadFeatures();

debug(DebugLevel.LOW, () -> executor.onCommand(Bukkit.getConsoleSender(), Objects.requireNonNull(command), "regionerator", new String[0]));
Expand Down
54 changes: 30 additions & 24 deletions src/main/java/com/github/jikoo/regionerator/util/yaml/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,36 @@ public void reload() {

ConfigUpdater.doUpdates(this);

reconsiderWorldValidity();

synchronized (lock) {
debugLevel = DebugLevel.of(getString("debug-level"));
}

deleteFreshChunks.set(!getBoolean("flagging.flag-generated-chunks-until-visited"));
flaggingRadius.set(Math.max(0, getInt("flagging.chunk-flag-radius")));

int secondsPerFlag = getInt("flagging.seconds-per-flag");
if (secondsPerFlag < 1) {
ticksPerFlag.set(10);
} else {
ticksPerFlag.set(20L * secondsPerFlag);
}

deletionRecovery.set(Math.max(0, getLong("deletion.recovery-time")));
deletionChunkCount.set(Math.max(1, getInt("deletion.expensive-checks-between-recovery")));
millisBetweenCycles.set(TimeUnit.HOURS.toMillis(Math.max(0, getInt("deletion.hours-between-cycles"))));
rememberCycleDelay.set(getBoolean("deletion.remember-next-cycle-time"));

cacheExpirationFrequency = TimeUnit.MILLISECONDS.convert(Math.max(0, getInt("cache.minimum-expiration-frequency")), TimeUnit.SECONDS);
cacheRetention = TimeUnit.MILLISECONDS.convert(Math.max(1, getInt("cache.retention")), TimeUnit.MINUTES);
cacheBatchMax = Math.max(1, getInt("cache.maximum-batch-size"));
cacheBatchDelay = Math.max(0L, getLong("cache.batch-delay"));
cacheMaxSize = Math.max(50_000, getInt("cache.max-cache-size"));

}

public void reconsiderWorldValidity() {
ConfigurationSection worldsSection = raw().getConfigurationSection("worlds");
Map<String, Long> worldFlagDurations = new HashMap<>();
if (worldsSection != null) {
Expand Down Expand Up @@ -97,31 +127,7 @@ public void reload() {
synchronized (lock) {
// Immutable, this should not be changed during run.
this.worlds = ImmutableMap.copyOf(worldFlagDurations);

debugLevel = DebugLevel.of(getString("debug-level"));
}

deleteFreshChunks.set(!getBoolean("flagging.flag-generated-chunks-until-visited"));
flaggingRadius.set(Math.max(0, getInt("flagging.chunk-flag-radius")));

int secondsPerFlag = getInt("flagging.seconds-per-flag");
if (secondsPerFlag < 1) {
ticksPerFlag.set(10);
} else {
ticksPerFlag.set(20L * secondsPerFlag);
}

deletionRecovery.set(Math.max(0, getLong("deletion.recovery-time")));
deletionChunkCount.set(Math.max(1, getInt("deletion.expensive-checks-between-recovery")));
millisBetweenCycles.set(TimeUnit.HOURS.toMillis(Math.max(0, getInt("deletion.hours-between-cycles"))));
rememberCycleDelay.set(getBoolean("deletion.remember-next-cycle-time"));

cacheExpirationFrequency = TimeUnit.MILLISECONDS.convert(Math.max(0, getInt("cache.minimum-expiration-frequency")), TimeUnit.SECONDS);
cacheRetention = TimeUnit.MILLISECONDS.convert(Math.max(1, getInt("cache.retention")), TimeUnit.MINUTES);
cacheBatchMax = Math.max(1, getInt("cache.maximum-batch-size"));
cacheBatchDelay = Math.max(0L, getLong("cache.batch-delay"));
cacheMaxSize = Math.max(50_000, getInt("cache.max-cache-size"));

}

public DebugLevel getDebugLevel() {
Expand Down

0 comments on commit 2e6e7ee

Please sign in to comment.