mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-03-13 07:09:10 +01:00
Waits until blueprints loaded before firing BentoBoxReady event
https://github.com/BentoBoxWorld/BentoBox/issues/985
This commit is contained in:
parent
2484421d92
commit
595de7a602
@ -9,6 +9,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
@ -89,6 +90,8 @@ public class BentoBox extends JavaPlugin {
|
|||||||
|
|
||||||
private Config<Settings> configObject;
|
private Config<Settings> configObject;
|
||||||
|
|
||||||
|
private BukkitTask blueprintLoadingTask;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable(){
|
public void onEnable(){
|
||||||
if (!ServerCompatibility.getInstance().checkCompatibility().isCanLaunch()) {
|
if (!ServerCompatibility.getInstance().checkCompatibility().isCanLaunch()) {
|
||||||
@ -163,7 +166,7 @@ public class BentoBox extends JavaPlugin {
|
|||||||
|
|
||||||
final long loadTime = System.currentTimeMillis() - loadStart;
|
final long loadTime = System.currentTimeMillis() - loadStart;
|
||||||
|
|
||||||
getServer().getScheduler().runTask(instance, () -> {
|
Bukkit.getScheduler().runTask(instance, () -> {
|
||||||
final long enableStart = System.currentTimeMillis();
|
final long enableStart = System.currentTimeMillis();
|
||||||
hooksManager.registerHook(new PlaceholderAPIHook());
|
hooksManager.registerHook(new PlaceholderAPIHook());
|
||||||
hooksManager.registerHook(new MVdWPlaceholderAPIHook());
|
hooksManager.registerHook(new MVdWPlaceholderAPIHook());
|
||||||
@ -183,7 +186,7 @@ public class BentoBox extends JavaPlugin {
|
|||||||
islandsManager.load();
|
islandsManager.load();
|
||||||
|
|
||||||
// Save islands & players data every X minutes
|
// Save islands & players data every X minutes
|
||||||
instance.getServer().getScheduler().runTaskTimer(instance, () -> {
|
Bukkit.getScheduler().runTaskTimer(instance, () -> {
|
||||||
playersManager.asyncSaveAll();
|
playersManager.asyncSaveAll();
|
||||||
islandsManager.asyncSaveAll();
|
islandsManager.asyncSaveAll();
|
||||||
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
|
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
|
||||||
@ -215,11 +218,18 @@ public class BentoBox extends JavaPlugin {
|
|||||||
TextVariables.VERSION, instance.getDescription().getVersion(),
|
TextVariables.VERSION, instance.getDescription().getVersion(),
|
||||||
"[time]", String.valueOf(loadTime + enableTime));
|
"[time]", String.valueOf(loadTime + enableTime));
|
||||||
|
|
||||||
|
// Poll for blueprints loading to be finished - async so could be a completely variable time
|
||||||
|
blueprintLoadingTask = Bukkit.getScheduler().runTaskTimer(instance, () -> {
|
||||||
|
if (getBlueprintsManager().isBlueprintsLoaded()) {
|
||||||
|
blueprintLoadingTask.cancel();
|
||||||
// Tell all addons that everything is loaded
|
// Tell all addons that everything is loaded
|
||||||
isLoaded = true;
|
isLoaded = true;
|
||||||
this.addonsManager.allLoaded();
|
this.addonsManager.allLoaded();
|
||||||
// Fire plugin ready event - this should go last after everything else
|
// Fire plugin ready event - this should go last after everything else
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
Bukkit.getServer().getPluginManager().callEvent(new BentoBoxReadyEvent());
|
||||||
|
instance.log("All blueprints loaded.");
|
||||||
|
}
|
||||||
|
}, 0L, 1L);
|
||||||
|
|
||||||
if (getSettings().getDatabaseType().equals(DatabaseSetup.DatabaseType.YAML)) {
|
if (getSettings().getDatabaseType().equals(DatabaseSetup.DatabaseType.YAML)) {
|
||||||
logWarning("*** You're still using YAML database ! ***");
|
logWarning("*** You're still using YAML database ! ***");
|
||||||
|
@ -11,9 +11,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -79,6 +81,8 @@ public class BlueprintsManager {
|
|||||||
|
|
||||||
private @NonNull BentoBox plugin;
|
private @NonNull BentoBox plugin;
|
||||||
|
|
||||||
|
private @NonNull Set<GameModeAddon> blueprintsLoaded;
|
||||||
|
|
||||||
|
|
||||||
public BlueprintsManager(@NonNull BentoBox plugin) {
|
public BlueprintsManager(@NonNull BentoBox plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -100,6 +104,8 @@ public class BlueprintsManager {
|
|||||||
// Register adapter factory
|
// Register adapter factory
|
||||||
builder.registerTypeAdapterFactory(new BentoboxTypeAdapterFactory(plugin));
|
builder.registerTypeAdapterFactory(new BentoboxTypeAdapterFactory(plugin));
|
||||||
gson = builder.create();
|
gson = builder.create();
|
||||||
|
// Loaded tracker
|
||||||
|
blueprintsLoaded = new HashSet<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -172,10 +178,13 @@ public class BlueprintsManager {
|
|||||||
* @param addon the {@link GameModeAddon} to load the blueprints of.
|
* @param addon the {@link GameModeAddon} to load the blueprints of.
|
||||||
*/
|
*/
|
||||||
public void loadBlueprintBundles(@NonNull GameModeAddon addon) {
|
public void loadBlueprintBundles(@NonNull GameModeAddon addon) {
|
||||||
|
// Set loading flag
|
||||||
|
blueprintsLoaded.add(addon);
|
||||||
Bukkit
|
Bukkit
|
||||||
.getScheduler()
|
.getScheduler()
|
||||||
.runTaskAsynchronously(
|
.runTaskAsynchronously(
|
||||||
plugin, () -> {
|
plugin, () -> {
|
||||||
|
// Load bundles
|
||||||
blueprintBundles.put(addon, new ArrayList<>());
|
blueprintBundles.put(addon, new ArrayList<>());
|
||||||
// See if there are any schems that need converting
|
// See if there are any schems that need converting
|
||||||
new SchemToBlueprint(plugin).convertSchems(addon);
|
new SchemToBlueprint(plugin).convertSchems(addon);
|
||||||
@ -185,9 +194,20 @@ public class BlueprintsManager {
|
|||||||
}
|
}
|
||||||
// Load blueprints
|
// Load blueprints
|
||||||
loadBlueprints(addon);
|
loadBlueprints(addon);
|
||||||
|
|
||||||
|
// Clear loading flag
|
||||||
|
blueprintsLoaded.remove(addon);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if all blueprints are loaded. Only query after all GameModes have been loaded.
|
||||||
|
* @return true if all blueprints are loaded
|
||||||
|
*/
|
||||||
|
public boolean isBlueprintsLoaded() {
|
||||||
|
return blueprintsLoaded.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
private boolean loadBundles(@NonNull GameModeAddon addon) {
|
private boolean loadBundles(@NonNull GameModeAddon addon) {
|
||||||
File bpf = getBlueprintsFolder(addon);
|
File bpf = getBlueprintsFolder(addon);
|
||||||
if (!bpf.exists()) {
|
if (!bpf.exists()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user