Fix OrderedObjectives, Starting CombatTutorial work

This commit is contained in:
Shaun Bennett 2016-01-19 16:34:51 -05:00
parent 80d55b2c9c
commit 9884742552
9 changed files with 130 additions and 13 deletions

View File

@ -76,16 +76,16 @@ public abstract class Objective<Data extends ObjectiveData> implements Listener
* Start this Objective for a player * Start this Objective for a player
* @param 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); _active.put(player.getUniqueId(), data);
_listeners.forEach(listener -> listener.onObjectiveStart(player, this)); _listeners.forEach(listener -> listener.onObjectiveStart(player, this));
customStart(player); customStart(player);
System.out.println(String.format("Tutorial> [%s] started objective [%s]", player.getName(), getName()));
} }
protected abstract void customStart(Player player); protected abstract void customStart(Player player);
@ -109,7 +109,7 @@ public abstract class Objective<Data extends ObjectiveData> implements Listener
* @param player * @param player
* @return * @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 * Called by ObjectiveGoals, used to notify this Objective that a goal has been completed
@ -152,6 +152,11 @@ public abstract class Objective<Data extends ObjectiveData> implements Listener
return new LinkedList<UUID>(_active.keySet()); return new LinkedList<UUID>(_active.keySet());
} }
public Data getData(Player player)
{
return _active.get(player.getUniqueId());
}
/** /**
* Unregister all listeners associated with this Objective * Unregister all listeners associated with this Objective
*/ */

View File

@ -40,6 +40,8 @@ public abstract class ObjectiveGoal implements Listener
public final void start(Player player) public final void start(Player player)
{ {
System.out.println(String.format("Tutorial> [%s] started objective goal [%s]", player.getName(), getName()));
_active.add(player.getUniqueId()); _active.add(player.getUniqueId());
customStart(player); customStart(player);
} }
@ -52,6 +54,8 @@ public abstract class ObjectiveGoal implements Listener
{ {
if (_active.contains(player.getUniqueId())) if (_active.contains(player.getUniqueId()))
{ {
System.out.println(String.format("Tutorial> [%s] finished objective goal [%s]", player.getName(), getName()));
_active.remove(player.getUniqueId()); _active.remove(player.getUniqueId());
customFinish(player); customFinish(player);

View File

@ -26,7 +26,7 @@ public abstract class OrderedObjective extends Objective<OrderedObjectiveData>
} }
@Override @Override
protected OrderedObjectiveData getData(Player player) protected OrderedObjectiveData createDataObject(Player player)
{ {
return new OrderedObjectiveData(); return new OrderedObjectiveData();
} }
@ -39,19 +39,30 @@ public abstract class OrderedObjective extends Objective<OrderedObjectiveData>
OrderedObjectiveData data = getData(player); OrderedObjectiveData data = getData(player);
assert index == data.getIndex(); assert index == data.getIndex();
if (data.getIndex() >= _goals.size()) if (data.getIndex() + 1 >= _goals.size())
{ {
finish(player); finish(player);
} }
else else
{ {
int nextIndex = data.getIndex() + 1; setGoal(player, data.getIndex() + 1);
ObjectiveGoal nextGoal = _goals.get(nextIndex);
data.setIndex(nextIndex);
nextGoal.start(player);
} }
} }
@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 @Override
protected List<ObjectiveGoal> getGoals() protected List<ObjectiveGoal> getGoals()
{ {

View File

@ -18,7 +18,7 @@ public abstract class SingleObjective extends Objective<ObjectiveData>
} }
@Override @Override
protected ObjectiveData getData(Player player) protected ObjectiveData createDataObject(Player player)
{ {
return _nullData; return _nullData;
} }

View File

@ -6,6 +6,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.Objective; import mineplex.core.common.objective.Objective;
import mineplex.game.clans.tutorial.Tutorial; import mineplex.game.clans.tutorial.Tutorial;
import mineplex.game.clans.tutorial.tutorials.combat.objectives.CustomizeKitObjective;
import mineplex.game.clans.tutorial.tutorials.combat.objectives.EquipArmorObjective; import mineplex.game.clans.tutorial.tutorials.combat.objectives.EquipArmorObjective;
public class CombatTutorial extends Tutorial public class CombatTutorial extends Tutorial
@ -15,6 +16,7 @@ public class CombatTutorial extends Tutorial
super(plugin, "Combat Tutorial", "combat", Material.DIAMOND_SWORD, (byte) 0); super(plugin, "Combat Tutorial", "combat", Material.DIAMOND_SWORD, (byte) 0);
addObjective(new EquipArmorObjective(plugin)); addObjective(new EquipArmorObjective(plugin));
addObjective(new CustomizeKitObjective(plugin));
} }
@Override @Override

View File

@ -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)
{
}
}

View File

@ -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());
}
}
}

View File

@ -1,5 +1,6 @@
package mineplex.minecraft.game.classcombat.shop; package mineplex.minecraft.game.classcombat.shop;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Sound; import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; 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.ClientClass;
import mineplex.minecraft.game.classcombat.Class.IPvpClass; import mineplex.minecraft.game.classcombat.Class.IPvpClass;
import mineplex.minecraft.game.classcombat.Class.repository.token.CustomBuildToken; 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; import mineplex.minecraft.game.classcombat.shop.page.CustomBuildPage;
public class ClassCombatShop extends ShopBase<ClassShopManager> public class ClassCombatShop extends ShopBase<ClassShopManager>
@ -48,6 +50,9 @@ public class ClassCombatShop extends ShopBase<ClassShopManager>
protected void openShopForPlayer(Player player) protected void openShopForPlayer(Player player)
{ {
OpenClassShopEvent event = new OpenClassShopEvent(player);
Bukkit.getServer().getPluginManager().callEvent(event);
if (_gameClass != null) if (_gameClass != null)
getPlugin().GetClassManager().Get(player).SetGameClass(_gameClass); getPlugin().GetClassManager().Get(player).SetGameClass(_gameClass);

View File

@ -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);
}
}