Update /quests info, code cleanup

This commit is contained in:
HappyPikachu 2017-07-28 12:56:41 -04:00
parent f74879aa74
commit 3370e50417
3 changed files with 75 additions and 73 deletions

View File

@ -13,8 +13,6 @@ import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -677,32 +675,6 @@ public class Quester {
return false;
}
public void damageBlock(Quest quest, ItemStack m) {
ItemStack temp = m;
temp.setAmount(0);
ItemStack damaged = temp;
ItemStack toDamage = temp;
for (ItemStack is : getQuestData(quest).blocksDamaged) {
if (m.getType() == is.getType() && m.getDurability() == is.getDurability()) {
damaged = is;
}
}
for (ItemStack is : getCurrentStage(quest).blocksToDamage) {
if (m.getType() == is.getType() && m.getDurability() == is.getDurability()) {
toDamage = is;
}
}
if (damaged.getAmount() < toDamage.getAmount()) {
ItemStack newDamaged = damaged;
newDamaged.setAmount(damaged.getAmount() + 1);
// TODO is this correct?
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);
}
}
}
public void breakBlock(Quest quest, ItemStack m) {
ItemStack temp = m;
temp.setAmount(0);
@ -729,6 +701,32 @@ public class Quester {
}
}
public void damageBlock(Quest quest, ItemStack m) {
ItemStack temp = m;
temp.setAmount(0);
ItemStack damaged = temp;
ItemStack toDamage = temp;
for (ItemStack is : getQuestData(quest).blocksDamaged) {
if (m.getType() == is.getType() && m.getDurability() == is.getDurability()) {
damaged = is;
}
}
for (ItemStack is : getCurrentStage(quest).blocksToDamage) {
if (m.getType() == is.getType() && m.getDurability() == is.getDurability()) {
toDamage = is;
}
}
if (damaged.getAmount() < toDamage.getAmount()) {
ItemStack newDamaged = damaged;
newDamaged.setAmount(damaged.getAmount() + 1);
// TODO is this correct?
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);
}
}
}
public void placeBlock(Quest quest, ItemStack m) {
ItemStack temp = m;
temp.setAmount(0);
@ -1061,14 +1059,6 @@ public class Quester {
if (testComplete(quest)) {
quest.nextStage(this);
}
} else if (objective.equalsIgnoreCase("damageBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get("completed") + ") " + Lang.get("damage") + " " + prettyItemString(material.getType().name());
String stack = getQuestData(quest).blocksDamaged.toString();
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
message = message + " " + amount + "/" + amount;
if (testComplete(quest)) {
quest.nextStage(this);
}
} else if (objective.equalsIgnoreCase("breakBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get("completed") + ") " + Lang.get("break") + " " + prettyItemString(material.getType().name());
String stack = getQuestData(quest).blocksBroken.toString();
@ -1078,6 +1068,14 @@ public class Quester {
if (testComplete(quest)) {
quest.nextStage(this);
}
} else if (objective.equalsIgnoreCase("damageBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get("completed") + ") " + Lang.get("damage") + " " + prettyItemString(material.getType().name());
String stack = getQuestData(quest).blocksDamaged.toString();
String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", "");
message = message + " " + amount + "/" + amount;
if (testComplete(quest)) {
quest.nextStage(this);
}
} else if (objective.equalsIgnoreCase("placeBlock")) {
String message = ChatColor.GREEN + "(" + Lang.get("completed") + ") " + Lang.get("place") + " " + prettyItemString(material.getType().name());
String stack = getQuestData(quest).blocksPlaced.toString();
@ -1224,18 +1222,6 @@ public class Quester {
public void addEmpties(Quest quest) {
QuestData data = new QuestData(this);
data.setDoJournalUpdate(false);
if (quest.getStage(0).blocksToDamage.isEmpty() == false) {
for (ItemStack i : quest.getStage(0).blocksToDamage) {
if (data.blocksDamaged.indexOf(i) != -1) {
// TODO Will this ever happen?
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.set(data.blocksDamaged.indexOf(temp), temp);
} else {
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.add(temp);
}
}
}
if (quest.getStage(0).blocksToBreak.isEmpty() == false) {
for (ItemStack i : quest.getStage(0).blocksToBreak) {
if (data.blocksBroken.indexOf(i) != -1) {
@ -1248,6 +1234,18 @@ public class Quester {
}
}
}
if (quest.getStage(0).blocksToDamage.isEmpty() == false) {
for (ItemStack i : quest.getStage(0).blocksToDamage) {
if (data.blocksDamaged.indexOf(i) != -1) {
// TODO Will this ever happen?
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.set(data.blocksDamaged.indexOf(temp), temp);
} else {
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.add(temp);
}
}
}
if (quest.getStage(0).blocksToPlace.isEmpty() == false) {
for (ItemStack i : quest.getStage(0).blocksToPlace) {
if (data.blocksPlaced.indexOf(i) != -1) {
@ -1354,18 +1352,6 @@ public class Quester {
public void addEmptiesFor(Quest quest, int stage) {
QuestData data = new QuestData(this);
data.setDoJournalUpdate(false);
if (quest.getStage(stage).blocksToDamage.isEmpty() == false) {
for (ItemStack i : quest.getStage(stage).blocksToDamage) {
if (data.blocksDamaged.indexOf(i) != -1) {
// TODO Will this ever happen?
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.set(data.blocksDamaged.indexOf(temp), temp);
} else {
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.add(temp);
}
}
}
if (quest.getStage(stage).blocksToBreak.isEmpty() == false) {
for (ItemStack i : quest.getStage(stage).blocksToBreak) {
if (data.blocksBroken.indexOf(i) != -1) {
@ -1378,6 +1364,18 @@ public class Quester {
}
}
}
if (quest.getStage(stage).blocksToDamage.isEmpty() == false) {
for (ItemStack i : quest.getStage(stage).blocksToDamage) {
if (data.blocksDamaged.indexOf(i) != -1) {
// TODO Will this ever happen?
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.set(data.blocksDamaged.indexOf(temp), temp);
} else {
ItemStack temp = new ItemStack(i.getType(), 0, i.getDurability());
data.blocksDamaged.add(temp);
}
}
}
if (quest.getStage(stage).blocksToPlace.isEmpty() == false) {
for (ItemStack i : quest.getStage(stage).blocksToPlace) {
if (data.blocksPlaced.indexOf(i) != -1) {
@ -1967,7 +1965,7 @@ public class Quester {
stage = getCurrentStage(quest);
if (stage == null) {
quest.completeQuest(this);
plugin.getLogger().log(Level.SEVERE, "[Quests] Invalid stage number for player: \"" + id + "\" on Quest \"" + quest.name + "\". Quest ended.");
plugin.getLogger().severe("[Quests] Invalid stage number for player: \"" + id + "\" on Quest \"" + quest.name + "\". Quest ended.");
continue;
}
addEmpties(quest);
@ -2533,7 +2531,7 @@ public class Quester {
questData.remove(quest);
}
} catch (Exception ex) {
Logger.getLogger(Quests.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}
@ -2541,7 +2539,7 @@ public class Quester {
try {
completedQuests.remove(quest.name);
} catch (Exception ex) {
Logger.getLogger(Quests.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}
@ -2551,7 +2549,7 @@ public class Quester {
questData.clear();
amountsCompleted.clear();
} catch (Exception ex) {
Logger.getLogger(Quests.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}
@ -2559,7 +2557,7 @@ public class Quester {
try {
currentQuests.put(key, val);
} catch (Exception ex) {
Logger.getLogger(Quests.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}
@ -2567,7 +2565,7 @@ public class Quester {
try {
questData.put(key, val);
} catch (Exception ex) {
Logger.getLogger(Quests.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
}
}

View File

@ -22,7 +22,7 @@ import java.util.UUID;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -1274,7 +1274,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
private boolean questsInfo(final CommandSender cs) {
cs.sendMessage(ChatColor.GOLD + Lang.get("quests") + " " + this.getDescription().getVersion());
cs.sendMessage(ChatColor.GOLD + Lang.get("createdBy") + " " + ChatColor.DARK_RED + "Blackvein");
cs.sendMessage(ChatColor.GOLD + Lang.get("createdBy") + " " + ChatColor.DARK_RED + "Blackvein"
+ ChatColor.GOLD + " " + Lang.get("continuedBy") + " " + ChatColor.DARK_RED + "FlyingPikachu");
cs.sendMessage(ChatColor.AQUA + "" + ChatColor.UNDERLINE + "https://www.spigotmc.org/resources/quests.3711/");
return true;
}
@ -3912,8 +3914,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
int numQuesters = 0;
int succeeded = 0;
int failed = 0;
final File dataFolder = new File(this.getDataFolder(), "data/");
final File oldDataFolder = new File(this.getDataFolder(), "data/old/");
final File dataFolder = new File(this.getDataFolder(), "data" + File.separator);
final File oldDataFolder = new File(this.getDataFolder(), "data" + File.separator + "old" + File.separator);
if (oldDataFolder.exists() == false || oldDataFolder.exists() && oldDataFolder.isDirectory() == false) {
oldDataFolder.mkdir();
}
@ -3960,7 +3962,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
idMap = fetcher.call();
} catch (Exception ex) {
getLogger().severe("Error retrieving data from Mojang account database. Error log:");
Logger.getLogger(Quests.class.getName()).log(Level.SEVERE, null, ex);
ex.printStackTrace();
return;
}
for (Entry<String, UUID> entry : idMap.entrySet()) {
@ -3990,7 +3992,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
}
getLogger().info("Conversion completed: " + converted + " Converted. " + failed + " Failed.");
getLogger().info("Old data files stored in /Quests/data/old");
getLogger().info("Old data files stored in "
+ File.separator + "Quests" + File.separator + "data" + File.separator + "old");
}
});
} else {

View File

@ -930,6 +930,7 @@ public class Lang {
langMap.put("quest", "Quest");
langMap.put("quests", "Quests");
langMap.put("createdBy", "Created by");
langMap.put("continuedBy", "and continued by");
langMap.put("questPoints", "Quest Points");
langMap.put("complete", "Complete");
langMap.put("redoable", "Redoable");