diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MaterialData.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MaterialData.java new file mode 100644 index 000000000..cf8210198 --- /dev/null +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/MaterialData.java @@ -0,0 +1,46 @@ +package mineplex.core.common; + +import org.bukkit.Material; + +public class MaterialData +{ + private final Material _material; + private final byte _data; + + private MaterialData(Material material, byte data) + { + _material = material; + _data = data; + } + + public static MaterialData of(Material material) + { + return new MaterialData(material, (byte) 0); + } + + public static MaterialData of(Material material, byte data) + { + return new MaterialData(material, data); + } + + @Override + public boolean equals(Object o) + { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MaterialData that = (MaterialData) o; + + if (_data != that._data) return false; + return _material == that._material; + + } + + @Override + public int hashCode() + { + int result = _material.hashCode(); + result = 31 * result + (int) _data; + return result; + } +} diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java index e360699fd..8d9c08d3b 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/objective/Objective.java @@ -1,6 +1,5 @@ package mineplex.core.common.objective; -import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -12,8 +11,7 @@ import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; /** - * An Objective represents - * + * An Objective represents a set of goals that need to be completed to move on to the next Objective in the quest */ public abstract class Objective implements Listener { @@ -86,6 +84,8 @@ public abstract class Objective implements Listener _listeners.forEach(listener -> listener.onObjectiveStart(player, this)); customStart(player); + + System.out.printf("Tutorial> [%s] started objective [%s]\n", player.getName(), getName()); } protected abstract void customStart(Player player); @@ -126,11 +126,13 @@ public abstract class Objective implements Listener protected final void finish(Player player) { + System.out.printf("Tutorial> [%s] finished objective [%s]\n", player.getName(), getName()); + _active.remove(player.getUniqueId()); - _listeners.forEach(listener -> listener.onObjectiveFinish(player, this)); - customFinish(player); + + _listeners.forEach(listener -> listener.onObjectiveFinish(player, this)); } protected abstract void customFinish(Player player); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java index 95eebea7a..c47ca193a 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/Tutorial.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; import org.bukkit.event.Listener; @@ -20,14 +21,22 @@ public abstract class Tutorial implements Listener, ObjectiveListener private String _name; private String _taskIdentifier; + // GUI Data + private Material _guiMaterial; + private byte _guiData; + private List _objectives; - public Tutorial(JavaPlugin plugin, String name, String taskIdentifier) + public Tutorial(JavaPlugin plugin, String name, String taskIdentifier, Material guiMaterial, byte data) { _plugin = plugin; _name = name; _taskIdentifier = taskIdentifier; + _guiMaterial = guiMaterial; + _guiData = data; + + _playerSessionMap = new HashMap<>(); _objectives = new ArrayList<>(); } @@ -38,6 +47,7 @@ public abstract class Tutorial implements Listener, ObjectiveListener public void start(Player player) { + System.out.printf("Tutorial> [%s] started tutorial [%s]\n", player.getName(), getName()); _playerSessionMap.put(player, new TutorialSession()); // Start at first objective! setObjective(player, 0); @@ -67,6 +77,16 @@ public abstract class Tutorial implements Listener, ObjectiveListener return _name; } + public Material getGuiMaterial() + { + return _guiMaterial; + } + + public byte getGuiData() + { + return _guiData; + } + public final String getTaskIdentifier() { return "clans.tutorial." + _taskIdentifier; @@ -76,8 +96,36 @@ public abstract class Tutorial implements Listener, ObjectiveListener public void onObjectiveFinish(Player player, Objective objective) { int index = _objectives.indexOf(objective); + + assert index != -1; + + if (index >= _objectives.size()) + { + finish(player); + } + else + { + setObjective(player, index + 1); + } } + @Override + public void onObjectiveStart(Player player, Objective objective) + { + + } + + private void finish(Player player) + { + _playerSessionMap.remove(player); + + System.out.printf("Tutorial> [%s] finished tutorial [%s]\n", player.getName(), getName()); + + onFinish(); + } + + protected abstract void onFinish(); + public void unregisterAll() { HandlerList.unregisterAll(this); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java index b46c9c87f..977efaf81 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/TutorialManager.java @@ -8,19 +8,30 @@ import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.donation.DonationManager; +import mineplex.game.clans.tutorial.gui.TutorialShop; import mineplex.game.clans.tutorial.tutorials.combat.CombatTutorial; public class TutorialManager extends MiniPlugin { - private EnumMap _tutorialMap; + private CoreClientManager _clientManager; + private DonationManager _donationManager; - public TutorialManager(JavaPlugin plugin) + private EnumMap _tutorialMap; + private EnumMap _shopMap; // Don't need to do anything with shops currently + + public TutorialManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager) { super("Clans Tutorial", plugin); + _clientManager = clientManager; + _donationManager = donationManager; + _tutorialMap = new EnumMap(TutorialType.class); + _shopMap = new EnumMap(TutorialType.class); addTutorial(TutorialType.COMBAT, new CombatTutorial(plugin)); } @@ -33,6 +44,7 @@ public class TutorialManager extends MiniPlugin } _tutorialMap.put(type, tutorial); + _shopMap.put(type, new TutorialShop(this, _clientManager, _donationManager, tutorial)); getPlugin().getServer().getPluginManager().registerEvents(tutorial, getPlugin()); } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/TutorialSelectPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/TutorialSelectPage.java new file mode 100644 index 000000000..c5731c040 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/TutorialSelectPage.java @@ -0,0 +1,43 @@ +package mineplex.game.clans.tutorial.gui; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.tutorial.Tutorial; +import mineplex.game.clans.tutorial.TutorialManager; +import mineplex.game.clans.tutorial.gui.button.DeclineButton; +import mineplex.game.clans.tutorial.gui.button.StartButton; + +public class TutorialSelectPage extends ShopPageBase +{ + public TutorialSelectPage(TutorialManager plugin, TutorialShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player) + { + super(plugin, shop, clientManager, donationManager, shop.getTutorial().getName(), player, 45); + + buildPage(); + } + + @Override + protected void buildPage() + { + Tutorial tutorial = getShop().getTutorial(); + + String name = tutorial.getName(); + Material material = tutorial.getGuiMaterial(); + byte data = tutorial.getGuiData(); + + ShopItem infoItem = new ShopItem(material, data, name, new String[0], 0, false, false); + addItem(13, infoItem); + + ShopItem startItem = new ShopItem(Material.EMERALD_BLOCK, "Start " + tutorial.getName(), new String[0], 0, false, false); + addButton(27 + 6, startItem, new StartButton(tutorial)); + + ShopItem declineButton = new ShopItem(Material.REDSTONE_BLOCK, "Cancel", new String[0], 0, false, false); + addButton(27 + 3, declineButton, new DeclineButton()); + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/TutorialShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/TutorialShop.java new file mode 100644 index 000000000..29a8c62f7 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/TutorialShop.java @@ -0,0 +1,33 @@ +package mineplex.game.clans.tutorial.gui; + +import org.bukkit.entity.Player; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.tutorial.Tutorial; +import mineplex.game.clans.tutorial.TutorialManager; + +public class TutorialShop extends ShopBase +{ + private final Tutorial _tutorial; + + public TutorialShop(TutorialManager plugin, CoreClientManager clientManager, DonationManager donationManager, Tutorial tutorial) + { + super(plugin, clientManager, donationManager, tutorial.getName()); + + _tutorial = tutorial; + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return new TutorialSelectPage(getPlugin(), this, getClientManager(), getDonationManager(), player); + } + + public Tutorial getTutorial() + { + return _tutorial; + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/button/DeclineButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/button/DeclineButton.java new file mode 100644 index 000000000..e1b283fae --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/button/DeclineButton.java @@ -0,0 +1,15 @@ +package mineplex.game.clans.tutorial.gui.button; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.shop.item.IButton; + +public class DeclineButton implements IButton +{ + @Override + public void onClick(Player player, ClickType clickType) + { + player.closeInventory(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/button/StartButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/button/StartButton.java new file mode 100644 index 000000000..8461ea669 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/gui/button/StartButton.java @@ -0,0 +1,28 @@ +package mineplex.game.clans.tutorial.gui.button; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.shop.item.IButton; +import mineplex.game.clans.tutorial.Tutorial; + +public class StartButton implements IButton +{ + private final Tutorial _tutorial; + + public StartButton(Tutorial tutorial) + { + _tutorial = tutorial; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if (!_tutorial.isInTutorial(player)) + { + _tutorial.start(player); + } + + player.closeInventory(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java index 973f8e711..e22a1d42c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/tutorial/tutorials/combat/CombatTutorial.java @@ -1,5 +1,6 @@ package mineplex.game.clans.tutorial.tutorials.combat; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -11,13 +12,13 @@ public class CombatTutorial extends Tutorial { public CombatTutorial(JavaPlugin plugin) { - super(plugin, "Combat Tutorial", "combat"); + super(plugin, "Combat Tutorial", "combat", Material.DIAMOND_SWORD, (byte) 0); addObjective(new EquipArmorObjective(plugin)); } @Override - public void onObjectiveStart(Player player, Objective objective) + protected void onFinish() { }