mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-25 20:25:45 +01:00
Support mcMMO Overhaul party using Unite
This commit is contained in:
parent
9da6fe3b4d
commit
20cecf8462
@ -125,7 +125,7 @@
|
||||
<dependency>
|
||||
<groupId>com.github.PikaMug</groupId>
|
||||
<artifactId>Unite</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -38,8 +38,11 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import ro.nicuch.citizensbooks.CitizensBooksAPI;
|
||||
import ro.nicuch.citizensbooks.CitizensBooksPlugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
|
||||
public class Dependencies {
|
||||
|
||||
@ -47,6 +50,7 @@ public class Dependencies {
|
||||
private static Economy economy = null;
|
||||
private static Permission permission = null;
|
||||
private static PartyProvider partyProvider = null;
|
||||
private static final Set<PartyProvider> partyProviders = new HashSet<>();
|
||||
private static WorldGuardAPI worldGuardApi = null;
|
||||
private static mcMMO mcmmo = null;
|
||||
private static Heroes heroes = null;
|
||||
@ -88,6 +92,15 @@ public class Dependencies {
|
||||
return partyProvider;
|
||||
}
|
||||
|
||||
public Set<PartyProvider> getPartyProviders() {
|
||||
if (partyProvider == null && isPluginAvailable("Unite")) {
|
||||
if (!setupParty()) {
|
||||
plugin.getLogger().warning("Party providers not found.");
|
||||
}
|
||||
}
|
||||
return partyProviders;
|
||||
}
|
||||
|
||||
public WorldGuardAPI getWorldGuardApi() {
|
||||
if (worldGuardApi == null && isPluginAvailable("WorldGuard")) {
|
||||
worldGuardApi = new WorldGuardAPI(plugin.getServer().getPluginManager().getPlugin("WorldGuard"));
|
||||
@ -260,6 +273,12 @@ public class Dependencies {
|
||||
.getRegistration(PartyProvider.class);
|
||||
if (rsp != null) {
|
||||
partyProvider = rsp.getProvider();
|
||||
for (final RegisteredServiceProvider<PartyProvider> rsp2 : plugin.getServer().getServicesManager()
|
||||
.getRegistrations(PartyProvider.class)) {
|
||||
if (rsp2 != null) {
|
||||
partyProviders.add(rsp2.getProvider());
|
||||
}
|
||||
}
|
||||
}
|
||||
return (partyProvider != null);
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ public class Options {
|
||||
private boolean allowCommands = true;
|
||||
private boolean allowQuitting = true;
|
||||
private boolean ignoreSilkTouch = true;
|
||||
private boolean useDungeonsXLPlugin = false;
|
||||
private String externalPartyPlugin = null;
|
||||
private boolean usePartiesPlugin = true;
|
||||
private boolean handleOfflinePlayers = false;
|
||||
private double shareDistance = 0.0D;
|
||||
@ -47,12 +47,12 @@ public class Options {
|
||||
this.ignoreSilkTouch = ignoreSilkTouch;
|
||||
}
|
||||
|
||||
public boolean canUseDungeonsXLPlugin() {
|
||||
return useDungeonsXLPlugin;
|
||||
public String getExternalPartyPlugin() {
|
||||
return externalPartyPlugin;
|
||||
}
|
||||
|
||||
public void setUseDungeonsXLPlugin(final boolean useDungeonsXLPlugin) {
|
||||
this.useDungeonsXLPlugin = useDungeonsXLPlugin;
|
||||
public void setExternalPartyPlugin(final String externalPartyPlugin) {
|
||||
this.externalPartyPlugin = externalPartyPlugin;
|
||||
}
|
||||
|
||||
public boolean canUsePartiesPlugin() {
|
||||
|
@ -285,7 +285,7 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
context.setSessionData(CK.OPT_ALLOW_COMMANDS, opt.canAllowCommands());
|
||||
context.setSessionData(CK.OPT_ALLOW_QUITTING, opt.canAllowQuitting());
|
||||
context.setSessionData(CK.OPT_IGNORE_SILK_TOUCH, opt.canIgnoreSilkTouch());
|
||||
context.setSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN, opt.canUseDungeonsXLPlugin());
|
||||
context.setSessionData(CK.OPT_EXTERNAL_PARTY_PLUGIN, opt.getExternalPartyPlugin());
|
||||
context.setSessionData(CK.OPT_USE_PARTIES_PLUGIN, opt.canUsePartiesPlugin());
|
||||
context.setSessionData(CK.OPT_SHARE_PROGRESS_LEVEL, opt.getShareProgressLevel());
|
||||
context.setSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY, opt.canShareSameQuestOnly());
|
||||
@ -907,8 +907,8 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
? context.getSessionData(CK.OPT_ALLOW_QUITTING) : null);
|
||||
opts.set("ignore-silk-touch", context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) != null
|
||||
? context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) : null);
|
||||
opts.set("use-dungeonsxl-plugin", context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) != null
|
||||
? context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) : null);
|
||||
opts.set("external-party-plugin", context.getSessionData(CK.OPT_EXTERNAL_PARTY_PLUGIN) != null
|
||||
? context.getSessionData(CK.OPT_EXTERNAL_PARTY_PLUGIN) : null);
|
||||
opts.set("use-parties-plugin", context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) != null
|
||||
? context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) : null);
|
||||
opts.set("share-progress-level", context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) != null
|
||||
|
@ -4030,7 +4030,7 @@ public class Quester implements Comparable<Quester> {
|
||||
if (plugin.getDependencies().getPartyProvider() != null) {
|
||||
final PartyProvider partyProvider = plugin.getDependencies().getPartyProvider();
|
||||
if (partyProvider != null) {
|
||||
if (quest.getOptions().canUsePartiesPlugin() || quest.getOptions().canUseDungeonsXLPlugin()) {
|
||||
if (quest.getOptions().canUsePartiesPlugin() || quest.getOptions().getExternalPartyPlugin() != null) {
|
||||
if (getUUID() != null && partyProvider.getPartyId(getUUID()) != null) {
|
||||
final String partyId = partyProvider.getPartyId(getUUID());
|
||||
final double distanceSquared = quest.getOptions().getShareDistance()
|
||||
|
@ -2296,8 +2296,8 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
if (config.contains("quests." + questKey + ".options.ignore-silk-touch")) {
|
||||
opts.setIgnoreSilkTouch(config.getBoolean("quests." + questKey + ".options.ignore-silk-touch"));
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".options.use-dungeonsxl-plugin")) {
|
||||
opts.setUseDungeonsXLPlugin(config.getBoolean("quests." + questKey + ".options.use-dungeonsxl-plugin"));
|
||||
if (config.contains("quests." + questKey + ".options.external-party-plugin")) {
|
||||
opts.setExternalPartyPlugin(config.getString("quests." + questKey + ".external-party-plugin"));
|
||||
}
|
||||
if (config.contains("quests." + questKey + ".options.use-parties-plugin")) {
|
||||
opts.setUsePartiesPlugin(config.getBoolean("quests." + questKey + ".options.use-parties-plugin"));
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
package me.blackvein.quests.convo.quests.options;
|
||||
|
||||
import me.pikamug.unite.api.objects.PartyProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.conversations.ConversationContext;
|
||||
import org.bukkit.conversations.Prompt;
|
||||
@ -26,6 +27,7 @@ import me.blackvein.quests.util.CK;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Objects;
|
||||
|
||||
public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
@ -116,6 +118,78 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
}
|
||||
|
||||
public class OptionsPluginPrompt extends QuestsEditorStringPrompt {
|
||||
public OptionsPluginPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("optPluginListTitle");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getQueryText(final ConversationContext context) {
|
||||
return Lang.get("optExternalPartyPluginPrompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
|
||||
if (context.getPlugin() != null) {
|
||||
final QuestsEditorPostOpenStringPromptEvent event
|
||||
= new QuestsEditorPostOpenStringPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n"
|
||||
+ ChatColor.DARK_PURPLE);
|
||||
boolean none = true;
|
||||
for (final PartyProvider q : plugin.getDependencies().getPartyProviders()) {
|
||||
text.append(q.getPluginName()).append(", ");
|
||||
none = false;
|
||||
}
|
||||
if (none) {
|
||||
text.append("(").append(Lang.get("none")).append(")\n");
|
||||
} else {
|
||||
text = new StringBuilder(text.substring(0, (text.length() - 2)));
|
||||
text.append("\n");
|
||||
}
|
||||
text.append(ChatColor.YELLOW).append(getQueryText(context));
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
if (input.equalsIgnoreCase("Quests")) {
|
||||
context.getForWhom().sendRawMessage(" " + ChatColor.AQUA + ChatColor.UNDERLINE
|
||||
+ "https://www.youtube.com/watch?v=gvdf5n-zI14");
|
||||
return new OptionsPluginPrompt(context);
|
||||
}
|
||||
String properCase = null;
|
||||
for (final PartyProvider partyProvider : plugin.getDependencies().getPartyProviders()) {
|
||||
if (input.equalsIgnoreCase(partyProvider.getPluginName())) {
|
||||
properCase = partyProvider.getPluginName();
|
||||
}
|
||||
}
|
||||
if (properCase == null) {
|
||||
String text = Lang.get("optNotAPluginName");
|
||||
text = text.replace("<plugin>", ChatColor.LIGHT_PURPLE + input + ChatColor.RED);
|
||||
context.getForWhom().sendRawMessage(text);
|
||||
return new OptionsPluginPrompt(context);
|
||||
}
|
||||
context.setSessionData(CK.OPT_EXTERNAL_PARTY_PLUGIN, properCase);
|
||||
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
|
||||
context.setSessionData(tempKey, null);
|
||||
return tempPrompt;
|
||||
}
|
||||
return tempPrompt;
|
||||
}
|
||||
}
|
||||
|
||||
public class OptionsTrueFalsePrompt extends QuestsEditorStringPrompt {
|
||||
public OptionsTrueFalsePrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
@ -512,7 +586,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
public String getSelectionText(final ConversationContext context, final int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
return ChatColor.YELLOW + Lang.get("optUseDungeonsXLPlugin");
|
||||
return ChatColor.YELLOW + Lang.get("optExternalPartyPlugin");
|
||||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("optUsePartiesPlugin");
|
||||
case 3:
|
||||
@ -534,16 +608,13 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
public String getAdditionalText(final ConversationContext context, final int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
final Boolean dungeonsOpt = (Boolean) context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN);
|
||||
if (dungeonsOpt == null) {
|
||||
final boolean defaultOpt = new Options().canUseDungeonsXLPlugin();
|
||||
return ChatColor.GRAY + "(" + (defaultOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
|
||||
final String externalOpt = (String) context.getSessionData(CK.OPT_EXTERNAL_PARTY_PLUGIN);
|
||||
if (plugin.getDependencies().getPartyProvider() == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
|
||||
} else if (externalOpt != null){
|
||||
return ChatColor.GRAY + "(" + ChatColor.AQUA + externalOpt + ChatColor.GRAY + ")";
|
||||
} else {
|
||||
return ChatColor.GRAY + "(" + (dungeonsOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(dungeonsOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(dungeonsOpt))) + ChatColor.GRAY + ")";
|
||||
return "";
|
||||
}
|
||||
case 2:
|
||||
final Boolean partiesOpt = (Boolean) context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN);
|
||||
@ -625,9 +696,9 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
public Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
|
||||
switch (input.intValue()) {
|
||||
case 1:
|
||||
tempKey = CK.OPT_USE_DUNGEONSXL_PLUGIN;
|
||||
tempKey = CK.OPT_EXTERNAL_PARTY_PLUGIN;
|
||||
tempPrompt = new OptionsMultiplayerPrompt(context);
|
||||
return new OptionsTrueFalsePrompt(context);
|
||||
return new OptionsPluginPrompt(context);
|
||||
case 2:
|
||||
tempKey = CK.OPT_USE_PARTIES_PLUGIN;
|
||||
tempPrompt = new OptionsMultiplayerPrompt(context);
|
||||
|
@ -143,7 +143,7 @@ public class CK {
|
||||
public static final String OPT_ALLOW_COMMANDS = "allowCommandsOpt";
|
||||
public static final String OPT_ALLOW_QUITTING = "allowQuittingOpt";
|
||||
public static final String OPT_IGNORE_SILK_TOUCH = "ignoreSilkTouchOpt";
|
||||
public static final String OPT_USE_DUNGEONSXL_PLUGIN = "useDungeonsXLPluginOpt";
|
||||
public static final String OPT_EXTERNAL_PARTY_PLUGIN = "externalPartyPluginOpt";
|
||||
public static final String OPT_USE_PARTIES_PLUGIN = "usePartiesPluginOpt";
|
||||
public static final String OPT_SHARE_PROGRESS_LEVEL = "shareProgressLevelOpt";
|
||||
public static final String OPT_SHARE_SAME_QUEST_ONLY = "shareSameQuestOnlyOpt";
|
||||
|
@ -488,7 +488,10 @@ optAllowCommands: "Allow commands during quest"
|
||||
optAllowQuitting: "Allow quitting during quest"
|
||||
optIgnoreSilkTouch: "Ignore blocks broken with Silk Touch"
|
||||
optCommandsDenied: "You cannot use commands during <quest>."
|
||||
optUseDungeonsXLPlugin: "Use DungeonsXL plugin"
|
||||
optPluginListTitle: "- Available Plugins -"
|
||||
optExternalPartyPlugin: "Set provider via Unite"
|
||||
optExternalPartyPluginPrompt: "Enter a plugin name, <clear>, <cancel>"
|
||||
optNotAPluginName: "<plugin> is not a plugin name!"
|
||||
optUsePartiesPlugin: "Use Parties plugin"
|
||||
optShareProgressLevel: "Level of progress sharing"
|
||||
optShareOnlySameQuest: "Share with the same quest only"
|
||||
|
Loading…
Reference in New Issue
Block a user