Merge branch 'develop' of https://github.com/BentoBoxWorld/BentoBox into develop

This commit is contained in:
Florian CUNY 2019-01-27 09:17:06 +01:00
commit 2b9bdf5cfe
5 changed files with 57 additions and 10 deletions

View File

@ -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;
@ -141,7 +142,6 @@ public class BentoBox extends JavaPlugin {
hooksManager = new HooksManager(this);
hooksManager.registerHook(new VaultHook());
hooksManager.registerHook(new PlaceholderAPIHook());
hooksManager.registerHook(new MultiverseCoreHook());
// Load addons. Addons may load worlds, so they must go before islands are loaded.
addonsManager = new AddonsManager(this);
@ -171,7 +171,9 @@ public class BentoBox extends JavaPlugin {
metrics.registerMetrics();
}
// Register Multiverse hook - MV loads AFTER BentoBox
// Make sure all worlds are already registered to Multiverse.
hooksManager.registerHook(new MultiverseCoreHook());
islandWorldManager.registerWorldsToMultiverse();
// Setup the Placeholders manager
@ -385,4 +387,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);
}
}

View File

@ -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,19 @@ 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
* @since 1.1.1
*/
public boolean inWorld(World world) {
if (world == null) {
return false;
}
return Util.sameWorld(world, islandWorld);
}
/**
* @return over world
*/
@ -99,4 +112,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.1
*/
@NonNull
public abstract ChunkGenerator getDefaultWorldGenerator(String worldName, String id);
}

View File

@ -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;

View File

@ -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;
@ -116,7 +117,6 @@ public class AddonsManager {
// Register the schems
plugin.getSchemsManager().loadIslands(gameMode);
}
// Addon successfully loaded
addon.setState(Addon.State.LOADED);
} catch (NoClassDefFoundError | NoSuchMethodError | NoSuchFieldError e) {
@ -134,6 +134,7 @@ public class AddonsManager {
public void enableAddons() {
if (!getLoadedAddons().isEmpty()) {
plugin.log("Enabling addons...");
getLoadedAddons().forEach(addon -> {
try {
addon.onEnable();
@ -351,4 +352,16 @@ 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
* @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);
}
}

View File

@ -1,12 +1,12 @@
package world.bentobox.bentobox.managers;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.hooks.Hook;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.hooks.Hook;
/**
* @author Poslovitch
*/
@ -25,10 +25,10 @@ public class HooksManager {
plugin.log("Hooking with " + hook.getPluginName() + "...");
if (hook.hook()) {
hooks.add(hook);
} else {
plugin.log("Could not hook with " + hook.getPluginName() + ((hook.getFailureCause() != null) ? " because: " + hook.getFailureCause() : "") + ". Skipping...");
return;
}
}
plugin.log("Could not hook with " + hook.getPluginName() + ((hook.getFailureCause() != null) ? " because: " + hook.getFailureCause() : "") + ". Skipping...");
}
public List<Hook> getHooks() {