Potential bug fixes

This commit is contained in:
HappyPikachu 2017-07-08 00:07:50 -04:00
parent 8ab76338f1
commit 2a84736d01
4 changed files with 50 additions and 83 deletions

View File

@ -498,15 +498,9 @@ public class Quester {
} }
} }
for (ItemStack is : getCurrentStage(quest).itemsToDeliver) { for (ItemStack is : getCurrentStage(quest).itemsToDeliver) {
int delivered = 0; int delivered = getQuestData(quest).itemsDelivered.get(is);
int amt = is.getAmount(); int amt = is.getAmount();
Integer npc = null; Integer npc = getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(is));
if (getQuestData(quest).itemsDelivered.get(is) != null) {
delivered = getQuestData(quest).itemsDelivered.get(is);
}
if (getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(is)) != null) {
npc = getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(is));
}
if (delivered < amt) { if (delivered < amt) {
String obj = Lang.get("deliver"); String obj = Lang.get("deliver");
obj = obj.replaceAll("<item>", ItemUtil.getName(is)); obj = obj.replaceAll("<item>", ItemUtil.getName(is));
@ -698,23 +692,17 @@ public class Quester {
toDamage = is; toDamage = is;
} }
} }
if (damaged != null && toDamage != null) { if (damaged.getAmount() < toDamage.getAmount()) {
if (damaged.getAmount() < toDamage.getAmount()) { ItemStack newDamaged = damaged;
ItemStack newDamaged = damaged; newDamaged.setAmount(damaged.getAmount() + 1);
newDamaged.setAmount(damaged.getAmount() + 1); // TODO is this correct?
// TODO is this correct? 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, null, null, null, null, null, null, null, null, null);
}
} }
} else {
// Do nothing
System.out.println(quest + " somehow threw a null value. Please report on Github!");
} }
} }
// Called when a block is broken in PlayerListener, hence ItemStack m will always have amount of 1
public void breakBlock(Quest quest, ItemStack m) { public void breakBlock(Quest quest, ItemStack m) {
ItemStack temp = m; ItemStack temp = m;
temp.setAmount(0); temp.setAmount(0);
@ -730,19 +718,14 @@ public class Quester {
toBreak = is; toBreak = is;
} }
} }
if (broken != null && toBreak != null) { if (broken.getAmount() < toBreak.getAmount()) {
if (broken.getAmount() < toBreak.getAmount()) { ItemStack newBroken = broken;
ItemStack newBroken = broken; newBroken.setAmount(broken.getAmount() + 1);
newBroken.setAmount(broken.getAmount() + 1); // TODO is this correct?
// TODO is this correct? 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, null, null, null, null, null, null, null, null, null);
}
} }
} else {
// Do nothing
System.out.println(quest + " somehow threw a null value. Please report on Github!");
} }
} }
@ -761,19 +744,14 @@ public class Quester {
toPlace = is; toPlace = is;
} }
} }
if (placed != null && toPlace != null) { if (placed.getAmount() < toPlace.getAmount()) {
if (placed.getAmount() < toPlace.getAmount()) { ItemStack newplaced = placed;
ItemStack newplaced = placed; newplaced.setAmount(placed.getAmount() + 1);
newplaced.setAmount(placed.getAmount() + 1); // TODO is this correct?
// TODO is this correct? 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, null, null, null, null, null, null, null, null, null);
}
} }
} else {
// Do nothing
System.out.println(quest + " somehow threw a null value. Please report on Github!");
} }
} }
@ -792,19 +770,14 @@ public class Quester {
toUse = is; toUse = is;
} }
} }
if (used != null && toUse != null) { if (used.getAmount() < toUse.getAmount()) {
if (used.getAmount() < toUse.getAmount()) { ItemStack newUsed = used;
ItemStack newUsed = used; newUsed.setAmount(used.getAmount() + 1);
newUsed.setAmount(used.getAmount() + 1); // TODO is this correct?
// TODO is this correct? 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, null, null, null, null, null, null, null, null, null);
}
} }
} else {
// Do nothing
System.out.println(quest + " somehow threw a null value. Please report on Github!");
} }
} }
@ -823,19 +796,14 @@ public class Quester {
toCut = is; toCut = is;
} }
} }
if (cut != null && toCut != null) { if (cut.getAmount() < toCut.getAmount()) {
if (cut.getAmount() < toCut.getAmount()) { ItemStack newCut = cut;
ItemStack newCut = cut; newCut.setAmount(cut.getAmount() + 1);
newCut.setAmount(cut.getAmount() + 1); // TODO is this correct?
// TODO is this correct? 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, null, null, null, null, null, null, null, null, null);
}
} }
} else {
// Do nothing
System.out.println(quest + " somehow threw a null value. Please report on Github!");
} }
} }
@ -881,7 +849,7 @@ public class Quester {
Location locationToKillWithin = questData.locationsToKillWithin.get(indexOfMobKilled); Location locationToKillWithin = questData.locationsToKillWithin.get(indexOfMobKilled);
double radius = questData.radiiToKillWithin.get(indexOfMobKilled); double radius = questData.radiiToKillWithin.get(indexOfMobKilled);
// Check world #name, not the object // Check world #name, not the object
if ((killedLocation.getWorld().getName() == locationToKillWithin.getWorld().getName()) == false) { if ((killedLocation.getWorld().getName().equals(locationToKillWithin.getWorld().getName())) == false) {
return; return;
} }
// Radius check, it's a "circle", not cuboid // Radius check, it's a "circle", not cuboid
@ -2001,7 +1969,7 @@ public class Quester {
for (String s : names) { for (String s : names) {
ItemStack is; ItemStack is;
// if (durability.get(names.indexOf(s)) != -1) { // if (durability.get(names.indexOf(s)) != -1) {
if (durability.indexOf(names.indexOf(s)) != -1) { if (durability.indexOf((short)names.indexOf(s)) != -1) {
is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s))); is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s)));
} else { } else {
// Legacy // Legacy
@ -2017,7 +1985,7 @@ public class Quester {
for (String s : names) { for (String s : names) {
ItemStack is; ItemStack is;
// if (durability.get(names.indexOf(s)) != -1) { // if (durability.get(names.indexOf(s)) != -1) {
if (durability.indexOf(names.indexOf(s)) != -1) { if (durability.indexOf((short)names.indexOf(s)) != -1) {
is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s))); is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s)));
} else { } else {
// Legacy // Legacy
@ -2033,7 +2001,7 @@ public class Quester {
for (String s : names) { for (String s : names) {
ItemStack is; ItemStack is;
// if (durability.get(names.indexOf(s)) != -1) { // if (durability.get(names.indexOf(s)) != -1) {
if (durability.indexOf(names.indexOf(s)) != -1) { if (durability.indexOf((short)names.indexOf(s)) != -1) {
is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s))); is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s)));
} else { } else {
// Legacy // Legacy
@ -2049,7 +2017,7 @@ public class Quester {
for (String s : names) { for (String s : names) {
ItemStack is; ItemStack is;
// if (durability.get(names.indexOf(s)) != -1) { // if (durability.get(names.indexOf(s)) != -1) {
if (durability.indexOf(names.indexOf(s)) != -1) { if (durability.indexOf((short)names.indexOf(s)) != -1) {
is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s))); is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s)));
} else { } else {
// Legacy // Legacy
@ -2065,7 +2033,7 @@ public class Quester {
for (String s : names) { for (String s : names) {
ItemStack is; ItemStack is;
// if (durability.get(names.indexOf(s)) != -1) { // if (durability.get(names.indexOf(s)) != -1) {
if (durability.indexOf(names.indexOf(s)) != -1) { if (durability.indexOf((short)names.indexOf(s)) != -1) {
is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s))); is = new ItemStack(Material.matchMaterial(s), amounts.get(names.indexOf(s)), durability.get(names.indexOf(s)));
} else { } else {
// Legacy // Legacy

View File

@ -1792,7 +1792,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
} }
} catch (Exception e) { } catch (Exception e) {
// TODO find source of NullPointerException from Github ticket #130 e.printStackTrace();
} }
} }
} else { } else {

View File

@ -3668,7 +3668,9 @@ public class CreateStagePrompt extends FixedSetPrompt {
break; break;
} }
} }
text += ChatColor.BLUE + found.getCountPrompt().toString() + "\n\n"; if (found != null) {
text += ChatColor.BLUE + found.getCountPrompt().toString() + "\n\n";
}
return text; return text;
} }
@ -3688,7 +3690,7 @@ public class CreateStagePrompt extends FixedSetPrompt {
break; break;
} }
} }
if (found.datamap.isEmpty() == false) { if (found != null && found.datamap.isEmpty() == false) {
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions); context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA_DESCRIPTIONS, found.descriptions);
return new ObjectiveCustomDataListPrompt(); return new ObjectiveCustomDataListPrompt();
} else { } else {

View File

@ -34,13 +34,10 @@ public class ItemUtil {
* @return -5&nbsp;-> stack enchantments are unequal<br> * @return -5&nbsp;-> stack enchantments are unequal<br>
*/ */
public static int compareItems(ItemStack one, ItemStack two, boolean ignoreAmount) { public static int compareItems(ItemStack one, ItemStack two, boolean ignoreAmount) {
if (one == null && two != null || one != null && two == null) { if (one == null || two == null) {
return 0; return 0;
} }
if (one == null && two == null) { if (one.getType().name().equals(two.getType().name()) == false) {
return 0;
}
if (one.getType().name() != two.getType().name()) {
return -1; return -1;
} else if ((one.getAmount() != two.getAmount()) && ignoreAmount == false) { } else if ((one.getAmount() != two.getAmount()) && ignoreAmount == false) {
return -2; return -2;