mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-20 23:21:33 +01:00
Merge pull request #491 from BentoBoxWorld/startup
Adds getDefaultWorldGenerator method to BentoBox
This commit is contained in:
commit
088adbfc71
@ -3,11 +3,12 @@ package world.bentobox.bentobox;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
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.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.configuration.Config;
|
import world.bentobox.bentobox.api.configuration.Config;
|
||||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
@ -141,7 +142,6 @@ public class BentoBox extends JavaPlugin {
|
|||||||
hooksManager = new HooksManager(this);
|
hooksManager = new HooksManager(this);
|
||||||
hooksManager.registerHook(new VaultHook());
|
hooksManager.registerHook(new VaultHook());
|
||||||
hooksManager.registerHook(new PlaceholderAPIHook());
|
hooksManager.registerHook(new PlaceholderAPIHook());
|
||||||
hooksManager.registerHook(new MultiverseCoreHook());
|
|
||||||
|
|
||||||
// Load addons. Addons may load worlds, so they must go before islands are loaded.
|
// Load addons. Addons may load worlds, so they must go before islands are loaded.
|
||||||
addonsManager = new AddonsManager(this);
|
addonsManager = new AddonsManager(this);
|
||||||
@ -171,7 +171,9 @@ public class BentoBox extends JavaPlugin {
|
|||||||
metrics.registerMetrics();
|
metrics.registerMetrics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Register Multiverse hook - MV loads AFTER BentoBox
|
||||||
// Make sure all worlds are already registered to Multiverse.
|
// Make sure all worlds are already registered to Multiverse.
|
||||||
|
hooksManager.registerHook(new MultiverseCoreHook());
|
||||||
islandWorldManager.registerWorldsToMultiverse();
|
islandWorldManager.registerWorldsToMultiverse();
|
||||||
|
|
||||||
// Setup the Placeholders manager
|
// Setup the Placeholders manager
|
||||||
@ -385,4 +387,12 @@ public class BentoBox extends JavaPlugin {
|
|||||||
public Optional<BStats> getMetrics() {
|
public Optional<BStats> getMetrics() {
|
||||||
return Optional.ofNullable(metrics);
|
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.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
@ -59,6 +59,19 @@ public abstract class GameModeAddon extends Addon {
|
|||||||
return Util.sameWorld(loc.getWorld(), islandWorld);
|
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
|
||||||
|
* @since 1.1.1
|
||||||
|
*/
|
||||||
|
public boolean inWorld(World world) {
|
||||||
|
if (world == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Util.sameWorld(world, islandWorld);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return over world
|
* @return over world
|
||||||
*/
|
*/
|
||||||
@ -99,4 +112,14 @@ public abstract class GameModeAddon extends Addon {
|
|||||||
public Optional<CompositeCommand> getAdminCommand() {
|
public Optional<CompositeCommand> getAdminCommand() {
|
||||||
return Optional.ofNullable(adminCommand);
|
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.1
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
public abstract ChunkGenerator getDefaultWorldGenerator(String worldName, String id);
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
|
|
||||||
|
@ -20,9 +20,10 @@ import java.util.stream.Collectors;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.eclipse.jdt.annotation.NonNull;
|
import org.eclipse.jdt.annotation.NonNull;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.addons.Addon;
|
import world.bentobox.bentobox.api.addons.Addon;
|
||||||
import world.bentobox.bentobox.api.addons.AddonClassLoader;
|
import world.bentobox.bentobox.api.addons.AddonClassLoader;
|
||||||
@ -116,7 +117,6 @@ public class AddonsManager {
|
|||||||
// Register the schems
|
// Register the schems
|
||||||
plugin.getSchemsManager().loadIslands(gameMode);
|
plugin.getSchemsManager().loadIslands(gameMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Addon successfully loaded
|
// Addon successfully loaded
|
||||||
addon.setState(Addon.State.LOADED);
|
addon.setState(Addon.State.LOADED);
|
||||||
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
|
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
|
||||||
@ -134,6 +134,7 @@ public class AddonsManager {
|
|||||||
public void enableAddons() {
|
public void enableAddons() {
|
||||||
if (!getLoadedAddons().isEmpty()) {
|
if (!getLoadedAddons().isEmpty()) {
|
||||||
plugin.log("Enabling addons...");
|
plugin.log("Enabling addons...");
|
||||||
|
|
||||||
getLoadedAddons().forEach(addon -> {
|
getLoadedAddons().forEach(addon -> {
|
||||||
try {
|
try {
|
||||||
addon.onEnable();
|
addon.onEnable();
|
||||||
@ -351,4 +352,16 @@ public class AddonsManager {
|
|||||||
addons.clear();
|
addons.clear();
|
||||||
addons.addAll(sortedAddons.values());
|
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
|
||||||
|
* @since 1.1.1
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package world.bentobox.bentobox.managers;
|
package world.bentobox.bentobox.managers;
|
||||||
|
|
||||||
import world.bentobox.bentobox.BentoBox;
|
|
||||||
import world.bentobox.bentobox.api.hooks.Hook;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.BentoBox;
|
||||||
|
import world.bentobox.bentobox.api.hooks.Hook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Poslovitch
|
* @author Poslovitch
|
||||||
*/
|
*/
|
||||||
@ -25,10 +25,10 @@ public class HooksManager {
|
|||||||
plugin.log("Hooking with " + hook.getPluginName() + "...");
|
plugin.log("Hooking with " + hook.getPluginName() + "...");
|
||||||
if (hook.hook()) {
|
if (hook.hook()) {
|
||||||
hooks.add(hook);
|
hooks.add(hook);
|
||||||
} else {
|
return;
|
||||||
plugin.log("Could not hook with " + hook.getPluginName() + ((hook.getFailureCause() != null) ? " because: " + hook.getFailureCause() : "") + ". Skipping...");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
plugin.log("Could not hook with " + hook.getPluginName() + ((hook.getFailureCause() != null) ? " because: " + hook.getFailureCause() : "") + ". Skipping...");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Hook> getHooks() {
|
public List<Hook> getHooks() {
|
||||||
|
Loading…
Reference in New Issue
Block a user