Add cleanup and setup

This commit is contained in:
Shaun Bennett 2016-03-25 08:43:37 +11:00
parent 85511b4c26
commit 051539dbf6
29 changed files with 84 additions and 71 deletions

View File

@ -1,5 +0,0 @@
package mineplex.core.common.objective;
public class ObjectiveData
{
}

View File

@ -14,8 +14,8 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveListener;
import mineplex.game.clans.tutorial.objective.Objective;
import mineplex.game.clans.tutorial.objective.ObjectiveListener;
import mineplex.core.common.util.C;
import mineplex.game.clans.message.ClansMessageManager;
@ -60,13 +60,16 @@ public abstract class Tutorial implements Listener, ObjectiveListener
System.out.println(String.format("Tutorial> [%s] started tutorial [%s]", player.getName(), getName()));
TutorialSession session = new TutorialSession();
if (_worldManager != null)
session.setRegion(_worldManager.getNextRegion());
TutorialRegion region = _worldManager == null ? null : _worldManager.getNextRegion();
session.setRegion(region);
_playerSessionMap.put(player, session);
// Start at first objective!
setObjective(player, 0);
onStart(player);
_objectives.forEach(objective -> objective.setup(player, region));
}
private void setObjective(Player player, int objective)
@ -149,6 +152,8 @@ public abstract class Tutorial implements Listener, ObjectiveListener
private void finish(Player player)
{
_objectives.forEach(objective -> objective.clean(player, getRegion(player)));
removePlayer(player);
System.out.println(String.format("Tutorial> [%s] finished tutorial [%s]", player.getName(), getName()));

View File

@ -1,6 +1,5 @@
package mineplex.core.common.objective;
package mineplex.game.clans.tutorial.objective;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@ -13,7 +12,7 @@ import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.tutorial.TutorialRegion;
/**
* An Objective represents a set of goals that need to be completed to move on to the next Objective in the quest
@ -148,6 +147,26 @@ public abstract class Objective<Plugin, Data extends ObjectiveData> implements L
*/
protected abstract void completeGoal(ObjectiveGoal goal, Player player);
/**
* Called when a player is finished the tutorial
* @param player
* @param region
*/
public void clean(Player player, TutorialRegion region)
{
getGoals().forEach(goal -> goal.clean(player, region));
}
/**
* Called when a player starts the tutorial
* @param player
* @param region
*/
public void setup(Player player, TutorialRegion region)
{
getGoals().forEach(goal -> goal.setup(player, region));
}
/**
* Returns a list of all the ObjectiveGoals used by this Objective
* Can return <code>null</code>

View File

@ -0,0 +1,5 @@
package mineplex.game.clans.tutorial.objective;
public class ObjectiveData
{
}

View File

@ -1,4 +1,4 @@
package mineplex.core.common.objective;
package mineplex.game.clans.tutorial.objective;
import java.util.HashSet;
import java.util.Set;
@ -7,6 +7,8 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import mineplex.game.clans.tutorial.TutorialRegion;
public abstract class ObjectiveGoal <T extends Objective> implements Listener
{
private T _objective;
@ -101,6 +103,22 @@ public abstract class ObjectiveGoal <T extends Objective> implements Listener
}
}
/**
* Called when a player starts the tutorial with this goal
*/
protected void setup(Player player, TutorialRegion region)
{
}
/**
* Called when a player finishes the tutorial with this goal
*/
protected void clean(Player player, TutorialRegion region)
{
}
public T getObjective()
{
return _objective;

View File

@ -1,4 +1,4 @@
package mineplex.core.common.objective;
package mineplex.game.clans.tutorial.objective;
import org.bukkit.entity.Player;

View File

@ -1,10 +1,9 @@
package mineplex.core.common.objective;
package mineplex.game.clans.tutorial.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;
import net.md_5.bungee.api.ChatColor;

View File

@ -1,4 +1,4 @@
package mineplex.core.common.objective;
package mineplex.game.clans.tutorial.objective;
public class OrderedObjectiveData extends ObjectiveData
{

View File

@ -1,7 +1,6 @@
package mineplex.core.common.objective;
package mineplex.game.clans.tutorial.objective;
import java.util.List;
import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

View File

@ -3,7 +3,7 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.OrderedObjective;
import mineplex.game.clans.tutorial.objective.OrderedObjective;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan.AttackEnemyGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan.BuildHouseGoal;

View File

@ -3,7 +3,7 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.OrderedObjective;
import mineplex.game.clans.tutorial.objective.OrderedObjective;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.classes.OpenClassManagerGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.classes.UseBullsChargeGoal;

View File

@ -3,10 +3,9 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.OrderedObjective;
import mineplex.game.clans.tutorial.objective.OrderedObjective;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.fields.GoToFieldsGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.fields.KillZombiesGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.fields.MineDiamondsGoal;
public class FieldsObjective extends OrderedObjective<ClansMainTutorial>

View File

@ -3,13 +3,8 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.OrderedObjective;
import mineplex.game.clans.tutorial.objective.OrderedObjective;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan.BuildHouseGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan.ClaimLandGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan.ClanDetailsGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan.CreateClanGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan.SetHomeGoal;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.end.TpClanHomeGoal;
public class FinalObjective extends OrderedObjective<ClansMainTutorial>

View File

@ -1,12 +1,10 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective;
import java.util.Optional;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.SingleObjective;
import mineplex.game.clans.tutorial.objective.SingleObjective;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;

View File

@ -3,7 +3,7 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.objective.OrderedObjective;
import mineplex.game.clans.tutorial.objective.OrderedObjective;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.goals.shops.GoToShopsGoal;

View File

@ -1,18 +1,15 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;

View File

@ -14,8 +14,7 @@ import org.bukkit.inventory.ItemStack;
import com.google.common.collect.Lists;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.ClansManager;

View File

@ -4,12 +4,10 @@ import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilPlayer;

View File

@ -3,7 +3,7 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClansCommandExecutedEvent;

View File

@ -3,10 +3,8 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
import mineplex.game.clans.clans.event.ClanCreationCompleteEvent;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;

View File

@ -3,11 +3,9 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.event.ClanSetHomeEvent;
import mineplex.game.clans.clans.event.ClansCommandPreExecutedEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ClanObjective;

View File

@ -1,13 +1,11 @@
package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.clan;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.Objective;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
public class StealEnemyPotatoesGoal extends ObjectiveGoal
{

View File

@ -5,8 +5,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEvent;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.Objective;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.UtilEvent;
import mineplex.core.common.util.UtilEvent.ActionType;

View File

@ -2,8 +2,8 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.classes;
import org.bukkit.entity.Player;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.Objective;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
public class UseBullsChargeGoal extends ObjectiveGoal
{

View File

@ -3,8 +3,8 @@ package mineplex.game.clans.tutorial.tutorials.clans.objective.goals.end;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.Objective;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.game.clans.clans.event.ClansCommandExecutedEvent;
public class TpClanHomeGoal extends ObjectiveGoal

View File

@ -5,12 +5,10 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.FieldsObjective;

View File

@ -8,8 +8,8 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDeathEvent;
import mineplex.core.common.DefaultHashMap;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.Objective;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
public class KillZombiesGoal extends ObjectiveGoal
{

View File

@ -12,9 +12,7 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.TutorialRegion;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.FieldsObjective;

View File

@ -5,13 +5,10 @@ import java.util.UUID;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import mineplex.core.common.objective.Objective;
import mineplex.core.common.objective.ObjectiveGoal;
import mineplex.game.clans.tutorial.objective.ObjectiveGoal;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.event.ClanCreatedEvent;
import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent;
import mineplex.game.clans.tutorial.tutorials.clans.ClansMainTutorial;
import mineplex.game.clans.tutorial.tutorials.clans.objective.ShopsObjective;