mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 11:45:31 +01:00
Added Multiverse-Core Hook
This commit is contained in:
parent
3f62e2f367
commit
f8d1626ba5
@ -12,6 +12,7 @@ import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
|
||||
import world.bentobox.bentobox.api.user.Notifier;
|
||||
import world.bentobox.bentobox.commands.BentoBoxCommand;
|
||||
import world.bentobox.bentobox.hooks.MultiverseCoreHook;
|
||||
import world.bentobox.bentobox.hooks.PlaceholderAPIHook;
|
||||
import world.bentobox.bentobox.hooks.VaultHook;
|
||||
import world.bentobox.bentobox.listeners.BannedVisitorCommands;
|
||||
@ -109,15 +110,15 @@ public class BentoBox extends JavaPlugin {
|
||||
new BentoBoxCommand();
|
||||
|
||||
// Start Island Worlds Manager
|
||||
islandWorldManager = new IslandWorldManager(instance);
|
||||
islandWorldManager = new IslandWorldManager(this);
|
||||
// Load schems manager
|
||||
schemsManager = new SchemsManager(instance);
|
||||
schemsManager = new SchemsManager(this);
|
||||
|
||||
// Locales manager must be loaded before addons
|
||||
localesManager = new LocalesManager(instance);
|
||||
localesManager = new LocalesManager(this);
|
||||
|
||||
// Load addons. Addons may load worlds, so they must go before islands are loaded.
|
||||
addonsManager = new AddonsManager(instance);
|
||||
addonsManager = new AddonsManager(this);
|
||||
addonsManager.loadAddons();
|
||||
// Enable addons
|
||||
addonsManager.enableAddons();
|
||||
@ -135,7 +136,7 @@ public class BentoBox extends JavaPlugin {
|
||||
islandsManager.save(true);
|
||||
}, getSettings().getDatabaseBackupPeriod() * 20 * 60L, getSettings().getDatabaseBackupPeriod() * 20 * 60L);
|
||||
|
||||
// Make sure all flag listeners are ready.
|
||||
// Make sure all flag listeners are registered.
|
||||
flagsManager.registerListeners();
|
||||
|
||||
// Load metrics
|
||||
@ -148,6 +149,10 @@ public class BentoBox extends JavaPlugin {
|
||||
hooksManager = new HooksManager(this);
|
||||
hooksManager.registerHook(new VaultHook());
|
||||
hooksManager.registerHook(new PlaceholderAPIHook());
|
||||
hooksManager.registerHook(new MultiverseCoreHook());
|
||||
|
||||
// Make sure all worlds are already registered to Multiverse.
|
||||
islandWorldManager.registerWorldsToMultiverse();
|
||||
|
||||
// Setup the Placeholders manager
|
||||
placeholdersManager = new PlaceholdersManager(this);
|
||||
|
@ -0,0 +1,36 @@
|
||||
package world.bentobox.bentobox.hooks;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import world.bentobox.bentobox.BentoBox;
|
||||
import world.bentobox.bentobox.api.hooks.Hook;
|
||||
|
||||
/**
|
||||
* Provides implementation and interfacing to interact with Multiverse.
|
||||
*
|
||||
* @author Poslovitch
|
||||
*/
|
||||
public class MultiverseCoreHook extends Hook {
|
||||
|
||||
private static final String MULTIVERSE_SET_GENERATOR = "mv modify set generator ";
|
||||
private static final String MULTIVERSE_IMPORT = "mv import ";
|
||||
|
||||
public MultiverseCoreHook() {
|
||||
super("Multiverse-Core");
|
||||
}
|
||||
|
||||
public void registerWorld(World world) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), MULTIVERSE_IMPORT + world.getName() + " normal -g " + BentoBox.getInstance().getName());
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), MULTIVERSE_SET_GENERATOR + BentoBox.getInstance().getName() + " " + world.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hook() {
|
||||
return true; // The hook process shouldn't fail
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFailureCause() {
|
||||
return null; // The hook process shouldn't fail
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import world.bentobox.bentobox.api.addons.Addon;
|
||||
import world.bentobox.bentobox.api.configuration.WorldSettings;
|
||||
import world.bentobox.bentobox.api.flags.Flag;
|
||||
import world.bentobox.bentobox.api.user.User;
|
||||
import world.bentobox.bentobox.hooks.MultiverseCoreHook;
|
||||
import world.bentobox.bentobox.lists.Flags;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
@ -32,8 +33,6 @@ import world.bentobox.bentobox.util.Util;
|
||||
*/
|
||||
public class IslandWorldManager {
|
||||
|
||||
private static final String MULTIVERSE_SET_GENERATOR = "mv modify set generator ";
|
||||
private static final String MULTIVERSE_IMPORT = "mv import ";
|
||||
private static final String NETHER = "_nether";
|
||||
private static final String THE_END = "_the_end";
|
||||
|
||||
@ -50,23 +49,18 @@ public class IslandWorldManager {
|
||||
worldSettings = new HashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a world with Multiverse if the plugin exists
|
||||
*
|
||||
* @param world
|
||||
* - world
|
||||
*/
|
||||
private void multiverseReg(World world) {
|
||||
if (!isUseOwnGenerator(world) && Bukkit.getServer().getPluginManager().isPluginEnabled("Multiverse-Core")) {
|
||||
Bukkit.getScheduler().runTask(plugin,
|
||||
() -> Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||
MULTIVERSE_IMPORT + world.getName() + " normal -g " + plugin.getName()));
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
if (!Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||
MULTIVERSE_SET_GENERATOR + plugin.getName() + " " + world.getName())) {
|
||||
plugin.logError("Multiverse is out of date! - Upgrade to latest version!");
|
||||
public void registerWorldsToMultiverse() {
|
||||
worlds.forEach((world, s) -> registerToMultiverse(world));
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Registers a world with Multiverse if Multiverse is available.
|
||||
*
|
||||
* @param world the World to register
|
||||
*/
|
||||
private void registerToMultiverse(World world) {
|
||||
if (!isUseOwnGenerator(world)) {
|
||||
plugin.getHooks().getHook("Multiverse-Core").ifPresent(hook -> ((MultiverseCoreHook) hook).registerWorld(world));
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +139,7 @@ public class IslandWorldManager {
|
||||
worlds.put(world, friendlyName);
|
||||
worldSettings.put(world, settings);
|
||||
// Call Multiverse
|
||||
multiverseReg(world);
|
||||
registerToMultiverse(world);
|
||||
// Set default island settings
|
||||
Flags.values().stream().filter(f -> f.getType().equals(Flag.Type.PROTECTION))
|
||||
.forEach(f -> settings.getDefaultIslandFlags().putIfAbsent(f, f.getDefaultRank()));
|
||||
|
Loading…
Reference in New Issue
Block a user