diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java new file mode 100644 index 000000000..bcb2fc9bc --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java @@ -0,0 +1,118 @@ +package mineplex.core.common.objective; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.UUID; + +import org.bukkit.entity.Player; + +/** + * An Objective represents + * + */ +public abstract class Objective +{ + private String _name; + private String _description; + + private HashMap _active; + private List _listeners; + + public Objective(String name, String description) + { + _name = name; + _description = description; + + _active = new HashMap<>(); + _listeners = new LinkedList<>(); + } + + /** + * Get the name of this Objective + */ + public String getName() + { + return _name; + } + + /** + * Get the description of this Objective + */ + public String getDescription() + { + return _description; + } + + /** + * Add an ObjectiveListener to this Objective + * @param listener + */ + public void addListener(ObjectiveListener listener) + { + _listeners.add(listener); + } + + /** + * Remove all ObjectiveListeners from this Objective + */ + public void clearListeners() + { + _listeners.clear(); + } + + /** + * Start this Objective for a player + * @param player + */ + public final void start(Player player) + { + Data data = getData(player); + _active.put(player.getUniqueId(), data); + + _listeners.forEach(listener -> listener.start(player, this)); + + customStart(player); + } + + protected abstract void customStart(Player player); + + /** + * Leave this objective for a specific player + * This does not count as completing the object + * @param player + */ + public final void leave(Player player) + { + _active.remove(player.getUniqueId()); + + customLeave(player); + } + + protected abstract void customLeave(Player player); + + /** + * Returns a new Data object for use in the active map + * @param player + * @return + */ + protected abstract Data getData(Player player); + + /** + * Called by ObjectiveGoals, used to notify this Objective that a goal has been completed + * @param goal + * @param player + */ + protected abstract void completeGoal(ObjectiveGoal goal, Player player); + + protected final void finish(Player player) + { + _active.remove(player.getUniqueId()); + + _listeners.forEach(listener -> listener.finish(player, this)); + + customFinish(player); + } + + protected abstract void customFinish(Player player); +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveData.java new file mode 100644 index 000000000..35a9d72f9 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveData.java @@ -0,0 +1,5 @@ +package mineplex.core.common.objective; + +public class ObjectiveData +{ +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java new file mode 100644 index 000000000..3f4b3c84e --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java @@ -0,0 +1,15 @@ +package mineplex.core.common.objective; + +public abstract class ObjectiveGoal +{ + private Objective _objective; + + private String _name; + private String _description; + + public ObjectiveGoal(Objective objective) + { + + } + +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveListener.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveListener.java new file mode 100644 index 000000000..eb28389b3 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveListener.java @@ -0,0 +1,10 @@ +package mineplex.core.common.objective; + +import org.bukkit.entity.Player; + +public interface ObjectiveListener +{ + public void start(Player player, Objective objective); + + public void finish(Player player, Objective objective); +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Objective.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Objective.java deleted file mode 100644 index af848e3f4..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Objective.java +++ /dev/null @@ -1,7 +0,0 @@ -package mineplex.game.clans.tutorial; - -public class Objective -{ - private String _name; - private String _desc; -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/ObjectiveGroup.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/ObjectiveGroup.java deleted file mode 100644 index ece3f655b..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/ObjectiveGroup.java +++ /dev/null @@ -1,9 +0,0 @@ -package mineplex.game.clans.tutorial; - -import java.util.List; - -public class ObjectiveGroup -{ - private String _name; - private List _objectives; -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java index 3c0ad10e3..06986486a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java @@ -5,6 +5,8 @@ import java.util.List; import org.bukkit.entity.Player; +import mineplex.core.common.objective.Objective; + public class Tutorial { private HashMap _playerSessionMap; @@ -12,5 +14,5 @@ public class Tutorial private String _name; private String _taskIdentifier; - private List _objectiveGroups; + private List _objectiveGroups; }