More work and refactoring on the tutorial
This commit is contained in:
parent
0da28faab8
commit
ce8586e5c5
@ -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<Data extends ObjectiveData>
|
||||
{
|
||||
private String _name;
|
||||
private String _description;
|
||||
|
||||
private HashMap<UUID, Data> _active;
|
||||
private List<ObjectiveListener> _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);
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package mineplex.core.common.objective;
|
||||
|
||||
public class ObjectiveData
|
||||
{
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package mineplex.game.clans.tutorial;
|
||||
|
||||
public class Objective
|
||||
{
|
||||
private String _name;
|
||||
private String _desc;
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
package mineplex.game.clans.tutorial;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ObjectiveGroup
|
||||
{
|
||||
private String _name;
|
||||
private List<Objective> _objectives;
|
||||
}
|
@ -5,6 +5,8 @@ import java.util.List;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.common.objective.Objective;
|
||||
|
||||
public class Tutorial
|
||||
{
|
||||
private HashMap<Player, TutorialSession> _playerSessionMap;
|
||||
@ -12,5 +14,5 @@ public class Tutorial
|
||||
private String _name;
|
||||
private String _taskIdentifier;
|
||||
|
||||
private List<ObjectiveGroup> _objectiveGroups;
|
||||
private List<Objective> _objectiveGroups;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user