From 7d08a0db5a5661cef2a120a9878d3b75c2dffa05 Mon Sep 17 00:00:00 2001 From: tastybento Date: Tue, 15 Jan 2019 19:33:53 -0800 Subject: [PATCH 1/3] 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. From f381301b25cd4469ce7d7d911d29b48ab44109e9 Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Wed, 16 Jan 2019 18:51:37 +0100 Subject: [PATCH 2/3] Added javadoc tags and NonNull/Nullable in GameModeAddon --- .../bentobox/api/addons/GameModeAddon.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 213eb64bf..c978ebd3e 100644 --- a/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java +++ b/src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java @@ -5,6 +5,9 @@ import java.util.Optional; import org.bukkit.Location; import org.bukkit.World; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; + import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.configuration.WorldSettings; import world.bentobox.bentobox.util.Util; @@ -12,21 +15,26 @@ import world.bentobox.bentobox.util.Util; /** * Defines the addon as a game mode. * A game mode creates worlds, registers world settings and has schems in a jar folder. - * @author tastybento, Postlovitch - * + * @author tastybento, Poslovitch */ public abstract class GameModeAddon extends Addon { protected World islandWorld; + @Nullable protected World netherWorld; + @Nullable protected World endWorld; /** * Main player command. Addons can use this hook to into this command. + * @since 1.1 */ + @Nullable protected CompositeCommand playerCommand; /** * Main admin command. Addons can use this hook to into this command. + * @since 1.1 */ + @Nullable protected CompositeCommand adminCommand; /** @@ -61,6 +69,7 @@ public abstract class GameModeAddon extends Addon { /** * @return nether world, or null if it does not exist */ + @Nullable public World getNetherWorld() { return netherWorld; } @@ -68,20 +77,25 @@ public abstract class GameModeAddon extends Addon { /** * @return end world, or null if it does not exist */ + @Nullable public World getEndWorld() { return endWorld; } /** * @return the main player command for this Game Mode Addon + * @since 1.1 */ + @NonNull public Optional getPlayerCommand() { return Optional.ofNullable(playerCommand); } /** * @return the main admin command for this Game Mode Addon + * @since 1.1 */ + @NonNull public Optional getAdminCommand() { return Optional.ofNullable(adminCommand); } From eeda960d42b8371b3a4fe3a93b3ef1e7803e3d9e Mon Sep 17 00:00:00 2001 From: Florian CUNY Date: Wed, 16 Jan 2019 18:53:11 +0100 Subject: [PATCH 3/3] Use #getEnabledAddons() in AddonsManager#getGameModeAddons() --- .../java/world/bentobox/bentobox/managers/AddonsManager.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java index 85f67532c..38ca21b1b 100644 --- a/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/AddonsManager.java @@ -244,8 +244,7 @@ public class AddonsManager { * @since 1.1 */ public List getGameModeAddons() { - return addons.stream() - .filter(addon -> addon.getState().equals(Addon.State.ENABLED)) + return getEnabledAddons().stream() .filter(GameModeAddon.class::isInstance) .map(GameModeAddon.class::cast) .collect(Collectors.toList());