Method comments

This commit is contained in:
PikaMug 2019-08-01 00:17:07 -04:00
parent 3c7bc452bb
commit 510c2d4c1e
2 changed files with 78 additions and 103 deletions

View File

@ -2941,18 +2941,6 @@ public class Quester {
Stage stage = getCurrentStage(quest); Stage stage = getCurrentStage(quest);
quest.updateCompass(this, stage); quest.updateCompass(this, stage);
exists = true; 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("<quest>",
* ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED); plugin.getServer().getPlayer(id).sendMessage(ChatColor.GOLD + "[Quests] "
* + ChatColor.RED + error); updateJournal(); }
*
* }
*/
break; 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<Quest> quests) { public void showGUIDisplay(NPC npc, LinkedList<Quest> quests) {
Player player = getPlayer(); Player player = getPlayer();
int size = ((quests.size() / 9) + 1) * 9; int size = ((quests.size() / 9) + 1) * 9;
@ -2999,6 +2992,13 @@ public class Quester {
player.openInventory(inv); player.openInventory(inv);
} }
/**
* Force Quester to quit the specified quest<p>
*
* Also cancels any timers
*
* @param quest The quest to quit
*/
public void hardQuit(Quest quest) { public void hardQuit(Quest quest) {
try { try {
currentQuests.remove(quest); 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) { public void hardRemove(Quest quest) {
try { try {
completedQuests.remove(quest.getName()); completedQuests.remove(quest.getName());
@ -3026,6 +3030,11 @@ public class Quester {
} }
} }
/**
* Forcibly clear Quester's list of current quests<p>
*
* Also resets associated quest data
*/
public void hardClear() { public void hardClear() {
try { try {
currentQuests.clear(); 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) { public void hardStagePut(Quest key, Integer val) {
try { try {
currentQuests.put(key, val); 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) { public void hardDataPut(Quest key, QuestData val) {
try { try {
questData.put(key, val); questData.put(key, val);
@ -3052,6 +3071,11 @@ public class Quester {
} }
} }
/**
* Reset compass target to Quester's bed spawn location<p>
*
* Will set to Quester's spawn location if bed spawn does not exist
*/
public void resetCompass() { public void resetCompass() {
if (!plugin.getSettings().canUseCompass()) if (!plugin.getSettings().canUseCompass())
return; return;
@ -3065,6 +3089,9 @@ public class Quester {
player.setCompassTarget(defaultLocation); player.setCompassTarget(defaultLocation);
} }
/**
* Gets first stage target from current quests, then updates compass accordingly
*/
public void findCompassTarget() { public void findCompassTarget() {
if (!plugin.getSettings().canUseCompass()) if (!plugin.getSettings().canUseCompass())
return; 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) { public boolean hasItem(ItemStack is) {
Inventory inv = getPlayer().getInventory(); Inventory inv = getPlayer().getInventory();
int playerAmount = 0; int playerAmount = 0;
@ -3247,91 +3279,4 @@ public class Quester {
} }
return true; 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<Integer> getChangedSlots(Inventory inInv, ItemStack inNew) {
List<Integer> changed = new ArrayList<Integer>();
if (inInv.contains(inNew.getType())) {
int amount = inNew.getAmount();
HashMap<Integer, ? extends ItemStack> 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;
}*/
} }

View File

@ -208,8 +208,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
getServer().getPluginManager().registerEvents(partiesListener, this); getServer().getPluginManager().registerEvents(partiesListener, this);
} }
// 10 - Delay loading of Quests, Events and modules // 10 - Delay loading of Quests, Actions and modules
delayLoadQuestInfo(); delayLoadQuestInfo(5L);
} }
@Override @Override
@ -481,7 +481,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
} }
private void delayLoadQuestInfo() { /**
* Load quests, actions, and modules after specified delay<p>
*
* At startup, this permits Citizens to fully load first
*/
private void delayLoadQuestInfo(long ticks) {
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override @Override
@ -500,7 +505,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
} }
loadModules(); 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) { public void loadModule(File jar) {
try { try {
@SuppressWarnings("resource") @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() { public void reloadQuests() {
quests.clear(); quests.clear();
events.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) { public Quester getQuester(UUID id) {
Quester quester = null; Quester quester = null;
for (Quester q: questers) { for (Quester q: questers) {
@ -1405,6 +1424,12 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return quester; return quester;
} }
/**
* Get online Quester from player name
*
* @param name Player name
* @return Quester, or null if offline
*/
public Quester getQuester(String name) { public Quester getQuester(String name) {
UUID id = null; UUID id = null;
Quester quester = null; Quester quester = null;
@ -1420,6 +1445,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return quester; return quester;
} }
/**
* Get a list of all online Questers
*
* @return list of online Questers
*/
public LinkedList<Quester> getOnlineQuesters() { public LinkedList<Quester> getOnlineQuesters() {
LinkedList<Quester> qs = new LinkedList<Quester>(); LinkedList<Quester> qs = new LinkedList<Quester>();
for (Player p : getServer().getOnlinePlayers()) { for (Player p : getServer().getOnlinePlayers()) {