Rework code for displaying objectives, part 2 for #575

This commit is contained in:
BuildTools 2018-12-21 02:50:54 -05:00
parent 40ac77261e
commit b482e9a0bf

View File

@ -1895,63 +1895,102 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
String serial = sbegin.substring(0, sbegin.indexOf(ChatColor.GREEN.toString()));
Stage stage = quester.getCurrentStage(quest);
System.out.println("obj= " + obj);
if (obj.contains(Lang.get(quester.getPlayer(), "break"))) {
for (ItemStack is : stage.blocksToBreak) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
if (Material.matchMaterial(serial) != null) {
if (Material.matchMaterial(serial).equals(is.getType())) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
break;
}
}
}
}
if (obj.contains(Lang.get(quester.getPlayer(), "damage"))) {
} else if (obj.contains(Lang.get(quester.getPlayer(), "damage"))) {
for (ItemStack is : stage.blocksToDamage) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
if (Material.matchMaterial(serial) != null) {
if (Material.matchMaterial(serial).equals(is.getType())) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
break;
}
}
}
}
if (obj.contains(Lang.get(quester.getPlayer(), "place"))) {
} else if (obj.contains(Lang.get(quester.getPlayer(), "place"))) {
for (ItemStack is : stage.blocksToPlace) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
if (Material.matchMaterial(serial) != null) {
if (Material.matchMaterial(serial).equals(is.getType())) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
break;
}
}
}
}
if (obj.contains(Lang.get(quester.getPlayer(), "use"))) {
} else if (obj.contains(Lang.get(quester.getPlayer(), "use"))) {
for (ItemStack is : stage.blocksToUse) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
if (Material.matchMaterial(serial) != null) {
if (Material.matchMaterial(serial).equals(is.getType())) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
break;
}
}
}
}
if (obj.contains(Lang.get(quester.getPlayer(), "cut"))) {
} else if (obj.contains(Lang.get(quester.getPlayer(), "cut"))) {
for (ItemStack is : stage.blocksToCut) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
}
}
// TODO change in Quester.java to use ItemStack instead of Material
/*if (s.contains(Lang.get(quester.getPlayer(), "enchantItem"))) {
for (Entry<Map<Enchantment, Material>, Integer> e : stage.itemsToEnchant.entrySet()) {
Map<Enchantment, Material> set = e.getKey();
Collection<Material> matSet = set.values();
for (Object o : matSet.toArray()) {
stacksWithPossibleEnchants.add((ItemStack)o));
if (Material.matchMaterial(serial) != null) {
if (Material.matchMaterial(serial).equals(is.getType())) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
break;
}
}
}
}*/
if (obj.contains(Lang.get(quester.getPlayer(), "deliver"))) {
}
//TODO find a better way to detect a deliver objective
else if (obj.contains(Lang.get(quester.getPlayer(), "deliver").split(" ")[0])) {
System.out.println("1");
for (ItemStack is : stage.itemsToDeliver) {
String enchant = "";
if (!is.getEnchantments().isEmpty()) {
//TODO parse multiple enchantments?
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>").replace(enchant, "<enchantment>"),
is.getType(), is.getDurability(), is.getEnchantments().entrySet().iterator().next().getKey());
if (Material.matchMaterial(serial) != null) {
if (Material.matchMaterial(serial).equals(is.getType())) {
System.out.println("2");
String enchant = "";
if (!is.getEnchantments().isEmpty()) {
System.out.println("3");
//TODO parse multiple enchantments?
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>").replace(enchant, "<enchantment>"),
is.getType(), is.getDurability(), is.getEnchantments().entrySet().iterator().next().getKey());
break;
} else {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<item>"), is.getType(), is.getDurability());
break;
}
}
}
}
}
if (obj.contains(Lang.get(quester.getPlayer(), "kill"))) {
} else if (obj.contains(Lang.get(quester.getPlayer(), "kill"))) {
for (EntityType type : stage.mobsToKill) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<mob>"), type);
try {
EntityType et = EntityType.valueOf(serial.toUpperCase().replace(" ", "_"));
if (et.equals(type)) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<mob>"), type);
}
} catch (IllegalArgumentException iae) {
// Do nothing
}
break;
}
}
if (obj.contains(Lang.get(quester.getPlayer(), "tame"))) {
} else if (obj.contains(Lang.get(quester.getPlayer(), "tame"))) {
for (Entry<EntityType, Integer> e : stage.mobsToTame.entrySet()) {
EntityType type = e.getKey();
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<mob>"), type);
try {
EntityType type = e.getKey();
EntityType et = EntityType.valueOf(serial.toUpperCase().replace(" ", "_"));
if (et.equals(type)) {
query.sendMessage(quester.getPlayer(), obj.replace(serial, "<mob>"), type);
break;
}
} catch (IllegalArgumentException iae) {
// Do nothing
}
}
} else {
quester.getPlayer().sendMessage(obj);
}
quester.getPlayer().sendMessage(obj);
} catch (IndexOutOfBoundsException e) {
quester.getPlayer().sendMessage(obj);
}