mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-14 14:45:41 +01:00
Add missing permission checks
This commit is contained in:
parent
26c39ec186
commit
f9c663b18a
@ -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("<least>", "1")
|
||||
.replace("<greatest>", String.valueOf(plugin.getSettings().getTopLimit())));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (topNumber < 1 || topNumber > plugin.getSettings().getTopLimit()) {
|
||||
cs.sendMessage(ChatColor.YELLOW + Lang.get("invalidRange").replace("<least>", "1")
|
||||
.replace("<greatest>", 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<String, Integer> questPoints = new HashMap<String, Integer>();
|
||||
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<String, Integer> questPoints = new HashMap<String, Integer>();
|
||||
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<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
|
||||
int numPrinted = 0;
|
||||
String msg = Lang.get("topQuestersTitle");
|
||||
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
|
||||
cs.sendMessage(ChatColor.GOLD + msg);
|
||||
for (Entry<String, Integer> 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<String, Integer> sortedMap = (LinkedHashMap<String, Integer>) sort(questPoints);
|
||||
int numPrinted = 0;
|
||||
String msg = Lang.get("topQuestersTitle");
|
||||
msg = msg.replace("<number>", ChatColor.DARK_PURPLE + "" + topNumber + ChatColor.GOLD);
|
||||
cs.sendMessage(ChatColor.GOLD + msg);
|
||||
for (Entry<String, Integer> 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<Quest, Integer> 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<Quest, Integer> 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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user