NEW item brewing objective

This commit is contained in:
PikaMug 2019-07-16 22:07:37 -04:00
parent 97d7185fc5
commit 65c90a9b29
13 changed files with 378 additions and 83 deletions

View File

@ -257,41 +257,6 @@ public class QuestData {
} }
}; };
public LinkedHashMap<String, Integer> potionsBrewed = new LinkedHashMap<String, Integer>() {
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<? extends String, ? extends Integer> m) {
super.putAll(m);
if (doJournalUpdate)
quester.updateJournal();
}
};
public LinkedHashMap<ItemStack, Integer> itemsCrafted = new LinkedHashMap<ItemStack, Integer>() { public LinkedHashMap<ItemStack, Integer> itemsCrafted = new LinkedHashMap<ItemStack, Integer>() {
private static final long serialVersionUID = 2774356294049526105L; private static final long serialVersionUID = 2774356294049526105L;
@ -329,7 +294,7 @@ public class QuestData {
public LinkedHashMap<ItemStack, Integer> itemsSmelted = new LinkedHashMap<ItemStack, Integer>() { public LinkedHashMap<ItemStack, Integer> itemsSmelted = new LinkedHashMap<ItemStack, Integer>() {
private static final long serialVersionUID = 2774356235274526105L; private static final long serialVersionUID = 2774356235274526106L;
@Override @Override
public Integer put(ItemStack key, Integer val) { public Integer put(ItemStack key, Integer val) {
@ -397,6 +362,41 @@ public class QuestData {
} }
}; };
public LinkedHashMap<ItemStack, Integer> itemsBrewed = new LinkedHashMap<ItemStack, Integer>() {
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<? extends ItemStack, ? extends Integer> m) {
super.putAll(m);
if (doJournalUpdate)
quester.updateJournal();
}
};
public LinkedHashMap<ItemStack, Integer> itemsDelivered = new LinkedHashMap<ItemStack, Integer>() { public LinkedHashMap<ItemStack, Integer> itemsDelivered = new LinkedHashMap<ItemStack, Integer>() {
private static final long serialVersionUID = 2712497347022734646L; private static final long serialVersionUID = 2712497347022734646L;

View File

@ -1007,14 +1007,15 @@ public class QuestFactory implements ConversationAbandonedListener {
LinkedList<Integer> cutNames; LinkedList<Integer> cutNames;
LinkedList<Integer> cutAmounts; LinkedList<Integer> cutAmounts;
LinkedList<Short> cutDurability; LinkedList<Short> cutDurability;
LinkedList<ItemStack> deliveryItems; LinkedList<ItemStack> craftItems;
LinkedList<ItemStack> smeltItems;
LinkedList<String> enchantments; LinkedList<String> enchantments;
LinkedList<Integer> enchantmentIds; LinkedList<Integer> enchantmentIds;
LinkedList<Integer> enchantmentAmounts; LinkedList<Integer> enchantmentAmounts;
LinkedList<ItemStack> brewItems;
Integer fish; Integer fish;
Integer players; Integer players;
LinkedList<ItemStack> craftItems; LinkedList<ItemStack> deliveryItems;
LinkedList<ItemStack> smeltItems;
LinkedList<Integer> deliveryNPCIds; LinkedList<Integer> deliveryNPCIds;
LinkedList<String> deliveryMessages; LinkedList<String> deliveryMessages;
LinkedList<Integer> npcTalkIds; LinkedList<Integer> npcTalkIds;
@ -1074,6 +1075,7 @@ public class QuestFactory implements ConversationAbandonedListener {
enchantments = null; enchantments = null;
enchantmentIds = null; enchantmentIds = null;
enchantmentAmounts = null; enchantmentAmounts = null;
brewItems = null;
fish = null; fish = null;
players = null; players = null;
deliveryItems = null; deliveryItems = null;
@ -1149,6 +1151,9 @@ public class QuestFactory implements ConversationAbandonedListener {
enchantmentIds = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_ENCHANT_NAMES); enchantmentIds = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_ENCHANT_NAMES);
enchantmentAmounts = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_ENCHANT_AMOUNTS); enchantmentAmounts = (LinkedList<Integer>) cc.getSessionData(pref + CK.S_ENCHANT_AMOUNTS);
} }
if (cc.getSessionData(pref + CK.S_BREW_ITEMS) != null) {
brewItems = (LinkedList<ItemStack>) cc.getSessionData(pref + CK.S_BREW_ITEMS);
}
if (cc.getSessionData(pref + CK.S_FISH) != null) { if (cc.getSessionData(pref + CK.S_FISH) != null) {
fish = (Integer) cc.getSessionData(pref + CK.S_FISH); fish = (Integer) cc.getSessionData(pref + CK.S_FISH);
} }
@ -1280,6 +1285,15 @@ public class QuestFactory implements ConversationAbandonedListener {
stage.set("enchantments", enchantments); stage.set("enchantments", enchantments);
stage.set("enchantment-item-names", enchantmentIds); stage.set("enchantment-item-names", enchantmentIds);
stage.set("enchantment-amounts", enchantmentAmounts); stage.set("enchantment-amounts", enchantmentAmounts);
if (brewItems != null && brewItems.isEmpty() == false) {
LinkedList<String> items = new LinkedList<String>();
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("fish-to-catch", fish);
stage.set("players-to-kill", players); stage.set("players-to-kill", players);
if (deliveryItems != null && deliveryItems.isEmpty() == false) { 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_NAMES, names);
cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts); cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts);
} }
if (stage.getItemsToBrew().isEmpty() == false) {
LinkedList<ItemStack> items = new LinkedList<ItemStack>();
for (ItemStack is : stage.getItemsToBrew()) {
items.add(is);
}
cc.setSessionData(pref + CK.S_BREW_ITEMS, items);
}
if (stage.fishToCatch != null) { if (stage.fishToCatch != null) {
cc.setSessionData(pref + CK.S_FISH, stage.fishToCatch); cc.setSessionData(pref + CK.S_FISH, stage.fishToCatch);
} }

View File

@ -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 (getCurrentStage(quest).fishToCatch != null) {
if (getQuestData(quest).getFishCaught() < getCurrentStage(quest).fishToCatch) { if (getQuestData(quest).getFishCaught() < getCurrentStage(quest).fishToCatch) {
unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "catchFish") + ChatColor.GREEN + ": " unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "catchFish") + ChatColor.GREEN + ": "
@ -965,6 +979,8 @@ public class Quester {
return !getCurrentStage(quest).itemsToSmelt.isEmpty(); return !getCurrentStage(quest).itemsToSmelt.isEmpty();
} else if (s.equalsIgnoreCase("enchantItem")) { } else if (s.equalsIgnoreCase("enchantItem")) {
return !getCurrentStage(quest).itemsToEnchant.isEmpty(); return !getCurrentStage(quest).itemsToEnchant.isEmpty();
} else if (s.equalsIgnoreCase("brewItem")) {
return !getCurrentStage(quest).itemsToBrew.isEmpty();
} else if (s.equalsIgnoreCase("catchFish")) { } else if (s.equalsIgnoreCase("catchFish")) {
return getCurrentStage(quest).fishToCatch != null; return getCurrentStage(quest).fishToCatch != null;
} else if (s.equalsIgnoreCase("killMob")) { } 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 " 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 " + + quest.getName() + " with " + i.getType() + " x " + i.getAmount() + " already crafted. Int -amount- reports value of " +
+ amount + ". Please report this error on Github!"); + 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; return;
} }
int req = getCurrentStage(quest).itemsToCraft.get(getCurrentStage(quest).itemsToCraft.indexOf(found)).getAmount(); 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 " 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 " + + quest.getName() + " with " + i.getType() + " x " + i.getAmount() + " already smelted. Int -amount- reports value of " +
+ amount + ". Please report this error on Github!"); + 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; return;
} }
int req = getCurrentStage(quest).itemsToSmelt.get(getCurrentStage(quest).itemsToSmelt.indexOf(found)).getAmount(); 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 * Mark fish as caught if Quester has such an objective
* *
@ -1847,6 +1900,15 @@ public class Quester {
p.sendMessage(message.replace("<item>", ItemUtil.getName(increment)) p.sendMessage(message.replace("<item>", ItemUtil.getName(increment))
.replace("<enchantment>", enchantment.getName())); .replace("<enchantment>", 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") + " <item> "
+ 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("<item>", ItemUtil.getName(is)));
}
} else if (objective.equalsIgnoreCase("deliverItem")) { } else if (objective.equalsIgnoreCase("deliverItem")) {
String obj = Lang.get(p, "deliver"); String obj = Lang.get(p, "deliver");
obj = obj.replace("<npc>", plugin.getNPCName(getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(goal)))); obj = obj.replace("<npc>", plugin.getNPCName(getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(goal))));
@ -2036,6 +2098,11 @@ public class Quester {
data.itemsEnchanted.put(map, 0); 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) { if (quest.getStage(stage).mobsToKill.isEmpty() == false) {
for (EntityType e : quest.getStage(stage).mobsToKill) { for (EntityType e : quest.getStage(stage).mobsToKill) {
data.mobsKilled.add(e); data.mobsKilled.add(e);
@ -2217,6 +2284,13 @@ public class Quester {
questSec.set("blocks-cut-amounts", blockAmounts); questSec.set("blocks-cut-amounts", blockAmounts);
questSec.set("blocks-cut-durability", blockDurability); questSec.set("blocks-cut-durability", blockDurability);
} }
if (questData.itemsCrafted.isEmpty() == false) {
LinkedList<Integer> craftAmounts = new LinkedList<Integer>();
for (Entry<ItemStack, Integer> e : questData.itemsCrafted.entrySet()) {
craftAmounts.add(e.getValue());
}
questSec.set("item-craft-amounts", craftAmounts);
}
if (questData.itemsSmelted.isEmpty() == false) { if (questData.itemsSmelted.isEmpty() == false) {
LinkedList<Integer> smeltAmounts = new LinkedList<Integer>(); LinkedList<Integer> smeltAmounts = new LinkedList<Integer>();
for (Entry<ItemStack, Integer> e : questData.itemsSmelted.entrySet()) { for (Entry<ItemStack, Integer> e : questData.itemsSmelted.entrySet()) {
@ -2240,6 +2314,13 @@ public class Quester {
questSec.set("enchantment-item-names", itemNames); questSec.set("enchantment-item-names", itemNames);
questSec.set("times-enchanted", enchAmounts); questSec.set("times-enchanted", enchAmounts);
} }
if (questData.itemsBrewed.isEmpty() == false) {
LinkedList<Integer> brewAmounts = new LinkedList<Integer>();
for (Entry<ItemStack, Integer> e : questData.itemsBrewed.entrySet()) {
brewAmounts.add(e.getValue());
}
questSec.set("item-brew-amounts", brewAmounts);
}
if (getCurrentStage(quest).fishToCatch != null) { if (getCurrentStage(quest).fishToCatch != null) {
questSec.set("fish-caught", questData.getFishCaught()); questSec.set("fish-caught", questData.getFishCaught());
} }
@ -2312,16 +2393,6 @@ public class Quester {
questSec.set("has-reached-location", has); questSec.set("has-reached-location", has);
questSec.set("radii-to-reach-within", radii); questSec.set("radii-to-reach-within", radii);
} }
if (questData.potionsBrewed.isEmpty() == false) {
LinkedList<String> potionNames = new LinkedList<String>();
LinkedList<Integer> potionAmounts = new LinkedList<Integer>();
for (Entry<String, Integer> 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) { if (questData.mobsTamed.isEmpty() == false) {
LinkedList<String> mobNames = new LinkedList<String>(); LinkedList<String> mobNames = new LinkedList<String>();
LinkedList<Integer> mobAmounts = new LinkedList<Integer>(); LinkedList<Integer> mobAmounts = new LinkedList<Integer>();
@ -2651,6 +2722,14 @@ public class Quester {
getQuestData(quest).itemsEnchanted.put(map, amounts.get(enchantments.indexOf(e))); getQuestData(quest).itemsEnchanted.put(map, amounts.get(enchantments.indexOf(e)));
} }
} }
if (questSec.contains("item-brew-amounts")) {
List<Integer> 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")) { if (questSec.contains("fish-caught")) {
getQuestData(quest).setFishCaught(questSec.getInt("fish-caught")); getQuestData(quest).setFishCaught(questSec.getInt("fish-caught"));
} }
@ -2736,13 +2815,6 @@ public class Quester {
getQuestData(quest).radiiToReachWithin.add(i); getQuestData(quest).radiiToReachWithin.add(i);
} }
} }
if (questSec.contains("potions-brewed-names")) {
List<String> names = questSec.getStringList("potions-brewed-names");
List<Integer> 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")) { if (questSec.contains("mobs-to-tame")) {
List<String> mobs = questSec.getStringList("mobs-to-tame"); List<String> mobs = questSec.getStringList("mobs-to-tame");
List<Integer> amounts = questSec.getIntegerList("mob-tame-amounts"); List<Integer> amounts = questSec.getIntegerList("mob-tame-amounts");

View File

@ -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") + " <item>"
+ 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("<item>", ItemUtil.getName(is)));
}
}
} else {
String message = ChatColor.GRAY + Lang.get(quester.getPlayer(), "brew") + " <item>"
+ 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("<item>", ItemUtil.getName(is)));
}
}
}
}
if (stage.fishToCatch != null) { if (stage.fishToCatch != null) {
if (data.getFishCaught() < stage.fishToCatch) { if (data.getFishCaught() < stage.fishToCatch) {
String message = ChatColor.GREEN + Lang.get(quester.getPlayer(), "catchFish") String message = ChatColor.GREEN + Lang.get(quester.getPlayer(), "catchFish")
@ -1933,6 +1975,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
List<Enchantment> enchantments = new LinkedList<Enchantment>(); List<Enchantment> enchantments = new LinkedList<Enchantment>();
List<Material> itemsToEnchant = new LinkedList<Material>(); List<Material> itemsToEnchant = new LinkedList<Material>();
List<Integer> amountsToEnchant = new LinkedList<Integer>(); List<Integer> amountsToEnchant = new LinkedList<Integer>();
List<String> itemsToBrew = new LinkedList<String>();
List<Integer> npcIdsToTalkTo = new LinkedList<Integer>(); List<Integer> npcIdsToTalkTo = new LinkedList<Integer>();
List<String> itemsToDeliver= new LinkedList<String>(); List<String> itemsToDeliver= new LinkedList<String>();
List<Integer> itemDeliveryTargetIds = new LinkedList<Integer>(); List<Integer> itemDeliveryTargetIds = new LinkedList<Integer>();
@ -2221,6 +2264,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing enchantment-amounts:"); 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.contains("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch")) {
if (config.getInt("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch", -999) != -999) { 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"); oStage.fishToCatch = config.getInt("quests." + questKey + ".stages.ordered." + s2 + ".fish-to-catch");

View File

@ -40,6 +40,7 @@ public class Stage {
protected LinkedList<ItemStack> itemsToCraft = new LinkedList<ItemStack>(); protected LinkedList<ItemStack> itemsToCraft = new LinkedList<ItemStack>();
protected LinkedList<ItemStack> itemsToSmelt = new LinkedList<ItemStack>(); protected LinkedList<ItemStack> itemsToSmelt = new LinkedList<ItemStack>();
protected Map<Map<Enchantment, Material>, Integer> itemsToEnchant = new HashMap<Map<Enchantment, Material>, Integer>(); protected Map<Map<Enchantment, Material>, Integer> itemsToEnchant = new HashMap<Map<Enchantment, Material>, Integer>();
protected LinkedList<ItemStack> itemsToBrew = new LinkedList<ItemStack>();
protected LinkedList<ItemStack> itemsToDeliver = new LinkedList<ItemStack>(); protected LinkedList<ItemStack> itemsToDeliver = new LinkedList<ItemStack>();
protected LinkedList<Integer> itemDeliveryTargets = new LinkedList<Integer>() { protected LinkedList<Integer> itemDeliveryTargets = new LinkedList<Integer>() {
@ -211,6 +212,14 @@ public class Stage {
this.itemsToEnchant = itemsToEnchant; this.itemsToEnchant = itemsToEnchant;
} }
public LinkedList<ItemStack> getItemsToBrew() {
return itemsToBrew;
}
public void setItemsToBrew(LinkedList<ItemStack> itemsToBrew) {
this.itemsToBrew = itemsToBrew;
}
public LinkedList<ItemStack> getItemsToDeliver() { public LinkedList<ItemStack> getItemsToDeliver() {
return itemsToDeliver; return itemsToDeliver;
} }
@ -507,6 +516,7 @@ public class Stage {
if (itemsToCraft.isEmpty() == false) { return true; } if (itemsToCraft.isEmpty() == false) { return true; }
if (itemsToSmelt.isEmpty() == false) { return true; } if (itemsToSmelt.isEmpty() == false) { return true; }
if (itemsToEnchant.isEmpty() == false) { return true; } if (itemsToEnchant.isEmpty() == false) { return true; }
if (itemsToBrew.isEmpty() == false) { return true; }
if (itemsToDeliver.isEmpty() == false) { return true; } if (itemsToDeliver.isEmpty() == false) { return true; }
if (citizensToInteract.isEmpty() == false) { return true; } if (citizensToInteract.isEmpty() == false) { return true; }
if (citizensToKill.isEmpty() == false) { return true; } if (citizensToKill.isEmpty() == false) { return true; }

View File

@ -541,7 +541,7 @@ public class PlayerListener implements Listener {
} }
@EventHandler @EventHandler
public void onSmeltItem(InventoryClickEvent evt) { public void onInventoryClick(InventoryClickEvent evt) {
if (evt.getWhoClicked() instanceof Player) { if (evt.getWhoClicked() instanceof Player) {
if (evt.getInventory().getType() == InventoryType.FURNACE) { if (evt.getInventory().getType() == InventoryType.FURNACE) {
if (evt.getSlotType() == SlotType.RESULT) { 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());
}
}
}
} }
} }
} }

View File

@ -67,7 +67,7 @@ public class CreateStagePrompt extends FixedSetPrompt {
hasObjective = true; hasObjective = true;
text += ChatColor.BLUE + "" + ChatColor.BOLD + "1" + ChatColor.RESET + ChatColor.GOLD + " - " + Lang.get("stageEditorBlocks") + "\n"; 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"; text += ChatColor.BLUE + "" + ChatColor.BOLD + "2" + ChatColor.RESET + ChatColor.GOLD + " - " + Lang.get("stageEditorItems") + ChatColor.GRAY + " (" + Lang.get("noneSet") + ")\n";
} else { } else {
hasObjective = true; hasObjective = true;

View File

@ -37,7 +37,7 @@ public class ItemsPrompt extends FixedSetPrompt {
private final QuestFactory questFactory; private final QuestFactory questFactory;
public ItemsPrompt(Quests plugin, int stageNum, QuestFactory qf) { public ItemsPrompt(Quests plugin, int stageNum, QuestFactory qf) {
super("1", "2", "3", "4"); super("1", "2", "3", "4", "5");
this.plugin = plugin; this.plugin = plugin;
this.stageNum = stageNum; this.stageNum = stageNum;
this.pref = "stage" + 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"; + 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<ItemStack> items = (LinkedList<ItemStack>) 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; return text;
} }
@ -105,6 +114,8 @@ public class ItemsPrompt extends FixedSetPrompt {
return new SmeltListPrompt(); return new SmeltListPrompt();
} else if (input.equalsIgnoreCase("3")) { } else if (input.equalsIgnoreCase("3")) {
return new EnchantmentListPrompt(); return new EnchantmentListPrompt();
} else if (input.equalsIgnoreCase("4")) {
return new BrewListPrompt();
} }
try { try {
return new CreateStagePrompt(plugin, stageNum, questFactory); return new CreateStagePrompt(plugin, stageNum, questFactory);
@ -169,7 +180,6 @@ public class ItemsPrompt extends FixedSetPrompt {
private List<ItemStack> getItems(ConversationContext context) { private List<ItemStack> getItems(ConversationContext context) {
return (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS); return (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
} }
} }
private class SmeltListPrompt extends FixedSetPrompt { private class SmeltListPrompt extends FixedSetPrompt {
@ -227,7 +237,6 @@ public class ItemsPrompt extends FixedSetPrompt {
private List<ItemStack> getItems(ConversationContext context) { private List<ItemStack> getItems(ConversationContext context) {
return (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS); return (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
} }
} }
private class EnchantmentListPrompt extends FixedSetPrompt { private class EnchantmentListPrompt extends FixedSetPrompt {
@ -456,4 +465,61 @@ public class ItemsPrompt extends FixedSetPrompt {
return new EnchantmentListPrompt(); 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<ItemStack> items = getItems(context);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_BREW_ITEMS, items);
} else {
LinkedList<ItemStack> items = new LinkedList<ItemStack>();
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<ItemStack> getItems(ConversationContext context) {
return (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
}
}
} }

View File

@ -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_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_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_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_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_PLAYER_KILL, cc.getSessionData(pref + CK.S_PLAYER_KILL));
cc.setSessionData(newPref + CK.S_DELIVERY_ITEMS, cc.getSessionData(pref + CK.S_DELIVERY_ITEMS)); 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_SMELT_ITEMS, null);
cc.setSessionData(pref + CK.S_ENCHANT_TYPES, null); cc.setSessionData(pref + CK.S_ENCHANT_TYPES, null);
cc.setSessionData(pref + CK.S_ENCHANT_NAMES, 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_FISH, null);
cc.setSessionData(pref + CK.S_PLAYER_KILL, null); cc.setSessionData(pref + CK.S_PLAYER_KILL, null);
cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, null); cc.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, null);

View File

@ -67,6 +67,7 @@ public class CK {
public static final String S_ENCHANT_TYPES = "enchantTypes"; public static final String S_ENCHANT_TYPES = "enchantTypes";
public static final String S_ENCHANT_NAMES = "enchantNames"; public static final String S_ENCHANT_NAMES = "enchantNames";
public static final String S_ENCHANT_AMOUNTS = "enchantAmounts"; 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_ITEMS = "deliveryItems";
public static final String S_DELIVERY_NPCS = "deliveryNPCs"; public static final String S_DELIVERY_NPCS = "deliveryNPCs";
public static final String S_DELIVERY_MESSAGES = "deliveryMessages"; public static final String S_DELIVERY_MESSAGES = "deliveryMessages";

View File

@ -33,7 +33,9 @@ import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
@SuppressWarnings("deprecation")
public class ItemUtil { public class ItemUtil {
/** /**
@ -55,7 +57,6 @@ public class ItemUtil {
* -8 if stack Written Book data is unequal * -8 if stack Written Book data is unequal
* -9 if stack Potion type is unequal * -9 if stack Potion type is unequal
*/ */
@SuppressWarnings("deprecation")
public static int compareItems(ItemStack one, ItemStack two, boolean ignoreAmount) { public static int compareItems(ItemStack one, ItemStack two, boolean ignoreAmount) {
if (one == null || two == null) { if (one == null || two == null) {
return 1; return 1;
@ -110,6 +111,7 @@ public class ItemUtil {
} }
} }
} }
if (one.getItemMeta() instanceof PotionMeta) {
if (Material.getMaterial("LINGERING_POTION") != null) { if (Material.getMaterial("LINGERING_POTION") != null) {
// Bukkit version is 1.9+ // Bukkit version is 1.9+
if (one.getType().equals(Material.POTION) || one.getType().equals(Material.LINGERING_POTION) || one.getType().equals(Material.SPLASH_POTION)) { if (one.getType().equals(Material.POTION) || one.getType().equals(Material.LINGERING_POTION) || one.getType().equals(Material.SPLASH_POTION)) {
@ -121,6 +123,18 @@ public class ItemUtil {
} }
} }
} }
}
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) { if (one.getEnchantments().equals(two.getEnchantments()) == false) {
return -5; return -5;
} }
@ -146,7 +160,6 @@ public class ItemUtil {
* @param durability The data value of the item, default of 0 * @param durability The data value of the item, default of 0
* @return ItemStack, or null if invalid format * @return ItemStack, or null if invalid format
*/ */
@SuppressWarnings("deprecation")
public static ItemStack processItemStack(String material, int amount, short durability) { public static ItemStack processItemStack(String material, int amount, short durability) {
try { try {
return new ItemStack(Material.getMaterial(material.toUpperCase()), amount, durability); return new ItemStack(Material.getMaterial(material.toUpperCase()), amount, durability);
@ -172,7 +185,6 @@ public class ItemUtil {
* @param data formatted string * @param data formatted string
* @return ItemStack, or null if invalid format * @return ItemStack, or null if invalid format
*/ */
@SuppressWarnings("deprecation")
public static ItemStack readItemStack(String data) { public static ItemStack readItemStack(String data) {
if (data == null) { if (data == null) {
return null; return null;
@ -384,7 +396,6 @@ public class ItemUtil {
* @param is ItemStack * @param is ItemStack
* @return formatted string, or null if invalid stack * @return formatted string, or null if invalid stack
*/ */
@SuppressWarnings("deprecation")
public static String serializeItemStack(ItemStack is) { public static String serializeItemStack(ItemStack is) {
String serial; String serial;
if (is == null) { if (is == null) {
@ -448,7 +459,6 @@ public class ItemUtil {
* @param is ItemStack to check * @param is ItemStack to check
* @return true display or item name, plus durability and amount, plus enchantments * @return true display or item name, plus durability and amount, plus enchantments
*/ */
@SuppressWarnings("deprecation")
public static String getDisplayString(ItemStack is) { public static String getDisplayString(ItemStack is) {
String text; String text;
if (is == null) { if (is == null) {
@ -481,7 +491,6 @@ public class ItemUtil {
* @param is ItemStack to check * @param is ItemStack to check
* @return true display or item name, plus durability and amount, if stack is not null * @return true display or item name, plus durability and amount, if stack is not null
*/ */
@SuppressWarnings("deprecation")
public static String getString(ItemStack is) { public static String getString(ItemStack is) {
if (is == null) { if (is == null) {
return null; return null;
@ -588,7 +597,6 @@ public class ItemUtil {
* @param e Enchantment to get localized name of * @param e Enchantment to get localized name of
* @return localized name * @return localized name
*/ */
@SuppressWarnings("deprecation") // since 1.13
private static String getEnchantmentName(Enchantment e) { private static String getEnchantmentName(Enchantment e) {
try { try {
return (Lang.get("ENCHANTMENT_" + e.getName())); return (Lang.get("ENCHANTMENT_" + e.getName()));
@ -599,7 +607,6 @@ public class ItemUtil {
} }
} }
@SuppressWarnings("deprecation") // since 1.13
public static Enchantment getEnchantmentFromProperName(String enchant) { public static Enchantment getEnchantmentFromProperName(String enchant) {
String ench = Lang.getKey(enchant.replace(" ", "")); String ench = Lang.getKey(enchant.replace(" ", ""));
ench = ench.replace("ENCHANTMENT_", ""); ench = ench.replace("ENCHANTMENT_", "");

View File

@ -28,8 +28,11 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Rabbit; import org.bukkit.entity.Rabbit;
import org.bukkit.entity.Villager.Career; import org.bukkit.entity.Villager.Career;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
@SuppressWarnings("deprecation")
public class LocaleQuery { public class LocaleQuery {
private static Class<?> craftMagicNumbers = null; private static Class<?> craftMagicNumbers = null;
private static Class<?> itemClazz = null; private static Class<?> itemClazz = null;
@ -38,6 +41,7 @@ public class LocaleQuery {
private static boolean hasBasePotionData = false; private static boolean hasBasePotionData = false;
private Map<String, String> oldBlocks = getBlockKeys(); private Map<String, String> oldBlocks = getBlockKeys();
private Map<String, String> oldItems = getItemKeys(); private Map<String, String> oldItems = getItemKeys();
private Map<String, String> oldPotions_18 = getPotionKeys_18();
private Map<String, String> oldPotions = getPotionKeys(); private Map<String, String> oldPotions = getPotionKeys();
private Map<String, String> oldLingeringPotions = getLingeringPotionKeys(); private Map<String, String> oldLingeringPotions = getLingeringPotionKeys();
private Map<String, String> oldSplashPotions = getSplashPotionKeys(); private Map<String, String> oldSplashPotions = getSplashPotionKeys();
@ -66,7 +70,7 @@ public class LocaleQuery {
* Send message with item name translated to the client's locale. * Send message with item name translated to the client's locale.
* Material is required. Durability arg is arbitrary for 1.13+ * Material is required. Durability arg is arbitrary for 1.13+
* and can be ignored by setting to a value less than 0. * and can be ignored by setting to a value less than 0.
* Enchantments are optional and may be left null or empty.<p> * Enchantments & meta are optional and may be left null or empty.<p>
* *
* Message should contain {@code <item>} string for replacement by * Message should contain {@code <item>} string for replacement by
* this method (along with applicable {@code <enchantment>} strings). * this method (along with applicable {@code <enchantment>} strings).
@ -76,9 +80,9 @@ public class LocaleQuery {
* @param material The item to be translated * @param material The item to be translated
* @param durability Durability for the item being translated * @param durability Durability for the item being translated
* @param enchantments Enchantments 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<Enchantment, Integer> enchantments, ItemMeta meta) {
public boolean sendMessage(Player player, String message, Material material, short durability, Map<Enchantment, Integer> enchantments) {
if (material == null) { if (material == null) {
return false; return false;
} }
@ -105,6 +109,8 @@ public class LocaleQuery {
} else if (material.equals(Material.SPLASH_POTION)) { } else if (material.equals(Material.SPLASH_POTION)) {
matKey = oldSplashPotions.get(((PotionMeta)i.getItemMeta()).getBasePotionData().getType().name()); 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)) { } else if (durability >= 0 && oldItems.containsKey(material.name() + "." + durability)) {
matKey = oldItems.get(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()); plugin.getLogger().severe("Unable to query Material: " + material.name());
return false; return false;
} }
if (meta != null && meta instanceof PotionMeta) {
matKey = "item.minecraft.potion.effect." + ((PotionMeta)meta).getBasePotionData().getType().name().toLowerCase();
}
if (enchantments != null && !enchantments.isEmpty()) { if (enchantments != null && !enchantments.isEmpty()) {
int count = 0; int count = 0;
for (Enchantment e : enchantments.keySet()) { for (Enchantment e : enchantments.keySet()) {
@ -148,6 +157,25 @@ public class LocaleQuery {
return true; 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.<p>
*
* Message should contain {@code <item>} string for replacement by
* this method (along with applicable {@code <enchantment>} 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<Enchantment, Integer> enchantments) {
return sendMessage(player, message, material, durability, enchantments, null);
}
/** /**
* Send message with enchantments translated to the client's locale. * Send message with enchantments translated to the client's locale.
* Map of Enchantment+level is required. * Map of Enchantment+level is required.
@ -159,7 +187,6 @@ public class LocaleQuery {
* @param message The message to be sent to the player * @param message The message to be sent to the player
* @param enchantments Enchantments for the item being translated * @param enchantments Enchantments for the item being translated
*/ */
@SuppressWarnings("deprecation")
public boolean sendMessage(Player player, String message, Map<Enchantment, Integer> enchantments) { public boolean sendMessage(Player player, String message, Map<Enchantment, Integer> enchantments) {
if (enchantments == null) { if (enchantments == null) {
return false; return false;
@ -1071,6 +1098,26 @@ public class LocaleQuery {
keys.put("WALL_BANNER.0", "item.WALL_BANNER.white.name"); // added keys.put("WALL_BANNER.0", "item.WALL_BANNER.white.name"); // added
return keys; return keys;
} }
public Map<String, String> getPotionKeys_18() {
LinkedHashMap<String, String> keys = new LinkedHashMap<String, String>();
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<String, String> getPotionKeys() { public Map<String, String> getPotionKeys() {
LinkedHashMap<String, String> keys = new LinkedHashMap<String, String>(); LinkedHashMap<String, String> keys = new LinkedHashMap<String, String>();
keys.put("UNCRAFTABLE", "potion.effect.empty"); keys.put("UNCRAFTABLE", "potion.effect.empty");

View File

@ -132,6 +132,7 @@ stageEditorItems: "Items"
stageEditorCraftItems: "Craft items" stageEditorCraftItems: "Craft items"
stageEditorSmeltItems: "Smelt items" stageEditorSmeltItems: "Smelt items"
stageEditorEnchantItems: "Enchant items" stageEditorEnchantItems: "Enchant items"
stageEditorBrewItems: "Brew items"
stageEditorNPCs: "NPCs" stageEditorNPCs: "NPCs"
stageEditorDeliverItems: "Deliver items" stageEditorDeliverItems: "Deliver items"
stageEditorTalkToNPCs: "Talk to NPCs" stageEditorTalkToNPCs: "Talk to NPCs"
@ -652,6 +653,7 @@ cut: "Cut"
craft: "Craft" craft: "Craft"
smelt: "Smelt" smelt: "Smelt"
enchantItem: "Enchant <item> with <enchantment>" enchantItem: "Enchant <item> with <enchantment>"
brew: "Brew"
catchFish: "Catch Fish" catchFish: "Catch Fish"
kill: "Kill" kill: "Kill"
killAtLocation: "Kill <mob> at <location>" killAtLocation: "Kill <mob> at <location>"