From f9c663b18a4723a1e00452aedfa3ecd97259a517 Mon Sep 17 00:00:00 2001 From: PikaMug <2267126+PikaMug@users.noreply.github.com> Date: Mon, 3 Feb 2020 06:08:08 -0500 Subject: [PATCH] Add missing permission checks --- .../quests/listeners/CmdExecutor.java | 270 +++++++++--------- 1 file changed, 138 insertions(+), 132 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java index 1b32a5e31..fcfec5238 100644 --- a/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java +++ b/main/src/main/java/me/blackvein/quests/listeners/CmdExecutor.java @@ -519,163 +519,169 @@ public class CmdExecutor implements CommandExecutor { } private boolean questsTop(final CommandSender cs, String[] args) { - if (args.length > 2) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("COMMAND_TOP_USAGE")); - } else { - int topNumber; - if (args.length == 1) { - topNumber = 5; // default + if (cs.hasPermission("quests.top")) { + if (args.length > 2) { + cs.sendMessage(ChatColor.YELLOW + Lang.get("COMMAND_TOP_USAGE")); } else { - try { - topNumber = Integer.parseInt(args[1]); - } catch (NumberFormatException e) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum")); + int topNumber; + if (args.length == 1) { + topNumber = 5; // default + } else { + try { + topNumber = Integer.parseInt(args[1]); + } catch (NumberFormatException e) { + cs.sendMessage(ChatColor.YELLOW + Lang.get("inputNum")); + return true; + } + } + if (topNumber < 1 || topNumber > plugin.getSettings().getTopLimit()) { + cs.sendMessage(ChatColor.YELLOW + Lang.get("invalidRange").replace("", "1") + .replace("", String.valueOf(plugin.getSettings().getTopLimit()))); return true; } - } - if (topNumber < 1 || topNumber > plugin.getSettings().getTopLimit()) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("invalidRange").replace("", "1") - .replace("", String.valueOf(plugin.getSettings().getTopLimit()))); - return true; - } - Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { - @Override - public void run() { - File folder = new File(plugin.getDataFolder(), "data"); - File[] playerFiles = folder.listFiles(); - Map questPoints = new HashMap(); - if (playerFiles != null) { - for (File f : playerFiles) { - if (!f.isDirectory()) { - FileConfiguration data = new YamlConfiguration(); - try { - data.load(f); - } catch (IOException e) { - e.printStackTrace(); - } catch (InvalidConfigurationException e) { - e.printStackTrace(); + Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() { + @Override + public void run() { + File folder = new File(plugin.getDataFolder(), "data"); + File[] playerFiles = folder.listFiles(); + Map questPoints = new HashMap(); + if (playerFiles != null) { + for (File f : playerFiles) { + if (!f.isDirectory()) { + FileConfiguration data = new YamlConfiguration(); + try { + data.load(f); + } catch (IOException e) { + e.printStackTrace(); + } catch (InvalidConfigurationException e) { + e.printStackTrace(); + } + questPoints.put(data.getString("lastKnownName", "Unknown"), + data.getInt("quest-points", 0)); } - questPoints.put(data.getString("lastKnownName", "Unknown"), - data.getInt("quest-points", 0)); + } + } + LinkedHashMap sortedMap = (LinkedHashMap) sort(questPoints); + int numPrinted = 0; + String msg = Lang.get("topQuestersTitle"); + msg = msg.replace("", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD); + cs.sendMessage(ChatColor.GOLD + msg); + for (Entry entry : sortedMap.entrySet()) { + numPrinted++; + cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - " + + ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " " + + Lang.get("questPoints")); + if (numPrinted == topNumber) { + break; } } } - LinkedHashMap sortedMap = (LinkedHashMap) sort(questPoints); - int numPrinted = 0; - String msg = Lang.get("topQuestersTitle"); - msg = msg.replace("", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD); - cs.sendMessage(ChatColor.GOLD + msg); - for (Entry entry : sortedMap.entrySet()) { - numPrinted++; - cs.sendMessage(ChatColor.YELLOW + String.valueOf(numPrinted) + ". " + entry.getKey() + " - " - + ChatColor.DARK_PURPLE + entry.getValue() + ChatColor.YELLOW + " " - + Lang.get("questPoints")); - if (numPrinted == topNumber) { - break; - } - } - } - }); + }); + } } return true; } private void questsStats(final CommandSender cs, String[] args) { - OfflinePlayer target; - if (args != null) { - target = getPlayer(args[1]); - if (target == null) { - try { - target = Bukkit.getOfflinePlayer(UUID.fromString(args[1])); - } catch (IllegalArgumentException e) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); - return; + if (cs.hasPermission("quests.stats")) { + OfflinePlayer target; + if (args != null) { + target = getPlayer(args[1]); + if (target == null) { + try { + target = Bukkit.getOfflinePlayer(UUID.fromString(args[1])); + } catch (IllegalArgumentException e) { + cs.sendMessage(ChatColor.YELLOW + Lang.get("playerNotFound")); + return; + } + } + } else { + target = Bukkit.getOfflinePlayer(((Player)cs).getUniqueId()); + } + Quester quester = plugin.getQuester(target.getUniqueId()); + cs.sendMessage(ChatColor.GOLD + "- " + target.getName() + " -"); + cs.sendMessage(ChatColor.YELLOW + Lang.get("questPointsDisplay") + " " + ChatColor.DARK_PURPLE + + quester.getQuestPoints()); + if (quester.getCurrentQuests().isEmpty()) { + cs.sendMessage(ChatColor.YELLOW + Lang.get("currentQuest") + " " + ChatColor.DARK_PURPLE+ Lang.get("none")); + } else { + cs.sendMessage(ChatColor.YELLOW + Lang.get("currentQuest")); + for (Entry set : quester.getCurrentQuests().entrySet()) { + Quest q = set.getKey(); + String msg = ChatColor.LIGHT_PURPLE + " - " + ChatColor.DARK_PURPLE + q.getName() + + ChatColor.LIGHT_PURPLE + " (" + Lang.get("stageEditorStage") + " " + (set.getValue() + 1) + ")"; + cs.sendMessage(msg); } } - } else { - target = Bukkit.getOfflinePlayer(((Player)cs).getUniqueId()); - } - Quester quester = plugin.getQuester(target.getUniqueId()); - cs.sendMessage(ChatColor.GOLD + "- " + target.getName() + " -"); - cs.sendMessage(ChatColor.YELLOW + Lang.get("questPointsDisplay") + " " + ChatColor.DARK_PURPLE - + quester.getQuestPoints()); - if (quester.getCurrentQuests().isEmpty()) { - cs.sendMessage(ChatColor.YELLOW + Lang.get("currentQuest") + " " + ChatColor.DARK_PURPLE+ Lang.get("none")); - } else { - cs.sendMessage(ChatColor.YELLOW + Lang.get("currentQuest")); - for (Entry set : quester.getCurrentQuests().entrySet()) { - Quest q = set.getKey(); - String msg = ChatColor.LIGHT_PURPLE + " - " + ChatColor.DARK_PURPLE + q.getName() - + ChatColor.LIGHT_PURPLE + " (" + Lang.get("stageEditorStage") + " " + (set.getValue() + 1) + ")"; - cs.sendMessage(msg); - } - } - String completed; - if (quester.getCompletedQuests().isEmpty()) { - completed = ChatColor.DARK_PURPLE + Lang.get("none"); - } else { - completed = ChatColor.DARK_PURPLE + ""; - for (String s : quester.getCompletedQuests()) { - completed += s; - if (quester.getAmountsCompleted().containsKey(s) && quester.getAmountsCompleted().get(s) > 1) { - completed += ChatColor.LIGHT_PURPLE + " (x" + quester.getAmountsCompleted().get(s) + ")"; - } - if (quester.getCompletedQuests().indexOf(s) < (quester.getCompletedQuests().size() - 1)) { - completed += ", "; + String completed; + if (quester.getCompletedQuests().isEmpty()) { + completed = ChatColor.DARK_PURPLE + Lang.get("none"); + } else { + completed = ChatColor.DARK_PURPLE + ""; + for (String s : quester.getCompletedQuests()) { + completed += s; + if (quester.getAmountsCompleted().containsKey(s) && quester.getAmountsCompleted().get(s) > 1) { + completed += ChatColor.LIGHT_PURPLE + " (x" + quester.getAmountsCompleted().get(s) + ")"; + } + if (quester.getCompletedQuests().indexOf(s) < (quester.getCompletedQuests().size() - 1)) { + completed += ", "; + } } } + cs.sendMessage(ChatColor.YELLOW + Lang.get("completedQuestsTitle")); + cs.sendMessage(completed); } - cs.sendMessage(ChatColor.YELLOW + Lang.get("completedQuestsTitle")); - cs.sendMessage(completed); } @SuppressWarnings("deprecation") private void questsJournal(final Player player) { - Quester quester = plugin.getQuester(player.getUniqueId()); - QuestsCommandPreQuestsJournalEvent preEvent = new QuestsCommandPreQuestsJournalEvent(quester); - plugin.getServer().getPluginManager().callEvent(preEvent); - if (preEvent.isCancelled()) { - return; - } - - Inventory inv = player.getInventory(); - if (quester.hasJournal) { - ItemStack[] arr = inv.getContents(); - for (int i = 0; i < arr.length; i++) { - if (arr[i] != null) { - if (ItemUtil.isJournal(arr[i])) { - inv.setItem(i, null); + if (((Player) player).hasPermission("quests.journal")) { + Quester quester = plugin.getQuester(player.getUniqueId()); + QuestsCommandPreQuestsJournalEvent preEvent = new QuestsCommandPreQuestsJournalEvent(quester); + plugin.getServer().getPluginManager().callEvent(preEvent); + if (preEvent.isCancelled()) { + return; + } + + Inventory inv = player.getInventory(); + if (quester.hasJournal) { + ItemStack[] arr = inv.getContents(); + for (int i = 0; i < arr.length; i++) { + if (arr[i] != null) { + if (ItemUtil.isJournal(arr[i])) { + inv.setItem(i, null); + } } } - } - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalPutAway")); - quester.hasJournal = false; - } else if (player.getItemInHand() == null || player.getItemInHand().getType().equals(Material.AIR)) { - ItemStack stack = new ItemStack(Material.WRITTEN_BOOK, 1); - ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); - stack.setItemMeta(meta); - player.setItemInHand(stack); - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")); - quester.hasJournal = true; - quester.updateJournal(); - } else if (inv.firstEmpty() != -1) { - ItemStack[] arr = inv.getContents(); - for (int i = 0; i < arr.length; i++) { - if (arr[i] == null) { - ItemStack stack = new ItemStack(Material.WRITTEN_BOOK, 1); - ItemMeta meta = stack.getItemMeta(); - meta.setDisplayName(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); - stack.setItemMeta(meta); - inv.setItem(i, stack); - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")); - quester.hasJournal = true; - quester.updateJournal(); - break; + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalPutAway")); + quester.hasJournal = false; + } else if (player.getItemInHand() == null || player.getItemInHand().getType().equals(Material.AIR)) { + ItemStack stack = new ItemStack(Material.WRITTEN_BOOK, 1); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); + stack.setItemMeta(meta); + player.setItemInHand(stack); + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")); + quester.hasJournal = true; + quester.updateJournal(); + } else if (inv.firstEmpty() != -1) { + ItemStack[] arr = inv.getContents(); + for (int i = 0; i < arr.length; i++) { + if (arr[i] == null) { + ItemStack stack = new ItemStack(Material.WRITTEN_BOOK, 1); + ItemMeta meta = stack.getItemMeta(); + meta.setDisplayName(ChatColor.LIGHT_PURPLE + Lang.get("journalTitle")); + stack.setItemMeta(meta); + inv.setItem(i, stack); + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalTaken")); + quester.hasJournal = true; + quester.updateJournal(); + break; + } } + } else { + player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalNoRoom")); } - } else { - player.sendMessage(ChatColor.YELLOW + Lang.get(player, "journalNoRoom")); } }