Add custom module submenu

This commit is contained in:
PikaMug 2021-10-09 02:38:57 -04:00
parent a8d59e6c12
commit 2b0c808503
9 changed files with 312 additions and 66 deletions

View File

@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.AbstractMap;
import java.util.HashMap;
import java.util.LinkedList;
@ -39,6 +40,11 @@ public abstract class CustomObjective implements Listener {
private boolean showCount = true;
private int count = 1;
public String getModuleName() {
return new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getName()
.replace(".jar", "");
}
public String getName() {
return name;
}

View File

@ -14,6 +14,7 @@ package me.blackvein.quests;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@ -28,6 +29,11 @@ public abstract class CustomRequirement {
public abstract boolean testRequirement(Player p, Map<String, Object> m);
public String getModuleName() {
return new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getName()
.replace(".jar", "");
}
public String getName() {
return name;
}

View File

@ -14,6 +14,7 @@ package me.blackvein.quests;
import org.bukkit.entity.Player;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
@ -28,6 +29,11 @@ public abstract class CustomReward {
public abstract void giveReward(Player p, Map<String, Object> m);
public String getModuleName() {
return new File(getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getName()
.replace(".jar", "");
}
public String getName() {
return name;
}

View File

@ -109,6 +109,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@ -156,7 +157,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
try {
Class.forName("me.blackvein.quests.libs.localelib.LocaleManager");
localeManager = new LocaleManager();
} catch (Exception ignored) {
} catch (final Exception ignored) {
getLogger().info("LocaleLib not present. Is this a debug environment?");
}
blockListener = new BlockListener(this);
@ -929,8 +930,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
public void loadModule(final File jar) {
try {
@SuppressWarnings("resource")
final
JarFile jarFile = new JarFile(jar);
final JarFile jarFile = new JarFile(jar);
final Enumeration<JarEntry> entry = jarFile.entries();
final URL[] urls = { new URL("jar:file:" + jar.getPath() + "!/") };
final ClassLoader cl = URLClassLoader.newInstance(urls, getClassLoader());
@ -951,31 +951,31 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (c != null) {
if (CustomRequirement.class.isAssignableFrom(c)) {
final Class<? extends CustomRequirement> requirementClass = c.asSubclass(CustomRequirement.class);
final Constructor<? extends CustomRequirement> cstrctr = requirementClass.getConstructor();
final CustomRequirement requirement = cstrctr.newInstance();
final Optional<CustomRequirement>oo=getCustomRequirement(requirement.getClass().getName());
final Constructor<? extends CustomRequirement> constructor = requirementClass.getConstructor();
final CustomRequirement requirement = constructor.newInstance();
final Optional<CustomRequirement>oo = getCustomRequirement(requirement.getClass().getName());
oo.ifPresent(customRequirements::remove);
customRequirements.add(requirement);
final String name = requirement.getName() == null ? "[" + jar.getName() + "]" : requirement.getName();
final String author = requirement.getAuthor() == null ? "[Unknown]" : requirement.getAuthor();
count++;
getLogger().info("Loaded Module: " + name + " by " + author);
getLogger().info("Loaded \"" + name + "\" by " + author);
} else if (CustomReward.class.isAssignableFrom(c)) {
final Class<? extends CustomReward> rewardClass = c.asSubclass(CustomReward.class);
final Constructor<? extends CustomReward> cstrctr = rewardClass.getConstructor();
final CustomReward reward = cstrctr.newInstance();
final Optional<CustomReward>oo=getCustomReward(reward.getClass().getName());
final Constructor<? extends CustomReward> constructor = rewardClass.getConstructor();
final CustomReward reward = constructor.newInstance();
final Optional<CustomReward>oo = getCustomReward(reward.getClass().getName());
oo.ifPresent(customRewards::remove);
customRewards.add(reward);
final String name = reward.getName() == null ? "[" + jar.getName() + "]" : reward.getName();
final String author = reward.getAuthor() == null ? "[Unknown]" : reward.getAuthor();
count++;
getLogger().info("Loaded Module: " + name + " by " + author);
getLogger().info("Loaded \"" + name + "\" by " + author);
} else if (CustomObjective.class.isAssignableFrom(c)) {
final Class<? extends CustomObjective> objectiveClass = c.asSubclass(CustomObjective.class);
final Constructor<? extends CustomObjective> cstrctr = objectiveClass.getConstructor();
final CustomObjective objective = cstrctr.newInstance();
final Optional<CustomObjective>oo=getCustomObjective(objective.getClass().getName());
final Constructor<? extends CustomObjective> constructor = objectiveClass.getConstructor();
final CustomObjective objective = constructor.newInstance();
final Optional<CustomObjective>oo = getCustomObjective(objective.getClass().getName());
if (oo.isPresent()) {
HandlerList.unregisterAll(oo.get());
customObjectives.remove(oo.get());
@ -984,7 +984,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
final String name = objective.getName() == null ? "[" + jar.getName() + "]" : objective.getName();
final String author = objective.getAuthor() == null ? "[Unknown]" : objective.getAuthor();
count++;
getLogger().info("Loaded Module: " + name + " by " + author);
getLogger().info("Loaded \"" + name + "\" by " + author);
try {
getServer().getPluginManager().registerEvents(objective, this);
getLogger().info("Registered events for custom objective \"" + name + "\"");
@ -998,7 +998,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
}
if (count == 0) {
getLogger().severe("Unable to load module from file: " + jar.getName()
+ ", jar file is not a valid module!");
+ ", file is not a valid module!");
}
} catch (final Exception e) {
getLogger().severe("Unable to load module from file: " + jar.getName());

View File

@ -33,6 +33,7 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
@ -40,6 +41,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeSet;
public class RequirementsPrompt extends QuestsEditorNumericPrompt {
@ -387,7 +389,7 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
return new RequirementsPrompt(context);
}
case 9:
return new CustomRequirementsPrompt(context);
return new CustomRequirementModulePrompt(context);
case 10:
if (hasRequirement) {
return new OverridePrompt.Builder()
@ -1389,10 +1391,88 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
}
}
public class CustomRequirementModulePrompt extends QuestsEditorStringPrompt {
public CustomRequirementModulePrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorModules");
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("stageEditorModulePrompt");
}
@Override
public @NotNull String getPromptText(@NotNull final ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRequirements().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final CustomRequirement cr : new TreeSet<>(plugin.getCustomRequirements())) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getModuleName()).append("\n");
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(@NotNull final ConversationContext context, @Nullable final String input) {
if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))
&& !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
String found = null;
// Check if we have a module with the specified name
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getModuleName().equalsIgnoreCase(input)) {
found = cr.getModuleName();
break;
}
}
if (found == null) {
// No? Check again, but with locale sensitivity
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getModuleName().toLowerCase().contains(input.toLowerCase())) {
found = cr.getModuleName();
break;
}
}
}
if (found != null) {
return new CustomRequirementsPrompt(found, context);
}
} else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new RequirementsPrompt(context);
} else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(CK.REQ_CUSTOM, null);
context.setSessionData(CK.REQ_CUSTOM_DATA, null);
context.setSessionData(CK.REQ_CUSTOM_DATA_TEMP, null);
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomCleared"));
}
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorModuleNotFound"));
return new CustomRequirementModulePrompt(context);
}
}
public class CustomRequirementsPrompt extends QuestsEditorStringPrompt {
public CustomRequirementsPrompt(final ConversationContext context) {
private final String moduleName;
public CustomRequirementsPrompt(final String moduleName, final ConversationContext context) {
super(context);
this.moduleName = moduleName;
}
@Override
@ -1434,16 +1514,8 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
CustomRequirement found = null;
// Check if we have a custom requirement with the specified name
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getName().equalsIgnoreCase(input)) {
found = cr;
break;
}
}
if (found == null) {
// No? Check again, but with locale sensitivity
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getModuleName().equals(moduleName)) {
if (cr.getName().toLowerCase().contains(input.toLowerCase())) {
found = cr;
break;
@ -1465,7 +1537,7 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
} else {
// Already added, so inform user
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomAlreadyAdded"));
return new CustomRequirementsPrompt(context);
return new CustomRequirementsPrompt(moduleName, context);
}
} else {
// The custom requirement hasn't been added yet, so let's do it
@ -1483,7 +1555,7 @@ public class RequirementsPrompt extends QuestsEditorNumericPrompt {
}
} else {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("reqCustomNotFound"));
return new CustomRequirementsPrompt(context);
return new CustomRequirementsPrompt(moduleName, context);
}
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(CK.REQ_CUSTOM, null);

View File

@ -16,12 +16,15 @@ import com.codisimus.plugins.phatloots.PhatLoot;
import com.codisimus.plugins.phatloots.PhatLootsAPI;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.herocraftonline.heroes.characters.classes.HeroClass;
import me.blackvein.quests.CustomObjective;
import me.blackvein.quests.CustomRequirement;
import me.blackvein.quests.CustomReward;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.generic.ItemStackPrompt;
import me.blackvein.quests.convo.generic.OverridePrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
import me.blackvein.quests.convo.quests.stages.StageMainPrompt;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent;
import me.blackvein.quests.util.CK;
@ -34,6 +37,7 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
@ -41,6 +45,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TreeSet;
public class RewardsPrompt extends QuestsEditorNumericPrompt {
@ -467,7 +472,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
return new RewardsPrompt(context);
}
case 11:
return new CustomRewardsPrompt(context);
return new CustomRewardModulePrompt(context);
case 12:
if (hasReward) {
return new OverridePrompt.Builder()
@ -1769,10 +1774,88 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
}
public class CustomRewardModulePrompt extends QuestsEditorStringPrompt {
public CustomRewardModulePrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorModules");
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("stageEditorModulePrompt");
}
@Override
public @NotNull String getPromptText(@NotNull final ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRewards().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final CustomReward cr : new TreeSet<>(plugin.getCustomRewards())) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getModuleName()).append("\n");
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(@NotNull final ConversationContext context, @Nullable final String input) {
if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))
&& !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
String found = null;
// Check if we have a module with the specified name
for (final CustomReward cr : plugin.getCustomRewards()) {
if (cr.getModuleName().equalsIgnoreCase(input)) {
found = cr.getModuleName();
break;
}
}
if (found == null) {
// No? Check again, but with locale sensitivity
for (final CustomReward cr : plugin.getCustomRewards()) {
if (cr.getModuleName().toLowerCase().contains(input.toLowerCase())) {
found = cr.getModuleName();
break;
}
}
}
if (found != null) {
return new CustomRewardsPrompt(found, context);
}
} else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new RewardsPrompt(context);
} else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(CK.REW_CUSTOM, null);
context.setSessionData(CK.REW_CUSTOM_DATA, null);
context.setSessionData(CK.REW_CUSTOM_DATA_TEMP, null);
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCustomCleared"));
}
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorModuleNotFound"));
return new CustomRewardModulePrompt(context);
}
}
public class CustomRewardsPrompt extends QuestsEditorStringPrompt {
public CustomRewardsPrompt(final ConversationContext context) {
private final String moduleName;
public CustomRewardsPrompt(final String moduleName, final ConversationContext context) {
super(context);
this.moduleName = moduleName;
}
@Override
@ -1794,14 +1877,17 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomRewards().isEmpty()) {
if (plugin.getCustomRequirements().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules\n").append(ChatColor.DARK_PURPLE)
.append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final CustomReward cr : plugin.getCustomRewards()) {
for (final CustomRequirement cr : plugin.getCustomRequirements()) {
if (cr.getModuleName().equals(moduleName)) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(cr.getName()).append("\n");
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
@ -1814,16 +1900,8 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel")) && !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
CustomReward found = null;
// Check if we have a custom reward with the specified name
for (final CustomReward cr : plugin.getCustomRewards()) {
if (cr.getName().equalsIgnoreCase(input)) {
found = cr;
break;
}
}
if (found == null) {
// No? Check again, but with locale sensitivity
for (final CustomReward cr : plugin.getCustomRewards()) {
if (cr.getModuleName().equals(moduleName)) {
if (cr.getName().toLowerCase().contains(input.toLowerCase())) {
found = cr;
break;
@ -1845,7 +1923,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
} else {
// Already added, so inform user
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCustomAlreadyAdded"));
return new CustomRewardsPrompt(context);
return new CustomRewardsPrompt(moduleName, context);
}
} else {
// The custom reward hasn't been added yet, so let's do it
@ -1863,7 +1941,7 @@ public class RewardsPrompt extends QuestsEditorNumericPrompt {
}
} else {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("rewCustomNotFound"));
return new CustomRewardsPrompt(context);
return new CustomRewardsPrompt(moduleName, context);
}
} else if (input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(CK.REW_CUSTOM, null);

View File

@ -37,6 +37,7 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.conversations.StringPrompt;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.AbstractMap;
import java.util.Arrays;
@ -44,7 +45,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeSet;
import java.util.UUID;
import java.util.stream.Collectors;
public class StageMainPrompt extends QuestsEditorNumericPrompt {
private final Quests plugin;
@ -478,7 +481,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
case 7:
return new PasswordListPrompt(context);
case 8:
return new CustomObjectivesPrompt(context);
return new CustomObjectiveModulePrompt(context);
case 9:
if (hasObjective) {
return new ActionListPrompt(context);
@ -2356,10 +2359,89 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
}
}
public class CustomObjectiveModulePrompt extends QuestsEditorStringPrompt {
public CustomObjectiveModulePrompt(final ConversationContext context) {
super(context);
}
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("stageEditorModules");
}
@Override
public String getQueryText(final ConversationContext context) {
return Lang.get("stageEditorModulePrompt");
}
@Override
public @NotNull String getPromptText(@NotNull final ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenStringPromptEvent event
= new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
final StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
if (plugin.getCustomObjectives().isEmpty()) {
text.append(ChatColor.DARK_AQUA).append(ChatColor.UNDERLINE)
.append("https://pikamug.gitbook.io/quests/casual/modules").append(ChatColor.RESET)
.append("\n");
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final String name : new TreeSet<>(plugin.getCustomObjectives().stream()
.map(CustomObjective::getModuleName).collect(Collectors.toSet()))) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(name).append("\n");
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(@NotNull final ConversationContext context, @Nullable final String input) {
if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))
&& !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
String found = null;
// Check if we have a module with the specified name
for (final CustomObjective co : plugin.getCustomObjectives()) {
if (co.getModuleName().equalsIgnoreCase(input)) {
found = co.getModuleName();
break;
}
}
if (found == null) {
// No? Check again, but with locale sensitivity
for (final CustomObjective co : plugin.getCustomObjectives()) {
if (co.getModuleName().toLowerCase().contains(input.toLowerCase())) {
found = co.getModuleName();
break;
}
}
}
if (found != null) {
return new CustomObjectivesPrompt(found, context);
}
} else if (input != null && input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new StageMainPrompt(stageNum, context);
} else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES, null);
context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA, null);
context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES_DATA_TEMP, null);
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorCustomCleared"));
}
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorModuleNotFound"));
return new CustomObjectiveModulePrompt(context);
}
}
public class CustomObjectivesPrompt extends QuestsEditorStringPrompt {
public CustomObjectivesPrompt(final ConversationContext context) {
private final String moduleName;
public CustomObjectivesPrompt(final String moduleName, final ConversationContext context) {
super(context);
this.moduleName = moduleName;
}
@Override
@ -2387,9 +2469,11 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
text.append(ChatColor.DARK_PURPLE).append("(").append(Lang.get("stageEditorNoModules")).append(") ");
} else {
for (final CustomObjective co : plugin.getCustomObjectives()) {
if (co.getModuleName().equals(moduleName)) {
text.append(ChatColor.DARK_PURPLE).append(" - ").append(co.getName()).append("\n");
}
}
}
return text.toString() + ChatColor.YELLOW + getQueryText(context);
}
@ -2399,16 +2483,8 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
if (input != null && !input.equalsIgnoreCase(Lang.get("cmdCancel"))
&& !input.equalsIgnoreCase(Lang.get("cmdClear"))) {
CustomObjective found = null;
// Check if we have a custom objective with the specified name
for (final CustomObjective co : plugin.getCustomObjectives()) {
if (co.getName().equalsIgnoreCase(input)) {
found = co;
break;
}
}
if (found == null) {
// No? Check again, but with locale sensitivity
for (final CustomObjective co : plugin.getCustomObjectives()) {
if (co.getModuleName().equals(moduleName)) {
if (co.getName().toLowerCase().contains(input.toLowerCase())) {
found = co;
break;
@ -2437,7 +2513,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
// Already added, so inform user
context.getForWhom().sendRawMessage(ChatColor.YELLOW
+ Lang.get("stageEditorCustomAlreadyAdded"));
return new CustomObjectivesPrompt(context);
return new CustomObjectivesPrompt(moduleName, context);
}
} else {
// The custom objective hasn't been added yet, so let's do it
@ -2461,7 +2537,7 @@ public class StageMainPrompt extends QuestsEditorNumericPrompt {
}
} else {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorModuleNotFound"));
return new CustomObjectivesPrompt(context);
return new CustomObjectivesPrompt(moduleName, context);
}
} else if (input != null && input.equalsIgnoreCase(Lang.get("cmdClear"))) {
context.setSessionData(stagePrefix + CK.S_CUSTOM_OBJECTIVES, null);

View File

@ -26,7 +26,7 @@ public class UpdateChecker {
private final Quests plugin;
private final int resourceId;
public UpdateChecker(Quests plugin, int resourceId) {
public UpdateChecker(final Quests plugin, final int resourceId) {
this.plugin = plugin;
this.resourceId = resourceId;
}
@ -34,8 +34,8 @@ public class UpdateChecker {
public void getVersion(final Consumer<String> consumer) {
if (plugin.getSettings().canUpdateCheck()) {
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource="
+ this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) {
try (final InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource="
+ this.resourceId).openStream(); final Scanner scanner = new Scanner(inputStream)) {
if (scanner.hasNext()) {
consumer.accept(scanner.next());
}

View File

@ -182,8 +182,10 @@ stageEditorPassword: "Password"
stageEditorAddPasswordDisplay: "Add password hints"
stageEditorAddPasswordPhrases: "Add password phrases"
stageEditorCustom: "Custom objectives"
stageEditorModules: "- Modules -"
stageEditorNoModules: "No modules loaded"
stageEditorModuleNotFound: "Custom objective module not found."
stageEditorModulePrompt: "Enter the name of a module, <clear>, <cancel>"
stageEditorCustomPrompt: "Enter the name of a custom objective to add, <clear>, <cancel>"
stageEditorCustomAlreadyAdded: "That custom objective has already been added!"
stageEditorCustomCleared: "Custom objectives cleared."