diff --git a/pom.xml b/pom.xml index 1355938e4..d84c450a6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ me.blackvein.quests quests - 3.3.8 + 3.4.0 quests https://github.com/FlyingPikachu/Quests/ jar @@ -131,7 +131,7 @@ net.milkbowl.vault Vault - 1.6.6 + 1.6.7 provided diff --git a/src/main/java/me/blackvein/quests/Event.java b/src/main/java/me/blackvein/quests/Event.java index 10c024063..3de7d74db 100644 --- a/src/main/java/me/blackvein/quests/Event.java +++ b/src/main/java/me/blackvein/quests/Event.java @@ -251,9 +251,9 @@ public class Event { if (teleport != null) { player.teleport(teleport); } - if (!(book == null && book.isEmpty() && plugin.citizensBooks == null)) { - if (plugin.citizensBooks.hasFilter(book)) { - plugin.citizensBooks.openBook(player, plugin.citizensBooks.getFilter(book)); + if (!(book == null && book.isEmpty() && Quests.citizensBooks == null)) { + if (Quests.citizensBooks.hasFilter(book)) { + Quests.citizensBooks.openBook(player, Quests.citizensBooks.getFilter(book)); } } if (failQuest == true) { diff --git a/src/main/java/me/blackvein/quests/NpcEffectThread.java b/src/main/java/me/blackvein/quests/NpcEffectThread.java index b08edff86..68219c1b9 100644 --- a/src/main/java/me/blackvein/quests/NpcEffectThread.java +++ b/src/main/java/me/blackvein/quests/NpcEffectThread.java @@ -14,7 +14,6 @@ package me.blackvein.quests; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -64,27 +63,27 @@ public class NpcEffectThread implements Runnable { // effectType is either effectType or Quests.repeatEffect private void showEffect(Player player, NPC npc, String effectType) { - if (Bukkit.getBukkitVersion().contains("1.7.9")) { + if (Quests.bukkitVersion == 179) { showEffect_R3(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.7.10")) { + } else if (Quests.bukkitVersion == 1710) { showEffect_R4(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.8.4") || Bukkit.getBukkitVersion().contains("1.8.5") || Bukkit.getBukkitVersion().contains("1.8.6") || Bukkit.getBukkitVersion().contains("1.8.7") || Bukkit.getBukkitVersion().contains("1.8.8")) { + } else if (Quests.bukkitVersion >= 184 && Quests.bukkitVersion <= 188) { showEffect_1_8_R3(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.8.3")) { + } else if (Quests.bukkitVersion == 183) { showEffect_1_8_R2(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.8")) { + } else if (Quests.bukkitVersion == 18) { showEffect_1_8_R1(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.9.4")) { + } else if (Quests.bukkitVersion == 194) { showEffect_1_9_R2(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.9")) { + } else if (Quests.bukkitVersion == 19) { showEffect_1_9_R1(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.10")) { + } else if (Quests.bukkitVersion == 110) { showEffect_1_10_R1(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.11")) { + } else if (Quests.bukkitVersion == 111) { showEffect_1_11_R1(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.12")) { + } else if (Quests.bukkitVersion == 112) { showEffect_1_12_R1(player, npc, effectType); - } else if (Bukkit.getBukkitVersion().contains("1.13")) { + } else if (Quests.bukkitVersion == 113) { showEffect_1_13_R1(player, npc, effectType); } } diff --git a/src/main/java/me/blackvein/quests/NpcListener.java b/src/main/java/me/blackvein/quests/NpcListener.java index b92de8e88..c0b5d2c88 100644 --- a/src/main/java/me/blackvein/quests/NpcListener.java +++ b/src/main/java/me/blackvein/quests/NpcListener.java @@ -45,7 +45,6 @@ public class NpcListener implements Listener { plugin = newPlugin; } - @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.LOWEST) public void onNPCRightClick(NPCRightClickEvent evt) { if (plugin.questFactory.selectingNPCs.contains(evt.getClicker())) { @@ -79,24 +78,36 @@ public class NpcListener implements Listener { } else if (!hand.getType().equals(Material.AIR)) { for (Integer n : quester.getCurrentStage(quest).itemDeliveryTargets) { if (n.equals(clicked.getId())) { + /*try { + String[] lang = Lang.get(player, "questInvalidDeliveryItem").split(""); + String prefix = lang[0]; + if (hand.hasItemMeta()) { + prefix += ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC + (hand.getItemMeta().hasDisplayName() ? hand.getItemMeta().getDisplayName() + ChatColor.GRAY + " (" : ""); + } + prefix += ChatColor.AQUA; + String suffix = (hand.getDurability() != 0 ? (":" + ChatColor.BLUE + hand.getDurability()) : "") + ChatColor.GRAY; + if (hand.hasItemMeta()) { + suffix += (hand.getItemMeta().hasDisplayName() ? ")" : ""); + } + suffix += " x " + ChatColor.DARK_AQUA + hand.getAmount() + ChatColor.RESET + lang[1]; + plugin.query.sendMessage(player, prefix, hand.getType(), suffix); + break; + } catch (IndexOutOfBoundsException e) { + plugin.getLogger().severe("Error splitting \"" + Lang.get(player, "questInvalidDeliveryItem") + "\". Maybe missing tag?"); + player.sendMessage(ChatColor.RED + "Error showing this text. Please contact an administrator."); + e.printStackTrace(); + }*/ String text = ""; if (hand.hasItemMeta()) { text += ChatColor.LIGHT_PURPLE + "" + ChatColor.ITALIC + (hand.getItemMeta().hasDisplayName() ? hand.getItemMeta().getDisplayName() + ChatColor.GRAY + " (" : ""); } - String base = "error"; - try { - base = ChatColor.AQUA + Items.itemByType(hand.getType()).getName(); - } catch (Exception ne) { - text = ChatColor.AQUA + Quester.prettyItemString(hand.getType().name()); - Bukkit.getLogger().severe("Likely caused by an incompatible version of Vault. Consider updating!"); - ne.printStackTrace(); - } - text += ChatColor.AQUA + base + (hand.getDurability() != 0 ? (":" + ChatColor.BLUE + hand.getDurability()) : "") + ChatColor.GRAY; + text += ChatColor.AQUA + "" + (hand.getDurability() != 0 ? (":" + ChatColor.BLUE + hand.getDurability()) : "") + ChatColor.GRAY; if (hand.hasItemMeta()) { text += (hand.getItemMeta().hasDisplayName() ? ")" : ""); } text += " x " + ChatColor.DARK_AQUA + hand.getAmount() + ChatColor.GRAY; - evt.getClicker().sendMessage(Lang.get(player, "questInvalidDeliveryItem").replaceAll("", text)); + plugin.query.sendMessage(player, Lang.get(player, "questInvalidDeliveryItem").replace("", text), hand.getType()); + //evt.getClicker().sendMessage(Lang.get(player, "questInvalidDeliveryItem").replaceAll("", text)); break; } } diff --git a/src/main/java/me/blackvein/quests/Quest.java b/src/main/java/me/blackvein/quests/Quest.java index 90196cfee..e3ad0a34b 100644 --- a/src/main/java/me/blackvein/quests/Quest.java +++ b/src/main/java/me/blackvein/quests/Quest.java @@ -327,7 +327,9 @@ public class Quest { none = null; } for (String s : permissions) { - Quests.permission.playerAdd(player, s); + if (Quests.permission != null) { + Quests.permission.playerAdd(player, s); + } none = null; } for (String s : mcmmoSkills) { diff --git a/src/main/java/me/blackvein/quests/Quester.java b/src/main/java/me/blackvein/quests/Quester.java index a0970305a..0738c2ce2 100644 --- a/src/main/java/me/blackvein/quests/Quester.java +++ b/src/main/java/me/blackvein/quests/Quester.java @@ -51,7 +51,6 @@ import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; import me.blackvein.quests.util.MiscUtil; import net.citizensnpcs.api.npc.NPC; -import net.milkbowl.vault.item.Items; public class Quester { @@ -310,6 +309,7 @@ public class Quester { return null; } + @SuppressWarnings("deprecation") public void takeQuest(Quest q, boolean override) { Player player = getPlayer(); long start = -1; @@ -414,7 +414,30 @@ public class Quester { msg = msg.replace("", q.name); getPlayer().sendMessage(ChatColor.GOLD + msg); for (String s : getObjectivesReal(q)) { - player.sendMessage(s); + // TODO ensure all applicable strings are translated + String sbegin = s.substring(s.indexOf(ChatColor.AQUA.toString()) + 2); + String serial = sbegin.substring(0, sbegin.indexOf(ChatColor.GREEN.toString())); + + String enchant = ""; + if (s.contains(ChatColor.LIGHT_PURPLE.toString())) { + String ebegin = s.substring(s.indexOf(ChatColor.LIGHT_PURPLE.toString()) + 2); + enchant = ebegin.substring(0, ebegin.indexOf(ChatColor.GREEN.toString())); + } + + // Order is important + if (Enchantment.getByName(Lang.getKey(enchant).replace("ENCHANTMENT_", "")) != null) { + Material m = Material.matchMaterial(serial); + Enchantment e = Enchantment.getByName(Lang.getKey(enchant).replace("ENCHANTMENT_", "")); + plugin.query.sendMessage(player, s.replace(serial, "").replace(enchant, ""), m, e); + } else if (Material.matchMaterial(serial) != null) { + Material m = Material.matchMaterial(serial); + plugin.query.sendMessage(player, s.replace(serial, ""), m); + } else if (EntityType.valueOf(serial.toUpperCase().replace(" ", "_")) != null) { + EntityType type = EntityType.valueOf(serial.toUpperCase().replace(" ", "_")); + plugin.query.sendMessage(player, s.replace(serial, ""), type); + } else { + player.sendMessage(s); + } } String stageStartMessage = stage.startMessage; if (stageStartMessage != null) { @@ -464,9 +487,9 @@ public class Quester { for (ItemStack e2 : getQuestData(quest).blocksBroken) { if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { if (e2.getAmount() < e.getAmount()) { - unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "break") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); + unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "break") + " " + ItemUtil.getName(e2) + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); } else { - finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "break") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); + finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "break") + " " + ItemUtil.getName(e2) + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); } } } @@ -475,9 +498,9 @@ public class Quester { 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(getPlayer(), "damage") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); + unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "damage") + " " + ItemUtil.getName(e2) + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); } else { - finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "damage") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); + finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "damage") + " " + ItemUtil.getName(e2) + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); } } } @@ -486,9 +509,9 @@ public class Quester { for (ItemStack e2 : getQuestData(quest).blocksPlaced) { if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { if (e2.getAmount() < e.getAmount()) { - unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "place") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); + unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "place") + " " + ItemUtil.getName(e2) + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); } else { - finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "place") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); + finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "place") + " " + ItemUtil.getName(e2) + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); } } } @@ -497,9 +520,9 @@ public class Quester { for (ItemStack e2 : getQuestData(quest).blocksUsed) { if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { if (e2.getAmount() < e.getAmount()) { - unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "use") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); + unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "use") + " " + ItemUtil.getName(e2) + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); } else { - finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "use") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); + finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "use") + " " + ItemUtil.getName(e2) + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); } } } @@ -508,9 +531,9 @@ public class Quester { for (ItemStack e2 : getQuestData(quest).blocksCut) { if (e2.getType().equals(e.getType()) && e2.getDurability() == e.getDurability()) { if (e2.getAmount() < e.getAmount()) { - unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "cut") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); + unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "cut") + " " + ItemUtil.getName(e2) + ChatColor.GREEN + ": " + e2.getAmount() + "/" + e.getAmount()); } else { - finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "cut") + " " + Items.itemByType(e2.getType()).getName() + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); + finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "cut") + " " + ItemUtil.getName(e2) + ChatColor.GRAY + ": " + e2.getAmount() + "/" + e.getAmount()); } } } @@ -553,13 +576,13 @@ public class Quester { if (enchantment2 == enchantment) { if (num1 < num2) { String obj = Lang.get(getPlayer(), "enchantItem"); - obj = obj.replace("", ItemUtil.getName(new ItemStack(mat))); - obj = obj.replace("", Quester.prettyEnchantmentString(enchantment)); + obj = obj.replace("", ItemUtil.getName(new ItemStack(mat)) + ChatColor.GREEN); + obj = obj.replace("", ChatColor.LIGHT_PURPLE + Quester.prettyEnchantmentString(enchantment) + ChatColor.GREEN); unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + num1 + "/" + num2); } else { String obj = Lang.get(getPlayer(), "enchantItem"); - obj = obj.replace("", ItemUtil.getName(new ItemStack(mat))); - obj = obj.replace("", Quester.prettyEnchantmentString(enchantment)); + obj = obj.replace("", ItemUtil.getName(new ItemStack(mat)) + ChatColor.GRAY); + obj = obj.replace("", ChatColor.LIGHT_PURPLE + Quester.prettyEnchantmentString(enchantment) + ChatColor.GRAY); finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + num1 + "/" + num2); } } @@ -571,19 +594,19 @@ public class Quester { if (getQuestData(quest).mobNumKilled.size() > getQuestData(quest).mobsKilled.indexOf(e2) && getCurrentStage(quest).mobNumToKill.size() > getCurrentStage(quest).mobsToKill.indexOf(e)) { if (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2)) < getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e))) { if (getCurrentStage(quest).locationsToKillWithin.isEmpty()) { - unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "kill") + " " + Quester.prettyMobString(e) + ChatColor.GREEN + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); + unfinishedObjectives.add(ChatColor.GREEN + Lang.get(getPlayer(), "kill") + " " + ChatColor.AQUA + Quester.prettyMobString(e) + ChatColor.GREEN + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); } else { String obj = Lang.get(getPlayer(), "killAtLocation"); - obj = obj.replace("", Quester.prettyMobString(e)); + obj = obj.replace("", ChatColor.LIGHT_PURPLE + Quester.prettyMobString(e)); obj = obj.replace("", getCurrentStage(quest).areaNames.get(getCurrentStage(quest).mobsToKill.indexOf(e))); unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); } } else { if (getCurrentStage(quest).locationsToKillWithin.isEmpty()) { - finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "kill") + " " + Quester.prettyMobString(e) + ChatColor.GRAY + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); + finishedObjectives.add(ChatColor.GRAY + Lang.get(getPlayer(), "kill") + " " + ChatColor.AQUA + Quester.prettyMobString(e) + ChatColor.GRAY + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); } else { String obj = Lang.get(getPlayer(), "killAtLocation"); - obj = obj.replace("", Quester.prettyMobString(e)); + obj = obj.replace("", ChatColor.LIGHT_PURPLE + Quester.prettyMobString(e)); obj = obj.replace("", getCurrentStage(quest).areaNames.get(getCurrentStage(quest).mobsToKill.indexOf(e))); finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + (getQuestData(quest).mobNumKilled.get(getQuestData(quest).mobsKilled.indexOf(e2))) + "/" + (getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(e)))); } @@ -610,14 +633,14 @@ public class Quester { index2++; if (delivered < amt) { String obj = Lang.get(getPlayer(), "deliver"); - obj = obj.replace("", ItemUtil.getName(is)); + obj = obj.replace("", ItemUtil.getName(is) + ChatColor.GREEN); obj = obj.replace("", plugin.getNPCName(npc)); - unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + delivered + "/" + amt); + unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + delivered + "/" + amt); } else { String obj = Lang.get(getPlayer(), "deliver"); - obj = obj.replace("", ItemUtil.getName(is)); + obj = obj.replace("", ItemUtil.getName(is) + ChatColor.GRAY); obj = obj.replace("", plugin.getNPCName(npc)); - finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + delivered + "/" + amt); + finishedObjectives.add(ChatColor.GRAY + obj + ": " + delivered + "/" + amt); } } for (Integer n : getCurrentStage(quest).citizensToInteract) { @@ -1247,46 +1270,47 @@ public class Quester { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("breakBlock")) { - String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "break") + " " + ItemUtil.getName(material); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "break") + " "; String stack = getQuestData(quest).blocksBroken.toString(); String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", ""); message = message + " " + amount + "/" + amount; - p.sendMessage(message); + plugin.query.sendMessage(p, message, material.getType()); if (testComplete(quest)) { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("damageBlock")) { - String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "damage") + " " + ItemUtil.getName(material); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "damage") + " "; String stack = getQuestData(quest).blocksDamaged.toString(); String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", ""); message = message + " " + amount + "/" + amount; + plugin.query.sendMessage(p, message, material.getType()); if (testComplete(quest)) { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("placeBlock")) { - String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "place") + " " + ItemUtil.getName(material); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "place") + " "; String stack = getQuestData(quest).blocksPlaced.toString(); String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", ""); message = message + " " + amount + "/" + amount; - p.sendMessage(message); + plugin.query.sendMessage(p, message, material.getType()); if (testComplete(quest)) { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("useBlock")) { - String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "use") + " " + ItemUtil.getName(material); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "use") + " "; String stack = getQuestData(quest).blocksUsed.toString(); String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", ""); message = message + " " + amount + "/" + amount; - p.sendMessage(message); + plugin.query.sendMessage(p, message, material.getType()); if (testComplete(quest)) { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("cutBlock")) { - String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "cut") + " " + ItemUtil.getName(material); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "cut") + " "; String stack = getQuestData(quest).blocksCut.toString(); String amount = stack.substring(stack.lastIndexOf(" x ") + 3).replace("}]", ""); message = message + " " + amount + "/" + amount; - p.sendMessage(message); + plugin.query.sendMessage(p, message, material.getType()); if (testComplete(quest)) { quest.nextStage(this); } @@ -1299,8 +1323,6 @@ public class Quester { } } else if (objective.equalsIgnoreCase("enchantItem")) { String obj = Lang.get(p, "enchantItem"); - obj = obj.replace("", ItemUtil.getName(material)); - obj = obj.replace("", Quester.prettyEnchantmentString(enchantment)); String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj; for (Map map : getCurrentStage(quest).itemsToEnchant.keySet()) { if (map.containsKey(enchantment)) { @@ -1308,23 +1330,22 @@ public class Quester { break; } } - p.sendMessage(message); + plugin.query.sendMessage(p, message, material.getType(), enchantment); if (testComplete(quest)) { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("deliverItem")) { String obj = Lang.get(p, "deliver"); - obj = obj.replace("", ItemUtil.getString(getCurrentStage(quest).itemsToDeliver.get(getCurrentStage(quest).itemsToDeliver.indexOf(delivery)))); obj = obj.replace("", plugin.getNPCName(getCurrentStage(quest).itemDeliveryTargets.get(getCurrentStage(quest).itemsToDeliver.indexOf(delivery)))); String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + obj; - p.sendMessage(message); + plugin.query.sendMessage(p, message, getCurrentStage(quest).itemsToDeliver.get(getCurrentStage(quest).itemsToDeliver.indexOf(delivery)).getType()); if (testComplete(quest)) { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("killMob")) { - String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "kill") + " " + mob.name(); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "kill") + " "; message = message + " " + getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(mob)) + "/" + getCurrentStage(quest).mobNumToKill.get(getCurrentStage(quest).mobsToKill.indexOf(mob)); - p.sendMessage(message); + plugin.query.sendMessage(p, message, mob); if (testComplete(quest)) { quest.nextStage(this); } @@ -1351,9 +1372,9 @@ public class Quester { quest.nextStage(this); } } else if (objective.equalsIgnoreCase("tameMob")) { - String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "tame") + " " + getCapitalized(mob.name()); + String message = ChatColor.GREEN + "(" + Lang.get(p, "completed") + ") " + Lang.get(p, "tame") + " "; message = message + " " + getCurrentStage(quest).mobsToTame.get(mob) + "/" + getCurrentStage(quest).mobsToTame.get(mob); - p.sendMessage(message); + plugin.query.sendMessage(p, message, mob); if (testComplete(quest)) { quest.nextStage(this); } @@ -1547,7 +1568,6 @@ public class Quester { /** * Cleans up item names. 'WOODEN_BUTTON' becomes 'Wooden Button' * - * @deprecated Use ItemUtil.getString(itemStack) instead if possible * @param itemName any item name, ideally * @return cleaned-up string */ diff --git a/src/main/java/me/blackvein/quests/Quests.java b/src/main/java/me/blackvein/quests/Quests.java index a3b006405..cd1f1e74e 100644 --- a/src/main/java/me/blackvein/quests/Quests.java +++ b/src/main/java/me/blackvein/quests/Quests.java @@ -94,7 +94,9 @@ import me.blackvein.quests.exceptions.InvalidStageException; import me.blackvein.quests.prompts.QuestAcceptPrompt; import me.blackvein.quests.util.ItemUtil; import me.blackvein.quests.util.Lang; +import me.blackvein.quests.util.LocaleQuery; import me.blackvein.quests.util.MiscUtil; + import me.clip.placeholderapi.PlaceholderAPIPlugin; import net.aufdemrand.denizen.Denizen; import net.aufdemrand.denizencore.scripts.ScriptRegistry; @@ -109,6 +111,7 @@ import ro.nicuch.citizensbooks.CitizensBooksPlugin; public class Quests extends JavaPlugin implements ConversationAbandonedListener { + public static int bukkitVersion = 0; // Dependencies public static Economy economy = null; public static Permission permission = null; @@ -136,6 +139,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener public String redoEffect = "angry_villager"; public boolean showQuestReqs = true; public boolean showQuestTitles = true; + public boolean translateItems = false; public boolean translateSubCommands = false; public boolean useCompass = true; // Interfaces @@ -159,6 +163,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener public NpcEffectThread effListener; public QuestTaskTrigger trigger; public Lang lang = new Lang(this); + public LocaleQuery query = new LocaleQuery(this); @SuppressWarnings("serial") class StageFailedException extends Exception { @@ -169,6 +174,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener @Override public void onEnable() { + bukkitVersion = Integer.valueOf(Bukkit.getServer().getBukkitVersion().split("-")[0].replace(".", "")); pListener = new PlayerListener(this); effListener = new NpcEffectThread(this); npcListener = new NpcListener(this); @@ -418,13 +424,15 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener if (getServer().getPluginManager().getPlugin("CitizensBooks") != null) { citizensBooks = ((CitizensBooksPlugin) getServer().getPluginManager().getPlugin("CitizensBooks")).getAPI(); } - if (!setupEconomy()) { - getLogger().warning("Economy not found."); + if (getServer().getPluginManager().getPlugin("Vault") != null) { + if (!setupEconomy()) { + getLogger().warning("Economy not found."); + } + if (!setupPermissions()) { + getLogger().warning("Permissions not found."); + } + vault = (Vault) getServer().getPluginManager().getPlugin("Vault"); } - if (!setupPermissions()) { - getLogger().warning("Permissions not found."); - } - vault = (Vault) getServer().getPluginManager().getPlugin("Vault"); } @Override @@ -520,6 +528,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener redoEffect = config.getString("npc-effects.redo-quest", "angry_villager"); showQuestReqs = config.getBoolean("show-requirements", true); showQuestTitles = config.getBoolean("show-titles", true); + translateItems = config.getBoolean("translate-items", false); translateSubCommands = config.getBoolean("translate-subcommands", false); useCompass = config.getBoolean("use-compass", true); try { @@ -1639,7 +1648,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } else { player.sendMessage(ChatColor.YELLOW + Lang.get(player, "alreadyConversing")); } - } else { } } } @@ -1790,7 +1798,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } if (q.moneyReq != 0) { - if (economy.getBalance(quester.getOfflinePlayer()) >= q.moneyReq) { + if (economy != null && economy.getBalance(quester.getOfflinePlayer()) >= q.moneyReq) { if (q.moneyReq == 1) { cs.sendMessage(ChatColor.GRAY + "- " + ChatColor.GREEN + q.moneyReq + " " + Quests.getCurrency(false)); } else { diff --git a/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java b/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java index 1657d0474..1b7506134 100644 --- a/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/ItemStackPrompt.java @@ -42,13 +42,11 @@ public class ItemStackPrompt extends FixedSetPrompt { // Stores ItemStack in "tempStack" context data // Stores name in "tempName" // Stores amount in "tempAmount" - // Stores data in "tempData" + // Stores durability in "tempData" // Stores enchantments in "tempEnchantments" // Stores display name in "tempDisplay" // Stores lore in "tempLore" - // Stores book title in "tempBookTitle" - // Stores book author in "tempBookAuthor" - // Stores book pages in "tempBookPages" + // Stores metadata in "tempMeta" final Prompt oldPrompt; public ItemStackPrompt(Prompt old) { @@ -492,7 +490,6 @@ public class ItemStackPrompt extends FixedSetPrompt { } } - @SuppressWarnings("deprecation") private String getItemData(ConversationContext cc) { if (cc.getSessionData("tempName") != null) { String item; diff --git a/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java b/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java index 71597c979..8ddfca341 100644 --- a/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java +++ b/src/main/java/me/blackvein/quests/prompts/RewardsPrompt.java @@ -194,7 +194,6 @@ public class RewardsPrompt extends FixedSetPrompt { text = text.replaceAll("", ChatColor.AQUA + (Quests.economy.currencyNamePlural().isEmpty() ? Lang.get("money") : Quests.economy.currencyNamePlural()) + ChatColor.YELLOW); } else { text = text.replaceAll("", ChatColor.AQUA + Lang.get("money") + ChatColor.YELLOW); - } return ChatColor.YELLOW + text; } diff --git a/src/main/java/me/blackvein/quests/util/ItemUtil.java b/src/main/java/me/blackvein/quests/util/ItemUtil.java index 5161911ca..3382522b7 100644 --- a/src/main/java/me/blackvein/quests/util/ItemUtil.java +++ b/src/main/java/me/blackvein/quests/util/ItemUtil.java @@ -31,7 +31,6 @@ import org.bukkit.inventory.meta.ItemMeta; import me.blackvein.quests.Quester; import me.blackvein.quests.Quests; -import net.milkbowl.vault.item.Items; public class ItemUtil { @@ -227,11 +226,29 @@ public class ItemUtil { return serial; } + /** + * Essentially the reverse of ItemMeta.serialize() + * + * Format is ([display]name:durability) with (enchantments:levels) x (amount) + * + * @param ItemMeta class, key/value map of metadata + * @return ItemMeta + */ public static ItemMeta deserializeItemMeta(Class itemMetaClass, Map args) { DelegateDeserialization delegate = itemMetaClass.getAnnotation(DelegateDeserialization.class); return (ItemMeta) ConfigurationSerialization.deserializeObject(args, delegate.value()); } + /** + * Returns a formatted display name. If none exists, returns item name. + * Also returns formatted durability and amount. + * A;so includes formatted enchantments. + * + * Format is ([display]name:durability) with (enchantments:levels) x (amount) + * + * @param is ItemStack to check + * @return true display or item name, plus durability and amount, plus enchantments + */ public static String getDisplayString(ItemStack is) { String text; if (is == null) { @@ -254,13 +271,22 @@ public class ItemUtil { } return text; } - + + /** + * Returns a formatted display name. If none exists, returns item name. + * Also returns formatted durability and amount. + * + * Format is ([display]name:durability) x (amount) + * + * @param is ItemStack to check + * @return true display or item name, plus durability and amount + */ public static String getString(ItemStack is) { String text; if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) { text = "" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.AQUA + " x " + is.getAmount(); } else { - text = ChatColor.AQUA + getName(is); + text = ChatColor.AQUA + Quester.prettyItemString(is.getType().name()); if (is.getDurability() != 0) { text += ChatColor.AQUA + ":" + is.getDurability(); } @@ -269,25 +295,24 @@ public class ItemUtil { return text; } - @SuppressWarnings("deprecation") + /** + * Returns a formatted display name. If none exists, returns item name. + * + * @param is ItemStack to check + * @return true display or item name + */ public static String getName(ItemStack is) { String text = ""; if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) { text = "" + ChatColor.DARK_AQUA + ChatColor.ITALIC + is.getItemMeta().getDisplayName(); } else { - try { - text = ChatColor.AQUA + Items.itemByType(is.getType()).getName(); - } catch (Exception ne) { - text = ChatColor.AQUA + Quester.prettyItemString(is.getType().name()); - Bukkit.getLogger().severe("This error is likely caused by an incompatible version of Vault. Please consider updating."); - ne.printStackTrace(); - } + text = ChatColor.AQUA + Quester.prettyItemString(is.getType().name()); } return text; } /** - * Ensures that an ItemStack if a valid, non-AIR material + * Ensures that an ItemStack is a valid, non-AIR material * * @param is ItemStack to check * @return true if stack is not null or Material.AIR diff --git a/src/main/java/me/blackvein/quests/util/LocaleQuery.java b/src/main/java/me/blackvein/quests/util/LocaleQuery.java new file mode 100644 index 000000000..e019746ee --- /dev/null +++ b/src/main/java/me/blackvein/quests/util/LocaleQuery.java @@ -0,0 +1,125 @@ +/******************************************************************************************************* + * Continued by FlyingPikachu/HappyPikachu with permission from _Blackvein_. All rights reserved. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN + * NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + *******************************************************************************************************/ + +package me.blackvein.quests.util; + +import java.lang.reflect.InvocationTargetException; +import me.blackvein.quests.Quester; +import me.blackvein.quests.Quests; + +import org.apache.commons.lang3.reflect.MethodUtils; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; + +public class LocaleQuery { + private static Class craftMagicNumbers = null; + private final Quests plugin; + + public LocaleQuery(Quests plugin){ + this.plugin = plugin; + setup(); + } + + public void sendMessage(Player player, String message, Material material) { + if (plugin.translateItems) { + String key = queryByType(material); + if (Quests.bukkitVersion <= 1122) { + if (key.startsWith("tile.") || key.startsWith("item.")) { + key = key + ".name"; + } + } + if (key != null) { + String msg = message.replace("", "\",{\"translate\":\"" + key + "\"},\""); + player.chat("/tellraw " + player.getName() + " [\"" + msg + "\"]"); + return; + } + } + player.sendMessage(message.replace("", Quester.prettyItemString(material.name()))); + } + + public void sendMessage(Player player, String message, Material material, Enchantment enchantment) { + if (plugin.translateItems) { + String key = queryByType(material); + if (Quests.bukkitVersion <= 1122) { + if (key.startsWith("tile.") || key.startsWith("item.")) { + key = key + ".name"; + } + } + String key2 = ""; + if (Quests.bukkitVersion <= 1122) { + key2 = "enchantment." + MiscUtil.getProperEnchantmentName(enchantment).replace("_", ".") + .replace("environmental", "all").replace("protection", "protect"); + } else { + key2 = "enchantment.minecraft." + enchantment.toString().toLowerCase(); + } + if (key != null && !key.equals("")) { + String msg = message.replace("", "\",{\"translate\":\"" + key + "\"},\"") + .replace("", "\",{\"translate\":\"" + key2 + "\"},\""); + player.chat("/tellraw " + player.getName() + " [\"" + msg + "\"]"); + return; + } + } + player.sendMessage(message.replace("", Quester.prettyItemString(material.name())) + .replace("", Quester.prettyEnchantmentString(enchantment))); + } + + public void sendMessage(Player player, String message, EntityType type) { + if (plugin.translateItems) { + String key = ""; + if (Quests.bukkitVersion <= 1122) { + key = "entity." + MiscUtil.getProperMobName(type) + ".name"; + } else { + key = "entity.minecraft." + type.toString().toLowerCase(); + } + if (!key.equals("")) { + String msg = message.replace("", "\",{\"translate\":\"" + key + "\"},\""); + player.chat("/tellraw " + player.getName() + " [\"" + msg + "\"]"); + return; + } + } + player.sendMessage(message.replace("", Quester.prettyMobString(type))); + } + + /** + * Creates a new LocaleQuery of the specified material + * @param material the item with the material + * @return the new LocaleQuery + * @throws IllegalArgumentException if an item with that material could not be found + */ + public String queryByType(Material material) throws IllegalArgumentException{ + try { + Object item = MethodUtils.invokeExactStaticMethod(craftMagicNumbers,"getItem", material); + + if (item == null) { + throw new IllegalArgumentException("An item with that material could not be found! (Perhaps you have specified a block?)"); + } + + String name = (String) MethodUtils.invokeExactMethod(item, "getName"); + return name; + } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + + public void setup() { + String version = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; + try { + craftMagicNumbers = Class.forName("org.bukkit.craftbukkit.{v}.util.CraftMagicNumbers".replace("{v}", version)); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } +} diff --git a/src/main/java/me/blackvein/quests/util/MiscUtil.java b/src/main/java/me/blackvein/quests/util/MiscUtil.java index 196cad018..6e7621b4f 100644 --- a/src/main/java/me/blackvein/quests/util/MiscUtil.java +++ b/src/main/java/me/blackvein/quests/util/MiscUtil.java @@ -15,6 +15,7 @@ package me.blackvein.quests.util; import java.util.LinkedList; import org.bukkit.ChatColor; +import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.EntityType; public class MiscUtil { @@ -29,6 +30,11 @@ public class MiscUtil { s = s.substring(1, s.length()); return s2 + s; } + + public static String getProperEnchantmentName(Enchantment enchantment) { + String name = enchantment.getName().toLowerCase(); + return name; + } public static String getProperMobName(EntityType type) { String name = type.name().toLowerCase(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 42152a589..c8655c12d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -15,5 +15,6 @@ npc-effects: redo-quest: angry_villager show-requirements: true show-titles: true +translate-items: false translate-subcommands: false use-compass: true \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7898ce43e..edb859821 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -5,8 +5,7 @@ description: An extensive questing system. website: https://www.spigotmc.org/resources/quests.3711/ dev-url: https://github.com/FlyingPikachu/Quests author: HappyPikachu -depend: [Vault] -softdepend: [Citizens, CitizensBooks, PhatLoots, PlaceholderAPI] +softdepend: [Citizens, CitizensBooks, PhatLoots, PlaceholderAPI, Vault] permissions: quests.quest: description: View current Quest objectives diff --git a/src/main/resources/strings.yml b/src/main/resources/strings.yml index 3408cbae1..805d79992 100644 --- a/src/main/resources/strings.yml +++ b/src/main/resources/strings.yml @@ -747,6 +747,7 @@ ENCHANTMENT_ARROW_FIRE: "Flame" ENCHANTMENT_ARROW_INFINITE: "Infinity" ENCHANTMENT_ARROW_KNOCKBACK: "Punch" ENCHANTMENT_BINDING_CURSE: "BindingCurse" +ENCHANTMENT_CHANNELING: "Channeling" ENCHANTMENT_DAMAGE_ALL: "Sharpness" ENCHANTMENT_DAMAGE_ARTHROPODS: "BaneOfArthropods" ENCHANTMENT_DEPTH_STRIDER: "DepthStrider" @@ -755,9 +756,11 @@ ENCHANTMENT_DIG_SPEED: "Efficiency" ENCHANTMENT_DURABILITY: "Unbreaking" ENCHANTMENT_FIRE_ASPECT: "FireAspect" ENCHANTMENT_FROST_WALKER: "FrostWalker" +ENCHANTMENT_IMPALING: "Impaling" ENCHANTMENT_KNOCKBACK: "Knockback" ENCHANTMENT_LOOT_BONUS_BLOCKS: "Fortune" ENCHANTMENT_LOOT_BONUS_MOBS: "Looting" +ENCHANTMENT_LOYALTY: "Loyalty" ENCHANTMENT_LUCK: "LuckOfTheSea" ENCHANTMENT_LURE: "Lure" ENCHANTMENT_MENDING: "Mending" @@ -767,6 +770,7 @@ ENCHANTMENT_PROTECTION_EXPLOSIONS: "BlastProtection" ENCHANTMENT_PROTECTION_FALL: "FeatherFalling" ENCHANTMENT_PROTECTION_FIRE: "FireProtection" ENCHANTMENT_PROTECTION_PROJECTILE: "ProjectileProtection" +ENCHANTMENT_RIPTIDE: "Riptide" ENCHANTMENT_SILK_TOUCH: "SilkTouch" ENCHANTMENT_SWEEPING_EDGE: "SweepingEdge" ENCHANTMENT_THORNS: "Thorns"