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 index bcb2fc9bc..a604a51a5 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java @@ -6,6 +6,7 @@ import java.util.List; import java.util.UUID; import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; /** * An Objective represents @@ -13,14 +14,16 @@ import org.bukkit.entity.Player; */ public abstract class Objective { + private JavaPlugin _plugin; private String _name; private String _description; private HashMap _active; private List _listeners; - public Objective(String name, String description) + public Objective(JavaPlugin plugin, String name, String description) { + _plugin = plugin; _name = name; _description = description; @@ -28,6 +31,11 @@ public abstract class Objective _listeners = new LinkedList<>(); } + public JavaPlugin getPlugin() + { + return _plugin; + } + /** * Get the name of this Objective */ @@ -70,7 +78,7 @@ public abstract class Objective Data data = getData(player); _active.put(player.getUniqueId(), data); - _listeners.forEach(listener -> listener.start(player, this)); + _listeners.forEach(listener -> listener.startObjective(player, this)); customStart(player); } @@ -109,10 +117,15 @@ public abstract class Objective { _active.remove(player.getUniqueId()); - _listeners.forEach(listener -> listener.finish(player, this)); + _listeners.forEach(listener -> listener.finishObjective(player, this)); customFinish(player); } protected abstract void customFinish(Player player); + + /** + * Unregister all listeners associated with this Objective + */ + public abstract void unregisterAll(); } 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 index 3f4b3c84e..daf666624 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveGoal.java @@ -1,15 +1,40 @@ package mineplex.core.common.objective; -public abstract class ObjectiveGoal +import java.util.HashSet; +import java.util.UUID; + +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +public abstract class ObjectiveGoal implements Listener { private Objective _objective; + private HashSet _active; private String _name; private String _description; - public ObjectiveGoal(Objective objective) + public ObjectiveGoal(Objective objective, String name, String description) { + _objective = objective; + _active = new HashSet<>(); + _name = name; + _description = description; } + public String getName() + { + return _name; + } + + public String getDescription() + { + return _description; + } + + public boolean contains(Player player) + { + return _active.contains(player.getUniqueId()); + } } 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 index eb28389b3..eb4f08287 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveListener.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/ObjectiveListener.java @@ -4,7 +4,7 @@ import org.bukkit.entity.Player; public interface ObjectiveListener { - public void start(Player player, Objective objective); + public void startObjective(Player player, Objective objective); - public void finish(Player player, Objective objective); + public void finishObjective(Player player, Objective objective); } diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java new file mode 100644 index 000000000..e31560f3a --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java @@ -0,0 +1,63 @@ +package mineplex.core.common.objective; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.plugin.java.JavaPlugin; + +public class OrderedObjective extends Objective +{ + private List _goals; + + public OrderedObjective(JavaPlugin plugin, String name, String description) + { + super(plugin, name, description); + + _goals = new ArrayList<>(); + } + + private void addGoal(ObjectiveGoal goal) + { + _goals.add(goal); + + getPlugin().getServer().getPluginManager().registerEvents(goal, getPlugin()); + } + + @Override + protected void customStart(Player player) + { + + } + + @Override + protected void customLeave(Player player) + { + + } + + @Override + protected OrderedObjectiveData getData(Player player) + { + return new OrderedObjectiveData(); + } + + @Override + protected void completeGoal(ObjectiveGoal goal, Player player) + { + + } + + @Override + protected void customFinish(Player player) + { + + } + + @Override + public void unregisterAll() + { + _goals.forEach(HandlerList::unregisterAll); + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjectiveData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjectiveData.java new file mode 100644 index 000000000..4d1201796 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjectiveData.java @@ -0,0 +1,11 @@ +package mineplex.core.common.objective; + +public class OrderedObjectiveData extends ObjectiveData +{ + private int _index; + + public OrderedObjectiveData() + { + _index = 0; + } +} 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 06986486a..1b757fec1 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 @@ -1,18 +1,75 @@ package mineplex.game.clans.tutorial; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.objective.Objective; +import mineplex.core.common.objective.ObjectiveListener; -public class Tutorial +public abstract class Tutorial implements Listener, ObjectiveListener { private HashMap _playerSessionMap; + private JavaPlugin _plugin; private String _name; private String _taskIdentifier; - private List _objectiveGroups; + private List _objectives; + + public Tutorial(JavaPlugin plugin, String name, String taskIdentifier) + { + _plugin = plugin; + _name = name; + _taskIdentifier = taskIdentifier; + + _objectives = new ArrayList<>(); + } + + protected void addObjective(Objective objective) + { + _objectives.add(objective); + } + + public void start(Player player) + { + _playerSessionMap.put(player, new TutorialSession()); + } + + public boolean isInTutorial(Player player) + { + return _playerSessionMap.containsKey(player); + } + + public JavaPlugin getPlugin() + { + return _plugin; + } + + public String getName() + { + return _name; + } + + public final String getTaskIdentifier() + { + return "clans.tutorial." + _taskIdentifier; + } + + @Override + public void finishObjective(Player player, Objective objective) + { + int index = _objectives.indexOf(objective); + } + + public void unregisterAll() + { + HandlerList.unregisterAll(this); + _objectives.forEach(Objective::unregisterAll); + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java index d59e4e819..40b9a0562 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java @@ -1,15 +1,58 @@ package mineplex.game.clans.tutorial; +import java.util.EnumMap; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.game.clans.tutorial.tutorials.combat.CombatTutorial; public class TutorialManager extends MiniPlugin { + private EnumMap _tutorialMap; + public TutorialManager(JavaPlugin plugin) { super("Clans Tutorial", plugin); + + _tutorialMap = new EnumMap(TutorialType.class); + + addTutorial(TutorialType.COMBAT, new CombatTutorial()); } + private void addTutorial(TutorialType type, Tutorial tutorial) + { + if (_tutorialMap.containsKey(type)) + { + _tutorialMap.remove(type).unregisterAll(); + } + + _tutorialMap.put(type, tutorial); + getPlugin().getServer().getPluginManager().registerEvents(tutorial, getPlugin()); + } + + public boolean inTutorial(Player player) + { + for (Tutorial tutorial : _tutorialMap.values()) + { + if (tutorial.isInTutorial(player)) + return true; + } + + return false; + } + + public boolean startTutorial(Player player, TutorialType type) + { + if (_tutorialMap.containsKey(type)) + { + _tutorialMap.get(type).start(player); + return true; + } + + return false; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java index 0a7e984d2..925e70cd3 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialSession.java @@ -2,6 +2,10 @@ package mineplex.game.clans.tutorial; public class TutorialSession { - private int _objectiveGroupIndex; private int _objectiveIndex; + + public TutorialSession() + { + + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialType.java new file mode 100644 index 000000000..93d5b38fe --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialType.java @@ -0,0 +1,6 @@ +package mineplex.game.clans.tutorial; + +public enum TutorialType +{ + COMBAT +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java new file mode 100644 index 000000000..f190dc220 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java @@ -0,0 +1,13 @@ +package mineplex.game.clans.tutorial.tutorials.combat; + +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.game.clans.tutorial.Tutorial; + +public class CombatTutorial extends Tutorial +{ + public CombatTutorial(JavaPlugin plugin) + { + super(plugin, "Combat Tutorial", "combat"); + } +}