some Tutorial code cleanup

This commit is contained in:
NewGarbo 2015-11-04 00:07:32 +00:00
parent 4bf92ce0a0
commit a455804dce
9 changed files with 71 additions and 95 deletions

View File

@ -15,9 +15,6 @@ import mineplex.core.shop.item.IButton;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
import mineplex.game.clans.clans.event.ClansPlayerBuyItemEvent; import mineplex.game.clans.clans.event.ClansPlayerBuyItemEvent;
import mineplex.game.clans.economy.GoldManager; import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.tutorials.TutorialManager;
import mineplex.game.clans.tutorials.TutorialType;
import mineplex.game.clans.tutorials.types.TutorialGettingStarted;
public class ShopItemButton<T extends ShopPageBase<?, ?>> implements IButton public class ShopItemButton<T extends ShopPageBase<?, ?>> implements IButton
{ {

View File

@ -47,19 +47,20 @@ public abstract class Tutorial implements ScoreboardElement, Listener
private final HashMap<Integer, TutorialTask> _tasks; private final HashMap<Integer, TutorialTask> _tasks;
private final HashMap<String, TutorialTask> _nameToTask; private final HashMap<String, TutorialTask> _nameToTask;
protected final HashMap<String, TutorialClient> _inTutorial; protected final HashMap<String, TutorialClient> _inTutorial;
private final TutorialType _type;
protected boolean _doScoreboard; protected boolean _doScoreboard;
protected boolean _ghostMode; protected boolean _ghostMode;
public Tutorial(final int rewardAmount, final GoldManager goldManager, final TaskManager taskManager, final ClansManager clansManager, final TutorialManager manager, final TutorialType type) protected String _uniqueId;
protected String _friendlyName;
public Tutorial(final int rewardAmount, final GoldManager goldManager, final TaskManager taskManager, final ClansManager clansManager, final TutorialManager manager)
{ {
_clansManager = clansManager; _clansManager = clansManager;
_goldManager = goldManager; _goldManager = goldManager;
_taskManager = taskManager; _taskManager = taskManager;
_rewardAmount = rewardAmount; _rewardAmount = rewardAmount;
_manager = manager; _manager = manager;
_type = type;
_tasks = new HashMap<>(); _tasks = new HashMap<>();
_inTutorial = new HashMap<>(); _inTutorial = new HashMap<>();
_nameToTask = new HashMap<>(); _nameToTask = new HashMap<>();
@ -80,21 +81,21 @@ public abstract class Tutorial implements ScoreboardElement, Listener
final TutorialClient ptutorial = _inTutorial.get(player.getName()); final TutorialClient ptutorial = _inTutorial.get(player.getName());
lines.add(C.cAqua + _type.getFriendlyName() + " Tutorial"); lines.add(C.cAqua + _friendlyName + " Tutorial");
for (final TutorialTask task : _tasks.values()) for (final TutorialTask task : _tasks.values())
{ {
if (get(player).getCurrentTask() == task.getID()) if (get(player).getCurrentTask() == task.getID())
{ {
lines.add(C.cDAqua + task.getID() + ". " + task.getName()); lines.add(C.cDAqua + task.getID() + ". " + task.getFriendlyName());
} }
else if (ptutorial.hasFinishedTask(task)) else if (ptutorial.hasFinishedTask(task))
{ {
lines.add(C.cGreen + task.getID() + ". " + task.getName()); lines.add(C.cGreen + task.getID() + ". " + task.getFriendlyName());
} }
else else
{ {
lines.add(C.cRed + task.getID() + ". " + task.getName()); lines.add(C.cRed + task.getID() + ". " + task.getFriendlyName());
} }
} }
@ -132,13 +133,13 @@ public abstract class Tutorial implements ScoreboardElement, Listener
_inTutorial.get(player.getName()).setTaskFinished(taskID); _inTutorial.get(player.getName()).setTaskFinished(taskID);
if (!_taskManager.hasCompletedTask(player, _type.getId() + task.getNameID())) if (!_taskManager.hasCompletedTask(player, _uniqueId + task.getUniqueId()))
{ {
_taskManager.completedTask(new Callback<Boolean>() _taskManager.completedTask(new Callback<Boolean>()
{ {
public void run(final Boolean completed) public void run(final Boolean completed)
{ {
UtilPlayer.message(player, F.main("Tutorials", "You have completed task " + F.elem(taskID + " (" + task.getName() + ")") + ". " + (_tasks.size() - taskID) + " tasks to go!")); UtilPlayer.message(player, F.main("Tutorials", "You have completed task " + F.elem(taskID + " (" + task.getFriendlyName() + ")") + ". " + (_tasks.size() - taskID) + " tasks to go!"));
if (taskID == _tasks.size()) if (taskID == _tasks.size())
{ {
@ -157,7 +158,7 @@ public abstract class Tutorial implements ScoreboardElement, Listener
player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f); player.playSound(player.getLocation(), Sound.LEVEL_UP, 2f, 1.5f);
} }
}, player, _type.getId() + task.getNameID()); }, player, _uniqueId + task.getUniqueId());
} }
} }
@ -176,11 +177,6 @@ public abstract class Tutorial implements ScoreboardElement, Listener
return _nameToTask.get(name); return _nameToTask.get(name);
} }
public TutorialType getType()
{
return _type;
}
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPickupItem(final PlayerPickupItemEvent event) public void onPickupItem(final PlayerPickupItemEvent event)
{ {
@ -222,9 +218,9 @@ public abstract class Tutorial implements ScoreboardElement, Listener
_inTutorial.remove(player.getName()); _inTutorial.remove(player.getName());
UtilFirework.launchFirework(player.getLocation(), Type.BALL_LARGE, Color.LIME, false, false, new Vector(0, 0, 0), 1); UtilFirework.launchFirework(player.getLocation(), Type.BALL_LARGE, Color.LIME, false, false, new Vector(0, 0, 0), 1);
UtilPlayer.message(player, F.main("Tutorials", "You have completed the " + F.elem(_type.getFriendlyName() + " Tutorial") + ".")); UtilPlayer.message(player, F.main("Tutorials", "You have completed the " + F.elem(_friendlyName + " Tutorial") + "."));
onFinished(player); onFinished(player);
if (!_taskManager.hasCompletedTask(player, _type.getId())) if (!_taskManager.hasCompletedTask(player, _uniqueId))
{ {
_taskManager.completedTask(new Callback<Boolean>() _taskManager.completedTask(new Callback<Boolean>()
{ {
@ -254,7 +250,7 @@ public abstract class Tutorial implements ScoreboardElement, Listener
}, i * 10); }, i * 10);
} }
} }
}, player, _type.getId()); }, player, _uniqueId);
} }
} }
@ -285,7 +281,7 @@ public abstract class Tutorial implements ScoreboardElement, Listener
onBegin(player); onBegin(player);
} }
public void cancelTutorial(final Player player) public void cancelFor(final Player player)
{ {
_inTutorial.remove(player.getName()); _inTutorial.remove(player.getName());
@ -314,9 +310,14 @@ public abstract class Tutorial implements ScoreboardElement, Listener
return _tasks; return _tasks;
} }
public boolean hasDoneBefore(final Player player) public boolean hasCompleted(final Player player)
{ {
return _taskManager.hasCompletedTask(player, _type.getId()); return _taskManager.hasCompletedTask(player, _uniqueId);
}
public String getUniqueId()
{
return _uniqueId;
} }
public TutorialClient get(final Player player) public TutorialClient get(final Player player)

View File

@ -28,7 +28,7 @@ public class TutorialClient
for (final int i : tutorial.getTasks().keySet()) for (final int i : tutorial.getTasks().keySet())
{ {
if (taskManager.hasCompletedTask(player, tutorial.getType().getId() + tutorial.getTask(i).getNameID())) if (taskManager.hasCompletedTask(player, tutorial.getUniqueId() + tutorial.getTask(i).getUniqueId()))
{ {
user._currentTask = i; user._currentTask = i;
} }

View File

@ -1,10 +1,9 @@
package mineplex.game.clans.tutorials; package mineplex.game.clans.tutorials;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.MiniPlugin; import mineplex.core.MiniPlugin;
@ -13,8 +12,8 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.task.TaskManager; import mineplex.core.task.TaskManager;
import mineplex.game.clans.clans.ClansManager; import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.economy.GoldManager; import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.tutorials.commands.SkipTutorialCommand;
import mineplex.game.clans.tutorials.commands.QAResetCommand; import mineplex.game.clans.tutorials.commands.QAResetCommand;
import mineplex.game.clans.tutorials.commands.SkipTutorialCommand;
import mineplex.game.clans.tutorials.commands.TaskInfoCommand; import mineplex.game.clans.tutorials.commands.TaskInfoCommand;
import mineplex.game.clans.tutorials.types.TutorialGettingStarted; import mineplex.game.clans.tutorials.types.TutorialGettingStarted;
import mineplex.game.clans.tutorials.types.TutorialOnGoingMap; import mineplex.game.clans.tutorials.types.TutorialOnGoingMap;
@ -23,7 +22,7 @@ public class TutorialManager extends MiniPlugin
{ {
public static TutorialManager Instance; public static TutorialManager Instance;
private final HashMap<TutorialType, Tutorial> _tutorials = new HashMap<>(); private final Map<Class<? extends Tutorial>, Tutorial> _tutorials = new HashMap<>();
private final TaskManager _taskManager; private final TaskManager _taskManager;
@ -35,8 +34,8 @@ public class TutorialManager extends MiniPlugin
_taskManager = taskManager; _taskManager = taskManager;
_tutorials.put(TutorialType.GETTING_STARTED, new TutorialGettingStarted(this, clansManager, goldManager, taskManager)); _tutorials.put(TutorialGettingStarted.class, new TutorialGettingStarted(this, clansManager, goldManager, taskManager));
_tutorials.put(TutorialType.ON_GOING, new TutorialOnGoingMap(this, clansManager, goldManager, taskManager)); _tutorials.put(TutorialOnGoingMap.class, new TutorialOnGoingMap(this, clansManager, goldManager, taskManager));
} }
public void addCommands() public void addCommands()
@ -46,31 +45,15 @@ public class TutorialManager extends MiniPlugin
this.addCommand(new QAResetCommand(this)); this.addCommand(new QAResetCommand(this));
} }
public void startTutorial(final TutorialType type, final Player player) public boolean startTutorial(final Class<? extends Tutorial> tutorial, final Player player)
{ {
for (final Tutorial tutorial : _tutorials.values()) if (_tutorials.containsKey(tutorial))
{ {
if (tutorial.getType().equals(type)) _tutorials.get(tutorial).startFor(player);
{ return _tutorials.get(tutorial).isInTutorial(player);
tutorial.startFor(player);
break;
}
}
} }
@EventHandler return false;
public void onPlayerJoin(final PlayerJoinEvent evt)
{
_plugin.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
{
public void run()
{
if (!_tutorials.get(TutorialType.GETTING_STARTED).hasDoneBefore(evt.getPlayer()))
{
_tutorials.get(TutorialType.GETTING_STARTED).startFor(evt.getPlayer());
}
}
}, 40L);
} }
public boolean isInTutorial(final Player player) public boolean isInTutorial(final Player player)
@ -92,8 +75,8 @@ public class TutorialManager extends MiniPlugin
{ {
if (tutorial.isInTutorial(player)) if (tutorial.isInTutorial(player))
{ {
tutorial.cancelTutorial(player); tutorial.cancelFor(player);
UtilPlayer.message(player, F.main("Tutorials", "You have cancelled the " + F.elem(tutorial.getType().getFriendlyName() + " Tutorial") + ".")); UtilPlayer.message(player, F.main("Tutorials", "You have cancelled the " + F.elem(tutorial._friendlyName + " Tutorial") + "."));
break; break;
} }
} }
@ -112,7 +95,7 @@ public class TutorialManager extends MiniPlugin
return null; return null;
} }
public HashMap<TutorialType, Tutorial> getTutorials() public Map<Class<? extends Tutorial>, Tutorial> getTutorials()
{ {
return _tutorials; return _tutorials;
} }

View File

@ -31,7 +31,7 @@ public class TutorialTask
return _finishMessage; return _finishMessage;
} }
public String getName() public String getFriendlyName()
{ {
return _name; return _name;
} }
@ -41,7 +41,7 @@ public class TutorialTask
return _description; return _description;
} }
public String getNameID() public String getUniqueId()
{ {
return _name.replace(" ", ""); return _name.replace(" ", "");
} }

View File

@ -1,26 +0,0 @@
package mineplex.game.clans.tutorials;
public enum TutorialType
{
GETTING_STARTED("Getting Started", "GettingStartedTutorial"),
ON_GOING("Ongoing Map", "OngoingMapTutorial");
private final String _uniqueId;
private final String _friendlyName;
TutorialType( final String friendlyName, final String uniqueId)
{
_uniqueId = uniqueId;
_friendlyName = friendlyName;
}
public String getId()
{
return _uniqueId;
}
public String getFriendlyName()
{
return _friendlyName;
}
}

View File

@ -8,7 +8,6 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.tutorials.TutorialManager; import mineplex.game.clans.tutorials.TutorialManager;
import mineplex.game.clans.tutorials.TutorialTask; import mineplex.game.clans.tutorials.TutorialTask;
import mineplex.game.clans.tutorials.TutorialType;
import mineplex.game.clans.tutorials.types.TutorialGettingStarted; import mineplex.game.clans.tutorials.types.TutorialGettingStarted;
// temp command // temp command
@ -27,19 +26,19 @@ public class QAResetCommand extends CommandBase<TutorialManager>
// ANNOYING PLEASE DON'T HARM ME IT'S // ANNOYING PLEASE DON'T HARM ME IT'S
// ONLY A TEMP COMMAND FOR TESTING // ONLY A TEMP COMMAND FOR TESTING
{ {
final TutorialGettingStarted tutorial = (TutorialGettingStarted) Plugin.getTutorials().get(TutorialType.GETTING_STARTED); final TutorialGettingStarted tutorial = (TutorialGettingStarted) Plugin.getTutorials().get(TutorialGettingStarted.class);
Plugin.getTaskManager().Get(caller).TasksCompleted.remove(Plugin.getTaskManager().getTaskId(tutorial.getType().getId())); Plugin.getTaskManager().Get(caller).TasksCompleted.remove(Plugin.getTaskManager().getTaskId(tutorial.getUniqueId()));
for (final TutorialTask task : tutorial.getTasks().values()) for (final TutorialTask task : tutorial.getTasks().values())
{ {
Plugin.getTaskManager().Get(caller).TasksCompleted.remove(Plugin.getTaskManager().getTaskId(tutorial.getType().getId() + task.getNameID())); Plugin.getTaskManager().Get(caller).TasksCompleted.remove(Plugin.getTaskManager().getTaskId(tutorial.getUniqueId() + task.getUniqueId()));
} }
UtilPlayer.message(caller, F.main("Tutorials", "Your Getting Started Tutorial progress has been deleted.")); UtilPlayer.message(caller, F.main("Tutorials", "Your Getting Started Tutorial progress has been deleted."));
TutorialManager.Instance.getTutorials().get(TutorialType.GETTING_STARTED).cancelTutorial(caller); TutorialManager.Instance.getTutorials().get(TutorialGettingStarted.class).cancelFor(caller);
TutorialManager.Instance.getTutorials().get(TutorialType.GETTING_STARTED).startFor(caller); TutorialManager.Instance.getTutorials().get(TutorialGettingStarted.class).startFor(caller);
if (args != null && args.length >= 1) if (args != null && args.length >= 1)
{ {
TutorialManager.Instance.getTutorial(caller).get(caller).setTaskFinished(Integer.parseInt(args[0])); TutorialManager.Instance.getTutorial(caller).get(caller).setTaskFinished(Integer.parseInt(args[0]));

View File

@ -7,6 +7,7 @@ import org.bukkit.Material;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
@ -14,6 +15,7 @@ import mineplex.core.common.util.UtilItem;
import mineplex.core.common.util.UtilItem.ArmorMaterial; import mineplex.core.common.util.UtilItem.ArmorMaterial;
import mineplex.core.common.util.UtilItem.ItemCategory; import mineplex.core.common.util.UtilItem.ItemCategory;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.task.TaskManager; import mineplex.core.task.TaskManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
@ -29,7 +31,6 @@ import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.tutorials.Tutorial; import mineplex.game.clans.tutorials.Tutorial;
import mineplex.game.clans.tutorials.TutorialClient; import mineplex.game.clans.tutorials.TutorialClient;
import mineplex.game.clans.tutorials.TutorialManager; import mineplex.game.clans.tutorials.TutorialManager;
import mineplex.game.clans.tutorials.TutorialType;
import mineplex.minecraft.game.classcombat.Class.ClientClass; import mineplex.minecraft.game.classcombat.Class.ClientClass;
import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent; import mineplex.minecraft.game.classcombat.Skill.event.SkillTriggerEvent;
@ -37,7 +38,7 @@ public class TutorialGettingStarted extends Tutorial
{ {
public TutorialGettingStarted(final TutorialManager manager, final ClansManager clansManager, final GoldManager goldManager, final TaskManager taskManager) public TutorialGettingStarted(final TutorialManager manager, final ClansManager clansManager, final GoldManager goldManager, final TaskManager taskManager)
{ {
super(50, goldManager, taskManager, clansManager, manager, TutorialType.GETTING_STARTED); super(50, goldManager, taskManager, clansManager, manager);
addTask(1, "Welcome", "Welcome to Clans! Before you start playing Clans, you need to create a Clan by typing {/c create [name]}! Don't worry though, at the end of this tutorial, you will be disbanding this clan."); addTask(1, "Welcome", "Welcome to Clans! Before you start playing Clans, you need to create a Clan by typing {/c create [name]}! Don't worry though, at the end of this tutorial, you will be disbanding this clan.");
addTask(2, "Viewing Clan Info", "Now you can view information about your clan. To do this type {/c [name]}! You can also use any clans name to get some information about them as well."); addTask(2, "Viewing Clan Info", "Now you can view information about your clan. To do this type {/c [name]}! You can also use any clans name to get some information about them as well.");
@ -53,6 +54,9 @@ public class TutorialGettingStarted extends Tutorial
_doScoreboard = true; _doScoreboard = true;
_ghostMode = true; _ghostMode = true;
_uniqueId = "GettingStartedTutorial";
_friendlyName = "Getting Started";
} }
@Override @Override
@ -61,6 +65,22 @@ public class TutorialGettingStarted extends Tutorial
UtilPlayer.message(player, F.main("Tutorials", "You are now ready to play, welcome to the game.")); UtilPlayer.message(player, F.main("Tutorials", "You are now ready to play, welcome to the game."));
} }
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent evt)
{
UtilServer.getServer().getScheduler().scheduleSyncDelayedTask(_manager.getPlugin(), new Runnable()
{
public void run()
{
if (!hasCompleted(evt.getPlayer()))
{
startFor(evt.getPlayer());
}
}
}, 40L);
}
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onClansShopButtonAdded(ClansShopAddButtonEvent event) public void onClansShopButtonAdded(ClansShopAddButtonEvent event)
{ {

View File

@ -12,15 +12,17 @@ import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent;
import mineplex.game.clans.economy.GoldManager; import mineplex.game.clans.economy.GoldManager;
import mineplex.game.clans.tutorials.Tutorial; import mineplex.game.clans.tutorials.Tutorial;
import mineplex.game.clans.tutorials.TutorialManager; import mineplex.game.clans.tutorials.TutorialManager;
import mineplex.game.clans.tutorials.TutorialType;
public class TutorialOnGoingMap extends Tutorial public class TutorialOnGoingMap extends Tutorial
{ {
public TutorialOnGoingMap(final TutorialManager manager, final ClansManager clansManager, final GoldManager goldManager, final TaskManager taskManager) public TutorialOnGoingMap(final TutorialManager manager, final ClansManager clansManager, final GoldManager goldManager, final TaskManager taskManager)
{ {
super(0, goldManager, taskManager, clansManager, manager, TutorialType.ON_GOING); super(0, goldManager, taskManager, clansManager, manager);
_doScoreboard = false; _doScoreboard = false;
_uniqueId = "OngoingMapTutorial";
_friendlyName = "Ongoing Map";
} }
@EventHandler @EventHandler