diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ShopItemButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ShopItemButton.java index 6b0d8b425..e7f434ad5 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ShopItemButton.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ShopItemButton.java @@ -15,9 +15,6 @@ import mineplex.core.shop.item.IButton; import mineplex.core.shop.page.ShopPageBase; import mineplex.game.clans.clans.event.ClansPlayerBuyItemEvent; 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> implements IButton { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java index 78b00a7bc..1f587012d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/Tutorial.java @@ -47,19 +47,20 @@ public abstract class Tutorial implements ScoreboardElement, Listener private final HashMap _tasks; private final HashMap _nameToTask; protected final HashMap _inTutorial; - private final TutorialType _type; protected boolean _doScoreboard; 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; _goldManager = goldManager; _taskManager = taskManager; _rewardAmount = rewardAmount; _manager = manager; - _type = type; _tasks = new HashMap<>(); _inTutorial = new HashMap<>(); _nameToTask = new HashMap<>(); @@ -80,21 +81,21 @@ public abstract class Tutorial implements ScoreboardElement, Listener 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()) { 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)) { - lines.add(C.cGreen + task.getID() + ". " + task.getName()); + lines.add(C.cGreen + task.getID() + ". " + task.getFriendlyName()); } 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); - if (!_taskManager.hasCompletedTask(player, _type.getId() + task.getNameID())) + if (!_taskManager.hasCompletedTask(player, _uniqueId + task.getUniqueId())) { _taskManager.completedTask(new Callback() { 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()) { @@ -157,7 +158,7 @@ public abstract class Tutorial implements ScoreboardElement, Listener 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); } - public TutorialType getType() - { - return _type; - } - @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPickupItem(final PlayerPickupItemEvent event) { @@ -222,9 +218,9 @@ public abstract class Tutorial implements ScoreboardElement, Listener _inTutorial.remove(player.getName()); 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); - if (!_taskManager.hasCompletedTask(player, _type.getId())) + if (!_taskManager.hasCompletedTask(player, _uniqueId)) { _taskManager.completedTask(new Callback() { @@ -254,7 +250,7 @@ public abstract class Tutorial implements ScoreboardElement, Listener }, i * 10); } } - }, player, _type.getId()); + }, player, _uniqueId); } } @@ -285,7 +281,7 @@ public abstract class Tutorial implements ScoreboardElement, Listener onBegin(player); } - public void cancelTutorial(final Player player) + public void cancelFor(final Player player) { _inTutorial.remove(player.getName()); @@ -314,9 +310,14 @@ public abstract class Tutorial implements ScoreboardElement, Listener 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) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialClient.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialClient.java index e3d8d1833..90c637904 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialClient.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialClient.java @@ -28,7 +28,7 @@ public class TutorialClient 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; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialManager.java index 159b8b705..6dacb4e43 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialManager.java @@ -1,10 +1,9 @@ package mineplex.game.clans.tutorials; import java.util.HashMap; +import java.util.Map; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; @@ -13,8 +12,8 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.task.TaskManager; import mineplex.game.clans.clans.ClansManager; 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.SkipTutorialCommand; import mineplex.game.clans.tutorials.commands.TaskInfoCommand; import mineplex.game.clans.tutorials.types.TutorialGettingStarted; import mineplex.game.clans.tutorials.types.TutorialOnGoingMap; @@ -23,7 +22,7 @@ public class TutorialManager extends MiniPlugin { public static TutorialManager Instance; - private final HashMap _tutorials = new HashMap<>(); + private final Map, Tutorial> _tutorials = new HashMap<>(); private final TaskManager _taskManager; @@ -35,8 +34,8 @@ public class TutorialManager extends MiniPlugin _taskManager = taskManager; - _tutorials.put(TutorialType.GETTING_STARTED, new TutorialGettingStarted(this, clansManager, goldManager, taskManager)); - _tutorials.put(TutorialType.ON_GOING, new TutorialOnGoingMap(this, clansManager, goldManager, taskManager)); + _tutorials.put(TutorialGettingStarted.class, new TutorialGettingStarted(this, clansManager, goldManager, taskManager)); + _tutorials.put(TutorialOnGoingMap.class, new TutorialOnGoingMap(this, clansManager, goldManager, taskManager)); } public void addCommands() @@ -46,31 +45,15 @@ public class TutorialManager extends MiniPlugin this.addCommand(new QAResetCommand(this)); } - public void startTutorial(final TutorialType type, final Player player) + public boolean startTutorial(final Class tutorial, final Player player) { - for (final Tutorial tutorial : _tutorials.values()) + if (_tutorials.containsKey(tutorial)) { - if (tutorial.getType().equals(type)) - { - tutorial.startFor(player); - break; - } + _tutorials.get(tutorial).startFor(player); + return _tutorials.get(tutorial).isInTutorial(player); } - } - - @EventHandler - 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); + + return false; } public boolean isInTutorial(final Player player) @@ -92,8 +75,8 @@ public class TutorialManager extends MiniPlugin { if (tutorial.isInTutorial(player)) { - tutorial.cancelTutorial(player); - UtilPlayer.message(player, F.main("Tutorials", "You have cancelled the " + F.elem(tutorial.getType().getFriendlyName() + " Tutorial") + ".")); + tutorial.cancelFor(player); + UtilPlayer.message(player, F.main("Tutorials", "You have cancelled the " + F.elem(tutorial._friendlyName + " Tutorial") + ".")); break; } } @@ -112,7 +95,7 @@ public class TutorialManager extends MiniPlugin return null; } - public HashMap getTutorials() + public Map, Tutorial> getTutorials() { return _tutorials; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialTask.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialTask.java index 476f63c75..fd916051a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialTask.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialTask.java @@ -31,7 +31,7 @@ public class TutorialTask return _finishMessage; } - public String getName() + public String getFriendlyName() { return _name; } @@ -41,7 +41,7 @@ public class TutorialTask return _description; } - public String getNameID() + public String getUniqueId() { return _name.replace(" ", ""); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialType.java deleted file mode 100644 index b6503104a..000000000 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/TutorialType.java +++ /dev/null @@ -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; - } -} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/commands/QAResetCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/commands/QAResetCommand.java index 99f6d8fe2..fb7261c70 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/commands/QAResetCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/commands/QAResetCommand.java @@ -8,7 +8,6 @@ import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.game.clans.tutorials.TutorialManager; import mineplex.game.clans.tutorials.TutorialTask; -import mineplex.game.clans.tutorials.TutorialType; import mineplex.game.clans.tutorials.types.TutorialGettingStarted; // temp command @@ -27,19 +26,19 @@ public class QAResetCommand extends CommandBase // ANNOYING PLEASE DON'T HARM ME IT'S // 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()) { - 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.")); - TutorialManager.Instance.getTutorials().get(TutorialType.GETTING_STARTED).cancelTutorial(caller); - TutorialManager.Instance.getTutorials().get(TutorialType.GETTING_STARTED).startFor(caller); + TutorialManager.Instance.getTutorials().get(TutorialGettingStarted.class).cancelFor(caller); + TutorialManager.Instance.getTutorials().get(TutorialGettingStarted.class).startFor(caller); if (args != null && args.length >= 1) { TutorialManager.Instance.getTutorial(caller).get(caller).setTaskFinished(Integer.parseInt(args[0])); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java index a74f8796d..a4676267b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialGettingStarted.java @@ -7,6 +7,7 @@ import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.inventory.ItemStack; 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.ItemCategory; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.task.TaskManager; import mineplex.core.updater.UpdateType; 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.TutorialClient; import mineplex.game.clans.tutorials.TutorialManager; -import mineplex.game.clans.tutorials.TutorialType; import mineplex.minecraft.game.classcombat.Class.ClientClass; 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) { - 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(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; _ghostMode = true; + + _uniqueId = "GettingStartedTutorial"; + _friendlyName = "Getting Started"; } @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.")); } + @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) public void onClansShopButtonAdded(ClansShopAddButtonEvent event) { @@ -274,5 +294,5 @@ public class TutorialGettingStarted extends Tutorial { UtilPlayer.message(player, F.main("Tutorials", "Welcome to the " + F.elem("Getting Started Tutorial!"))); } - + } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialOnGoingMap.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialOnGoingMap.java index c6d365c0f..f9e5a7448 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialOnGoingMap.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorials/types/TutorialOnGoingMap.java @@ -12,15 +12,17 @@ import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent; import mineplex.game.clans.economy.GoldManager; import mineplex.game.clans.tutorials.Tutorial; import mineplex.game.clans.tutorials.TutorialManager; -import mineplex.game.clans.tutorials.TutorialType; public class TutorialOnGoingMap extends Tutorial { 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; + + _uniqueId = "OngoingMapTutorial"; + _friendlyName = "Ongoing Map"; } @EventHandler