Add convenience methods. Bump version number

This commit is contained in:
PikaMug 2020-01-26 21:50:39 -05:00
parent cdbfb0bb96
commit ac74bf8470
10 changed files with 96 additions and 45 deletions

2
dist/pom.xml vendored
View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>3.8.5</version> <version>3.8.6</version>
</parent> </parent>
<artifactId>quests-dist</artifactId> <artifactId>quests-dist</artifactId>
<packaging>pom</packaging> <packaging>pom</packaging>

View File

@ -4,7 +4,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>3.8.5</version> <version>3.8.6</version>
</parent> </parent>
<artifactId>quests-main</artifactId> <artifactId>quests-main</artifactId>

View File

@ -801,28 +801,25 @@ public class Quest {
/** /**
* Force player to quit quest and inform them of their failure * Force player to quit quest and inform them of their failure
* *
* @param q The quester to be ejected * @param quester The quester to be ejected
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void failQuest(Quester q) { public void failQuest(Quester quester) {
QuesterPreFailQuestEvent preEvent = new QuesterPreFailQuestEvent(q, this); QuesterPreFailQuestEvent preEvent = new QuesterPreFailQuestEvent(quester, this);
plugin.getServer().getPluginManager().callEvent(preEvent); plugin.getServer().getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled()) { if (preEvent.isCancelled()) {
return; return;
} }
if (plugin.getServer().getPlayer(q.getUUID()) != null) { Player player = quester.getPlayer();
Player player = plugin.getServer().getPlayer(q.getUUID()); String[] messages = {
player.sendMessage(ChatColor.GOLD + Lang.get(player, "questObjectivesTitle").replace("<quest>", name)); ChatColor.GOLD + Lang.get(player, "questObjectivesTitle").replace("<quest>", name),
player.sendMessage(ChatColor.RED + Lang.get(player, "questFailed")); ChatColor.RED + Lang.get(player, "questFailed")
q.hardQuit(this); };
q.saveData(); quester.quitQuest(this, messages);
if (player.isOnline()) {
player.updateInventory(); player.updateInventory();
} else {
q.hardQuit(this);
q.saveData();
} }
q.updateJournal(); QuesterPostFailQuestEvent postEvent = new QuesterPostFailQuestEvent(quester, this);
QuesterPostFailQuestEvent postEvent = new QuesterPostFailQuestEvent(q, this);
plugin.getServer().getPluginManager().callEvent(postEvent); plugin.getServer().getPluginManager().callEvent(postEvent);
} }

View File

@ -571,6 +571,39 @@ public class Quester {
} }
} }
/**
* End a quest for this Quester
*
* @param quest The quest to start
* @param message Message to inform player, can be left null or empty
* @since 3.8.6
*/
public void quitQuest(Quest quest, String message) {
quitQuest(quest, new String[] {message});
}
/**
* End a quest for this Quester
*
* @param quest The quest to start
* @param messages Messages to inform player, can be left null or empty
* @since 3.8.6
*/
public void quitQuest(Quest quest, String[] messages) {
if (quest == null) {
return;
}
hardQuit(quest);
for (String message : messages) {
if (message != null && !message.equals("") && getPlayer().isOnline()) {
getPlayer().sendMessage(message);
}
}
saveData();
loadData();
updateJournal();
}
public LinkedList<String> getCurrentRequirements(Quest quest, boolean ignoreOverrides) { public LinkedList<String> getCurrentRequirements(Quest quest, boolean ignoreOverrides) {
if (quest == null) { if (quest == null) {
return new LinkedList<String>(); return new LinkedList<String>();
@ -3348,6 +3381,7 @@ public class Quester {
/** /**
* Show an inventory GUI with quest items to the specified player * Show an inventory GUI with quest items to the specified player
*
* @param npc The NPC from which the GUI is bound * @param npc The NPC from which the GUI is bound
* @param quests List of quests to use for displaying items * @param quests List of quests to use for displaying items
*/ */
@ -3394,9 +3428,9 @@ public class Quester {
} }
/** /**
* Force Quester to quit the specified quest<p> * Force Quester to quit the specified quest (canceling any timers), then update Quest Journal<p>
* *
* Also cancels any timers * Does not save changes to disk. Consider {@link #quitQuest(Quest, String)} or {@link #quitQuest(Quest, String[])}
* *
* @param quest The quest to quit * @param quest The quest to quit
*/ */
@ -3420,7 +3454,10 @@ public class Quester {
} }
/** /**
* Forcibly remove quest from Quester's list of completed quests * Forcibly remove quest from Quester's list of completed quests, then update Quest Journal<p>
*
* Does not save changes to disk. Consider calling {@link #saveData()} followed by {@link #loadData()}
*
* @param quest The quest to remove * @param quest The quest to remove
*/ */
public void hardRemove(Quest quest) { public void hardRemove(Quest quest) {
@ -3432,9 +3469,9 @@ public class Quester {
} }
/** /**
* Forcibly clear Quester's list of current quests<p> * Forcibly clear Quester's list of current quests and data, then update Quest Journal<p>
* *
* Also resets associated quest data * Does not save changes to disk. Consider calling {@link #saveData()} followed by {@link #loadData()}
*/ */
public void hardClear() { public void hardClear() {
try { try {
@ -3447,7 +3484,10 @@ public class Quester {
} }
/** /**
* Forcibly set Quester's current stage * Forcibly set Quester's current stage, then update Quest Journal
*
* Does not save changes to disk. Consider calling {@link #saveData()} followed by {@link #loadData()}
*
* @param key The quest to set stage of * @param key The quest to set stage of
* @param val The stage number to set * @param val The stage number to set
*/ */
@ -3460,7 +3500,10 @@ public class Quester {
} }
/** /**
* Forcibly set Quester's quest data * Forcibly set Quester's quest data, then update Quest Journal<p>
*
* Does not save changes to disk. Consider calling {@link #saveData()} followed by {@link #loadData()}
*
* @param key The quest to set stage of * @param key The quest to set stage of
* @param val The data to set * @param val The data to set
*/ */
@ -3508,6 +3551,7 @@ public class Quester {
/** /**
* Check whether the Quester's inventory contains the specified item * Check whether the Quester's inventory contains the specified item
*
* @param is The item with a specified amount to check * @param is The item with a specified amount to check
* @return true if the inventory contains at least the amount of the specified stack * @return true if the inventory contains at least the amount of the specified stack
*/ */

View File

@ -3277,11 +3277,31 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return ConfigUtil.checkList(list, clazz); return ConfigUtil.checkList(list, clazz);
} }
/**
* Get a Quest by ID
*
* @param id ID of the quest
* @return Exact match or null if not found
* @since 3.8.6
*/
public Quest getQuestById(String id) {
if (id == null) {
return null;
}
LinkedList<Quest> qs = quests;
for (Quest q : qs) {
if (q.getId().equals(id)) {
return q;
}
}
return null;
}
/** /**
* Get a Quest by name * Get a Quest by name
* *
* @param name Name of the quest * @param name Name of the quest
* @return Quest or null if not found * @return Closest match or null if not found
*/ */
public Quest getQuest(String name) { public Quest getQuest(String name) {
if (name == null) { if (name == null) {
@ -3310,7 +3330,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
* Get an Action by name * Get an Action by name
* *
* @param name Name of the action * @param name Name of the action
* @return Action or null if not found * @return Closest match or null if not found
*/ */
public Action getAction(String name) { public Action getAction(String name) {
if (name == null) { if (name == null) {

View File

@ -695,13 +695,9 @@ public class CmdExecutor implements CommandExecutor {
if (event.isCancelled()) { if (event.isCancelled()) {
return; return;
} }
quester.hardQuit(quest);
String msg = Lang.get("questQuit"); String msg = Lang.get("questQuit");
msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW); msg = msg.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.YELLOW);
player.sendMessage(ChatColor.YELLOW + msg); quester.quitQuest(quest, msg);
quester.saveData();
quester.loadData();
quester.updateJournal();
} else { } else {
player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questQuitDisabled")); player.sendMessage(ChatColor.YELLOW + Lang.get(player, "questQuitDisabled"));
} }
@ -1291,20 +1287,14 @@ public class CmdExecutor implements CommandExecutor {
cs.sendMessage(ChatColor.RED + Lang.get("questNotFound")); cs.sendMessage(ChatColor.RED + Lang.get("questNotFound"));
return; return;
} }
quester.hardQuit(quest);
String msg1 = Lang.get("questForceQuit"); String msg1 = Lang.get("questForceQuit");
msg1 = msg1.replace("<player>", ChatColor.GREEN + target.getName() + ChatColor.GOLD); msg1 = msg1.replace("<player>", ChatColor.GREEN + target.getName() + ChatColor.GOLD);
msg1 = msg1.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD); msg1 = msg1.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD);
cs.sendMessage(ChatColor.GOLD + msg1); cs.sendMessage(ChatColor.GOLD + msg1);
if (target.isOnline()) { String msg2 = Lang.get((Player)target, "questForcedQuit");
Player p = (Player)target;
String msg2 = Lang.get(p, "questForcedQuit");
msg2 = msg2.replace("<player>", ChatColor.GREEN + cs.getName() + ChatColor.GOLD); msg2 = msg2.replace("<player>", ChatColor.GREEN + cs.getName() + ChatColor.GOLD);
msg2 = msg2.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD); msg2 = msg2.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.GOLD);
p.sendMessage(ChatColor.GREEN + msg2); quester.quitQuest(quest, msg2);
}
quester.saveData();
quester.updateJournal();
} }
} else { } else {
cs.sendMessage(ChatColor.RED + Lang.get("noPermission")); cs.sendMessage(ChatColor.RED + Lang.get("noPermission"));

View File

@ -6,12 +6,12 @@
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>3.8.5</version> <version>3.8.6</version>
<name>quests</name> <name>quests</name>
<url>https://github.com/PikaMug/Quests/</url> <url>https://github.com/PikaMug/Quests/</url>
<properties> <properties>
<revision>3.8.5</revision> <revision>3.8.6</revision>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.target>1.8</maven.compiler.target>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>3.8.5</version> <version>3.8.6</version>
</parent> </parent>
<properties> <properties>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>3.8.5</version> <version>3.8.6</version>
</parent> </parent>
<properties> <properties>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>me.blackvein.quests</groupId> <groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId> <artifactId>quests-parent</artifactId>
<version>3.8.5</version> <version>3.8.6</version>
</parent> </parent>
<properties> <properties>