Code cleanup

This commit is contained in:
HappyPikachu 2017-07-28 13:31:08 -04:00
parent 3370e50417
commit d13683445d
2 changed files with 16 additions and 29 deletions

View File

@ -356,17 +356,6 @@ public class Quester {
LinkedList<String> unfinishedObjectives = new LinkedList<String>(); LinkedList<String> unfinishedObjectives = new LinkedList<String>();
LinkedList<String> finishedObjectives = new LinkedList<String>(); LinkedList<String> finishedObjectives = new LinkedList<String>();
LinkedList<String> objectives = new LinkedList<String>(); LinkedList<String> objectives = new LinkedList<String>();
for (ItemStack e : getCurrentStage(quest).blocksToDamage) {
for (ItemStack e2 : getQuestData(quest).blocksDamaged) {
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
if (e2.getAmount() < e.getAmount()) {
unfinishedObjectives.add(ChatColor.GREEN + Lang.get("damage") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount());
} else {
finishedObjectives.add(ChatColor.GRAY + Lang.get("damage") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount());
}
}
}
}
for (ItemStack e : getCurrentStage(quest).blocksToBreak) { for (ItemStack e : getCurrentStage(quest).blocksToBreak) {
for (ItemStack e2 : getQuestData(quest).blocksBroken) { for (ItemStack e2 : getQuestData(quest).blocksBroken) {
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
@ -378,6 +367,17 @@ public class Quester {
} }
} }
} }
for (ItemStack e : getCurrentStage(quest).blocksToDamage) {
for (ItemStack e2 : getQuestData(quest).blocksDamaged) {
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
if (e2.getAmount() < e.getAmount()) {
unfinishedObjectives.add(ChatColor.GREEN + Lang.get("damage") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount());
} else {
finishedObjectives.add(ChatColor.GRAY + Lang.get("damage") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount());
}
}
}
}
for (ItemStack e : getCurrentStage(quest).blocksToPlace) { for (ItemStack e : getCurrentStage(quest).blocksToPlace) {
for (ItemStack e2 : getQuestData(quest).blocksPlaced) { for (ItemStack e2 : getQuestData(quest).blocksPlaced) {
if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) {
@ -693,7 +693,6 @@ public class Quester {
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?
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);
@ -719,7 +718,6 @@ public class Quester {
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?
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);
@ -745,7 +743,6 @@ public class Quester {
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?
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);
@ -771,7 +768,6 @@ public class Quester {
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?
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);
@ -797,7 +793,6 @@ public class Quester {
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?
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);
@ -930,9 +925,9 @@ public class Quester {
} }
} }
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
System.out.println("An error has occurred with Quests. Please report on Github. Include the info below"); plugin.getLogger().severe("An error has occurred with Quests. Please report on Github. Include the info below");
System.out.println("index = " + getQuestData(quest).locationsReached.indexOf(location)); plugin.getLogger().severe("index = " + getQuestData(quest).locationsReached.indexOf(location));
System.out.println("locationsReached = " + getQuestData(quest).locationsReached.toString()); plugin.getLogger().severe("locationsReached = " + getQuestData(quest).locationsReached.toString());
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -1448,13 +1443,6 @@ public class Quester {
data.citizenNumKilled.add(0); data.citizenNumKilled.add(0);
} }
} }
if (quest.getStage(stage).blocksToCut.isEmpty() == false) {
for (ItemStack is : quest.getStage(stage).blocksToCut) {
// TODO should be .set() ?
is.setAmount(0);
data.blocksCut.add(is);
}
}
if (quest.getStage(stage).locationsToReach.isEmpty() == false) { if (quest.getStage(stage).locationsToReach.isEmpty() == false) {
for (Location l : quest.getStage(stage).locationsToReach) { for (Location l : quest.getStage(stage).locationsToReach) {
data.locationsReached.add(l); data.locationsReached.add(l);

View File

@ -1115,7 +1115,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
cs.sendMessage(ChatColor.RED + Lang.get("questCmdNoPerms")); cs.sendMessage(ChatColor.RED + Lang.get("questCmdNoPerms"));
} }
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
System.out.println("Please report this full error in Github ticket #130");
npe.printStackTrace(); npe.printStackTrace();
} }
} }
@ -1131,7 +1130,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
quester.hardClear(); quester.hardClear();
quester.saveData(); quester.saveData();
quester.updateJournal(); quester.updateJournal();
final File dataFolder = new File(this.getDataFolder(), "data/"); final File dataFolder = new File(this.getDataFolder(), "data" + File.separator);
final File found = new File(dataFolder, quester.id + ".yml"); final File found = new File(dataFolder, quester.id + ".yml");
found.delete(); found.delete();
addToBlacklist(quester.id); addToBlacklist(quester.id);
@ -1164,7 +1163,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
quester.hardClear(); quester.hardClear();
quester.saveData(); quester.saveData();
quester.updateJournal(); quester.updateJournal();
final File dataFolder = new File(this.getDataFolder(), "data/"); final File dataFolder = new File(this.getDataFolder(), "data" + File.separator);
final File found = new File(dataFolder, id + ".yml"); final File found = new File(dataFolder, id + ".yml");
found.delete(); found.delete();
String msg = Lang.get("questReset"); String msg = Lang.get("questReset");