mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-23 19:15:49 +01:00
Better support duplicate material types per obj, fixes #689
This commit is contained in:
parent
304a003463
commit
63cf5f71a7
@ -1013,7 +1013,7 @@ public class Quester {
|
||||
if (getQuestData(quest).blocksBroken.contains(broken)) {
|
||||
getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken.indexOf(broken), newBroken);
|
||||
if (broken.getAmount() == toBreak.getAmount()) {
|
||||
finishObjective(quest, "breakBlock", m, null, null, null, null, null, null, null, null, null);
|
||||
finishObjective(quest, "breakBlock", m, toBreak, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1063,7 +1063,7 @@ public class Quester {
|
||||
if (getQuestData(quest).blocksDamaged.contains(damaged)) {
|
||||
getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged.indexOf(damaged), newDamaged);
|
||||
if (damaged.getAmount() == toDamage.getAmount()) {
|
||||
finishObjective(quest, "damageBlock", m, null, null, null, null, null, null, null, null, null);
|
||||
finishObjective(quest, "damageBlock", m, toDamage, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1113,7 +1113,7 @@ public class Quester {
|
||||
if (getQuestData(quest).blocksPlaced.contains(placed)) {
|
||||
getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced.indexOf(placed), newplaced);
|
||||
if (placed.getAmount() == toPlace.getAmount()) {
|
||||
finishObjective(quest, "placeBlock", m, null, null, null, null, null, null, null, null, null);
|
||||
finishObjective(quest, "placeBlock", m, toPlace, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1163,7 +1163,7 @@ public class Quester {
|
||||
if (getQuestData(quest).blocksUsed.contains(used)) {
|
||||
getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed.indexOf(used), newUsed);
|
||||
if (used.getAmount() == toUse.getAmount()) {
|
||||
finishObjective(quest, "useBlock", m, null, null, null, null, null, null, null, null, null);
|
||||
finishObjective(quest, "useBlock", m, toUse, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1213,7 +1213,7 @@ public class Quester {
|
||||
if (getQuestData(quest).blocksCut.contains(cut)) {
|
||||
getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(cut), newCut);
|
||||
if (cut.getAmount() == toCut.getAmount()) {
|
||||
finishObjective(quest, "cutBlock", m, null, null, null, null, null, null, null, null, null);
|
||||
finishObjective(quest, "cutBlock", m, toCut, null, null, null, null, null, null, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1482,17 +1482,17 @@ public class Quester {
|
||||
* @param objective
|
||||
* Type of objective, e.g. "password" or "damageBlock"
|
||||
* @param increment
|
||||
* Material being damaged, broken, etc. (amount usually = 1)
|
||||
* Final amount material being applied
|
||||
* @param goal
|
||||
* Material being delivered (amount usually = required number of item)
|
||||
* Total required amount of material
|
||||
* @param enchantment
|
||||
* Enchantment being applied by user
|
||||
* @param mob
|
||||
* Mob to be killed or tamed
|
||||
* Mob being killed or tamed
|
||||
* @param extra
|
||||
* Extra mob enum like career or ocelot type
|
||||
* @param npc
|
||||
* NPC to talk to or kill
|
||||
* NPC being talked to or killed
|
||||
* @param location
|
||||
* Location for user to reach
|
||||
* @param color
|
||||
@ -1522,45 +1522,35 @@ public class Quester {
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("breakBlock")) {
|
||||
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "break") + " <item>";
|
||||
String stack = getQuestData(quest).blocksBroken.toString();
|
||||
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
|
||||
message = message + " " + amount + "/" + amount;
|
||||
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
|
||||
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
|
||||
if (testComplete(quest)) {
|
||||
quest.nextStage(this);
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("damageBlock")) {
|
||||
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "damage") + " <item>";
|
||||
String stack = getQuestData(quest).blocksDamaged.toString();
|
||||
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
|
||||
message = message + " " + amount + "/" + amount;
|
||||
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
|
||||
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
|
||||
if (testComplete(quest)) {
|
||||
quest.nextStage(this);
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("placeBlock")) {
|
||||
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "place") + " <item>";
|
||||
String stack = getQuestData(quest).blocksPlaced.toString();
|
||||
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
|
||||
message = message + " " + amount + "/" + amount;
|
||||
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
|
||||
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
|
||||
if (testComplete(quest)) {
|
||||
quest.nextStage(this);
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("useBlock")) {
|
||||
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "use") + " <item>";
|
||||
String stack = getQuestData(quest).blocksUsed.toString();
|
||||
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
|
||||
message = message + " " + amount + "/" + amount;
|
||||
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
|
||||
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
|
||||
if (testComplete(quest)) {
|
||||
quest.nextStage(this);
|
||||
}
|
||||
} else if (objective.equalsIgnoreCase("cutBlock")) {
|
||||
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "cut") + " <item>";
|
||||
String stack = getQuestData(quest).blocksCut.toString();
|
||||
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
|
||||
message = message + " " + amount + "/" + amount;
|
||||
message = message + " " + goal.getAmount() + "/" + goal.getAmount();
|
||||
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
|
||||
if (testComplete(quest)) {
|
||||
quest.nextStage(this);
|
||||
@ -3035,4 +3025,4 @@ public class Quester {
|
||||
}
|
||||
return playerAmount >= is.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
@ -627,7 +627,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
try {
|
||||
// TODO ensure all applicable strings are translated
|
||||
String sbegin = obj.substring(obj.indexOf(ChatColor.AQUA.toString()) + 2);
|
||||
String serial = sbegin.substring(0, sbegin.indexOf(ChatColor.GREEN.toString()));
|
||||
String serial = "";
|
||||
if (sbegin.contains(ChatColor.GREEN.toString())) {
|
||||
serial = sbegin.substring(0, sbegin.indexOf(ChatColor.GREEN.toString()));
|
||||
} else if (sbegin.contains(ChatColor.GRAY.toString())) {
|
||||
serial = sbegin.substring(0, sbegin.indexOf(ChatColor.GRAY.toString()));
|
||||
}
|
||||
Stage stage = quester.getCurrentStage(quest);
|
||||
if (obj.contains(Lang.get(quester.getPlayer(), "break"))) {
|
||||
for (ItemStack is : stage.blocksToBreak) {
|
||||
@ -1392,19 +1397,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing break-block-durability:");
|
||||
}
|
||||
}
|
||||
int breakIndex = 0;
|
||||
for (String s : breaknames) {
|
||||
ItemStack is;
|
||||
if (breakdurability.get(breaknames.indexOf(s)) != -1) {
|
||||
is = ItemUtil.processItemStack(s, breakamounts.get(breaknames.indexOf(s)), breakdurability.get(breaknames.indexOf(s)));
|
||||
if (breakdurability.get(breakIndex) != -1) {
|
||||
is = ItemUtil.processItemStack(s, breakamounts.get(breakIndex), breakdurability.get(breakIndex));
|
||||
} else {
|
||||
// Legacy
|
||||
is = ItemUtil.processItemStack(s, breakamounts.get(breaknames.indexOf(s)), (short) 0);
|
||||
is = ItemUtil.processItemStack(s, breakamounts.get(breakIndex), (short) 0);
|
||||
}
|
||||
if (Material.matchMaterial(s) != null) {
|
||||
oStage.blocksToBreak.add(is);
|
||||
} else {
|
||||
stageFailed("" + s + " inside break-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!");
|
||||
}
|
||||
breakIndex++;
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".damage-block-names")) {
|
||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".damage-block-names"), String.class)) {
|
||||
@ -1431,19 +1438,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing damage-block-durability:");
|
||||
}
|
||||
}
|
||||
int damageIndex = 0;
|
||||
for (String s : damagenames) {
|
||||
ItemStack is;
|
||||
if (damagedurability.get(damagenames.indexOf(s)) != -1) {
|
||||
is = ItemUtil.processItemStack(s, damageamounts.get(damagenames.indexOf(s)), damagedurability.get(damagenames.indexOf(s)));
|
||||
if (damagedurability.get(damageIndex) != -1) {
|
||||
is = ItemUtil.processItemStack(s, damageamounts.get(damageIndex), damagedurability.get(damageIndex));
|
||||
} else {
|
||||
// Legacy
|
||||
is = ItemUtil.processItemStack(s, damageamounts.get(damagenames.indexOf(s)), (short) 0);
|
||||
is = ItemUtil.processItemStack(s, damageamounts.get(damageIndex), (short) 0);
|
||||
}
|
||||
if (Material.matchMaterial(s) != null) {
|
||||
oStage.blocksToDamage.add(is);
|
||||
} else {
|
||||
stageFailed("" + s + " inside damage-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!");
|
||||
}
|
||||
damageIndex++;
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".place-block-names")) {
|
||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".place-block-names"), String.class)) {
|
||||
@ -1470,19 +1479,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing place-block-durability:");
|
||||
}
|
||||
}
|
||||
int placeIndex = 0;
|
||||
for (String s : placenames) {
|
||||
ItemStack is;
|
||||
if (placedurability.get(placenames.indexOf(s)) != -1) {
|
||||
is = ItemUtil.processItemStack(s, placeamounts.get(placenames.indexOf(s)), placedurability.get(placenames.indexOf(s)));
|
||||
if (placedurability.get(placeIndex) != -1) {
|
||||
is = ItemUtil.processItemStack(s, placeamounts.get(placeIndex), placedurability.get(placeIndex));
|
||||
} else {
|
||||
// Legacy
|
||||
is = ItemUtil.processItemStack(s, placeamounts.get(placenames.indexOf(s)), (short) 0);
|
||||
is = ItemUtil.processItemStack(s, placeamounts.get(placeIndex), (short) 0);
|
||||
}
|
||||
if (Material.matchMaterial(s) != null) {
|
||||
oStage.blocksToPlace.add(is);
|
||||
} else {
|
||||
stageFailed("" + s + " inside place-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!");
|
||||
}
|
||||
placeIndex++;
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".use-block-names")) {
|
||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".use-block-names"), String.class)) {
|
||||
@ -1509,19 +1520,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing use-block-durability:");
|
||||
}
|
||||
}
|
||||
int useIndex = 0;
|
||||
for (String s : usenames) {
|
||||
ItemStack is;
|
||||
if (usedurability.get(usenames.indexOf(s)) != -1) {
|
||||
is = ItemUtil.processItemStack(s, useamounts.get(usenames.indexOf(s)), usedurability.get(usenames.indexOf(s)));
|
||||
if (usedurability.get(useIndex) != -1) {
|
||||
is = ItemUtil.processItemStack(s, useamounts.get(useIndex), usedurability.get(useIndex));
|
||||
} else {
|
||||
// Legacy
|
||||
is = ItemUtil.processItemStack(s, useamounts.get(usenames.indexOf(s)), (short) 0);
|
||||
is = ItemUtil.processItemStack(s, useamounts.get(useIndex), (short) 0);
|
||||
}
|
||||
if (Material.matchMaterial(s) != null) {
|
||||
oStage.blocksToUse.add(is);
|
||||
} else {
|
||||
stageFailed("" + s + " inside use-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!");
|
||||
}
|
||||
useIndex++;
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".cut-block-names")) {
|
||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".cut-block-names"), String.class)) {
|
||||
@ -1548,19 +1561,21 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing cut-block-durability:");
|
||||
}
|
||||
}
|
||||
int cutIndex = 0;
|
||||
for (String s : cutnames) {
|
||||
ItemStack is;
|
||||
if (cutdurability.get(cutnames.indexOf(s)) != -1) {
|
||||
is = ItemUtil.processItemStack(s, cutamounts.get(cutnames.indexOf(s)), cutdurability.get(cutnames.indexOf(s)));
|
||||
if (cutdurability.get(cutIndex) != -1) {
|
||||
is = ItemUtil.processItemStack(s, cutamounts.get(cutIndex), cutdurability.get(cutIndex));
|
||||
} else {
|
||||
// Legacy
|
||||
is = ItemUtil.processItemStack(s, cutamounts.get(cutnames.indexOf(s)), (short) 0);
|
||||
is = ItemUtil.processItemStack(s, cutamounts.get(cutIndex), (short) 0);
|
||||
}
|
||||
if (Material.matchMaterial(s) != null) {
|
||||
oStage.blocksToCut.add(is);
|
||||
} else {
|
||||
stageFailed("" + s + " inside cut-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!");
|
||||
}
|
||||
cutIndex++;
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft")) {
|
||||
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft"), String.class)) {
|
||||
|
@ -437,26 +437,28 @@ public class PlayerListener implements Listener {
|
||||
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
|
||||
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
|
||||
for (Quest quest : quester.getCurrentQuests().keySet()) {
|
||||
if (quester.containsObjective(quest, "breakBlock")) {
|
||||
if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false && evt.isCancelled() == false) {
|
||||
ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability());
|
||||
quester.breakBlock(quest, i);
|
||||
if (evt.isCancelled() == false) {
|
||||
if (quester.containsObjective(quest, "breakBlock")) {
|
||||
if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) {
|
||||
ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability());
|
||||
quester.breakBlock(quest, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (quester.containsObjective(quest, "placeBlock")) {
|
||||
for (ItemStack is : quester.getQuestData(quest).blocksPlaced) {
|
||||
if (is.getAmount() > 0) {
|
||||
if (evt.isCancelled() == false) {
|
||||
if (quester.containsObjective(quest, "placeBlock")) {
|
||||
for (ItemStack is : quester.getQuestData(quest).blocksPlaced) {
|
||||
if (is.getAmount() > 0) {
|
||||
int index = quester.getQuestData(quest).blocksPlaced.indexOf(is);
|
||||
is.setAmount(is.getAmount() - 1);
|
||||
quester.getQuestData(quest).blocksPlaced.set(index, is);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS) && quester.containsObjective(quest, "cutBlock")) {
|
||||
ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability());
|
||||
quester.cutBlock(quest, i);
|
||||
if (quester.containsObjective(quest, "cutBlock")) {
|
||||
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS)) {
|
||||
ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability());
|
||||
quester.cutBlock(quest, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user