From 0c5e34ad84fddf28e2a90882c85b4e3dfbf1a38f Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Thu, 29 Oct 2015 12:56:00 +0000 Subject: [PATCH] Finished the tutorial changes that I wanted to add. Added a few more events for shop stuff, to make the code a bit cleaner. Might continue the idea of more events in Clans. Added an optional argument to QAResetCommand which will allow you to reset to a specific task number. Quite useful when testing tasks that are one of the last ones! --- .../mineplex/core/common/util/UtilItem.java | 4 +- .../game/clans/clans/ClansDisplay.java | 5 +- .../clans/event/ClansPlayerBuyItemEvent.java | 99 +++++++++++++ .../clans/event/ClansShopAddButtonEvent.java | 138 ++++++++++++++++++ .../event/PlayerEnterTerritoryEvent.java | 1 - .../game/clans/shop/ClansShopPage.java | 32 ++-- .../game/clans/shop/ShopItemButton.java | 34 +++-- .../mineplex/game/clans/shop/pvp/PvpPage.java | 2 +- .../game/clans/tutorials/TutorialClient.java | 7 +- .../tutorials/commands/QAResetCommand.java | 14 +- .../types/TutorialGettingStarted.java | 116 ++++++++------- 11 files changed, 360 insertions(+), 92 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansPlayerBuyItemEvent.java create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansShopAddButtonEvent.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java index eeae53536..f879aafac 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilItem.java @@ -2,6 +2,7 @@ package mineplex.core.common.util; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; import java.util.LinkedList; @@ -911,7 +912,8 @@ public class UtilItem public static List listIn(ItemCategory... attr) { - List attributes = Arrays.asList(attr); + List attributes = new ArrayList<>(attr.length); + Collections.addAll(attributes, attr); List list = new ArrayList<>(); for (Entry> mat : _materials.entrySet()) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java index 7cd23e690..565b45b71 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansDisplay.java @@ -65,10 +65,7 @@ public class ClansDisplay extends MiniPlugin boolean safe = Clans.getClanUtility().isSafe(player); - if (!client.getOwner().equals(owner)) - { - UtilServer.getServer().getPluginManager().callEvent(new PlayerEnterTerritoryEvent(player, client.getOwner(), owner)); - } + UtilServer.getServer().getPluginManager().callEvent(new PlayerEnterTerritoryEvent(player, client.getOwner(), owner)); if (!client.isMapOn()) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansPlayerBuyItemEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansPlayerBuyItemEvent.java new file mode 100644 index 000000000..ac35eecfb --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansPlayerBuyItemEvent.java @@ -0,0 +1,99 @@ +package mineplex.game.clans.clans.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.shop.ShopItemButton; + +public class ClansPlayerBuyItemEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private ShopPageBase _page; + private int _cost; + private int _amount; + private ItemStack _item; + + private ShopItemButton> _button; + + private boolean _cancelled; + + public ClansPlayerBuyItemEvent(Player player, ShopPageBase page, ShopItemButton> shopItemButton, ItemStack item, int cost, int amount) + { + _page = page; + _button = shopItemButton; + _amount = amount; + _item = item; + _player = player; + _cost = cost; + } + + public Player getPlayer() + { + return _player; + } + + public ShopPageBase getPage() + { + return _page; + } + + public ItemStack getItem() + { + return _item; + } + + public void setItem(ItemStack item) + { + _item = item; + } + + public int getCost() + { + return _cost; + } + + public void setCost(int cost) + { + _cost = cost; + } + + public int getAmount() + { + return _amount; + } + + public void setAmount(int amount) + { + _amount = amount; + } + + public ShopItemButton> getButton() + { + return _button; + } + + public boolean isCancelled() + { + return _cancelled; + } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansShopAddButtonEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansShopAddButtonEvent.java new file mode 100644 index 000000000..535fb68b2 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/ClansShopAddButtonEvent.java @@ -0,0 +1,138 @@ +package mineplex.game.clans.clans.event; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import mineplex.core.shop.ShopBase; + +public class ClansShopAddButtonEvent extends Event +{ + private static final HandlerList handlers = new HandlerList(); + + private final Player _player; + private final ShopBase _shop; + private Material _material; + private int _buyPrice; + private int _sellPrice; + private byte _data; + private String _displayName; + private int _amount; + private int _slot; + + private boolean _cancelled; + + public ClansShopAddButtonEvent(Player player, ShopBase shop, int slot, Material material, int buyPrice, int sellPrice, byte data, String displayName, int amount) + { + _player = player; + _shop = shop; + _slot = slot; + _material = material; + _buyPrice = buyPrice; + _sellPrice = sellPrice; + _data = data; + _displayName = displayName; + _amount = amount; + } + + public Player getPlayer() + { + return _player; + } + + public ShopBase getShop() + { + return _shop; + } + + public Material getMaterial() + { + return _material; + } + + public int getBuyPrice() + { + return _buyPrice; + } + + public void setBuyPrice(int buyPrice) + { + _buyPrice = buyPrice; + } + + public int getSellPrice() + { + return _sellPrice; + } + + public void setSellPrice(int sellPrice) + { + _sellPrice = sellPrice; + } + + public int getSlot() + { + return _slot; + } + + public void setSlot(int slot) + { + _slot = slot; + } + + public byte getData() + { + return _data; + } + + public void setData(byte data) + { + _data = data; + } + + public void setMaterial(Material material) + { + _material = material; + } + + public void setDisplayName(String displayName) + { + _displayName = displayName; + } + + public void setAmount(int amount) + { + _amount = amount; + } + + public String getDisplayName() + { + return _displayName; + } + + public int getAmount() + { + return _amount; + } + + public boolean isCancelled() + { + return _cancelled; + } + + public void setCancelled(boolean cancelled) + { + _cancelled = cancelled; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java index c90ea9e4b..1ea5fb90f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/event/PlayerEnterTerritoryEvent.java @@ -43,5 +43,4 @@ public class PlayerEnterTerritoryEvent extends Event { return handlers; } - } \ No newline at end of file diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java index c27bd963d..0d67e5689 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/ClansShopPage.java @@ -2,16 +2,15 @@ package mineplex.game.clans.shop; import org.bukkit.Material; import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.UtilServer; import mineplex.core.donation.DonationManager; import mineplex.core.shop.ShopBase; import mineplex.core.shop.page.ShopPageBase; import mineplex.game.clans.Clans; import mineplex.game.clans.clans.ClansManager; -import mineplex.game.clans.tutorials.TutorialManager; -import mineplex.game.clans.tutorials.types.TutorialGettingStarted; +import mineplex.game.clans.clans.event.ClansShopAddButtonEvent; public abstract class ClansShopPage> extends ShopPageBase { @@ -64,17 +63,24 @@ public abstract class ClansShopPage> extends Sh public void addShopItem(int slot, Material material, int buyPrice, int sellPrice, byte data, String displayName, int amount) { - if (TutorialManager.Instance.isInTutorial(getPlayer()) && TutorialManager.Instance.getTutorial(getPlayer()) instanceof TutorialGettingStarted) - { - if (((TutorialGettingStarted) TutorialManager.Instance.getTutorial(getPlayer())).nullPrices(new ItemStack(material, amount), getPlayer())) - { - buyPrice = 0; - sellPrice = 0; - } - } + ClansShopAddButtonEvent event = new ClansShopAddButtonEvent(getPlayer(), getShop(), slot, material, buyPrice, sellPrice, data, displayName, amount); + UtilServer.getServer().getPluginManager().callEvent(event); - PvpItem item = new PvpItem(material, data, 1, displayName, buyPrice, sellPrice, 64); - addButton(slot, item, new ShopItemButton>(this, buyPrice, sellPrice, material, data, amount)); + if (event.isCancelled()) return; + + slot = event.getSlot(); + material = event.getMaterial(); + buyPrice = event.getBuyPrice(); + sellPrice = event.getSellPrice(); + data = event.getData(); + displayName = event.getDisplayName(); + amount = event.getAmount(); + + if (!event.isCancelled()) + { + PvpItem item = new PvpItem(material, data, 1, displayName, buyPrice, sellPrice, 64); + addButton(slot, item, new ShopItemButton>(this, buyPrice, sellPrice, material, data, amount)); + } } public void addShopItem(int index, ClansShopItem item, String displayName) 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 b4ae59cb7..6b0d8b425 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 @@ -10,8 +10,10 @@ import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.InventoryUtil; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; 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; @@ -34,7 +36,7 @@ public class ShopItemButton> implements IButton public ShopItemButton(T page, int buyPrice, int sellPrice, Material material) { - this(page, buyPrice, sellPrice, material, (byte)0, 1); + this(page, buyPrice, sellPrice, material, (byte) 0, 1); } @Override @@ -44,7 +46,7 @@ public class ShopItemButton> implements IButton if (clickType == ClickType.SHIFT_RIGHT || clickType == ClickType.RIGHT) { - int amount = 1; // # of items removed/sold from inventory + int amount = 1; // # of items removed/sold from inventory if (!hasItem(player, _item)) { @@ -55,11 +57,11 @@ public class ShopItemButton> implements IButton if (shiftClick) { - amount = InventoryUtil.getCountOfObjectsRemoved((CraftInventory)player.getInventory(), 36, _item); + amount = InventoryUtil.getCountOfObjectsRemoved((CraftInventory) player.getInventory(), 36, _item); } else { - InventoryUtil.removeItem((CraftInventory)player.getInventory(), 36, _item); + InventoryUtil.removeItem((CraftInventory) player.getInventory(), 36, _item); } int reward = amount * _sellPrice; @@ -75,16 +77,30 @@ public class ShopItemButton> implements IButton if (goldCount >= cost) { + final ItemStack eventItem = _item.clone(); + eventItem.setAmount(amount); + GoldManager.getInstance().deductGold(new Callback() { public void run(Boolean success) { if (success) { - giftItem(player, amount); - GoldManager.notify(player, String.format("You have purchased %d item(s) for %dg!", amount, cost)); + ClansPlayerBuyItemEvent event = new ClansPlayerBuyItemEvent(player, _page, ShopItemButton.this, eventItem, cost, amount); + UtilServer.getServer().getPluginManager().callEvent(event); - ((TutorialGettingStarted) TutorialManager.Instance.getTutorials().get(TutorialType.GETTING_STARTED)).onItemBought(player, _item); + if (event.isCancelled()) + { + GoldManager.getInstance().addGold(player, cost); + return; + } + + _item = event.getItem(); + final int finalCost = event.getCost(); + final int finalAmount = event.getAmount(); + + giftItem(player, finalAmount); + GoldManager.notify(player, String.format("You have purchased %d item(s) for %dg!", finalAmount, finalCost)); _page.playAcceptSound(player); } @@ -108,14 +124,14 @@ public class ShopItemButton> implements IButton private boolean hasItem(Player player, ItemStack item) { - return InventoryUtil.first((CraftInventory)player.getInventory(), 36, item, true) != -1; + return InventoryUtil.first((CraftInventory) player.getInventory(), 36, item, true) != -1; } private void notify(Player player, String message) { UtilPlayer.message(player, F.main("Shop", message)); } - + private void giftItem(Player player, int amount) { ItemStack item = _item.clone(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/pvp/PvpPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/pvp/PvpPage.java index 4dba7fb2c..f06045627 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/pvp/PvpPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/pvp/PvpPage.java @@ -34,7 +34,7 @@ public class PvpPage extends ClansShopPage addShopItem(38, ClansShopItem.CHAINMAIL_BOOTS, "Ranger Boots"); addShopItem(12, ClansShopItem.IRON_HELMET, "Knight Helmet"); - addShopItem(21, ClansShopItem.IRON_HELMET, "Knight Chestplate"); + addShopItem(21, ClansShopItem.IRON_CHESTPLATE, "Knight Chestplate"); addShopItem(30, ClansShopItem.IRON_LEGGINGS, "Knight Leggings"); addShopItem(39, ClansShopItem.IRON_BOOTS, "Knight Boots"); 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 7e392e3de..ae21b938b 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 @@ -1,9 +1,8 @@ package mineplex.game.clans.tutorials; -import java.util.HashMap; - import org.bukkit.entity.Player; +import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilServer; import mineplex.core.task.TaskManager; @@ -13,7 +12,7 @@ public class TutorialClient private final Tutorial _tutorial; private final Player _player; - private final HashMap _data = new HashMap<>(); + private final NautHashMap _data = new NautHashMap<>(); private int _currentTask = 1; public TutorialClient(final Player player, final TaskManager taskManager, final Tutorial tutorial) @@ -93,7 +92,7 @@ public class TutorialClient _data.put(name, value); } - public HashMap getData() + public NautHashMap getData() { return _data; } 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 10e622087..99f6d8fe2 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 @@ -1,7 +1,5 @@ package mineplex.game.clans.tutorials.commands; -import java.util.Arrays; - import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; @@ -24,30 +22,28 @@ public class QAResetCommand extends CommandBase @Override public void Execute(final Player caller, final String[] args) { - for (int i = 0; i < 11; i++) // THIS IS A VERY BAD WORK AROUND AND I AM + for (int i = 0; i < 16; i++) // THIS IS A VERY BAD WORK AROUND AND I AM // SORRY, IT'S JUST A BUG THAT'S // ANNOYING PLEASE DON'T HARM ME IT'S // ONLY A TEMP COMMAND FOR TESTING { final TutorialGettingStarted tutorial = (TutorialGettingStarted) Plugin.getTutorials().get(TutorialType.GETTING_STARTED); - UtilPlayer.message(caller, F.main("Tutorials", Arrays.toString(Plugin.getTaskManager().Get(caller).TasksCompleted.toArray()))); - Plugin.getTaskManager().Get(caller).TasksCompleted.remove(Plugin.getTaskManager().getTaskId(tutorial.getType().getId())); - UtilPlayer.message(caller, F.main("Tutorials", "Removed " + F.elem(tutorial.getType().getId()))); for (final TutorialTask task : tutorial.getTasks().values()) { Plugin.getTaskManager().Get(caller).TasksCompleted.remove(Plugin.getTaskManager().getTaskId(tutorial.getType().getId() + task.getNameID())); - UtilPlayer.message(caller, F.main("Tutorials", "Removed " + F.elem(tutorial.getType().getId() + task.getNameID()) + " (" + Plugin.getTaskManager().getTaskId(tutorial.getType().getId() + task.getNameID()) + ")")); } - UtilPlayer.message(caller, F.main("Tutorials", Arrays.toString(Plugin.getTaskManager().Get(caller).TasksCompleted.toArray()))); - 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); + 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 301382358..080bf72a7 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 @@ -1,5 +1,8 @@ package mineplex.game.clans.tutorials.types; +import java.util.HashMap; +import java.util.Map; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.entity.Player; @@ -18,6 +21,8 @@ import mineplex.core.task.TaskManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.clans.event.ClansPlayerBuyItemEvent; +import mineplex.game.clans.clans.event.ClansShopAddButtonEvent; import mineplex.game.clans.clans.event.PlayerEnterTerritoryEvent; import mineplex.game.clans.economy.GoldManager; import mineplex.game.clans.tutorials.Tutorial; @@ -54,16 +59,20 @@ public class TutorialGettingStarted extends Tutorial UtilPlayer.message(player, F.main("Tutorials", "You are now ready to play, welcome to the game.")); } - public boolean nullPrices(ItemStack item, final Player player) + @EventHandler(priority = EventPriority.MONITOR) + public void onClansShopButtonAdded(ClansShopAddButtonEvent event) { + final Player player = event.getPlayer(); + final Material type = event.getMaterial(); + if (!isInTutorial(player)) { - return false; + return; } TutorialClient client = get(player); - if (UtilItem.isWeapon(item)) + if (UtilItem.isWeapon(type) && hasFinishedTask(player, "Buy Armor") && !hasFinishedTask(player, "Use An Ability")) { boolean hasBoughtWeapon = false; @@ -76,13 +85,18 @@ public class TutorialGettingStarted extends Tutorial } } - return !hasBoughtWeapon; + if (!hasBoughtWeapon) + { + event.setBuyPrice(0); + event.setSellPrice(0); + } } - else if (UtilItem.isArmour(item)) + + if (UtilItem.isArmour(type) && hasFinishedTask(player, "Visit The Shops") && !hasFinishedTask(player, "Buy Armor")) { - boolean hasBoughtSet = false; - ArmourMaterial armourBought = null; - int armourBoughtAmount = 0; + boolean hasBoughtFullSet = false; + Map armourBought = new HashMap<>(); + ArmourMaterial partialSetType = null; for (Material armour : UtilItem.listIn(ItemCategory.ARMOUR)) { @@ -90,25 +104,55 @@ public class TutorialGettingStarted extends Tutorial { ArmourMaterial armourType = ArmourMaterial.of(armour); - if (armourBought != null && !armourType.equals(armourBought)) + armourBought.put(armourType, armourBought.containsKey(armourType) ? armourBought.get(armourType) + 1 : 0); + + if (armourBought.get(armourType) >= 3) { - continue; + hasBoughtFullSet = true; } - armourBought = armourType; - armourBoughtAmount++; - if (armourBoughtAmount == 3) - { - hasBoughtSet = true; - } + partialSetType = armourType; } } - return !hasBoughtSet; + if (!hasBoughtFullSet && (partialSetType != null ? ArmourMaterial.of(type).equals(partialSetType) : true) && !client.getData().containsKey(type.name() + "_bought")) + { + event.setBuyPrice(0); + event.setSellPrice(0); + } } - else + } + + @EventHandler + public void onPlayerBuyItem(ClansPlayerBuyItemEvent event) + { + final Player player = event.getPlayer(); + final ItemStack item = event.getItem(); + final TutorialClient client = get(player); + + if (isInTutorial(player) && get(player).hasFinishedTask(getTask("Visit The Shops")) && !get(player).hasFinishedTask(getTask("Buy Armor"))) { - return false; + if (UtilItem.isArmour(item) || UtilItem.isWeapon(item)) + { + Map armourBought = new HashMap<>(); + + for (Material armour : UtilItem.listIn(ItemCategory.ARMOUR)) + { + if (client.getData().containsKey(armour.name() + "_bought")) + { + ArmourMaterial armourType = ArmourMaterial.of(armour); + + armourBought.put(armourType, armourBought.containsKey(armourType) ? armourBought.get(armourType) + 1 : 0); + } + } + + if (armourBought.containsKey(ArmourMaterial.of(item.getType())) && armourBought.get(ArmourMaterial.of(item.getType())) >= 3) + { + finishTask(player, "Buy Armor"); + } + + client.setData(item.getType().name() + "_bought", true); + } } } @@ -137,15 +181,15 @@ public class TutorialGettingStarted extends Tutorial System.out.println(oldTerritory + ", " + newTerritory); - if (isInTutorial(player) && newTerritory.contains("Spawn") && get(player).hasFinishedTask(getTask(3)) && !get(player).hasFinishedTask(getTask("Leave Spawn"))) + if (isInTutorial(player) && newTerritory.contains("Spawn") && get(player).hasFinishedTask(getTask("Viewing Clan Info")) && !get(player).hasFinishedTask(getTask("Leave Spawn"))) { finishTask(player, "Leave Spawn"); } - else if (isInTutorial(player) && newTerritory.contains("Wilderness") && get(player).hasFinishedTask(getTask(4)) && !get(player).hasFinishedTask(getTask("Go To The Wilderness"))) + else if (isInTutorial(player) && newTerritory.contains("Wilderness") && get(player).hasFinishedTask(getTask("Leave Spawn")) && !get(player).hasFinishedTask(getTask("Go To The Wilderness"))) { finishTask(player, "Go To The Wilderness"); } - else if (isInTutorial(player) && newTerritory.contains("Shops") && get(player).hasFinishedTask(getTask(6)) && !get(player).hasFinishedTask(getTask("Visit The Shops"))) + else if (isInTutorial(player) && newTerritory.contains("Shops") && get(player).hasFinishedTask(getTask("Claiming Territory")) && !get(player).hasFinishedTask(getTask("Visit The Shops"))) { finishTask(player, "Visit The Shops"); } @@ -163,34 +207,6 @@ public class TutorialGettingStarted extends Tutorial return true; } - public void onItemBought(final Player player, final ItemStack item) - { - if (isInTutorial(player) && get(player).hasFinishedTask(getTask("Visit The Shops")) && !get(player).hasFinishedTask(getTask("Buy Armor"))) - { - if (UtilItem.isArmour(item) || UtilItem.isWeapon(item)) - { - int amount = 0; - for (Material material : UtilItem.listIn(ItemCategory.ARMOUR, ArmourMaterial.of(item.getType()).asCategory())) - { - if (get(player).getData().containsKey(material.name() + "_bought")) - { - amount++; - } - } - - if (amount < 3) - { - get(player).setData("amount", ((int) get(player).getData("amount")) + 1); - get(player).setData(item.getType() + "_bought", true); - } - else - { - finishTask(player, "Buy Armor"); - } - } - } - } - @EventHandler(priority = EventPriority.MONITOR) public void onInventoryClick(final InventoryClickEvent event) {