mirror of
https://github.com/PikaMug/Quests.git
synced 2025-02-27 09:51:20 +01:00
Improve the item enchanting objective, untested. Fixes #1247
This commit is contained in:
parent
d98f1daad3
commit
766ce10d25
@ -19,8 +19,6 @@ import java.util.Map;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -327,13 +325,12 @@ public class QuestData {
|
||||
}
|
||||
};
|
||||
|
||||
public LinkedHashMap<Map<Enchantment, Material>, Integer> itemsEnchanted
|
||||
= new LinkedHashMap<Map<Enchantment, Material>, Integer>() {
|
||||
public LinkedHashMap<ItemStack, Integer> itemsEnchanted = new LinkedHashMap<ItemStack, Integer>() {
|
||||
|
||||
private static final long serialVersionUID = 416869352279205852L;
|
||||
|
||||
@Override
|
||||
public Integer put(final Map<Enchantment, Material> key, final Integer val) {
|
||||
public Integer put(final ItemStack key, final Integer val) {
|
||||
final Integer data = super.put(key, val);
|
||||
if (doJournalUpdate)
|
||||
quester.updateJournal();
|
||||
@ -356,7 +353,7 @@ public class QuestData {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putAll(final Map<? extends Map<Enchantment, Material>, ? extends Integer> m) {
|
||||
public void putAll(final Map<? extends ItemStack, ? extends Integer> m) {
|
||||
super.putAll(m);
|
||||
if (doJournalUpdate)
|
||||
quester.updateJournal();
|
||||
|
@ -26,7 +26,6 @@ import java.util.UUID;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.InvalidConfigurationException;
|
||||
@ -37,7 +36,6 @@ import org.bukkit.conversations.ConversationAbandonedListener;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.ConversationFactory;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -48,7 +46,6 @@ import me.blackvein.quests.convo.quests.stages.StageMenuPrompt;
|
||||
import me.blackvein.quests.interfaces.ReloadCallback;
|
||||
import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.ConfigUtil;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
|
||||
@ -360,19 +357,11 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
|
||||
}
|
||||
if (!stage.getItemsToEnchant().isEmpty()) {
|
||||
final LinkedList<String> enchants = new LinkedList<String>();
|
||||
final LinkedList<String> names = new LinkedList<String>();
|
||||
final LinkedList<Integer> amounts = new LinkedList<Integer>();
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> e : stage.getItemsToEnchant().entrySet()) {
|
||||
amounts.add(e.getValue());
|
||||
for (final Entry<Enchantment, Material> e2 : e.getKey().entrySet()) {
|
||||
names.add(e2.getValue().name());
|
||||
enchants.add(ItemUtil.getPrettyEnchantmentName(e2.getKey()));
|
||||
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
|
||||
for (final ItemStack is : stage.getItemsToEnchant()) {
|
||||
items.add(is);
|
||||
}
|
||||
}
|
||||
context.setSessionData(pref + CK.S_ENCHANT_TYPES, enchants);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_NAMES, names);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
|
||||
}
|
||||
if (!stage.getItemsToBrew().isEmpty()) {
|
||||
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
|
||||
@ -725,12 +714,8 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS) : null);
|
||||
stage.set("items-to-smelt", context.getSessionData(pref + CK.S_SMELT_ITEMS) != null
|
||||
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS) : null);
|
||||
stage.set("enchantments", context.getSessionData(pref + CK.S_ENCHANT_TYPES) != null
|
||||
? (LinkedList<String>) context.getSessionData(pref + CK.S_ENCHANT_TYPES) : null);
|
||||
stage.set("enchantment-item-names", context.getSessionData(pref + CK.S_ENCHANT_NAMES) != null
|
||||
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_ENCHANT_NAMES) : null);
|
||||
stage.set("enchantment-amounts", context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS) != null
|
||||
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS) : null);
|
||||
stage.set("items-to-enchant", context.getSessionData(pref + CK.S_ENCHANT_ITEMS) != null
|
||||
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS) : null);
|
||||
stage.set("items-to-brew", context.getSessionData(pref + CK.S_BREW_ITEMS) != null
|
||||
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS) : null);
|
||||
stage.set("items-to-consume", context.getSessionData(pref + CK.S_CONSUME_ITEMS) != null
|
||||
|
@ -24,7 +24,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
@ -933,10 +932,10 @@ public class Quester {
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
if (crafted < amt) {
|
||||
final String obj = Lang.get(getPlayer(), "craft") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "craftItem").replace("<item>", ItemUtil.getName(is));
|
||||
unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + crafted + "/" + amt);
|
||||
} else {
|
||||
final String obj = Lang.get(getPlayer(), "craft") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "craftItem").replace("<item>", ItemUtil.getName(is));
|
||||
finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + crafted + "/" + amt);
|
||||
}
|
||||
}
|
||||
@ -947,56 +946,25 @@ public class Quester {
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
if (smelted < amt) {
|
||||
final String obj = Lang.get(getPlayer(), "smelt") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "smeltItem").replace("<item>", ItemUtil.getName(is));
|
||||
unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + smelted + "/" + amt);
|
||||
} else {
|
||||
final String obj = Lang.get(getPlayer(), "smelt") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "smeltItem").replace("<item>", ItemUtil.getName(is));
|
||||
finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + smelted + "/" + amt);
|
||||
}
|
||||
}
|
||||
Map<Enchantment, Material> set;
|
||||
Map<Enchantment, Material> set2;
|
||||
Set<Enchantment> enchantSet;
|
||||
Set<Enchantment> enchantSet2;
|
||||
Collection<Material> matSet;
|
||||
Enchantment enchantment = null;
|
||||
Enchantment enchantment2 = null;
|
||||
Material mat = null;
|
||||
int num1;
|
||||
int num2;
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> e : getCurrentStage(quest).itemsToEnchant.entrySet()) {
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> e2 : getQuestData(quest).itemsEnchanted.entrySet()) {
|
||||
set = e2.getKey();
|
||||
set2 = e.getKey();
|
||||
enchantSet = set.keySet();
|
||||
enchantSet2 = set2.keySet();
|
||||
for (final Object o : enchantSet.toArray()) {
|
||||
enchantment = (Enchantment) o;
|
||||
for (final ItemStack is : getCurrentStage(quest).itemsToEnchant) {
|
||||
int enchanted = 0;
|
||||
if (getQuestData(quest).itemsEnchanted.containsKey(is)) {
|
||||
enchanted = getQuestData(quest).itemsEnchanted.get(is);
|
||||
}
|
||||
for (final Object o : enchantSet2.toArray()) {
|
||||
enchantment2 = (Enchantment) o;
|
||||
}
|
||||
num1 = e2.getValue();
|
||||
num2 = e.getValue();
|
||||
matSet = set.values();
|
||||
for (final Object o : matSet.toArray()) {
|
||||
mat = (Material) o;
|
||||
}
|
||||
if (enchantment2 == enchantment) {
|
||||
if (num1 < num2) {
|
||||
String obj = Lang.get(getPlayer(), "enchantItem");
|
||||
obj = obj.replace("<item>", ItemUtil.getName(new ItemStack(mat)) + ChatColor.GREEN);
|
||||
obj = obj.replace("<enchantment>", ChatColor.DARK_AQUA
|
||||
+ ItemUtil.getPrettyEnchantmentName(enchantment) + ChatColor.GREEN);
|
||||
unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + num1 + "/" + num2);
|
||||
final int amt = is.getAmount();
|
||||
if (enchanted < amt) {
|
||||
final String obj = Lang.get(getPlayer(), "enchItem").replace("<item>", ItemUtil.getName(is));
|
||||
unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + enchanted + "/" + amt);
|
||||
} else {
|
||||
String obj = Lang.get(getPlayer(), "enchantItem");
|
||||
obj = obj.replace("<item>", ItemUtil.getName(new ItemStack(mat)) + ChatColor.GRAY);
|
||||
obj = obj.replace("<enchantment>", ChatColor.DARK_AQUA
|
||||
+ ItemUtil.getPrettyEnchantmentName(enchantment) + ChatColor.GRAY);
|
||||
finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + num1 + "/" + num2);
|
||||
}
|
||||
}
|
||||
final String obj = Lang.get(getPlayer(), "enchItem").replace("<item>", ItemUtil.getName(is));
|
||||
finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + enchanted + "/" + amt);
|
||||
}
|
||||
}
|
||||
for (final ItemStack is : getCurrentStage(quest).itemsToBrew) {
|
||||
@ -1006,10 +974,10 @@ public class Quester {
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
if (brewed < amt) {
|
||||
final String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "brewItem").replace("<item>", ItemUtil.getName(is));
|
||||
unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + brewed + "/" + amt);
|
||||
} else {
|
||||
final String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "brewItem").replace("<item>", ItemUtil.getName(is));
|
||||
finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + brewed + "/" + amt);
|
||||
}
|
||||
}
|
||||
@ -1020,10 +988,10 @@ public class Quester {
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
if (consumed < amt) {
|
||||
final String obj = Lang.get(getPlayer(), "consume") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "consumeItem").replace("<item>", ItemUtil.getName(is));
|
||||
unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + consumed + "/" + amt);
|
||||
} else {
|
||||
final String obj = Lang.get(getPlayer(), "consume") + " " + ItemUtil.getName(is);
|
||||
final String obj = Lang.get(getPlayer(), "consumeItem").replace("<item>", ItemUtil.getName(is));
|
||||
finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + consumed + "/" + amt);
|
||||
}
|
||||
}
|
||||
@ -1842,38 +1810,49 @@ public class Quester {
|
||||
* Mark item as enchanted if Quester has such an objective
|
||||
*
|
||||
* @param quest The quest for which the item is being enchanted
|
||||
* @param e The enchantment to be applied
|
||||
* @param m The item being enchanted
|
||||
* @param i The item being enchanted
|
||||
*/
|
||||
public void enchantItem(final Quest quest, final Enchantment e, final Material m) {
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> entry : getQuestData(quest).itemsEnchanted.entrySet()) {
|
||||
if (entry.getKey().containsKey(e) && entry.getKey().containsValue(m)) {
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> entry2 : getCurrentStage(quest).itemsToEnchant
|
||||
.entrySet()) {
|
||||
if (entry2.getKey().containsKey(e) && entry2.getKey().containsValue(m)) {
|
||||
if (entry.getValue() < entry2.getValue()) {
|
||||
final Integer num = entry.getValue() + 1;
|
||||
getQuestData(quest).itemsEnchanted.put(entry.getKey(), num);
|
||||
if (num.equals(entry2.getValue())) {
|
||||
final ItemStack finalToEnchant = new ItemStack(m, entry.getValue());
|
||||
|
||||
finishObjective(quest, "enchantItem", new ItemStack(m, 1), finalToEnchant, e, null,
|
||||
null, null, null, null, null, null);
|
||||
public void enchantItem(final Quest quest, final ItemStack i) {
|
||||
final Player player = getPlayer();
|
||||
ItemStack found = null;
|
||||
for (final ItemStack is : getQuestData(quest).itemsEnchanted.keySet()) {
|
||||
if (ItemUtil.compareItems(i, is, true) == 0) {
|
||||
found = is;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found != null) {
|
||||
final int amount = getQuestData(quest).itemsEnchanted.get(found);
|
||||
if (getCurrentStage(quest).itemsToEnchant.indexOf(found) < 0) {
|
||||
plugin.getLogger().severe("Index out of bounds while enchanting " + found.getType() + " x "
|
||||
+ found.getAmount() + " for quest " + quest.getName() + " with " + i.getType() + " x "
|
||||
+ i.getAmount() + " already enchanted. List amount reports value of " + amount
|
||||
+ ". Please report this error on Github!");
|
||||
player.sendMessage(ChatColor.RED
|
||||
+ "Quests had a problem enchanting your item, please contact an administrator!");
|
||||
return;
|
||||
}
|
||||
final int req = getCurrentStage(quest).itemsToEnchant.get(getCurrentStage(quest).itemsToEnchant
|
||||
.indexOf(found)).getAmount();
|
||||
final Material m = i.getType();
|
||||
if (amount < req) {
|
||||
if ((i.getAmount() + amount) >= req) {
|
||||
getQuestData(quest).itemsEnchanted.put(found, req);
|
||||
finishObjective(quest, "enchItem", new ItemStack(m, 1), found, null, null, null, null, null, null,
|
||||
null, null);
|
||||
|
||||
// Multiplayer
|
||||
final ItemStack finalFound = found;
|
||||
dispatchMultiplayerObjectives(quest, getCurrentStage(quest), (final Quester q) -> {
|
||||
q.getQuestData(quest).itemsEnchanted.put(entry.getKey(), num);
|
||||
q.finishObjective(quest, "enchantItem", new ItemStack(m, 1), finalToEnchant, null,
|
||||
null, null, null, null, null, null, null);
|
||||
q.getQuestData(quest).itemsEnchanted.put(finalFound, req);
|
||||
q.finishObjective(quest, "enchItem", new ItemStack(m, 1), finalFound, null, null, null, null,
|
||||
null, null, null, null);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
getQuestData(quest).itemsEnchanted.put(found, (amount + i.getAmount()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2500,8 +2479,8 @@ public class Quester {
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("craftItem")) {
|
||||
final ItemStack is = getCurrentStage(quest).itemsToCraft.get(getCurrentStage(quest).itemsToCraft.indexOf(goal));
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "craft") + " <item> "
|
||||
+ is.getAmount() + "/" + is.getAmount();
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "craftItem")
|
||||
+ " " + is.getAmount() + "/" + is.getAmount();
|
||||
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
plugin.getLocaleQuery().sendMessage(p, message, goal.getType(), goal.getDurability(), null);
|
||||
@ -2510,8 +2489,8 @@ public class Quester {
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("smeltItem")) {
|
||||
final ItemStack is = getCurrentStage(quest).itemsToSmelt.get(getCurrentStage(quest).itemsToSmelt.indexOf(goal));
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "smelt") + " <item> "
|
||||
+ is.getAmount() + "/" + is.getAmount();
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "smeltItem")
|
||||
+ " " + is.getAmount() + "/" + is.getAmount();
|
||||
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
plugin.getLocaleQuery().sendMessage(p, message, goal.getType(), goal.getDurability(), null);
|
||||
@ -2519,27 +2498,19 @@ public class Quester {
|
||||
p.sendMessage(message.replace("<item>", ItemUtil.getName(is)));
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("enchantItem")) {
|
||||
final String obj = Lang.get(p, "enchantItem");
|
||||
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj;
|
||||
final Map<Enchantment, Integer> ench = new HashMap<Enchantment, Integer>();
|
||||
ench.put(enchantment, enchantment.getStartLevel());
|
||||
for (final Map<Enchantment, Material> map : getCurrentStage(quest).itemsToEnchant.keySet()) {
|
||||
if (map.containsKey(enchantment)) {
|
||||
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
|
||||
break;
|
||||
}
|
||||
}
|
||||
final ItemStack is = getCurrentStage(quest).itemsToEnchant.get(getCurrentStage(quest).itemsToEnchant.indexOf(goal));
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "enchItem")
|
||||
+ " " + is.getAmount() + "/" + is.getAmount();
|
||||
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), ench);
|
||||
plugin.getLocaleQuery().sendMessage(p, message, goal.getType(), goal.getDurability(), null);
|
||||
} else {
|
||||
p.sendMessage(message.replace("<item>", ItemUtil.getName(increment))
|
||||
.replace("<enchantment>", enchantment.getName()));
|
||||
p.sendMessage(message.replace("<item>", ItemUtil.getName(is)));
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("brewItem")) {
|
||||
final ItemStack is = getCurrentStage(quest).itemsToBrew.get(getCurrentStage(quest).itemsToBrew.indexOf(goal));
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "brew") + " <item> "
|
||||
+ is.getAmount() + "/" + is.getAmount();
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "brewItem")
|
||||
+ " " + is.getAmount() + "/" + is.getAmount();
|
||||
if (plugin.getSettings().canTranslateNames() && goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
plugin.getLocaleQuery().sendMessage(p, message, goal.getType(), goal.getDurability(), null,
|
||||
@ -2550,8 +2521,8 @@ public class Quester {
|
||||
} else if (objective.equalsIgnoreCase("consumeItem")) {
|
||||
final ItemStack is = getCurrentStage(quest).itemsToConsume.get(getCurrentStage(quest).itemsToConsume
|
||||
.indexOf(goal));
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "consume")
|
||||
+ " <item> " + is.getAmount() + "/" + is.getAmount();
|
||||
final String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "consumeItem")
|
||||
+ " " + is.getAmount() + "/" + is.getAmount();
|
||||
if (plugin.getSettings().canTranslateNames() && !goal.hasItemMeta()
|
||||
&& !goal.getItemMeta().hasDisplayName()) {
|
||||
plugin.getLocaleQuery().sendMessage(p, message, goal.getType(), goal.getDurability(), null);
|
||||
@ -2742,9 +2713,8 @@ public class Quester {
|
||||
}
|
||||
}
|
||||
if (quest.getStage(stage).itemsToEnchant.isEmpty() == false) {
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> e : quest.getStage(stage).itemsToEnchant.entrySet()) {
|
||||
final Map<Enchantment, Material> map = e.getKey();
|
||||
data.itemsEnchanted.put(map, 0);
|
||||
for (final ItemStack is : quest.getStage(stage).itemsToEnchant) {
|
||||
data.itemsEnchanted.put(is, 0);
|
||||
}
|
||||
}
|
||||
if (quest.getStage(stage).itemsToBrew.isEmpty() == false) {
|
||||
@ -2989,20 +2959,11 @@ public class Quester {
|
||||
questSec.set("item-smelt-amounts", smeltAmounts);
|
||||
}
|
||||
if (questData.itemsEnchanted.isEmpty() == false) {
|
||||
final LinkedList<String> enchantments = new LinkedList<String>();
|
||||
final LinkedList<String> itemNames = new LinkedList<String>();
|
||||
final LinkedList<Integer> enchAmounts = new LinkedList<Integer>();
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> e : questData.itemsEnchanted.entrySet()) {
|
||||
final Map<Enchantment, Material> enchMap = e.getKey();
|
||||
enchAmounts.add(questData.itemsEnchanted.get(enchMap));
|
||||
for (final Entry<Enchantment, Material> e2 : enchMap.entrySet()) {
|
||||
enchantments.add(ItemUtil.getPrettyEnchantmentName(e2.getKey()));
|
||||
itemNames.add(e2.getValue().name());
|
||||
final LinkedList<Integer> enchantAmounts = new LinkedList<Integer>();
|
||||
for (final Entry<ItemStack, Integer> e : questData.itemsEnchanted.entrySet()) {
|
||||
enchantAmounts.add(e.getValue());
|
||||
}
|
||||
}
|
||||
questSec.set("enchantments", enchantments);
|
||||
questSec.set("enchantment-item-names", itemNames);
|
||||
questSec.set("times-enchanted", enchAmounts);
|
||||
questSec.set("item-enchant-amounts", enchantAmounts);
|
||||
}
|
||||
if (questData.itemsBrewed.isEmpty() == false) {
|
||||
final LinkedList<Integer> brewAmounts = new LinkedList<Integer>();
|
||||
@ -3412,22 +3373,13 @@ public class Quester {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (questSec.contains("enchantments")) {
|
||||
final LinkedList<Enchantment> enchantments = new LinkedList<Enchantment>();
|
||||
final LinkedList<Material> materials = new LinkedList<Material>();
|
||||
final LinkedList<Integer> amounts = new LinkedList<Integer>();
|
||||
final List<String> enchantNames = questSec.getStringList("enchantments");
|
||||
final List<String> names = questSec.getStringList("enchantment-item-names");
|
||||
final List<Integer> times = questSec.getIntegerList("times-enchanted");
|
||||
for (final String s : enchantNames) {
|
||||
enchantments.add(ItemUtil.getEnchantmentFromProperName(s));
|
||||
materials.add(Material.matchMaterial(names.get(enchantNames.indexOf(s))));
|
||||
amounts.add(times.get(enchantNames.indexOf(s)));
|
||||
if (questSec.contains("item-enchant-amounts")) {
|
||||
final List<Integer> enchantAmounts = questSec.getIntegerList("item-enchant-amounts");
|
||||
for (int i = 0; i < enchantAmounts.size(); i++) {
|
||||
if (i < getCurrentStage(quest).itemsToEnchant.size()) {
|
||||
getQuestData(quest).itemsEnchanted.put(getCurrentStage(quest).itemsToEnchant
|
||||
.get(i), enchantAmounts.get(i));
|
||||
}
|
||||
for (final Enchantment e : enchantments) {
|
||||
final Map<Enchantment, Material> map = new HashMap<Enchantment, Material>();
|
||||
map.put(e, materials.get(enchantments.indexOf(e)));
|
||||
getQuestData(quest).itemsEnchanted.put(map, amounts.get(enchantments.indexOf(e)));
|
||||
}
|
||||
}
|
||||
if (questSec.contains("item-brew-amounts")) {
|
||||
|
@ -25,7 +25,6 @@ import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -824,8 +823,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
final ChatColor color = crafted < amt ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + Lang.get(quester.getPlayer(), "craft") + " <item>"
|
||||
+ color + ": " + crafted + "/" + is.getAmount();
|
||||
String message = color + Lang.get(quester.getPlayer(), "craftItem") + color + ": " + crafted + "/"
|
||||
+ is.getAmount();
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message);
|
||||
}
|
||||
@ -843,8 +842,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
final ChatColor color = smelted < amt ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + Lang.get(quester.getPlayer(), "smelt") + " <item>"
|
||||
+ color + ": " + smelted + "/" + is.getAmount();
|
||||
String message = color + Lang.get(quester.getPlayer(), "smeltItem") + color + ": " + smelted + "/"
|
||||
+ is.getAmount();
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message);
|
||||
}
|
||||
@ -855,50 +854,29 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
quester.getPlayer().sendMessage(message.replace("<item>", ItemUtil.getName(is)));
|
||||
}
|
||||
}
|
||||
Map<Enchantment, Material> set;
|
||||
Map<Enchantment, Material> set2;
|
||||
Set<Enchantment> enchantSet;
|
||||
Set<Enchantment> enchantSet2;
|
||||
Collection<Material> matSet;
|
||||
Enchantment enchantment = null;
|
||||
Enchantment enchantment2 = null;
|
||||
Material mat = null;
|
||||
int num1;
|
||||
int num2;
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> e : stage.itemsToEnchant.entrySet()) {
|
||||
for (final Entry<Map<Enchantment, Material>, Integer> e2 : data.itemsEnchanted.entrySet()) {
|
||||
set = e2.getKey();
|
||||
set2 = e.getKey();
|
||||
enchantSet = set.keySet();
|
||||
enchantSet2 = set2.keySet();
|
||||
for (final Object o : enchantSet.toArray()) {
|
||||
enchantment = (Enchantment) o;
|
||||
for (final ItemStack is : stage.itemsToEnchant) {
|
||||
int enchanted = 0;
|
||||
if (data.itemsEnchanted.containsKey(is)) {
|
||||
enchanted = data.itemsEnchanted.get(is);
|
||||
}
|
||||
for (final Object o : enchantSet2.toArray()) {
|
||||
enchantment2 = (Enchantment) o;
|
||||
}
|
||||
num1 = e2.getValue();
|
||||
num2 = e.getValue();
|
||||
matSet = set.values();
|
||||
for (final Object o : matSet.toArray()) {
|
||||
mat = (Material) o;
|
||||
}
|
||||
if (enchantment2 == enchantment) {
|
||||
final ChatColor color = num1 < num2 ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + Lang.get(quester.getPlayer(), "enchantItem")
|
||||
+ color + ": " + num1 + "/" + num2;
|
||||
final int amt = is.getAmount();
|
||||
final ChatColor color = enchanted < amt ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + Lang.get(quester.getPlayer(), "enchItem") + color + ": " + enchanted + "/"
|
||||
+ is.getAmount();
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message);
|
||||
}
|
||||
final Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
|
||||
enchs.put(enchantment, 1);
|
||||
if (getSettings().canTranslateNames()) {
|
||||
localeQuery.sendMessage(quester.getPlayer(), message, mat, (short) 0, enchs);
|
||||
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(new ItemStack(mat)))
|
||||
.replace("<enchantment>", enchantment.getName()));
|
||||
}
|
||||
quester.getPlayer().sendMessage(message.replace("<item>", ItemUtil.getName(is)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -909,8 +887,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
final ChatColor color = brewed < amt ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + Lang.get(quester.getPlayer(), "brew") + " <item>"
|
||||
+ color + ": " + brewed + "/" + is.getAmount();
|
||||
String message = color + Lang.get(quester.getPlayer(), "brewItem") + color + ": " + brewed + "/"
|
||||
+ is.getAmount();
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message);
|
||||
}
|
||||
@ -935,8 +913,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
final int amt = is.getAmount();
|
||||
final ChatColor color = consumed < amt ? ChatColor.GREEN : ChatColor.GRAY;
|
||||
String message = color + Lang.get(quester.getPlayer(), "consume") + " <item>"
|
||||
+ color + ": " + consumed + "/" + is.getAmount();
|
||||
String message = color + Lang.get(quester.getPlayer(), "consumeItem") + color + ": " + consumed + "/"
|
||||
+ is.getAmount();
|
||||
if (depends.getPlaceholderApi() != null) {
|
||||
message = PlaceholderAPI.setPlaceholders(quester.getPlayer(), message);
|
||||
}
|
||||
@ -1986,9 +1964,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
final List<String> areaNames = new LinkedList<String>();
|
||||
List<ItemStack> itemsToCraft = new LinkedList<ItemStack>();
|
||||
List<ItemStack> itemsToSmelt = new LinkedList<ItemStack>();
|
||||
final List<Enchantment> enchantments = new LinkedList<Enchantment>();
|
||||
final List<Material> itemsToEnchant = new LinkedList<Material>();
|
||||
List<Integer> amountsToEnchant = new LinkedList<Integer>();
|
||||
List<ItemStack> itemsToEnchant = new LinkedList<ItemStack>();
|
||||
List<ItemStack> itemsToBrew = new LinkedList<ItemStack>();
|
||||
List<ItemStack> itemsToConsume = new LinkedList<ItemStack>();
|
||||
List<Integer> npcIdsToTalkTo = new LinkedList<Integer>();
|
||||
@ -2312,6 +2288,24 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-enchant")) {
|
||||
itemsToEnchant = (List<ItemStack>) config.get("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".items-to-enchant");
|
||||
if (ConfigUtil.checkList(itemsToEnchant, ItemStack.class)) {
|
||||
for (final ItemStack stack : itemsToEnchant) {
|
||||
if (stack != null) {
|
||||
oStage.itemsToEnchant.add(stack);
|
||||
} else {
|
||||
throw new StageFormatException("items-to-enchant has invalid formatting "
|
||||
+ stack, quest, stageNum);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Legacy
|
||||
final LinkedList<Material> types = new LinkedList<Material>();
|
||||
final LinkedList<Enchantment> enchs = new LinkedList<Enchantment>();
|
||||
final LinkedList<Integer> amts = new LinkedList<Integer>();
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantments")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".enchantments"), String.class)) {
|
||||
@ -2319,7 +2313,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
+ ".enchantments")) {
|
||||
final Enchantment e = ItemUtil.getEnchantmentFromProperName(enchant);
|
||||
if (e != null) {
|
||||
enchantments.add(e);
|
||||
enchs.add(e);
|
||||
} else {
|
||||
throw new StageFormatException("enchantments has invalid enchantment "
|
||||
+ enchant, quest, stageNum);
|
||||
@ -2334,7 +2328,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
for (final String item : config.getStringList("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".enchantment-item-names")) {
|
||||
if (Material.matchMaterial(item) != null) {
|
||||
itemsToEnchant.add(Material.matchMaterial(item));
|
||||
types.add(Material.matchMaterial(item));
|
||||
} else {
|
||||
throw new StageFormatException("enchantment-item-names has invalid item name "
|
||||
+ item, quest, stageNum);
|
||||
@ -2349,14 +2343,30 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".enchantment-amounts")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".enchantment-amounts"), Integer.class)) {
|
||||
amountsToEnchant = config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".enchantment-amounts");
|
||||
for (final int i : config.getIntegerList("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".enchantment-amounts")) {
|
||||
amts.add(i);
|
||||
}
|
||||
} else {
|
||||
throw new StageFormatException("enchantment-amounts is not a list of numbers", quest, stageNum);
|
||||
}
|
||||
} else {
|
||||
throw new StageFormatException("enchantment-amounts is missing", quest, stageNum);
|
||||
}
|
||||
if (!enchs.isEmpty() && !types.isEmpty() && !amts.isEmpty()) {
|
||||
for (int i = 0; i < enchs.size(); i++) {
|
||||
final ItemStack stack = new ItemStack(types.get(i), amts.get(i));
|
||||
stack.addEnchantment(enchs.get(0), 1);
|
||||
if (stack != null) {
|
||||
oStage.itemsToEnchant.add(stack);
|
||||
} else {
|
||||
throw new StageFormatException("Legacy items-to-enchant has invalid formatting "
|
||||
+ stack, quest, stageNum);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".items-to-brew")) {
|
||||
itemsToBrew = (List<ItemStack>) config.get("quests." + questKey + ".stages.ordered." + stageNum
|
||||
@ -2669,13 +2679,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
oStage.locationsToKillWithin.addAll(locationsToKillWithin);
|
||||
oStage.radiiToKillWithin.addAll(radiiToKillWithin);
|
||||
oStage.killNames.addAll(areaNames);
|
||||
final Map<Map<Enchantment, Material>, Integer> enchants = new HashMap<Map<Enchantment, Material>, Integer>();
|
||||
for (final Enchantment e : enchantments) {
|
||||
final Map<Enchantment, Material> map = new HashMap<Enchantment, Material>();
|
||||
map.put(e, itemsToEnchant.get(enchantments.indexOf(e)));
|
||||
enchants.put(map, amountsToEnchant.get(enchantments.indexOf(e)));
|
||||
}
|
||||
oStage.itemsToEnchant = enchants;
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + stageNum + ".locations-to-reach")) {
|
||||
if (ConfigUtil.checkList(config.getList("quests." + questKey + ".stages.ordered." + stageNum
|
||||
+ ".locations-to-reach"), String.class)) {
|
||||
|
@ -20,9 +20,7 @@ import java.util.Map.Entry;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -41,8 +39,7 @@ public class Stage {
|
||||
protected Integer playersToKill;
|
||||
protected LinkedList<ItemStack> itemsToCraft = new LinkedList<ItemStack>();
|
||||
protected LinkedList<ItemStack> itemsToSmelt = new LinkedList<ItemStack>();
|
||||
protected Map<Map<Enchantment, Material>, Integer> itemsToEnchant
|
||||
= new HashMap<Map<Enchantment, Material>, Integer>();
|
||||
protected LinkedList<ItemStack> itemsToEnchant = new LinkedList<ItemStack>();
|
||||
protected LinkedList<ItemStack> itemsToBrew = new LinkedList<ItemStack>();
|
||||
protected LinkedList<ItemStack> itemsToConsume = new LinkedList<ItemStack>();
|
||||
protected LinkedList<ItemStack> itemsToDeliver = new LinkedList<ItemStack>();
|
||||
@ -220,12 +217,11 @@ public class Stage {
|
||||
this.itemsToSmelt = itemsToSmelt;
|
||||
}
|
||||
|
||||
public Map<Map<Enchantment, Material>, Integer> getItemsToEnchant() {
|
||||
public LinkedList<ItemStack> getItemsToEnchant() {
|
||||
return itemsToEnchant;
|
||||
}
|
||||
|
||||
public void setItemsToEnchant(
|
||||
final Map<Map<Enchantment, Material>, Integer> itemsToEnchant) {
|
||||
public void setItemsToEnchant(final LinkedList<ItemStack> itemsToEnchant) {
|
||||
this.itemsToEnchant = itemsToEnchant;
|
||||
}
|
||||
|
||||
|
@ -16,22 +16,17 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import me.blackvein.quests.convo.generic.ItemStackPrompt;
|
||||
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
|
||||
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
|
||||
import me.blackvein.quests.convo.quests.stages.StageMainPrompt;
|
||||
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
|
||||
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent;
|
||||
import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.ItemUtil;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import me.blackvein.quests.util.MiscUtil;
|
||||
|
||||
public class ItemsPrompt extends QuestsEditorNumericPrompt {
|
||||
private final int stageNum;
|
||||
@ -120,18 +115,14 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
|
||||
return text;
|
||||
}
|
||||
case 3:
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null) {
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
final LinkedList<String> enchants = (LinkedList<String>) context.getSessionData(pref + CK.S_ENCHANT_TYPES);
|
||||
final LinkedList<String> names = (LinkedList<String>) context.getSessionData(pref + CK.S_ENCHANT_NAMES);
|
||||
final LinkedList<Integer> amnts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS);
|
||||
for (int i = 0; i < enchants.size(); i++) {
|
||||
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getPrettyItemName(names.get(i))
|
||||
+ ChatColor.GRAY + " " + Lang.get("with") + " " + ChatColor.AQUA
|
||||
+ ItemUtil.getPrettyEnchantmentName(ItemUtil.getEnchantmentFromProperName(enchants.get(i)))
|
||||
+ ChatColor.GRAY + " x " + ChatColor.DARK_AQUA + amnts.get(i) + "\n";
|
||||
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_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";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
@ -455,7 +446,7 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private final int size = 5;
|
||||
private final int size = 3;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
@ -471,12 +462,10 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
|
||||
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
return ChatColor.BLUE;
|
||||
case 4:
|
||||
case 2:
|
||||
return ChatColor.RED;
|
||||
case 5:
|
||||
case 3:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
@ -487,14 +476,10 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
|
||||
public String getSelectionText(final ConversationContext context, final int number) {
|
||||
switch(number) {
|
||||
case 1:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorSetEnchantments");
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem");
|
||||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorSetItemNames");
|
||||
case 3:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorSetEnchantAmounts");
|
||||
case 4:
|
||||
return ChatColor.RED + Lang.get("clear");
|
||||
case 5:
|
||||
case 3:
|
||||
return ChatColor.GREEN + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
@ -506,45 +491,41 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
|
||||
public String getAdditionalText(final ConversationContext context, final int number) {
|
||||
switch(number) {
|
||||
case 1:
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_TYPES) == null) {
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
for (final String s : (List<String>) context.getSessionData(pref + CK.S_ENCHANT_TYPES)) {
|
||||
text += ChatColor.GRAY + " - " + ChatColor.AQUA + s + "\n";
|
||||
for (final ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS)) {
|
||||
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
case 2:
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_NAMES) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
for (final String s : (List<String>) context.getSessionData(pref + CK.S_ENCHANT_NAMES)) {
|
||||
text += ChatColor.GRAY + " - " + ChatColor.AQUA + ItemUtil.getPrettyItemName(s) + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
case 3:
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
String text = "\n";
|
||||
for (final int i : (List<Integer>) context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS)) {
|
||||
text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + "\n";
|
||||
}
|
||||
return text;
|
||||
}
|
||||
case 4:
|
||||
case 5:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
// Check/add newly made item
|
||||
if (context.getSessionData("newItem") != null) {
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) != null) {
|
||||
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS);
|
||||
items.add((ItemStack) context.getSessionData("tempStack"));
|
||||
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
|
||||
} else {
|
||||
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
|
||||
items.add((ItemStack) context.getSessionData("tempStack"));
|
||||
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
|
||||
}
|
||||
context.setSessionData("newItem", null);
|
||||
context.setSessionData("tempStack", null);
|
||||
}
|
||||
|
||||
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
@ -556,212 +537,23 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
|
||||
return text;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
|
||||
switch(input.intValue()) {
|
||||
case 1:
|
||||
return new ItemEnchantTypesPrompt(context);
|
||||
return new ItemStackPrompt(context, ItemsEnchantListPrompt.this);
|
||||
case 2:
|
||||
return new ItemEnchantItemsPrompt(context);
|
||||
case 3:
|
||||
return new ItemEnchantAmountsPrompt(context);
|
||||
case 4:
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
|
||||
context.setSessionData(pref + CK.S_ENCHANT_TYPES, null);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_NAMES, null);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, null);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, null);
|
||||
return new ItemsEnchantListPrompt(context);
|
||||
case 5:
|
||||
int one;
|
||||
int two;
|
||||
int three;
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_TYPES) != null) {
|
||||
one = ((List<String>) context.getSessionData(pref + CK.S_ENCHANT_TYPES)).size();
|
||||
} else {
|
||||
one = 0;
|
||||
}
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_NAMES) != null) {
|
||||
two = ((List<String>) context.getSessionData(pref + CK.S_ENCHANT_NAMES)).size();
|
||||
} else {
|
||||
two = 0;
|
||||
}
|
||||
if (context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS) != null) {
|
||||
three = ((List<Integer>) context.getSessionData(pref + CK.S_ENCHANT_AMOUNTS)).size();
|
||||
} else {
|
||||
three = 0;
|
||||
}
|
||||
if (one == two && two == three) {
|
||||
case 3:
|
||||
return new ItemsPrompt(stageNum, context);
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
|
||||
return new ItemsEnchantListPrompt(context);
|
||||
}
|
||||
default:
|
||||
return new ItemsPrompt(stageNum, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemEnchantTypesPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public ItemEnchantTypesPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("stageEditorEnchantments");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("stageEditorEnchantTypePrompt");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
String text = ChatColor.LIGHT_PURPLE + "- " + ChatColor.DARK_PURPLE + getTitle(context)
|
||||
+ ChatColor.LIGHT_PURPLE + " -\n";
|
||||
for (int i = 0; i < Enchantment.values().length; i++) {
|
||||
if (i == Enchantment.values().length - 1) {
|
||||
text += ChatColor.GREEN + MiscUtil.snakeCaseToUpperCamelCase(Enchantment.values()[i].getName()) + " ";
|
||||
} else {
|
||||
text += ChatColor.GREEN + MiscUtil.snakeCaseToUpperCamelCase(Enchantment.values()[i].getName()) + ", ";
|
||||
}
|
||||
}
|
||||
text = text.substring(0, text.length() - 1);
|
||||
return text + "\n" + ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
final LinkedList<String> enchTypes = new LinkedList<String>();
|
||||
for (final String s : input.split(" ")) {
|
||||
if (ItemUtil.getEnchantmentFromProperName(s) != null) {
|
||||
if (enchTypes.contains(s) == false) {
|
||||
enchTypes.add(s);
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + " " + Lang.get("listDuplicate"));
|
||||
return new ItemEnchantTypesPrompt(context);
|
||||
}
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + ChatColor.RED + " "
|
||||
+ Lang.get("stageEditorInvalidEnchantment"));
|
||||
return new ItemEnchantTypesPrompt(context);
|
||||
}
|
||||
}
|
||||
context.setSessionData(pref + CK.S_ENCHANT_TYPES, enchTypes);
|
||||
}
|
||||
return new ItemsEnchantListPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemEnchantItemsPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public ItemEnchantItemsPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("stageEditorItemNamesPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
final String[] args = input.split(" ");
|
||||
final LinkedList<String> names = new LinkedList<String>();
|
||||
for (final String s : args) {
|
||||
try {
|
||||
if (Material.matchMaterial(s) != null) {
|
||||
names.add(s);
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + ChatColor.RED + " "
|
||||
+ Lang.get("stageEditorInvalidItemName"));
|
||||
return new ItemEnchantItemsPrompt(context);
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
|
||||
+ Lang.get("stageEditorNotListofNumbers"));
|
||||
return new ItemEnchantItemsPrompt(context);
|
||||
}
|
||||
}
|
||||
context.setSessionData(pref + CK.S_ENCHANT_NAMES, names);
|
||||
}
|
||||
return new ItemsEnchantListPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemEnchantAmountsPrompt extends QuestsEditorStringPrompt {
|
||||
|
||||
public ItemEnchantAmountsPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("stageEditorEnchantAmountsPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPromptText(final ConversationContext context) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
|
||||
return ChatColor.YELLOW + getQueryText(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final ConversationContext context, final String input) {
|
||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||
final String[] args = input.split(" ");
|
||||
final LinkedList<Integer> amounts = new LinkedList<Integer>();
|
||||
for (final String s : args) {
|
||||
try {
|
||||
if (Integer.parseInt(s) > 0) {
|
||||
amounts.add(Integer.parseInt(s));
|
||||
} else {
|
||||
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("invalidMinimum")
|
||||
.replace("<number>", "1"));
|
||||
return new ItemEnchantAmountsPrompt(context);
|
||||
}
|
||||
} catch (final NumberFormatException e) {
|
||||
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
|
||||
+ Lang.get("stageEditorNotListofNumbers"));
|
||||
return new ItemEnchantAmountsPrompt(context);
|
||||
}
|
||||
}
|
||||
context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, amounts);
|
||||
}
|
||||
return new ItemsEnchantListPrompt(context);
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemsBrewListPrompt extends QuestsEditorNumericPrompt {
|
||||
|
||||
public ItemsBrewListPrompt(final ConversationContext context) {
|
||||
|
@ -250,7 +250,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
case 2:
|
||||
if (context.getSessionData(stagePrefix + CK.S_CRAFT_ITEMS) == null
|
||||
&& context.getSessionData(stagePrefix + CK.S_SMELT_ITEMS) == null
|
||||
&& context.getSessionData(stagePrefix + CK.S_ENCHANT_TYPES) == null
|
||||
&& context.getSessionData(stagePrefix + CK.S_ENCHANT_ITEMS) == null
|
||||
&& context.getSessionData(stagePrefix + CK.S_BREW_ITEMS) == null
|
||||
&& context.getSessionData(stagePrefix + CK.S_CONSUME_ITEMS) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
@ -542,7 +542,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
|
||||
|| context.getSessionData(stagePrefix + CK.S_CUT_NAMES) != null
|
||||
|| context.getSessionData(stagePrefix + CK.S_CRAFT_ITEMS) != null
|
||||
|| context.getSessionData(stagePrefix + CK.S_SMELT_ITEMS) != null
|
||||
|| context.getSessionData(stagePrefix + CK.S_ENCHANT_TYPES) != null
|
||||
|| context.getSessionData(stagePrefix + CK.S_ENCHANT_ITEMS) != null
|
||||
|| context.getSessionData(stagePrefix + CK.S_BREW_ITEMS) != null
|
||||
|| context.getSessionData(stagePrefix + CK.S_CONSUME_ITEMS) != null
|
||||
|| context.getSessionData(stagePrefix + CK.S_DELIVERY_NPCS) != null
|
||||
|
@ -158,10 +158,7 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt {
|
||||
+ CK.S_CUT_DURABILITY));
|
||||
context.setSessionData(newPref + CK.S_CRAFT_ITEMS, context.getSessionData(pref + CK.S_CRAFT_ITEMS));
|
||||
context.setSessionData(newPref + CK.S_SMELT_ITEMS, context.getSessionData(pref + CK.S_SMELT_ITEMS));
|
||||
context.setSessionData(newPref + CK.S_ENCHANT_TYPES, context.getSessionData(pref + CK.S_ENCHANT_TYPES));
|
||||
context.setSessionData(newPref + CK.S_ENCHANT_NAMES, context.getSessionData(pref + CK.S_ENCHANT_NAMES));
|
||||
context.setSessionData(newPref + CK.S_ENCHANT_AMOUNTS, context.getSessionData(pref
|
||||
+ CK.S_ENCHANT_AMOUNTS));
|
||||
context.setSessionData(newPref + CK.S_ENCHANT_ITEMS, context.getSessionData(pref + CK.S_ENCHANT_ITEMS));
|
||||
context.setSessionData(newPref + CK.S_BREW_ITEMS, context.getSessionData(pref + CK.S_BREW_ITEMS));
|
||||
context.setSessionData(newPref + CK.S_FISH, context.getSessionData(pref + CK.S_FISH));
|
||||
context.setSessionData(newPref + CK.S_PLAYER_KILL, context.getSessionData(pref + CK.S_PLAYER_KILL));
|
||||
@ -242,12 +239,10 @@ public class StageMenuPrompt extends QuestsEditorNumericPrompt {
|
||||
context.setSessionData(pref + CK.S_CUT_DURABILITY, null);
|
||||
context.setSessionData(pref + CK.S_CRAFT_ITEMS, null);
|
||||
context.setSessionData(pref + CK.S_SMELT_ITEMS, null);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_TYPES, null);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_NAMES, null);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, null);
|
||||
context.setSessionData(pref + CK.S_BREW_ITEMS, null);
|
||||
context.setSessionData(pref + CK.S_FISH, null);
|
||||
context.setSessionData(pref + CK.S_PLAYER_KILL, null);
|
||||
context.setSessionData(pref + CK.S_ENCHANT_AMOUNTS, null);
|
||||
context.setSessionData(pref + CK.S_DELIVERY_ITEMS, null);
|
||||
context.setSessionData(pref + CK.S_DELIVERY_NPCS, null);
|
||||
context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, null);
|
||||
|
@ -14,7 +14,6 @@
|
||||
package me.blackvein.quests.listeners;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -130,9 +129,10 @@ public class ItemListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEnchantItem(final EnchantItemEvent evt) {
|
||||
final Player player = evt.getEnchanter();
|
||||
if (plugin.canUseQuests(player.getUniqueId())) {
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
if (plugin.canUseQuests(evt.getEnchanter().getUniqueId())) {
|
||||
final ItemStack enchantedItem = evt.getItem().clone();
|
||||
enchantedItem.setAmount(1);
|
||||
final Quester quester = plugin.getQuester(evt.getEnchanter().getUniqueId());
|
||||
for (final Quest quest : plugin.getQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
return;
|
||||
@ -140,15 +140,11 @@ public class ItemListener implements Listener {
|
||||
|
||||
if (quester.getCurrentQuests().containsKey(quest)
|
||||
&& quester.getCurrentStage(quest).containsObjective("enchantItem")) {
|
||||
for (final Enchantment e : evt.getEnchantsToAdd().keySet()) {
|
||||
quester.enchantItem(quest, e, evt.getItem().getType());
|
||||
}
|
||||
quester.enchantItem(quest, enchantedItem);
|
||||
}
|
||||
|
||||
quester.dispatchMultiplayerEverything(quest, "enchantItem", (final Quester q) -> {
|
||||
for (final Enchantment e : evt.getEnchantsToAdd().keySet()) {
|
||||
q.enchantItem(quest, e, evt.getItem().getType());
|
||||
}
|
||||
quester.enchantItem(quest, enchantedItem);
|
||||
return null;
|
||||
});
|
||||
}
|
||||
@ -161,8 +157,7 @@ public class ItemListener implements Listener {
|
||||
if (plugin.canUseQuests(evt.getPlayer().getUniqueId())) {
|
||||
final ItemStack consumedItem = evt.getItem().clone();
|
||||
consumedItem.setAmount(1);
|
||||
final Player player = evt.getPlayer();
|
||||
final Quester quester = plugin.getQuester(player.getUniqueId());
|
||||
final Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
|
||||
for (final Quest quest : plugin.getQuests()) {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
return;
|
||||
|
@ -68,9 +68,10 @@ public class CK {
|
||||
public static final String S_CRAFT_ITEMS = "craftItems";
|
||||
public static final String S_SMELT_ITEMS = "smeltItems";
|
||||
public static final String S_CONSUME_ITEMS = "consumeItems";
|
||||
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_ENCHANT_ITEMS = "enchantItems";
|
||||
//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";
|
||||
|
@ -633,11 +633,11 @@ damage: "Damage"
|
||||
place: "Place"
|
||||
use: "Use"
|
||||
cut: "Shear"
|
||||
craft: "Craft"
|
||||
smelt: "Smelt"
|
||||
enchantItem: "Enchant <item> with <enchantment>"
|
||||
brew: "Brew"
|
||||
consume: "Consume"
|
||||
craftItem: "Craft <item>"
|
||||
smeltItem: "Smelt <item>"
|
||||
enchItem: "Enchant <item>"
|
||||
brewItem: "Brew <item>"
|
||||
consumeItem: "Consume <item>"
|
||||
catchFish: "Catch Fish"
|
||||
milkCow: "Milk Cow"
|
||||
kill: "Kill"
|
||||
|
Loading…
Reference in New Issue
Block a user