From 65c90a9b295b789e64e2aa41421735b6ef6e6660 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Tue, 16 Jul 2019 22:07:37 -0400 Subject: [PATCH] NEW item brewing objective --- .../java/me/blackvein/quests/QuestData.java | 72 ++++++------ .../me/blackvein/quests/QuestFactory.java | 27 ++++- .../java/me/blackvein/quests/Quester.java | 110 +++++++++++++++--- .../main/java/me/blackvein/quests/Quests.java | 58 +++++++++ .../main/java/me/blackvein/quests/Stage.java | 10 ++ .../quests/listeners/PlayerListener.java | 11 +- .../quests/prompts/CreateStagePrompt.java | 2 +- .../blackvein/quests/prompts/ItemsPrompt.java | 74 +++++++++++- .../quests/prompts/StagesPrompt.java | 2 + .../java/me/blackvein/quests/util/CK.java | 1 + .../me/blackvein/quests/util/ItemUtil.java | 37 +++--- .../me/blackvein/quests/util/LocaleQuery.java | 55 ++++++++- main/src/main/resources/strings.yml | 2 + 13 files changed, 378 insertions(+), 83 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/QuestData.java b/main/src/main/java/me/blackvein/quests/QuestData.java index c1dd86e9f..fba1e062e 100644 --- a/main/src/main/java/me/blackvein/quests/QuestData.java +++ b/main/src/main/java/me/blackvein/quests/QuestData.java @@ -257,41 +257,6 @@ public class QuestData { } }; - public LinkedHashMap potionsBrewed = new LinkedHashMap() { - - private static final long serialVersionUID = 5079308756224324031L; - - @Override - public Integer put(String key, Integer val) { - Integer data = super.put(key, val); - if (doJournalUpdate) - quester.updateJournal(); - return data; - } - - @Override - public Integer remove(Object key) { - Integer i = super.remove(key); - if (doJournalUpdate) - quester.updateJournal(); - return i; - } - - @Override - public void clear() { - super.clear(); - if (doJournalUpdate) - quester.updateJournal(); - } - - @Override - public void putAll(Map m) { - super.putAll(m); - if (doJournalUpdate) - quester.updateJournal(); - } - }; - public LinkedHashMap itemsCrafted = new LinkedHashMap() { private static final long serialVersionUID = 2774356294049526105L; @@ -329,7 +294,7 @@ public class QuestData { public LinkedHashMap itemsSmelted = new LinkedHashMap() { - private static final long serialVersionUID = 2774356235274526105L; + private static final long serialVersionUID = 2774356235274526106L; @Override public Integer put(ItemStack key, Integer val) { @@ -397,6 +362,41 @@ public class QuestData { } }; + public LinkedHashMap itemsBrewed = new LinkedHashMap() { + + private static final long serialVersionUID = 2774356235274526107L; + + @Override + public Integer put(ItemStack key, Integer val) { + Integer data = super.put(key, val); + if (doJournalUpdate) + quester.updateJournal(); + return data; + } + + @Override + public Integer remove(Object key) { + Integer i = super.remove(key); + if (doJournalUpdate) + quester.updateJournal(); + return i; + } + + @Override + public void clear() { + super.clear(); + if (doJournalUpdate) + quester.updateJournal(); + } + + @Override + public void putAll(Map m) { + super.putAll(m); + if (doJournalUpdate) + quester.updateJournal(); + } + }; + public LinkedHashMap itemsDelivered = new LinkedHashMap() { private static final long serialVersionUID = 2712497347022734646L; diff --git a/main/src/main/java/me/blackvein/quests/QuestFactory.java b/main/src/main/java/me/blackvein/quests/QuestFactory.java index dce178247..275da59a4 100644 --- a/main/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/main/src/main/java/me/blackvein/quests/QuestFactory.java @@ -1007,14 +1007,15 @@ public class QuestFactory implements ConversationAbandonedListener { LinkedList cutNames; LinkedList cutAmounts; LinkedList cutDurability; - LinkedList deliveryItems; + LinkedList craftItems; + LinkedList smeltItems; LinkedList enchantments; LinkedList enchantmentIds; LinkedList enchantmentAmounts; + LinkedList brewItems; Integer fish; Integer players; - LinkedList craftItems; - LinkedList smeltItems; + LinkedList deliveryItems; LinkedList deliveryNPCIds; LinkedList deliveryMessages; LinkedList npcTalkIds; @@ -1074,6 +1075,7 @@ public class QuestFactory implements ConversationAbandonedListener { enchantments = null; enchantmentIds = null; enchantmentAmounts = null; + brewItems = null; fish = null; players = null; deliveryItems = null; @@ -1149,6 +1151,9 @@ public class QuestFactory implements ConversationAbandonedListener { enchantmentIds = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_NAMES); enchantmentAmounts = (LinkedList) cc.getSessionData(pref + CK.S_ENCHANT_AMOUNTS); } + if (cc.getSessionData(pref + CK.S_BREW_ITEMS) != null) { + brewItems = (LinkedList) cc.getSessionData(pref + CK.S_BREW_ITEMS); + } if (cc.getSessionData(pref + CK.S_FISH) != null) { fish = (Integer) cc.getSessionData(pref + CK.S_FISH); } @@ -1280,6 +1285,15 @@ public class QuestFactory implements ConversationAbandonedListener { stage.set("enchantments", enchantments); stage.set("enchantment-item-names", enchantmentIds); stage.set("enchantment-amounts", enchantmentAmounts); + if (brewItems != null && brewItems.isEmpty() == false) { + LinkedList items = new LinkedList(); + for (ItemStack is : brewItems) { + items.add(ItemUtil.serializeItemStack(is)); + } + stage.set("items-to-brew", items); + } else { + stage.set("items-to-brew", null); + } stage.set("fish-to-catch", fish); stage.set("players-to-kill", players); if (deliveryItems != null && deliveryItems.isEmpty() == false) { @@ -1642,6 +1656,13 @@ public class QuestFactory implements ConversationAbandonedListener { cc.setSessionData(pref + CK.S_ENCHANT_NAMES, names); cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts); } + if (stage.getItemsToBrew().isEmpty() == false) { + LinkedList items = new LinkedList(); + for (ItemStack is : stage.getItemsToBrew()) { + items.add(is); + } + cc.setSessionData(pref + CK.S_BREW_ITEMS, items); + } if (stage.fishToCatch != null) { cc.setSessionData(pref + CK.S_FISH, stage.fishToCatch); } diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 20e621ed6..6d0fa8146 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -702,6 +702,20 @@ public class Quester { } } } + for (ItemStack is : getCurrentStage(quest).itemsToBrew) { + int brewed = 0; + if (getQuestData(quest).itemsBrewed.containsKey(is)) { + brewed = getQuestData(quest).itemsBrewed.get(is); + } + int amt = is.getAmount(); + if (brewed < amt) { + String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is); + unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + brewed + "/" + amt); + } else { + String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is); + finishedObjectives.add(ChatColor.GRAY + obj + ": " + brewed + "/" + amt); + } + } if (getCurrentStage(quest).fishToCatch != null) { if (getQuestData(quest).getFishCaught() < getCurrentStage(quest).fishToCatch) { unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "catchFish") + ChatColor.GREEN + ": " @@ -965,6 +979,8 @@ public class Quester { return !getCurrentStage(quest).itemsToSmelt.isEmpty(); } else if (s.equalsIgnoreCase("enchantItem")) { return !getCurrentStage(quest).itemsToEnchant.isEmpty(); + } else if (s.equalsIgnoreCase("brewItem")) { + return !getCurrentStage(quest).itemsToBrew.isEmpty(); } else if (s.equalsIgnoreCase("catchFish")) { return getCurrentStage(quest).fishToCatch != null; } else if (s.equalsIgnoreCase("killMob")) { @@ -1324,7 +1340,7 @@ public class Quester { plugin.getLogger().severe("Index out of bounds while crafting " + found.getType() + " x " + found.getAmount() + " for quest " + quest.getName() + " with " + i.getType() + " x " + i.getAmount() + " already crafted. Int -amount- reports value of " + + amount + ". Please report this error on Github!"); - player.sendMessage("Quests had a problem crafting your item, please contact an administrator!"); + player.sendMessage(ChatColor.RED + "Quests had a problem crafting your item, please contact an administrator!"); return; } int req = getCurrentStage(quest).itemsToCraft.get(getCurrentStage(quest).itemsToCraft.indexOf(found)).getAmount(); @@ -1361,7 +1377,7 @@ public class Quester { plugin.getLogger().severe("Index out of bounds while smelting " + found.getType() + " x " + found.getAmount() + " for quest " + quest.getName() + " with " + i.getType() + " x " + i.getAmount() + " already smelted. Int -amount- reports value of " + + amount + ". Please report this error on Github!"); - player.sendMessage("Quests had a problem smelting your item, please contact an administrator!"); + player.sendMessage(ChatColor.RED + "Quests had a problem smelting your item, please contact an administrator!"); return; } int req = getCurrentStage(quest).itemsToSmelt.get(getCurrentStage(quest).itemsToSmelt.indexOf(found)).getAmount(); @@ -1404,6 +1420,43 @@ public class Quester { } } + /** + * Mark item as brewed if Quester has such an objective + * + * @param quest The quest for which the item is being brewed + * @param i The item being brewed + */ + public void brewItem(Quest quest, ItemStack i) { + Player player = getPlayer(); + ItemStack found = null; + for (ItemStack is : getQuestData(quest).itemsBrewed.keySet()) { + if (ItemUtil.compareItems(i, is, true) == 0) { + found = is; + break; + } + } + if (found != null) { + int amount = getQuestData(quest).itemsBrewed.get(found); + if (getCurrentStage(quest).itemsToBrew.indexOf(found) < 0) { + plugin.getLogger().severe("Index out of bounds while brewing " + found.getType() + " x " + found.getAmount() + " for quest " + + quest.getName() + " with " + i.getType() + " x " + i.getAmount() + " already smelted. Int -amount- reports value of " + + + amount + ". Please report this error on Github!"); + player.sendMessage(ChatColor.RED + "Quests had a problem brewing your item, please contact an administrator!"); + return; + } + int req = getCurrentStage(quest).itemsToBrew.get(getCurrentStage(quest).itemsToBrew.indexOf(found)).getAmount(); + Material m = i.getType(); + if (amount < req) { + if ((i.getAmount() + amount) >= req) { + getQuestData(quest).itemsBrewed.put(found, req); + finishObjective(quest, "brewItem", new ItemStack(m, 1), found, null, null, null, null, null, null, null, null); + } else { + getQuestData(quest).itemsBrewed.put(found, (amount + i.getAmount())); + } + } + } + } + /** * Mark fish as caught if Quester has such an objective * @@ -1847,6 +1900,15 @@ public class Quester { p.sendMessage(message.replace("", ItemUtil.getName(increment)) .replace("", enchantment.getName())); } + } else if (objective.equalsIgnoreCase("brewItem")) { + ItemStack is = getCurrentStage(quest).itemsToBrew.get(getCurrentStage(quest).itemsToBrew.indexOf(goal)); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "brew") + " " + + is.getAmount() + "/" + is.getAmount(); + if (plugin.getSettings().canTranslateItems() && !increment.hasItemMeta() && !increment.getItemMeta().hasDisplayName()) { + plugin.getLocaleQuery().sendMessage(p, message, goal.getType(), goal.getDurability(), null); + } else { + p.sendMessage(message.replace("", ItemUtil.getName(is))); + } } else if (objective.equalsIgnoreCase("deliverItem")) { String obj = Lang.get(p, "deliver"); obj = obj.replace("", plugin.getNPCName(getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(goal)))); @@ -2036,6 +2098,11 @@ public class Quester { data.itemsEnchanted.put(map, 0); } } + if (quest.getStage(stage).itemsToBrew.isEmpty() == false) { + for (ItemStack is : quest.getStage(stage).itemsToBrew) { + data.itemsBrewed.put(is, 0); + } + } if (quest.getStage(stage).mobsToKill.isEmpty() == false) { for (EntityType e : quest.getStage(stage).mobsToKill) { data.mobsKilled.add(e); @@ -2217,6 +2284,13 @@ public class Quester { questSec.set("blocks-cut-amounts", blockAmounts); questSec.set("blocks-cut-durability", blockDurability); } + if (questData.itemsCrafted.isEmpty() == false) { + LinkedList craftAmounts = new LinkedList(); + for (Entry e : questData.itemsCrafted.entrySet()) { + craftAmounts.add(e.getValue()); + } + questSec.set("item-craft-amounts", craftAmounts); + } if (questData.itemsSmelted.isEmpty() == false) { LinkedList smeltAmounts = new LinkedList(); for (Entry e : questData.itemsSmelted.entrySet()) { @@ -2240,6 +2314,13 @@ public class Quester { questSec.set("enchantment-item-names", itemNames); questSec.set("times-enchanted", enchAmounts); } + if (questData.itemsBrewed.isEmpty() == false) { + LinkedList brewAmounts = new LinkedList(); + for (Entry e : questData.itemsBrewed.entrySet()) { + brewAmounts.add(e.getValue()); + } + questSec.set("item-brew-amounts", brewAmounts); + } if (getCurrentStage(quest).fishToCatch != null) { questSec.set("fish-caught", questData.getFishCaught()); } @@ -2312,16 +2393,6 @@ public class Quester { questSec.set("has-reached-location", has); questSec.set("radii-to-reach-within", radii); } - if (questData.potionsBrewed.isEmpty() == false) { - LinkedList potionNames = new LinkedList(); - LinkedList potionAmounts = new LinkedList(); - for (Entry entry : questData.potionsBrewed.entrySet()) { - potionNames.add(entry.getKey()); - potionAmounts.add(entry.getValue()); - } - questSec.set("potions-brewed-names", potionNames); - questSec.set("potions-brewed-amounts", potionAmounts); - } if (questData.mobsTamed.isEmpty() == false) { LinkedList mobNames = new LinkedList(); LinkedList mobAmounts = new LinkedList(); @@ -2651,6 +2722,14 @@ public class Quester { getQuestData(quest).itemsEnchanted.put(map, amounts.get(enchantments.indexOf(e))); } } + if (questSec.contains("item-brew-amounts")) { + List brewAmounts = questSec.getIntegerList("item-brew-amounts"); + for (int i = 0; i < brewAmounts.size(); i++) { + if (i < getCurrentStage(quest).itemsToBrew.size()) { + getQuestData(quest).itemsBrewed.put(getCurrentStage(quest).itemsToBrew.get(i), brewAmounts.get(i)); + } + } + } if (questSec.contains("fish-caught")) { getQuestData(quest).setFishCaught(questSec.getInt("fish-caught")); } @@ -2736,13 +2815,6 @@ public class Quester { getQuestData(quest).radiiToReachWithin.add(i); } } - if (questSec.contains("potions-brewed-names")) { - List names = questSec.getStringList("potions-brewed-names"); - List amounts = questSec.getIntegerList("potions-brewed-amounts"); - for (String s : names) { - getQuestData(quest).potionsBrewed.put(s, amounts.get(names.indexOf(s))); - } - } if (questSec.contains("mobs-to-tame")) { List mobs = questSec.getStringList("mobs-to-tame"); List amounts = questSec.getIntegerList("mob-tame-amounts"); diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index 5c7727d7a..7894da272 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -936,6 +936,48 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } } + for (ItemStack is : stage.itemsToBrew) { + int brewed = 0; + if (data.itemsBrewed.containsKey(is)) { + brewed = data.itemsBrewed.get(is); + } + int amt = is.getAmount(); + if (brewed < amt) { + String message = ChatColor.GREEN + Lang.get(quester.getPlayer(), "brew") + " " + + ChatColor.GREEN + ": " + brewed + "/" + is.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateItems()) { + if (is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { + // Bukkit version is 1.9+ + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), is.getEnchantments(), is.getItemMeta()); + } else if (Material.getMaterial("LINGERING_POTION") == null && !is.hasItemMeta() ) { + // Bukkit version is below 1.9 + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), is.getEnchantments()); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); + } + } + } else { + String message = ChatColor.GRAY + Lang.get(quester.getPlayer(), "brew") + " " + + ChatColor.GRAY + ": " + brewed + "/" + is.getAmount(); + if (depends.getPlaceholderApi() != null) { + message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message); + } + if (getSettings().canTranslateItems()) { + if (is.hasItemMeta() && !is.getItemMeta().hasDisplayName()) { + // Bukkit version is 1.9+ + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), is.getEnchantments(), is.getItemMeta()); + } else if (Material.getMaterial("LINGERING_POTION") == null && !is.hasItemMeta() ) { + // Bukkit version is below 1.9 + localeQuery.sendMessage(quester.getPlayer(), message, is.getType(), is.getDurability(), is.getEnchantments()); + } else { + quester.getPlayer().sendMessage(message.replace("", ItemUtil.getName(is))); + } + } + } + } if (stage.fishToCatch != null) { if (data.getFishCaught() < stage.fishToCatch) { String message = ChatColor.GREEN + Lang.get(quester.getPlayer(), "catchFish") @@ -1933,6 +1975,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener List enchantments = new LinkedList(); List itemsToEnchant = new LinkedList(); List amountsToEnchant = new LinkedList(); + List itemsToBrew = new LinkedList(); List npcIdsToTalkTo = new LinkedList(); List itemsToDeliver= new LinkedList(); List itemDeliveryTargetIds = new LinkedList(); @@ -2221,6 +2264,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing enchantment-amounts:"); } } + if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew")) { + if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew"), String.class)) { + itemsToBrew = config.getStringList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-brew"); + for (String item : itemsToBrew) { + ItemStack is = ItemUtil.readItemStack("" + item); + if (is != null) { + oStage.getItemsToBrew().add(is); + } else { + stageFailed("" + item + " inside items-to-brew: inside Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!"); + } + } + } else { + stageFailed("items-to-brew: in Stage " + s2 + " of Quest " + quest.getName() + " is not formatted properly!"); + } + } if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch")) { if (config.getInt("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch", -999) != -999) { oStage.fishToCatch = config.getInt("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch"); diff --git a/main/src/main/java/me/blackvein/quests/Stage.java b/main/src/main/java/me/blackvein/quests/Stage.java index 8a0c6e3c1..75f611a8d 100644 --- a/main/src/main/java/me/blackvein/quests/Stage.java +++ b/main/src/main/java/me/blackvein/quests/Stage.java @@ -40,6 +40,7 @@ public class Stage { protected LinkedList itemsToCraft = new LinkedList(); protected LinkedList itemsToSmelt = new LinkedList(); protected Map, Integer> itemsToEnchant = new HashMap, Integer>(); + protected LinkedList itemsToBrew = new LinkedList(); protected LinkedList itemsToDeliver = new LinkedList(); protected LinkedList itemDeliveryTargets = new LinkedList() { @@ -210,6 +211,14 @@ public class Stage { Map, Integer> itemsToEnchant) { this.itemsToEnchant = itemsToEnchant; } + + public LinkedList getItemsToBrew() { + return itemsToBrew; + } + + public void setItemsToBrew(LinkedList itemsToBrew) { + this.itemsToBrew = itemsToBrew; + } public LinkedList getItemsToDeliver() { return itemsToDeliver; @@ -507,6 +516,7 @@ public class Stage { if (itemsToCraft.isEmpty() == false) { return true; } if (itemsToSmelt.isEmpty() == false) { return true; } if (itemsToEnchant.isEmpty() == false) { return true; } + if (itemsToBrew.isEmpty() == false) { return true; } if (itemsToDeliver.isEmpty() == false) { return true; } if (citizensToInteract.isEmpty() == false) { return true; } if (citizensToKill.isEmpty() == false) { return true; } diff --git a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java index 466407f3e..56c6d2440 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java +++ b/main/src/main/java/me/blackvein/quests/listeners/PlayerListener.java @@ -541,7 +541,7 @@ public class PlayerListener implements Listener { } @EventHandler - public void onSmeltItem(InventoryClickEvent evt) { + public void onInventoryClick(InventoryClickEvent evt) { if (evt.getWhoClicked() instanceof Player) { if (evt.getInventory().getType() == InventoryType.FURNACE) { if (evt.getSlotType() == SlotType.RESULT) { @@ -552,6 +552,15 @@ public class PlayerListener implements Listener { } } } + } else if (evt.getInventory().getType() == InventoryType.BREWING) { + if (evt.getSlotType() == SlotType.CRAFTING) { + Quester quester = plugin.getQuester(evt.getWhoClicked().getUniqueId()); + for (Quest quest : quester.getCurrentQuests().keySet()) { + if (quester.containsObjective(quest, "brewItem")) { + quester.brewItem(quest, evt.getCurrentItem()); + } + } + } } } } diff --git a/main/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java b/main/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java index 5c2f3cda9..df500198a 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/CreateStagePrompt.java @@ -67,7 +67,7 @@ public class CreateStagePrompt extends FixedSetPrompt { hasObjective = true; text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.GOLD + " - " + Lang.get("stageEditorBlocks") + "\n"; } - if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null && context.getSessionData(pref + CK.S_SMELT_ITEMS) == null && context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null) { + if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null && context.getSessionData(pref + CK.S_SMELT_ITEMS) == null && context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null && context.getSessionData(pref + CK.S_BREW_ITEMS) == null) { text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GOLD + " - " + Lang.get("stageEditorItems") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; } else { hasObjective = true; diff --git a/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java index 7adbc3ccf..7e5e46ac2 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/ItemsPrompt.java @@ -37,7 +37,7 @@ public class ItemsPrompt extends FixedSetPrompt { private final QuestFactory questFactory; public ItemsPrompt(Quests plugin, int stageNum, QuestFactory qf) { - super("1", "2", "3", "4"); + super("1", "2", "3", "4", "5"); this.plugin = plugin; this.stageNum = stageNum; this.pref = "stage" + stageNum; @@ -93,7 +93,16 @@ public class ItemsPrompt extends FixedSetPrompt { + ItemUtil.getPrettyEnchantmentName(ItemUtil.getEnchantmentFromProperName(enchants.get(i))) + ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + amnts.get(i) + "\n"; } } - text += ChatColor.GREEN + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.DARK_PURPLE + "- " + Lang.get("done") + "\n"; + if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) { + text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "- " + Lang.get("stageEditorBrewItems") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + } else { + text += ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "4 " + ChatColor.RESET + ChatColor.LIGHT_PURPLE + "- " + Lang.get("stageEditorBrewItems") + "\n"; + LinkedList items = (LinkedList) context.getSessionData(pref + CK.S_BREW_ITEMS); + for (int i = 0; i < items.size(); i++) { + text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i)) + ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + "\n"; + } + } + text += ChatColor.GREEN + "" + ChatColor.BOLD + "5 " + ChatColor.RESET + ChatColor.DARK_PURPLE + "- " + Lang.get("done") + "\n"; return text; } @@ -105,6 +114,8 @@ public class ItemsPrompt extends FixedSetPrompt { return new SmeltListPrompt(); } else if (input.equalsIgnoreCase("3")) { return new EnchantmentListPrompt(); + } else if (input.equalsIgnoreCase("4")) { + return new BrewListPrompt(); } try { return new CreateStagePrompt(plugin, stageNum, questFactory); @@ -169,7 +180,6 @@ public class ItemsPrompt extends FixedSetPrompt { private List getItems(ConversationContext context) { return (List) context.getSessionData(pref + CK.S_CRAFT_ITEMS); } - } private class SmeltListPrompt extends FixedSetPrompt { @@ -227,7 +237,6 @@ public class ItemsPrompt extends FixedSetPrompt { private List getItems(ConversationContext context) { return (List) context.getSessionData(pref + CK.S_SMELT_ITEMS); } - } private class EnchantmentListPrompt extends FixedSetPrompt { @@ -456,4 +465,61 @@ public class ItemsPrompt extends FixedSetPrompt { return new EnchantmentListPrompt(); } } + + private class BrewListPrompt extends FixedSetPrompt { + + public BrewListPrompt() { + super("1", "2", "3"); + } + + @Override + public String getPromptText(ConversationContext context) { + // Check/add newly made item + if (context.getSessionData("newItem") != null) { + if (context.getSessionData(pref + CK.S_BREW_ITEMS) != null) { + List items = getItems(context); + items.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(pref + CK.S_BREW_ITEMS, items); + } else { + LinkedList items = new LinkedList(); + items.add((ItemStack) context.getSessionData("tempStack")); + context.setSessionData(pref + CK.S_BREW_ITEMS, items); + } + context.setSessionData("newItem", null); + context.setSessionData("tempStack", null); + } + String text = ChatColor.GOLD + "- " + Lang.get("stageEditorBrewItems") + " -\n"; + if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) { + text += ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n"; + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("stageEditorDeliveryAddItem") + "\n"; + } else { + text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("stageEditorDeliveryAddItem") + "\n"; + for (ItemStack is : getItems(context)) { + text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n"; + } + } + text += ChatColor.RED + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("clear") + "\n"; + text += ChatColor.GREEN + "" + ChatColor.BOLD + "3" + ChatColor.RESET + ChatColor.YELLOW + " - " + Lang.get("done"); + return text; + } + + @Override + protected Prompt acceptValidatedInput(ConversationContext context, String input) { + if (input.equalsIgnoreCase("1")) { + return new ItemStackPrompt(BrewListPrompt.this); + } else if (input.equalsIgnoreCase("2")) { + context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared")); + context.setSessionData(pref + CK.S_BREW_ITEMS, null); + return new BrewListPrompt(); + } else if (input.equalsIgnoreCase("3")) { + return new ItemsPrompt(plugin, stageNum, questFactory); + } + return null; + } + + @SuppressWarnings("unchecked") + private List getItems(ConversationContext context) { + return (List) context.getSessionData(pref + CK.S_BREW_ITEMS); + } + } } \ No newline at end of file diff --git a/main/src/main/java/me/blackvein/quests/prompts/StagesPrompt.java b/main/src/main/java/me/blackvein/quests/prompts/StagesPrompt.java index d454d21e7..f3b796ccb 100644 --- a/main/src/main/java/me/blackvein/quests/prompts/StagesPrompt.java +++ b/main/src/main/java/me/blackvein/quests/prompts/StagesPrompt.java @@ -117,6 +117,7 @@ public class StagesPrompt extends StringPrompt { cc.setSessionData(newPref + CK.S_ENCHANT_TYPES, cc.getSessionData(pref + CK.S_ENCHANT_TYPES)); cc.setSessionData(newPref + CK.S_ENCHANT_NAMES, cc.getSessionData(pref + CK.S_ENCHANT_NAMES)); cc.setSessionData(newPref + CK.S_ENCHANT_AMOUNTS, cc.getSessionData(pref + CK.S_ENCHANT_AMOUNTS)); + cc.setSessionData(newPref + CK.S_BREW_ITEMS, cc.getSessionData(pref + CK.S_BREW_ITEMS)); cc.setSessionData(newPref + CK.S_FISH, cc.getSessionData(pref + CK.S_FISH)); cc.setSessionData(newPref + CK.S_PLAYER_KILL, cc.getSessionData(pref + CK.S_PLAYER_KILL)); cc.setSessionData(newPref + CK.S_DELIVERY_ITEMS, cc.getSessionData(pref + CK.S_DELIVERY_ITEMS)); @@ -176,6 +177,7 @@ public class StagesPrompt extends StringPrompt { cc.setSessionData(pref + CK.S_SMELT_ITEMS, null); cc.setSessionData(pref + CK.S_ENCHANT_TYPES, null); cc.setSessionData(pref + CK.S_ENCHANT_NAMES, null); + cc.setSessionData(pref + CK.S_BREW_ITEMS, null); cc.setSessionData(pref + CK.S_FISH, null); cc.setSessionData(pref + CK.S_PLAYER_KILL, null); cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, null); diff --git a/main/src/main/java/me/blackvein/quests/util/CK.java b/main/src/main/java/me/blackvein/quests/util/CK.java index 983cb955b..0f050ffe9 100644 --- a/main/src/main/java/me/blackvein/quests/util/CK.java +++ b/main/src/main/java/me/blackvein/quests/util/CK.java @@ -67,6 +67,7 @@ public class CK { public static final String S_ENCHANT_TYPES = "enchantTypes"; public static final String S_ENCHANT_NAMES = "enchantNames"; public static final String S_ENCHANT_AMOUNTS = "enchantAmounts"; + public static final String S_BREW_ITEMS = "brewItems"; public static final String S_DELIVERY_ITEMS = "deliveryItems"; public static final String S_DELIVERY_NPCS = "deliveryNPCs"; public static final String S_DELIVERY_MESSAGES = "deliveryMessages"; diff --git a/main/src/main/java/me/blackvein/quests/util/ItemUtil.java b/main/src/main/java/me/blackvein/quests/util/ItemUtil.java index b78ec96f4..4b51437a0 100644 --- a/main/src/main/java/me/blackvein/quests/util/ItemUtil.java +++ b/main/src/main/java/me/blackvein/quests/util/ItemUtil.java @@ -33,7 +33,9 @@ import org.bukkit.inventory.meta.BookMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.Potion; +@SuppressWarnings("deprecation") public class ItemUtil { /** @@ -55,7 +57,6 @@ public class ItemUtil { * -8 if stack Written Book data is unequal * -9 if stack Potion type is unequal */ - @SuppressWarnings("deprecation") public static int compareItems(ItemStack one, ItemStack two, boolean ignoreAmount) { if (one == null || two == null) { return 1; @@ -110,17 +111,30 @@ public class ItemUtil { } } } - if (Material.getMaterial("LINGERING_POTION") != null) { - // Bukkit version is 1.9+ - if (one.getType().equals(Material.POTION) || one.getType().equals(Material.LINGERING_POTION) || one.getType().equals(Material.SPLASH_POTION)) { - PotionMeta pmeta1 = (PotionMeta) one.getItemMeta(); - PotionMeta pmeta2 = (PotionMeta) one.getItemMeta(); - if (pmeta1.getBasePotionData().getType().equals(pmeta2.getBasePotionData().getType()) == false) { - return -9; + if (one.getItemMeta() instanceof PotionMeta) { + if (Material.getMaterial("LINGERING_POTION") != null) { + // Bukkit version is 1.9+ + if (one.getType().equals(Material.POTION) || one.getType().equals(Material.LINGERING_POTION) || one.getType().equals(Material.SPLASH_POTION)) { + PotionMeta pmeta1 = (PotionMeta) one.getItemMeta(); + PotionMeta pmeta2 = (PotionMeta) one.getItemMeta(); + if (pmeta1.getBasePotionData().getType().equals(pmeta2.getBasePotionData().getType()) == false) { + return -9; + } } } } } + if (Material.getMaterial("LINGERING_POTION") == null) { + // Bukkit version is below 1.9 + Potion pot1 = new Potion(one.getDurability()); + Potion pot2 = new Potion(two.getDurability()); + if (pot1.getType() == null || pot2.getType() == null) { + return -9; + } + if (!pot1.getType().equals(pot2.getType())) { + return -9; + } + } if (one.getEnchantments().equals(two.getEnchantments()) == false) { return -5; } @@ -146,7 +160,6 @@ public class ItemUtil { * @param durability The data value of the item, default of 0 * @return ItemStack, or null if invalid format */ - @SuppressWarnings("deprecation") public static ItemStack processItemStack(String material, int amount, short durability) { try { return new ItemStack(Material.getMaterial(material.toUpperCase()), amount, durability); @@ -172,7 +185,6 @@ public class ItemUtil { * @param data formatted string * @return ItemStack, or null if invalid format */ - @SuppressWarnings("deprecation") public static ItemStack readItemStack(String data) { if (data == null) { return null; @@ -384,7 +396,6 @@ public class ItemUtil { * @param is ItemStack * @return formatted string, or null if invalid stack */ - @SuppressWarnings("deprecation") public static String serializeItemStack(ItemStack is) { String serial; if (is == null) { @@ -448,7 +459,6 @@ public class ItemUtil { * @param is ItemStack to check * @return true display or item name, plus durability and amount, plus enchantments */ - @SuppressWarnings("deprecation") public static String getDisplayString(ItemStack is) { String text; if (is == null) { @@ -481,7 +491,6 @@ public class ItemUtil { * @param is ItemStack to check * @return true display or item name, plus durability and amount, if stack is not null */ - @SuppressWarnings("deprecation") public static String getString(ItemStack is) { if (is == null) { return null; @@ -588,7 +597,6 @@ public class ItemUtil { * @param e Enchantment to get localized name of * @return localized name */ - @SuppressWarnings("deprecation") // since 1.13 private static String getEnchantmentName(Enchantment e) { try { return (Lang.get("ENCHANTMENT_" + e.getName())); @@ -599,7 +607,6 @@ public class ItemUtil { } } - @SuppressWarnings("deprecation") // since 1.13 public static Enchantment getEnchantmentFromProperName(String enchant) { String ench = Lang.getKey(enchant.replace(" ", "")); ench = ench.replace("ENCHANTMENT_", ""); diff --git a/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java b/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java index b9d4e4ade..dcf73cbbd 100644 --- a/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java +++ b/main/src/main/java/me/blackvein/quests/util/LocaleQuery.java @@ -28,8 +28,11 @@ import org.bukkit.entity.Player; import org.bukkit.entity.Rabbit; import org.bukkit.entity.Villager.Career; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.PotionMeta; +import org.bukkit.potion.Potion; +@SuppressWarnings("deprecation") public class LocaleQuery { private static Class craftMagicNumbers = null; private static Class itemClazz = null; @@ -38,6 +41,7 @@ public class LocaleQuery { private static boolean hasBasePotionData = false; private Map oldBlocks = getBlockKeys(); private Map oldItems = getItemKeys(); + private Map oldPotions_18 = getPotionKeys_18(); private Map oldPotions = getPotionKeys(); private Map oldLingeringPotions = getLingeringPotionKeys(); private Map oldSplashPotions = getSplashPotionKeys(); @@ -66,7 +70,7 @@ public class LocaleQuery { * Send message with item name translated to the client's locale. * Material is required. Durability arg is arbitrary for 1.13+ * and can be ignored by setting to a value less than 0. - * Enchantments are optional and may be left null or empty.

+ * Enchantments & meta are optional and may be left null or empty.

* * Message should contain {@code } string for replacement by * this method (along with applicable {@code } strings). @@ -76,9 +80,9 @@ public class LocaleQuery { * @param material The item to be translated * @param durability Durability for the item being translated * @param enchantments Enchantments for the item being translated + * @param meta ItemMeta for the item being translated */ - @SuppressWarnings("deprecation") - public boolean sendMessage(Player player, String message, Material material, short durability, Map enchantments) { + public boolean sendMessage(Player player, String message, Material material, short durability, Map enchantments, ItemMeta meta) { if (material == null) { return false; } @@ -105,6 +109,8 @@ public class LocaleQuery { } else if (material.equals(Material.SPLASH_POTION)) { matKey = oldSplashPotions.get(((PotionMeta)i.getItemMeta()).getBasePotionData().getType().name()); } + } else if (new Potion(durability).getType() != null) { + matKey = oldPotions_18.get(new Potion(durability).getType().name()); } } else if (durability >= 0 && oldItems.containsKey(material.name() + "." + durability)) { matKey = oldItems.get(material.name() + "." + durability); @@ -130,6 +136,9 @@ public class LocaleQuery { plugin.getLogger().severe("Unable to query Material: " + material.name()); return false; } + if (meta != null && meta instanceof PotionMeta) { + matKey = "item.minecraft.potion.effect." + ((PotionMeta)meta).getBasePotionData().getType().name().toLowerCase(); + } if (enchantments != null && !enchantments.isEmpty()) { int count = 0; for (Enchantment e : enchantments.keySet()) { @@ -148,6 +157,25 @@ public class LocaleQuery { return true; } + /** + * Send message with item name translated to the client's locale. + * Material is required. Durability arg is arbitrary for 1.13+ + * and can be ignored by setting to a value less than 0. + * Enchantments are optional and may be left null or empty.

+ * + * Message should contain {@code } string for replacement by + * this method (along with applicable {@code } strings). + * + * @param player The player whom the message is to be sent to + * @param message The message to be sent to the player + * @param material The item to be translated + * @param durability Durability for the item being translated + * @param enchantments Enchantments for the item being translated + */ + public boolean sendMessage(Player player, String message, Material material, short durability, Map enchantments) { + return sendMessage(player, message, material, durability, enchantments, null); + } + /** * Send message with enchantments translated to the client's locale. * Map of Enchantment+level is required. @@ -159,7 +187,6 @@ public class LocaleQuery { * @param message The message to be sent to the player * @param enchantments Enchantments for the item being translated */ - @SuppressWarnings("deprecation") public boolean sendMessage(Player player, String message, Map enchantments) { if (enchantments == null) { return false; @@ -1071,6 +1098,26 @@ public class LocaleQuery { keys.put("WALL_BANNER.0", "item.WALL_BANNER.white.name"); // added return keys; } + + public Map getPotionKeys_18() { + LinkedHashMap keys = new LinkedHashMap(); + keys.put("WATER", "potion.empty"); + keys.put("SPEED", "potion.moveSpeed.postfix"); + keys.put("SLOWNESS", "potion.moveSlowdown.postfix"); + keys.put("STRENGTH", "potion.damageBoost.postfix"); + keys.put("WEAKNESS", "potion.weakness.postfix"); + keys.put("INSTANT_HEAL", "potion.effect.healing"); + keys.put("INSTANT_DAMAGE", "potion.harm.postfix"); + keys.put("JUMP", "potion.jump.postfix"); + keys.put("REGEN", "potion.regeneration.postfix"); + keys.put("FIRE_RESISTANCE", "potion.fireResistance.postfix"); + keys.put("WATER_BREATHING", "potion.waterBreathing.postfix"); + keys.put("INVISIBILITY", "potion.invisibility.postfix"); + keys.put("NIGHT_VISION", "potion.nightVision.postfix"); + keys.put("POISON", "potion.poison.postfix"); + return keys; + } + public Map getPotionKeys() { LinkedHashMap keys = new LinkedHashMap(); keys.put("UNCRAFTABLE", "potion.effect.empty"); diff --git a/main/src/main/resources/strings.yml b/main/src/main/resources/strings.yml index 11416741f..658f665ac 100644 --- a/main/src/main/resources/strings.yml +++ b/main/src/main/resources/strings.yml @@ -132,6 +132,7 @@ stageEditorItems: "Items" stageEditorCraftItems: "Craft items" stageEditorSmeltItems: "Smelt items" stageEditorEnchantItems: "Enchant items" +stageEditorBrewItems: "Brew items" stageEditorNPCs: "NPCs" stageEditorDeliverItems: "Deliver items" stageEditorTalkToNPCs: "Talk to NPCs" @@ -652,6 +653,7 @@ cut: "Cut" craft: "Craft" smelt: "Smelt" enchantItem: "Enchant with " +brew: "Brew" catchFish: "Catch Fish" kill: "Kill" killAtLocation: "Kill at "