Better support duplicate material types per obj, fixes #689

This commit is contained in:
BuildTools 2019-02-16 05:43:55 -05:00
parent 304a003463
commit 63cf5f71a7
3 changed files with 61 additions and 54 deletions

View File

@ -1013,7 +1013,7 @@ public class Quester {
if (getQuestData(quest).blocksBroken.contains(broken)) { if (getQuestData(quest).blocksBroken.contains(broken)) {
getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken.indexOf(broken), newBroken); getQuestData(quest).blocksBroken.set(getQuestData(quest).blocksBroken.indexOf(broken), newBroken);
if (broken.getAmount() == toBreak.getAmount()) { 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)) { if (getQuestData(quest).blocksDamaged.contains(damaged)) {
getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged.indexOf(damaged), newDamaged); getQuestData(quest).blocksDamaged.set(getQuestData(quest).blocksDamaged.indexOf(damaged), newDamaged);
if (damaged.getAmount() == toDamage.getAmount()) { 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)) { if (getQuestData(quest).blocksPlaced.contains(placed)) {
getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced.indexOf(placed), newplaced); getQuestData(quest).blocksPlaced.set(getQuestData(quest).blocksPlaced.indexOf(placed), newplaced);
if (placed.getAmount() == toPlace.getAmount()) { 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)) { if (getQuestData(quest).blocksUsed.contains(used)) {
getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed.indexOf(used), newUsed); getQuestData(quest).blocksUsed.set(getQuestData(quest).blocksUsed.indexOf(used), newUsed);
if (used.getAmount() == toUse.getAmount()) { 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)) { if (getQuestData(quest).blocksCut.contains(cut)) {
getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(cut), newCut); getQuestData(quest).blocksCut.set(getQuestData(quest).blocksCut.indexOf(cut), newCut);
if (cut.getAmount() == toCut.getAmount()) { 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 * @param objective
* Type of objective, e.g. "password" or "damageBlock" * Type of objective, e.g. "password" or "damageBlock"
* @param increment * @param increment
* Material being damaged, broken, etc. (amount usually = 1) * Final amount material being applied
* @param goal * @param goal
* Material being delivered (amount usually = required number of item) * Total required amount of material
* @param enchantment * @param enchantment
* Enchantment being applied by user * Enchantment being applied by user
* @param mob * @param mob
* Mob to be killed or tamed * Mob being killed or tamed
* @param extra * @param extra
* Extra mob enum like career or ocelot type * Extra mob enum like career or ocelot type
* @param npc * @param npc
* NPC to talk to or kill * NPC being talked to or killed
* @param location * @param location
* Location for user to reach * Location for user to reach
* @param color * @param color
@ -1522,45 +1522,35 @@ public class Quester {
} }
} else if (objective.equalsIgnoreCase("breakBlock")) { } else if (objective.equalsIgnoreCase("breakBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "break") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "break") + " <item>";
String stack = getQuestData(quest).blocksBroken.toString(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
message = message + " " + amount + "/" + amount;
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null); plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
if (testComplete(quest)) { if (testComplete(quest)) {
quest.nextStage(this); quest.nextStage(this);
} }
} else if (objective.equalsIgnoreCase("damageBlock")) { } else if (objective.equalsIgnoreCase("damageBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "damage") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "damage") + " <item>";
String stack = getQuestData(quest).blocksDamaged.toString(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
message = message + " " + amount + "/" + amount;
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null); plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
if (testComplete(quest)) { if (testComplete(quest)) {
quest.nextStage(this); quest.nextStage(this);
} }
} else if (objective.equalsIgnoreCase("placeBlock")) { } else if (objective.equalsIgnoreCase("placeBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "place") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "place") + " <item>";
String stack = getQuestData(quest).blocksPlaced.toString(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
message = message + " " + amount + "/" + amount;
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null); plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
if (testComplete(quest)) { if (testComplete(quest)) {
quest.nextStage(this); quest.nextStage(this);
} }
} else if (objective.equalsIgnoreCase("useBlock")) { } else if (objective.equalsIgnoreCase("useBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "use") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "use") + " <item>";
String stack = getQuestData(quest).blocksUsed.toString(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
message = message + " " + amount + "/" + amount;
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null); plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
if (testComplete(quest)) { if (testComplete(quest)) {
quest.nextStage(this); quest.nextStage(this);
} }
} else if (objective.equalsIgnoreCase("cutBlock")) { } else if (objective.equalsIgnoreCase("cutBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "cut") + " <item>"; String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "cut") + " <item>";
String stack = getQuestData(quest).blocksCut.toString(); message = message + " " + goal.getAmount() + "/" + goal.getAmount();
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
message = message + " " + amount + "/" + amount;
plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null); plugin.getLocaleQuery().sendMessage(p, message, increment.getType(), increment.getDurability(), null);
if (testComplete(quest)) { if (testComplete(quest)) {
quest.nextStage(this); quest.nextStage(this);

View File

@ -627,7 +627,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
try { try {
// TODO ensure all applicable strings are translated // TODO ensure all applicable strings are translated
String sbegin = obj.substring(obj.indexOf(ChatColor.AQUA.toString()) + 2); 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); Stage stage = quester.getCurrentStage(quest);
if (obj.contains(Lang.get(quester.getPlayer(), "break"))) { if (obj.contains(Lang.get(quester.getPlayer(), "break"))) {
for (ItemStack is : stage.blocksToBreak) { 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:"); stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing break-block-durability:");
} }
} }
int breakIndex = 0;
for (String s : breaknames) { for (String s : breaknames) {
ItemStack is; ItemStack is;
if (breakdurability.get(breaknames.indexOf(s)) != -1) { if (breakdurability.get(breakIndex) != -1) {
is = ItemUtil.processItemStack(s, breakamounts.get(breaknames.indexOf(s)), breakdurability.get(breaknames.indexOf(s))); is = ItemUtil.processItemStack(s, breakamounts.get(breakIndex), breakdurability.get(breakIndex));
} else { } else {
// Legacy // 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) { if (Material.matchMaterial(s) != null) {
oStage.blocksToBreak.add(is); oStage.blocksToBreak.add(is);
} else { } else {
stageFailed("" + s + " inside break-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!"); 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 (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".damage-block-names")) {
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".damage-block-names"), String.class)) { 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:"); stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing damage-block-durability:");
} }
} }
int damageIndex = 0;
for (String s : damagenames) { for (String s : damagenames) {
ItemStack is; ItemStack is;
if (damagedurability.get(damagenames.indexOf(s)) != -1) { if (damagedurability.get(damageIndex) != -1) {
is = ItemUtil.processItemStack(s, damageamounts.get(damagenames.indexOf(s)), damagedurability.get(damagenames.indexOf(s))); is = ItemUtil.processItemStack(s, damageamounts.get(damageIndex), damagedurability.get(damageIndex));
} else { } else {
// Legacy // 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) { if (Material.matchMaterial(s) != null) {
oStage.blocksToDamage.add(is); oStage.blocksToDamage.add(is);
} else { } else {
stageFailed("" + s + " inside damage-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!"); 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 (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".place-block-names")) {
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".place-block-names"), String.class)) { 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:"); stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing place-block-durability:");
} }
} }
int placeIndex = 0;
for (String s : placenames) { for (String s : placenames) {
ItemStack is; ItemStack is;
if (placedurability.get(placenames.indexOf(s)) != -1) { if (placedurability.get(placeIndex) != -1) {
is = ItemUtil.processItemStack(s, placeamounts.get(placenames.indexOf(s)), placedurability.get(placenames.indexOf(s))); is = ItemUtil.processItemStack(s, placeamounts.get(placeIndex), placedurability.get(placeIndex));
} else { } else {
// Legacy // 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) { if (Material.matchMaterial(s) != null) {
oStage.blocksToPlace.add(is); oStage.blocksToPlace.add(is);
} else { } else {
stageFailed("" + s + " inside place-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!"); 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 (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".use-block-names")) {
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".use-block-names"), String.class)) { 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:"); stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing use-block-durability:");
} }
} }
int useIndex = 0;
for (String s : usenames) { for (String s : usenames) {
ItemStack is; ItemStack is;
if (usedurability.get(usenames.indexOf(s)) != -1) { if (usedurability.get(useIndex) != -1) {
is = ItemUtil.processItemStack(s, useamounts.get(usenames.indexOf(s)), usedurability.get(usenames.indexOf(s))); is = ItemUtil.processItemStack(s, useamounts.get(useIndex), usedurability.get(useIndex));
} else { } else {
// Legacy // 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) { if (Material.matchMaterial(s) != null) {
oStage.blocksToUse.add(is); oStage.blocksToUse.add(is);
} else { } else {
stageFailed("" + s + " inside use-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!"); 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 (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".cut-block-names")) {
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".cut-block-names"), String.class)) { 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:"); stageFailed("Stage " + s2 + " of Quest " + quest.getName() + " is missing cut-block-durability:");
} }
} }
int cutIndex = 0;
for (String s : cutnames) { for (String s : cutnames) {
ItemStack is; ItemStack is;
if (cutdurability.get(cutnames.indexOf(s)) != -1) { if (cutdurability.get(cutIndex) != -1) {
is = ItemUtil.processItemStack(s, cutamounts.get(cutnames.indexOf(s)), cutdurability.get(cutnames.indexOf(s))); is = ItemUtil.processItemStack(s, cutamounts.get(cutIndex), cutdurability.get(cutIndex));
} else { } else {
// Legacy // 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) { if (Material.matchMaterial(s) != null) {
oStage.blocksToCut.add(is); oStage.blocksToCut.add(is);
} else { } else {
stageFailed("" + s + " inside cut-block-names: inside Stage " + s2 + " of Quest " + quest.getName() + " is not a valid item name!"); 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 (config.contains("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft")) {
if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft"), String.class)) { if (checkList(config.getList("quests." + questKey + ".stages.ordered." + s2 + ".items-to-craft"), String.class)) {

View File

@ -437,8 +437,9 @@ public class PlayerListener implements Listener {
if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) { if (plugin.checkQuester(evt.getPlayer().getUniqueId()) == false) {
Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId()); Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
for (Quest quest : quester.getCurrentQuests().keySet()) { for (Quest quest : quester.getCurrentQuests().keySet()) {
if (evt.isCancelled() == false) {
if (quester.containsObjective(quest, "breakBlock")) { if (quester.containsObjective(quest, "breakBlock")) {
if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false && evt.isCancelled() == false) { if (evt.getPlayer().getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH) == false) {
ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability()); ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability());
quester.breakBlock(quest, i); quester.breakBlock(quest, i);
} }
@ -446,21 +447,22 @@ public class PlayerListener implements Listener {
if (quester.containsObjective(quest, "placeBlock")) { if (quester.containsObjective(quest, "placeBlock")) {
for (ItemStack is : quester.getQuestData(quest).blocksPlaced) { for (ItemStack is : quester.getQuestData(quest).blocksPlaced) {
if (is.getAmount() > 0) { if (is.getAmount() > 0) {
if (evt.isCancelled() == false) {
int index = quester.getQuestData(quest).blocksPlaced.indexOf(is); int index = quester.getQuestData(quest).blocksPlaced.indexOf(is);
is.setAmount(is.getAmount() - 1); is.setAmount(is.getAmount() - 1);
quester.getQuestData(quest).blocksPlaced.set(index, is); quester.getQuestData(quest).blocksPlaced.set(index, is);
} }
} }
} }
} if (quester.containsObjective(quest, "cutBlock")) {
if (evt.getPlayer().getItemInHand().getType().equals(Material.SHEARS) && 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()); ItemStack i = new ItemStack(evt.getBlock().getType(), 1, evt.getBlock().getState().getData().toItemStack().getDurability());
quester.cutBlock(quest, i); quester.cutBlock(quest, i);
} }
} }
} }
} }
}
}
@EventHandler @EventHandler
public void onPlayerShearEntity(PlayerShearEntityEvent evt) { public void onPlayerShearEntity(PlayerShearEntityEvent evt) {