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>
<groupId>me.blackvein.quests</groupId>
<artifactId>quests-parent</artifactId>
<version>3.8.5</version>
<version>3.8.6</version>
</parent>
<artifactId>quests-dist</artifactId>
<packaging>pom</packaging>

View File

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

View File

@ -801,28 +801,25 @@ public class Quest {
/**
* 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")
public void failQuest(Quester q) {
QuesterPreFailQuestEvent preEvent = new QuesterPreFailQuestEvent(q, this);
public void failQuest(Quester quester) {
QuesterPreFailQuestEvent preEvent = new QuesterPreFailQuestEvent(quester, this);
plugin.getServer().getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled()) {
return;
}
if (plugin.getServer().getPlayer(q.getUUID()) != null) {
Player player = plugin.getServer().getPlayer(q.getUUID());
player.sendMessage(ChatColor.GOLD + Lang.get(player, "questObjectivesTitle").replace("<quest>", name));
player.sendMessage(ChatColor.RED + Lang.get(player, "questFailed"));
q.hardQuit(this);
q.saveData();
Player player = quester.getPlayer();
String[] messages = {
ChatColor.GOLD + Lang.get(player, "questObjectivesTitle").replace("<quest>", name),
ChatColor.RED + Lang.get(player, "questFailed")
};
quester.quitQuest(this, messages);
if (player.isOnline()) {
player.updateInventory();
} else {
q.hardQuit(this);
q.saveData();
}
q.updateJournal();
QuesterPostFailQuestEvent postEvent = new QuesterPostFailQuestEvent(q, this);
QuesterPostFailQuestEvent postEvent = new QuesterPostFailQuestEvent(quester, this);
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) {
if (quest == null) {
return new LinkedList<String>();
@ -3348,6 +3381,7 @@ 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
*/
@ -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
*/
@ -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
*/
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() {
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 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 val The data to set
*/
@ -3508,6 +3551,7 @@ 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
*/

View File

@ -3277,11 +3277,31 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
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
*
* @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) {
if (name == null) {
@ -3310,7 +3330,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
* Get an Action by name
*
* @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) {
if (name == null) {

View File

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

View File

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

View File

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

View File

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

View File

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