mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-26 04:36:06 +01:00
Move conversation listener to separate class
This commit is contained in:
parent
43e2044b98
commit
71511a4f8a
@ -29,6 +29,7 @@ import me.blackvein.quests.exceptions.StageFormatException;
|
|||||||
import me.blackvein.quests.interfaces.ReloadCallback;
|
import me.blackvein.quests.interfaces.ReloadCallback;
|
||||||
import me.blackvein.quests.listeners.BlockListener;
|
import me.blackvein.quests.listeners.BlockListener;
|
||||||
import me.blackvein.quests.listeners.CmdExecutor;
|
import me.blackvein.quests.listeners.CmdExecutor;
|
||||||
|
import me.blackvein.quests.listeners.ConvoListener;
|
||||||
import me.blackvein.quests.listeners.ItemListener;
|
import me.blackvein.quests.listeners.ItemListener;
|
||||||
import me.blackvein.quests.listeners.NpcListener;
|
import me.blackvein.quests.listeners.NpcListener;
|
||||||
import me.blackvein.quests.listeners.PartiesListener;
|
import me.blackvein.quests.listeners.PartiesListener;
|
||||||
@ -66,8 +67,6 @@ import org.bukkit.configuration.InvalidConfigurationException;
|
|||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.conversations.Conversable;
|
import org.bukkit.conversations.Conversable;
|
||||||
import org.bukkit.conversations.ConversationAbandonedEvent;
|
|
||||||
import org.bukkit.conversations.ConversationAbandonedListener;
|
|
||||||
import org.bukkit.conversations.ConversationContext;
|
import org.bukkit.conversations.ConversationContext;
|
||||||
import org.bukkit.conversations.ConversationFactory;
|
import org.bukkit.conversations.ConversationFactory;
|
||||||
import org.bukkit.conversations.Prompt;
|
import org.bukkit.conversations.Prompt;
|
||||||
@ -116,7 +115,7 @@ import java.util.jar.JarEntry;
|
|||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class Quests extends JavaPlugin implements ConversationAbandonedListener {
|
public class Quests extends JavaPlugin {
|
||||||
|
|
||||||
private boolean loading = true;
|
private boolean loading = true;
|
||||||
private String bukkitVersion = "0";
|
private String bukkitVersion = "0";
|
||||||
@ -136,6 +135,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
private QuestFactory questFactory;
|
private QuestFactory questFactory;
|
||||||
private ActionFactory actionFactory;
|
private ActionFactory actionFactory;
|
||||||
private ConditionFactory conditionFactory;
|
private ConditionFactory conditionFactory;
|
||||||
|
private ConvoListener convoListener;
|
||||||
private BlockListener blockListener;
|
private BlockListener blockListener;
|
||||||
private ItemListener itemListener;
|
private ItemListener itemListener;
|
||||||
private NpcListener npcListener;
|
private NpcListener npcListener;
|
||||||
@ -161,6 +161,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
} catch (final Exception ignored) {
|
} catch (final Exception ignored) {
|
||||||
getLogger().info("LocaleLib not present. Is this a debug environment?");
|
getLogger().info("LocaleLib not present. Is this a debug environment?");
|
||||||
}
|
}
|
||||||
|
convoListener = new ConvoListener();
|
||||||
blockListener = new BlockListener(this);
|
blockListener = new BlockListener(this);
|
||||||
itemListener = new ItemListener(this);
|
itemListener = new ItemListener(this);
|
||||||
npcListener = new NpcListener(this);
|
npcListener = new NpcListener(this);
|
||||||
@ -220,10 +221,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
.withPrefix(context -> ChatColor.GRAY.toString())
|
.withPrefix(context -> ChatColor.GRAY.toString())
|
||||||
.withFirstPrompt(new QuestAcceptPrompt()).withTimeout(settings.getAcceptTimeout())
|
.withFirstPrompt(new QuestAcceptPrompt()).withTimeout(settings.getAcceptTimeout())
|
||||||
.thatExcludesNonPlayersWithMessage("Console may not perform this conversation!")
|
.thatExcludesNonPlayersWithMessage("Console may not perform this conversation!")
|
||||||
.addConversationAbandonedListener(this);
|
.addConversationAbandonedListener(convoListener);
|
||||||
this.npcConversationFactory = new ConversationFactory(this).withModality(false)
|
this.npcConversationFactory = new ConversationFactory(this).withModality(false)
|
||||||
.withFirstPrompt(new NpcOfferQuestPrompt()).withTimeout(settings.getAcceptTimeout())
|
.withFirstPrompt(new NpcOfferQuestPrompt()).withTimeout(settings.getAcceptTimeout())
|
||||||
.withLocalEcho(false).addConversationAbandonedListener(this);
|
.withLocalEcho(false).addConversationAbandonedListener(convoListener);
|
||||||
|
|
||||||
// 10 - Register listeners
|
// 10 - Register listeners
|
||||||
getServer().getPluginManager().registerEvents(getBlockListener(), this);
|
getServer().getPluginManager().registerEvents(getBlockListener(), this);
|
||||||
@ -533,6 +534,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
return conditionFactory;
|
return conditionFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ConvoListener getConvoListener() {
|
||||||
|
return convoListener;
|
||||||
|
}
|
||||||
|
|
||||||
public BlockListener getBlockListener() {
|
public BlockListener getBlockListener() {
|
||||||
return blockListener;
|
return blockListener;
|
||||||
}
|
}
|
||||||
@ -577,18 +582,6 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
|||||||
return storage;
|
return storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void conversationAbandoned(final ConversationAbandonedEvent abandonedEvent) {
|
|
||||||
if (!abandonedEvent.gracefulExit()) {
|
|
||||||
try {
|
|
||||||
abandonedEvent.getContext().getForWhom().sendRawMessage(ChatColor.YELLOW
|
|
||||||
+ Lang.get((Player) abandonedEvent.getContext().getForWhom(), "questTimeout"));
|
|
||||||
} catch (final Exception e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class QuestAcceptPrompt extends MiscStringPrompt {
|
public class QuestAcceptPrompt extends MiscStringPrompt {
|
||||||
|
|
||||||
private ConversationContext cc;
|
private ConversationContext cc;
|
||||||
|
@ -0,0 +1,23 @@
|
|||||||
|
package me.blackvein.quests.listeners;
|
||||||
|
|
||||||
|
import me.blackvein.quests.util.Lang;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedListener;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class ConvoListener implements ConversationAbandonedListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void conversationAbandoned(@NotNull final ConversationAbandonedEvent abandonedEvent) {
|
||||||
|
if (!abandonedEvent.gracefulExit()) {
|
||||||
|
try {
|
||||||
|
abandonedEvent.getContext().getForWhom().sendRawMessage(ChatColor.YELLOW
|
||||||
|
+ Lang.get((Player) abandonedEvent.getContext().getForWhom(), "questTimeout"));
|
||||||
|
} catch (final Exception e) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user