Fix OrderedObjectives, Starting CombatTutorial work
This commit is contained in:
parent
80d55b2c9c
commit
9884742552
@ -76,16 +76,16 @@ public abstract class Objective<Data extends ObjectiveData> 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<Data extends ObjectiveData> 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<Data extends ObjectiveData> implements Listener
|
||||
return new LinkedList<UUID>(_active.keySet());
|
||||
}
|
||||
|
||||
public Data getData(Player player)
|
||||
{
|
||||
return _active.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister all listeners associated with this Objective
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
|
@ -26,7 +26,7 @@ public abstract class OrderedObjective extends Objective<OrderedObjectiveData>
|
||||
}
|
||||
|
||||
@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>
|
||||
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<ObjectiveGoal> getGoals()
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ public abstract class SingleObjective extends Objective<ObjectiveData>
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ObjectiveData getData(Player player)
|
||||
protected ObjectiveData createDataObject(Player player)
|
||||
{
|
||||
return _nullData;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -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<ClassShopManager>
|
||||
@ -48,6 +50,9 @@ public class ClassCombatShop extends ShopBase<ClassShopManager>
|
||||
|
||||
protected void openShopForPlayer(Player player)
|
||||
{
|
||||
OpenClassShopEvent event = new OpenClassShopEvent(player);
|
||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if (_gameClass != null)
|
||||
getPlugin().GetClassManager().Get(player).SetGameClass(_gameClass);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user