Supply external conversation hooks, part 10. Fixes #570

This commit is contained in:
PikaMug 2019-09-05 15:31:46 -04:00
parent b584a4b0f8
commit f8fa9dc57c
4 changed files with 81 additions and 11 deletions

View File

@ -543,7 +543,7 @@ public class Quester {
* *
* @param quest The quest to get objectives of * @param quest The quest to get objectives of
* @param ignoreOverrides Whether to ignore objective-overrides * @param ignoreOverrides Whether to ignore objective-overrides
* @return * @return List of detailed objectives
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public LinkedList<String> getObjectives(Quest quest, boolean ignoreOverrides) { public LinkedList<String> getObjectives(Quest quest, boolean ignoreOverrides) {
@ -635,10 +635,10 @@ public class Quester {
int amt = is.getAmount(); int amt = is.getAmount();
if (crafted < amt) { if (crafted < amt) {
String obj = Lang.get(getPlayer(), "craft") + " " + ItemUtil.getName(is); String obj = Lang.get(getPlayer(), "craft") + " " + ItemUtil.getName(is);
unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + crafted + "/" + amt); unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + crafted + "/" + amt);
} else { } else {
String obj = Lang.get(getPlayer(), "craft") + " " + ItemUtil.getName(is); String obj = Lang.get(getPlayer(), "craft") + " " + ItemUtil.getName(is);
finishedObjectives.add(ChatColor.GRAY + obj + ": " + crafted + "/" + amt); finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + crafted + "/" + amt);
} }
} }
for (ItemStack is : getCurrentStage(quest).itemsToSmelt) { for (ItemStack is : getCurrentStage(quest).itemsToSmelt) {
@ -649,10 +649,10 @@ public class Quester {
int amt = is.getAmount(); int amt = is.getAmount();
if (smelted < amt) { if (smelted < amt) {
String obj = Lang.get(getPlayer(), "smelt") + " " + ItemUtil.getName(is); String obj = Lang.get(getPlayer(), "smelt") + " " + ItemUtil.getName(is);
unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + smelted + "/" + amt); unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + smelted + "/" + amt);
} else { } else {
String obj = Lang.get(getPlayer(), "smelt") + " " + ItemUtil.getName(is); String obj = Lang.get(getPlayer(), "smelt") + " " + ItemUtil.getName(is);
finishedObjectives.add(ChatColor.GRAY + obj + ": " + smelted + "/" + amt); finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + smelted + "/" + amt);
} }
} }
Map<Enchantment, Material> set; Map<Enchantment, Material> set;
@ -706,10 +706,10 @@ public class Quester {
int amt = is.getAmount(); int amt = is.getAmount();
if (brewed < amt) { if (brewed < amt) {
String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is); String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is);
unfinishedObjectives.add(ChatColor.GREEN + obj + ": " + brewed + "/" + amt); unfinishedObjectives.add(ChatColor.GREEN + obj + ChatColor.GREEN + ": " + brewed + "/" + amt);
} else { } else {
String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is); String obj = Lang.get(getPlayer(), "brew") + " " + ItemUtil.getName(is);
finishedObjectives.add(ChatColor.GRAY + obj + ": " + brewed + "/" + amt); finishedObjectives.add(ChatColor.GRAY + obj + ChatColor.GRAY + ": " + brewed + "/" + amt);
} }
} }
if (getCurrentStage(quest).fishToCatch != null) { if (getCurrentStage(quest).fishToCatch != null) {
@ -2501,12 +2501,12 @@ public class Quester {
data.set("amountsCompleted", list2); data.set("amountsCompleted", list2);
} }
// #getPlayer is faster // #getPlayer is faster
OfflinePlayer represented_player = getPlayer(); OfflinePlayer representedPlayer = getPlayer();
if (represented_player == null) { if (representedPlayer == null) {
represented_player = getOfflinePlayer(); representedPlayer = getOfflinePlayer();
} }
data.set("hasJournal", hasJournal); data.set("hasJournal", hasJournal);
data.set("lastKnownName", represented_player.getName()); data.set("lastKnownName", representedPlayer.getName());
return data; return data;
} }

View File

@ -0,0 +1,29 @@
package me.blackvein.quests.events.command;
import me.blackvein.quests.Quester;
import me.blackvein.quests.events.QuestsEvent;
/**
* Represents a Quests command-related event
*/
public abstract class QuestsCommandEvent extends QuestsEvent {
protected Quester quester;
public QuestsCommandEvent(final Quester quester) {
this.quester = quester;
}
public QuestsCommandEvent(final Quester quester, boolean async) {
super(async);
this.quester = quester;
}
/**
* Returns the quester involved in this event
*
* @return Quester which is involved in this event
*/
public final Quester getQuester() {
return quester;
}
}

View File

@ -0,0 +1,34 @@
package me.blackvein.quests.events.command;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quester;
public class QuestsCommandPreQuestsJournalEvent extends QuestsCommandEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
public QuestsCommandPreQuestsJournalEvent(Quester quester) {
super(quester);
}
@Override
public boolean isCancelled() {
return cancel;
}
@Override
public void setCancelled(boolean cancel) {
this.cancel = cancel;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@ -30,6 +30,7 @@ import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests; import me.blackvein.quests.Quests;
import me.blackvein.quests.Requirements; import me.blackvein.quests.Requirements;
import me.blackvein.quests.Stage; import me.blackvein.quests.Stage;
import me.blackvein.quests.events.command.QuestsCommandPreQuestsJournalEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPreOpenMainPromptEvent; import me.blackvein.quests.events.editor.quests.QuestsEditorPreOpenMainPromptEvent;
import me.blackvein.quests.events.quest.QuestQuitEvent; import me.blackvein.quests.events.quest.QuestQuitEvent;
import me.blackvein.quests.exceptions.InvalidStageException; import me.blackvein.quests.exceptions.InvalidStageException;
@ -582,6 +583,12 @@ public class CmdExecutor implements CommandExecutor {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void questsJournal(final Player player) { private void questsJournal(final Player player) {
Quester quester = plugin.getQuester(player.getUniqueId()); Quester quester = plugin.getQuester(player.getUniqueId());
QuestsCommandPreQuestsJournalEvent preEvent = new QuestsCommandPreQuestsJournalEvent(quester);
plugin.getServer().getPluginManager().callEvent(preEvent);
if (preEvent.isCancelled()) {
return;
}
Inventory inv = player.getInventory(); Inventory inv = player.getInventory();
if (quester.hasJournal) { if (quester.hasJournal) {
ItemStack[] arr = inv.getContents(); ItemStack[] arr = inv.getContents();