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 85b8ce28e..262c26513 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 @@ -76,16 +76,16 @@ public abstract class Objective implements Listener * Start this Objective for a player * @param player */ - public final void start(Player player) + public void start(Player player) { - Data data = getData(player); + System.out.println(String.format("Tutorial> [%s] started objective [%s]", player.getName(), getName())); + + Data data = createDataObject(player); _active.put(player.getUniqueId(), data); _listeners.forEach(listener -> listener.onObjectiveStart(player, this)); customStart(player); - - System.out.println(String.format("Tutorial> [%s] started objective [%s]", player.getName(), getName())); } protected abstract void customStart(Player player); @@ -109,7 +109,7 @@ public abstract class Objective implements Listener * @param player * @return */ - protected abstract Data getData(Player player); + protected abstract Data createDataObject(Player player); /** * Called by ObjectiveGoals, used to notify this Objective that a goal has been completed @@ -152,6 +152,11 @@ public abstract class Objective implements Listener return new LinkedList(_active.keySet()); } + public Data getData(Player player) + { + return _active.get(player.getUniqueId()); + } + /** * Unregister all listeners associated with this Objective */ 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 b764d56bb..230c73235 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 @@ -40,6 +40,8 @@ public abstract class ObjectiveGoal implements Listener public final void start(Player player) { + System.out.println(String.format("Tutorial> [%s] started objective goal [%s]", player.getName(), getName())); + _active.add(player.getUniqueId()); customStart(player); } @@ -52,6 +54,8 @@ public abstract class ObjectiveGoal implements Listener { if (_active.contains(player.getUniqueId())) { + System.out.println(String.format("Tutorial> [%s] finished objective goal [%s]", player.getName(), getName())); + _active.remove(player.getUniqueId()); customFinish(player); 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 index 896f8c58c..407eb7f6d 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/OrderedObjective.java @@ -26,7 +26,7 @@ public abstract class OrderedObjective extends Objective } @Override - protected OrderedObjectiveData getData(Player player) + protected OrderedObjectiveData createDataObject(Player player) { return new OrderedObjectiveData(); } @@ -39,19 +39,30 @@ public abstract class OrderedObjective extends Objective OrderedObjectiveData data = getData(player); assert index == data.getIndex(); - if (data.getIndex() >= _goals.size()) + if (data.getIndex() + 1 >= _goals.size()) { finish(player); } else { - int nextIndex = data.getIndex() + 1; - ObjectiveGoal nextGoal = _goals.get(nextIndex); - data.setIndex(nextIndex); - nextGoal.start(player); + setGoal(player, data.getIndex() + 1); } } + @Override + protected void customStart(Player player) + { + setGoal(player, 0); + } + + private void setGoal(Player player, int index) + { + OrderedObjectiveData data = getData(player); // Should never be null! + ObjectiveGoal nextGoal = _goals.get(index); + data.setIndex(index); + nextGoal.start(player); + } + @Override protected List getGoals() { diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java index e5d5a9992..0de525913 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/SingleObjective.java @@ -18,7 +18,7 @@ public abstract class SingleObjective extends Objective } @Override - protected ObjectiveData getData(Player player) + protected ObjectiveData createDataObject(Player player) { return _nullData; } 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 index e22a1d42c..f4483be77 100644 --- 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 @@ -6,6 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.common.objective.Objective; import mineplex.game.clans.tutorial.Tutorial; +import mineplex.game.clans.tutorial.tutorials.combat.objectives.CustomizeKitObjective; import mineplex.game.clans.tutorial.tutorials.combat.objectives.EquipArmorObjective; public class CombatTutorial extends Tutorial @@ -15,6 +16,7 @@ public class CombatTutorial extends Tutorial super(plugin, "Combat Tutorial", "combat", Material.DIAMOND_SWORD, (byte) 0); addObjective(new EquipArmorObjective(plugin)); + addObjective(new CustomizeKitObjective(plugin)); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/CustomizeKitObjective.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/CustomizeKitObjective.java new file mode 100644 index 000000000..367129fc1 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/CustomizeKitObjective.java @@ -0,0 +1,35 @@ +package mineplex.game.clans.tutorial.tutorials.combat.objectives; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.common.objective.OrderedObjective; +import mineplex.game.clans.tutorial.tutorials.combat.objectives.goals.OpenCustomizationGoal; + +public class CustomizeKitObjective extends OrderedObjective +{ + public CustomizeKitObjective(JavaPlugin plugin) + { + super(plugin, "Customize Kit", "Customize your kit"); + + addGoal(new OpenCustomizationGoal(this)); + } + + @Override + protected void customStart(Player player) + { + super.customStart(player); + } + + @Override + protected void customLeave(Player player) + { + + } + + @Override + protected void customFinish(Player player) + { + + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/goals/OpenCustomizationGoal.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/goals/OpenCustomizationGoal.java new file mode 100644 index 000000000..7e0b8476d --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/objectives/goals/OpenCustomizationGoal.java @@ -0,0 +1,37 @@ +package mineplex.game.clans.tutorial.tutorials.combat.objectives.goals; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import mineplex.core.common.objective.Objective; +import mineplex.core.common.objective.ObjectiveGoal; +import mineplex.minecraft.game.classcombat.shop.event.OpenClassShopEvent; + +public class OpenCustomizationGoal extends ObjectiveGoal +{ + public OpenCustomizationGoal(Objective objective) + { + super(objective, "Open Customization", "Open Customization"); + } + + @Override + protected void customStart(Player player) + { + + } + + @Override + protected void customFinish(Player player) + { + + } + + @EventHandler + public void onOpenClassShop(OpenClassShopEvent event) + { + if (contains(event.getPlayer())) + { + finish(event.getPlayer()); + } + } +} diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/ClassCombatShop.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/ClassCombatShop.java index 5696309d3..cab66ec23 100644 --- a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/ClassCombatShop.java +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/ClassCombatShop.java @@ -1,5 +1,6 @@ package mineplex.minecraft.game.classcombat.shop; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; @@ -19,6 +20,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.minecraft.game.classcombat.Class.ClientClass; import mineplex.minecraft.game.classcombat.Class.IPvpClass; import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken; +import mineplex.minecraft.game.classcombat.shop.event.OpenClassShopEvent; import mineplex.minecraft.game.classcombat.shop.page.CustomBuildPage; public class ClassCombatShop extends ShopBase @@ -47,7 +49,10 @@ public class ClassCombatShop extends ShopBase } protected void openShopForPlayer(Player player) - { + { + OpenClassShopEvent event = new OpenClassShopEvent(player); + Bukkit.getServer().getPluginManager().callEvent(event); + if (_gameClass != null) getPlugin().GetClassManager().Get(player).SetGameClass(_gameClass); diff --git a/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/event/OpenClassShopEvent.java b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/event/OpenClassShopEvent.java new file mode 100644 index 000000000..cd52d54e1 --- /dev/null +++ b/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/shop/event/OpenClassShopEvent.java @@ -0,0 +1,18 @@ +package mineplex.minecraft.game.classcombat.shop.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +public class OpenClassShopEvent extends PlayerEvent +{ + private static final HandlerList handlers = new HandlerList(); + public static HandlerList getHandlerList() { return handlers; } + public HandlerList getHandlers() { return handlers; } + + public OpenClassShopEvent(Player who) + { + super(who); + } + +}