mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-03-11 22:31:45 +01:00
Adds getDefaultWorldGenerator method to BentoBox
This may help with Multiverse compatibility. May fix https://github.com/BentoBoxWorld/BentoBox/issues/431 Adding as PR because GameMode addons will need changing to new Interface.
This commit is contained in:
parent
4e81baf45e
commit
5b2ad730df
@ -3,11 +3,12 @@ package world.bentobox.bentobox;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.api.configuration.Config;
|
||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||
@ -385,4 +386,12 @@ public class BentoBox extends JavaPlugin {
|
||||
public Optional<BStats> getMetrics() {
|
||||
return Optional.ofNullable(metrics);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.bukkit.plugin.java.JavaPlugin#getDefaultWorldGenerator(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||
return addonsManager.getDefaultWorldGenerator(worldName, id);
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import java.util.Optional;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
@ -59,6 +59,18 @@ public abstract class GameModeAddon extends Addon {
|
||||
return Util.sameWorld(loc.getWorld(), islandWorld);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if world is governed by this game mode
|
||||
* @param world - world to check
|
||||
* @return true if in a world or false if not
|
||||
*/
|
||||
public boolean inWorld(World world) {
|
||||
if (world == null) {
|
||||
return false;
|
||||
}
|
||||
return Util.sameWorld(world, islandWorld);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return over world
|
||||
*/
|
||||
@ -99,4 +111,14 @@ public abstract class GameModeAddon extends Addon {
|
||||
public Optional<CompositeCommand> getAdminCommand() {
|
||||
return Optional.ofNullable(adminCommand);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines the world generator for this game mode
|
||||
* @param worldName - name of world that this applies to
|
||||
* @param id - id if any
|
||||
* @return Chunk generator
|
||||
* @since 1.1
|
||||
*/
|
||||
@NonNull
|
||||
public abstract ChunkGenerator getDefaultWorldGenerator(String worldName, String id);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
|
||||
@ -88,6 +89,7 @@ public class Database<T> {
|
||||
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | SecurityException
|
||||
| IntrospectionException e) {
|
||||
logger.severe(() -> "Could not save object to database! Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -20,9 +20,10 @@ import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.eclipse.jdt.annotation.NonNull;
|
||||
import org.eclipse.jdt.annotation.Nullable;
|
||||
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.addons.AddonClassLoader;
|
||||
@ -107,15 +108,6 @@ public class AddonsManager {
|
||||
try {
|
||||
// Run the onLoad.
|
||||
addon.onLoad();
|
||||
// If this is a GameModeAddon create the worlds, register it and load the schems
|
||||
if (addon instanceof GameModeAddon) {
|
||||
GameModeAddon gameMode = (GameModeAddon) addon;
|
||||
// Create the gameWorlds
|
||||
gameMode.createWorlds();
|
||||
plugin.getIWM().addGameMode(gameMode);
|
||||
// Register the schems
|
||||
plugin.getSchemsManager().loadIslands(gameMode);
|
||||
}
|
||||
|
||||
// Addon successfully loaded
|
||||
addon.setState(Addon.State.LOADED);
|
||||
@ -134,7 +126,18 @@ public class AddonsManager {
|
||||
public void enableAddons() {
|
||||
if (!getLoadedAddons().isEmpty()) {
|
||||
plugin.log("Enabling addons...");
|
||||
|
||||
getLoadedAddons().forEach(addon -> {
|
||||
// If this is a GameModeAddon create the worlds, register it and load the schems
|
||||
if (addon instanceof GameModeAddon) {
|
||||
GameModeAddon gameMode = (GameModeAddon) addon;
|
||||
// Create the gameWorlds
|
||||
gameMode.createWorlds();
|
||||
plugin.getIWM().addGameMode(gameMode);
|
||||
// Register the schems
|
||||
plugin.getSchemsManager().loadIslands(gameMode);
|
||||
}
|
||||
|
||||
try {
|
||||
addon.onEnable();
|
||||
Bukkit.getPluginManager().callEvent(new AddonEvent().builder().addon(addon).reason(AddonEvent.Reason.ENABLE).build());
|
||||
@ -176,6 +179,7 @@ public class AddonsManager {
|
||||
addon.setState(Addon.State.ERROR);
|
||||
plugin.logError("Skipping " + addon.getDescription().getName() + " due to an unhandled exception...");
|
||||
plugin.logError("STACKTRACE: " + throwable.getClass().getSimpleName() + " - " + throwable.getMessage() + " - " + throwable.getCause());
|
||||
throwable.printStackTrace();
|
||||
if (plugin.getConfig().getBoolean("debug")) {
|
||||
plugin.logDebug(throwable.toString());
|
||||
plugin.logDebug(throwable.getStackTrace());
|
||||
@ -351,4 +355,15 @@ public class AddonsManager {
|
||||
addons.clear();
|
||||
addons.addAll(sortedAddons.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the world generator if it exists
|
||||
* @param worldName - name of world
|
||||
* @param id - specific generator id
|
||||
* @return ChunkGenerator or null if none found
|
||||
*/
|
||||
public ChunkGenerator getDefaultWorldGenerator(String worldName, String id) {
|
||||
return getGameModeAddons().stream().filter(gm -> gm.inWorld(Bukkit.getWorld(worldName))).findFirst().map(gm -> gm.getDefaultWorldGenerator(worldName, id)).orElse(null);
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user