From 7d08a0db5a5661cef2a120a9878d3b75c2dffa05 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 15 Jan 2019 19:33:53 -0800 Subject: [PATCH] Enable main player and admin command declaration See https://github.com/BentoBoxWorld/BentoBox/issues/448 --- .../bentobox/api/addons/GameModeAddon.java | 23 +++++++++++++++++++ .../bentobox/managers/AddonsManager.java | 12 ++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java b/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java index 37940bfeb..213eb64bf 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java @@ -1,8 +1,11 @@ package world.bentobox.bentobox.api.addons; +import java.util.Optional; + import org.bukkit.Location; import org.bukkit.World; +import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.util.Util; @@ -17,6 +20,14 @@ public abstract class GameModeAddon extends Addon { protected World islandWorld; protected World netherWorld; protected World endWorld; + /** + * Main player command. Addons can use this hook to into this command. + */ + protected CompositeCommand playerCommand; + /** + * Main admin command. Addons can use this hook to into this command. + */ + protected CompositeCommand adminCommand; /** * Make the worlds for this GameMode in this method. BentoBox will call it @@ -61,5 +72,17 @@ public abstract class GameModeAddon extends Addon { return endWorld; } + /** + * @return the main player command for this Game Mode Addon + */ + public Optional getPlayerCommand() { + return Optional.ofNullable(playerCommand); + } + /** + * @return the main admin command for this Game Mode Addon + */ + public Optional getAdminCommand() { + return Optional.ofNullable(adminCommand); + } } diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 59062b1a5..85f67532c 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -239,6 +239,18 @@ public class AddonsManager { return addons; } + /** + * @return List of enabled game mode addons + * @since 1.1 + */ + public List getGameModeAddons() { + return addons.stream() + .filter(addon -> addon.getState().equals(Addon.State.ENABLED)) + .filter(GameModeAddon.class::isInstance) + .map(GameModeAddon.class::cast) + .collect(Collectors.toList()); + } + /** * Gets the list of Addons that are loaded. * @return list of loaded Addons.