From 510c2d4c1e168ba417f39a9bbb9d74f9ce404399 Mon Sep 17 00:00:00 2001 From: PikaMug Date: Thu, 1 Aug 2019 00:17:07 -0400 Subject: [PATCH] Method comments --- .../java/me/blackvein/quests/Quester.java | 143 ++++++------------ .../main/java/me/blackvein/quests/Quests.java | 38 ++++- 2 files changed, 78 insertions(+), 103 deletions(-) diff --git a/main/src/main/java/me/blackvein/quests/Quester.java b/main/src/main/java/me/blackvein/quests/Quester.java index 4e7e41e23..cd3c1653c 100644 --- a/main/src/main/java/me/blackvein/quests/Quester.java +++ b/main/src/main/java/me/blackvein/quests/Quester.java @@ -2941,18 +2941,6 @@ public class Quester { Stage stage = getCurrentStage(quest); quest.updateCompass(this, stage); exists = true; - // Meh, let's not. - /* - * if (q.equals(quest) == false) { - * - * hardQuit(quest); - * - * if (plugin.getServer().getPlayer(id) != null) { String error = Lang.get("questModified"); error = error.replace("", - * ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED); plugin.getServer().getPlayer(id).sendMessage(ChatColor.GOLD + "[Quests] " - * + ChatColor.RED + error); updateJournal(); } - * - * } - */ break; } } @@ -2966,6 +2954,11 @@ public class Quester { } } + /** + * Show an inventory GUI with quest items to the specified player + * @param npc The NPC from which the GUI is bound + * @param quests List of quests to use for displaying items + */ public void showGUIDisplay(NPC npc, LinkedList quests) { Player player = getPlayer(); int size = ((quests.size() / 9) + 1) * 9; @@ -2999,6 +2992,13 @@ public class Quester { player.openInventory(inv); } + /** + * Force Quester to quit the specified quest

+ * + * Also cancels any timers + * + * @param quest The quest to quit + */ public void hardQuit(Quest quest) { try { currentQuests.remove(quest); @@ -3018,6 +3018,10 @@ public class Quester { } } + /** + * Forcibly remove quest from Quester's list of completed quests + * @param quest The quest to remove + */ public void hardRemove(Quest quest) { try { completedQuests.remove(quest.getName()); @@ -3026,6 +3030,11 @@ public class Quester { } } + /** + * Forcibly clear Quester's list of current quests

+ * + * Also resets associated quest data + */ public void hardClear() { try { currentQuests.clear(); @@ -3036,6 +3045,11 @@ public class Quester { } } + /** + * Forcibly set Quester's current stage + * @param key The quest to set stage of + * @param val The stage number to set + */ public void hardStagePut(Quest key, Integer val) { try { currentQuests.put(key, val); @@ -3044,6 +3058,11 @@ public class Quester { } } + /** + * Forcibly set Quester's quest data + * @param key The quest to set stage of + * @param val The data to set + */ public void hardDataPut(Quest key, QuestData val) { try { questData.put(key, val); @@ -3052,6 +3071,11 @@ public class Quester { } } + /** + * Reset compass target to Quester's bed spawn location

+ * + * Will set to Quester's spawn location if bed spawn does not exist + */ public void resetCompass() { if (!plugin.getSettings().canUseCompass()) return; @@ -3065,6 +3089,9 @@ public class Quester { player.setCompassTarget(defaultLocation); } + /** + * Gets first stage target from current quests, then updates compass accordingly + */ public void findCompassTarget() { if (!plugin.getSettings().canUseCompass()) return; @@ -3078,6 +3105,11 @@ public class Quester { } } + /** + * Check whether the Quester's inventory contains the specified item + * @param is The item with a specified amount to check + * @return true if the inventory contains at least the amount of the specified stack + */ public boolean hasItem(ItemStack is) { Inventory inv = getPlayer().getInventory(); int playerAmount = 0; @@ -3247,91 +3279,4 @@ public class Quester { } return true; } - - // I'm not sure why these methods are here. They've been in the class for a long time but aren't used anywhere? - - /*public static String checkPlacement(Inventory inv, int rawSlot) { - if (rawSlot < 0) { - return Lang.get("questNoDrop"); - } - InventoryType type = inv.getType(); - if (type.equals(InventoryType.BREWING)) { - if (rawSlot < 4) { - return Lang.get("questNoBrew"); - } - } else if (type.equals(InventoryType.CHEST)) { - if (inv.getContents().length == 27) { - if (rawSlot < 27) { - return Lang.get("questNoStore"); - } - } else { - if (rawSlot < 54) { - return Lang.get("questNoStore"); - } - } - } else if (type.equals(InventoryType.CRAFTING)) { - if (rawSlot < 5) { - return Lang.get("questNoCraft"); - } else if (rawSlot < 9) { - return Lang.get("questNoEquip"); - } - } else if (type.equals(InventoryType.DISPENSER)) { - if (rawSlot < 9) { - return Lang.get("questNoDispense"); - } - } else if (type.equals(InventoryType.ENCHANTING)) { - if (rawSlot == 0) { - return Lang.get("questNoEnchant"); - } - } else if (type.equals(InventoryType.ENDER_CHEST)) { - if (rawSlot < 27) { - return Lang.get("questNoStore"); - } - } else if (type.equals(InventoryType.FURNACE)) { - if (rawSlot < 3) { - return Lang.get("questNoSmelt"); - } - } else if (type.equals(InventoryType.WORKBENCH)) { - if (rawSlot < 10) { - return Lang.get("questNoCraft"); - } - } - return null; - }*/ - - /*public static List getChangedSlots(Inventory inInv, ItemStack inNew) { - List changed = new ArrayList(); - if (inInv.contains(inNew.getType())) { - int amount = inNew.getAmount(); - HashMap items = inInv.all(inNew.getType()); - for (int i = 0; i < inInv.getSize(); i++) { - if (!items.containsKey((Integer) i)) { - continue; - } - ItemStack item = items.get((Integer) i); - int slotamount = item.getMaxStackSize() - item.getAmount(); - if (slotamount > 1) { - if (amount > slotamount) { - int toAdd = slotamount - amount; - amount = amount - toAdd; - changed.add(i); - } else { - changed.add(i); - amount = 0; - break; - } - } - } - if (amount > 0) { - if (inInv.firstEmpty() != -1) { - changed.add(inInv.firstEmpty()); - } - } - } else { - if (inInv.firstEmpty() != -1) { - changed.add(inInv.firstEmpty()); - } - } - return changed; - }*/ } \ No newline at end of file diff --git a/main/src/main/java/me/blackvein/quests/Quests.java b/main/src/main/java/me/blackvein/quests/Quests.java index d7ae845a0..dae671826 100644 --- a/main/src/main/java/me/blackvein/quests/Quests.java +++ b/main/src/main/java/me/blackvein/quests/Quests.java @@ -208,8 +208,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener getServer().getPluginManager().registerEvents(partiesListener, this); } - // 10 - Delay loading of Quests, Events and modules - delayLoadQuestInfo(); + // 10 - Delay loading of Quests, Actions and modules + delayLoadQuestInfo(5L); } @Override @@ -481,7 +481,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } - private void delayLoadQuestInfo() { + /** + * Load quests, actions, and modules after specified delay

+ * + * At startup, this permits Citizens to fully load first + */ + private void delayLoadQuestInfo(long ticks) { getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { @Override @@ -500,7 +505,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } loadModules(); } - }, 5L); + }, ticks); } /** @@ -575,6 +580,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } + /** + * Load the specified jar as a module + * + * @param jar A custom reward/requirement/objective jar + */ public void loadModule(File jar) { try { @SuppressWarnings("resource") @@ -1356,6 +1366,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } + /** + * Reload quests, player data, actions, config settings, lang and modules, in that order + */ public void reloadQuests() { quests.clear(); events.clear(); @@ -1382,6 +1395,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener } } + /** + * Get online Quester from player UUID + * + * @param id Player UUID + * @return Quester, or null if offline + */ public Quester getQuester(UUID id) { Quester quester = null; for (Quester q: questers) { @@ -1405,6 +1424,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener return quester; } + /** + * Get online Quester from player name + * + * @param name Player name + * @return Quester, or null if offline + */ public Quester getQuester(String name) { UUID id = null; Quester quester = null; @@ -1420,6 +1445,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener return quester; } + /** + * Get a list of all online Questers + * + * @return list of online Questers + */ public LinkedList getOnlineQuesters() { LinkedList qs = new LinkedList(); for (Player p : getServer().getOnlinePlayers()) {