mirror of
https://github.com/PikaMug/Quests.git
synced 2025-01-24 01:02:00 +01:00
New per-quest option for toggling Silk Touch restriction, fixes #1411
This commit is contained in:
parent
5d5d833320
commit
5f3951cca8
@ -15,12 +15,13 @@ package me.blackvein.quests;
|
||||
public class Options {
|
||||
private boolean allowCommands = true;
|
||||
private boolean allowQuitting = true;
|
||||
private boolean ignoreSilkTouch = true;
|
||||
private boolean useDungeonsXLPlugin = false;
|
||||
private boolean usePartiesPlugin = true;
|
||||
private int shareProgressLevel = 1;
|
||||
private boolean requireSameQuest = true;
|
||||
|
||||
public boolean getAllowCommands() {
|
||||
public boolean canAllowCommands() {
|
||||
return allowCommands;
|
||||
}
|
||||
|
||||
@ -28,7 +29,7 @@ public class Options {
|
||||
this.allowCommands = allowCommands;
|
||||
}
|
||||
|
||||
public boolean getAllowQuitting() {
|
||||
public boolean canAllowQuitting() {
|
||||
return allowQuitting;
|
||||
}
|
||||
|
||||
@ -36,7 +37,15 @@ public class Options {
|
||||
this.allowQuitting = allowQuitting;
|
||||
}
|
||||
|
||||
public boolean getUseDungeonsXLPlugin() {
|
||||
public boolean canIgnoreSilkTouch() {
|
||||
return ignoreSilkTouch;
|
||||
}
|
||||
|
||||
public void setIgnoreSilkTouch(final boolean ignoreSilkTouch) {
|
||||
this.ignoreSilkTouch = ignoreSilkTouch;
|
||||
}
|
||||
|
||||
public boolean canUseDungeonsXLPlugin() {
|
||||
return useDungeonsXLPlugin;
|
||||
}
|
||||
|
||||
@ -44,7 +53,7 @@ public class Options {
|
||||
this.useDungeonsXLPlugin = useDungeonsXLPlugin;
|
||||
}
|
||||
|
||||
public boolean getUsePartiesPlugin() {
|
||||
public boolean canUsePartiesPlugin() {
|
||||
return usePartiesPlugin;
|
||||
}
|
||||
|
||||
@ -60,7 +69,7 @@ public class Options {
|
||||
this.shareProgressLevel = shareProgressLevel;
|
||||
}
|
||||
|
||||
public boolean getRequireSameQuest() {
|
||||
public boolean canRequireSameQuest() {
|
||||
return requireSameQuest;
|
||||
}
|
||||
|
||||
|
@ -267,12 +267,13 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
}
|
||||
context.setSessionData(CK.PLN_OVERRIDE, pln.getOverride());
|
||||
final Options opt = q.getOptions();
|
||||
context.setSessionData(CK.OPT_ALLOW_COMMANDS, opt.getAllowCommands());
|
||||
context.setSessionData(CK.OPT_ALLOW_QUITTING, opt.getAllowQuitting());
|
||||
context.setSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN, opt.getUseDungeonsXLPlugin());
|
||||
context.setSessionData(CK.OPT_USE_PARTIES_PLUGIN, opt.getUsePartiesPlugin());
|
||||
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_USE_PARTIES_PLUGIN, opt.canUsePartiesPlugin());
|
||||
context.setSessionData(CK.OPT_SHARE_PROGRESS_LEVEL, opt.getShareProgressLevel());
|
||||
context.setSessionData(CK.OPT_REQUIRE_SAME_QUEST, opt.getRequireSameQuest());
|
||||
context.setSessionData(CK.OPT_REQUIRE_SAME_QUEST, opt.canRequireSameQuest());
|
||||
// Stages (Objectives)
|
||||
int index = 1;
|
||||
for (final Stage stage : q.getStages()) {
|
||||
@ -938,6 +939,8 @@ public class QuestFactory implements ConversationAbandonedListener {
|
||||
? (Boolean) context.getSessionData(CK.OPT_ALLOW_COMMANDS) : null);
|
||||
opts.set("allow-quitting", context.getSessionData(CK.OPT_ALLOW_QUITTING) != null
|
||||
? (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING) : null);
|
||||
opts.set("ignore-silk-touch", context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) != null
|
||||
? (Boolean) context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) : null);
|
||||
opts.set("use-dungeonsxl-plugin", context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) != null
|
||||
? (Boolean) context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) : null);
|
||||
opts.set("use-parties-plugin", context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) != null
|
||||
|
@ -3983,7 +3983,7 @@ public class Quester {
|
||||
return;
|
||||
}
|
||||
if (this.getCurrentStage(quest).containsObjective(objectiveType)
|
||||
|| !quest.getOptions().getRequireSameQuest()) {
|
||||
|| !quest.getOptions().canRequireSameQuest()) {
|
||||
fun.apply(q);
|
||||
}
|
||||
}
|
||||
@ -4016,7 +4016,7 @@ public class Quester {
|
||||
return;
|
||||
}
|
||||
if ((q.getCurrentQuests().containsKey(quest) && currentStage.equals(q.getCurrentStage(quest)))
|
||||
|| !quest.getOptions().getRequireSameQuest()) {
|
||||
|| !quest.getOptions().canRequireSameQuest()) {
|
||||
fun.apply(q);
|
||||
}
|
||||
}
|
||||
@ -4035,7 +4035,7 @@ public class Quester {
|
||||
}
|
||||
final List<Quester> mq = new LinkedList<Quester>();
|
||||
if (plugin.getDependencies().getPartiesApi() != null) {
|
||||
if (quest.getOptions().getUsePartiesPlugin()) {
|
||||
if (quest.getOptions().canUsePartiesPlugin()) {
|
||||
final Party party = plugin.getDependencies().getPartiesApi().getParty(plugin.getDependencies()
|
||||
.getPartiesApi().getPartyPlayer(getUUID()).getPartyName());
|
||||
if (party != null) {
|
||||
@ -4049,7 +4049,7 @@ public class Quester {
|
||||
}
|
||||
}
|
||||
if (plugin.getDependencies().getDungeonsApi() != null) {
|
||||
if (quest.getOptions().getUseDungeonsXLPlugin()) {
|
||||
if (quest.getOptions().canUseDungeonsXLPlugin()) {
|
||||
final DGroup group = (DGroup) plugin.getDependencies().getDungeonsApi().getPlayerGroup(getPlayer());
|
||||
if (group != null) {
|
||||
for (final UUID id : group.getMembers()) {
|
||||
|
@ -1930,6 +1930,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
|
||||
// Legacy
|
||||
opts.setAllowQuitting(getConfig().getBoolean("allow-quitting"));
|
||||
}
|
||||
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"));
|
||||
}
|
||||
|
@ -282,7 +282,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private final int size = 3;
|
||||
private final int size = 4;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
@ -298,10 +298,10 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
return ChatColor.BLUE;
|
||||
case 2:
|
||||
return ChatColor.BLUE;
|
||||
case 3:
|
||||
return ChatColor.BLUE;
|
||||
case 4:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
@ -316,6 +316,8 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("optAllowQuitting");
|
||||
case 3:
|
||||
return ChatColor.YELLOW + Lang.get("optIgnoreSilkTouch");
|
||||
case 4:
|
||||
return ChatColor.YELLOW + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
@ -327,7 +329,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
switch (number) {
|
||||
case 1:
|
||||
if (context.getSessionData(CK.OPT_ALLOW_COMMANDS) == null) {
|
||||
final boolean defaultOpt = new Options().getAllowCommands();
|
||||
final boolean defaultOpt = new Options().canAllowCommands();
|
||||
return ChatColor.GRAY + "(" + (defaultOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
|
||||
@ -339,17 +341,29 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
case 2:
|
||||
if (context.getSessionData(CK.OPT_ALLOW_QUITTING) == null) {
|
||||
final boolean defaultOpt = new Options().getAllowQuitting();
|
||||
final boolean defaultOpt = new Options().canAllowQuitting();
|
||||
return ChatColor.GRAY + "(" + (defaultOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
|
||||
} else {
|
||||
final boolean quittingOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING);
|
||||
final boolean quittingOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING);
|
||||
return ChatColor.GRAY + "(" + (quittingOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(quittingOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(quittingOpt))) + ChatColor.GRAY + ")";
|
||||
}
|
||||
case 3:
|
||||
if (context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) == null) {
|
||||
final boolean defaultOpt = new Options().canIgnoreSilkTouch();
|
||||
return ChatColor.GRAY + "(" + (defaultOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
|
||||
} else {
|
||||
final boolean quittingOpt = (Boolean) context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH);
|
||||
return ChatColor.GRAY + "(" + (quittingOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(quittingOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(quittingOpt))) + ChatColor.GRAY + ")";
|
||||
}
|
||||
case 4:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
@ -381,6 +395,10 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
tempPrompt = new OptionsGeneralPrompt(context);
|
||||
return new OptionsTrueFalsePrompt(context);
|
||||
case 3:
|
||||
tempKey = CK.OPT_IGNORE_SILK_TOUCH;
|
||||
tempPrompt = new OptionsGeneralPrompt(context);
|
||||
return new OptionsTrueFalsePrompt(context);
|
||||
case 4:
|
||||
tempKey = null;
|
||||
tempPrompt = null;
|
||||
try {
|
||||
@ -453,7 +471,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
switch (number) {
|
||||
case 1:
|
||||
if (context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) == null) {
|
||||
final boolean defaultOpt = new Options().getUseDungeonsXLPlugin();
|
||||
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 + ")";
|
||||
@ -465,7 +483,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
case 2:
|
||||
if (context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) == null) {
|
||||
final boolean defaultOpt = new Options().getUsePartiesPlugin();
|
||||
final boolean defaultOpt = new Options().canUsePartiesPlugin();
|
||||
return ChatColor.GRAY + "("+ (defaultOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
|
||||
@ -485,7 +503,7 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
|
||||
}
|
||||
case 4:
|
||||
if (context.getSessionData(CK.OPT_REQUIRE_SAME_QUEST) == null) {
|
||||
final boolean defaultOpt = new Options().getRequireSameQuest();
|
||||
final boolean defaultOpt = new Options().canRequireSameQuest();
|
||||
return ChatColor.GRAY + "(" + (defaultOpt ? ChatColor.GREEN
|
||||
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
|
||||
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
package me.blackvein.quests.listeners;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -30,6 +31,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import me.blackvein.quests.Quest;
|
||||
import me.blackvein.quests.Quester;
|
||||
import me.blackvein.quests.Quests;
|
||||
import me.blackvein.quests.util.Lang;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
|
||||
@ -52,16 +54,23 @@ public class BlockListener implements Listener {
|
||||
if (!quester.meetsCondition(quest, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (quester.getCurrentQuests().containsKey(quest)
|
||||
&& quester.getCurrentStage(quest).containsObjective("breakBlock")) {
|
||||
if (!player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
if (quest.getOptions().canIgnoreSilkTouch()
|
||||
&& player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
player.sendMessage(ChatColor.RED + Lang.get(player, "optionSilkTouchFail")
|
||||
.replace("<quest>", quest.getName()));
|
||||
} else {
|
||||
quester.breakBlock(quest, blockItemStack);
|
||||
}
|
||||
}
|
||||
quester.dispatchMultiplayerEverything(quest, "breakBlock", (final Quester q) -> {
|
||||
if (!player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
q.breakBlock(quest, blockItemStack);
|
||||
if (quest.getOptions().canIgnoreSilkTouch()
|
||||
&& player.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
|
||||
player.sendMessage(ChatColor.RED + Lang.get(player, "optionSilkTouchFail")
|
||||
.replace("<quest>", quest.getName()));
|
||||
} else {
|
||||
quester.breakBlock(quest, blockItemStack);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
@ -735,7 +735,7 @@ public class CmdExecutor implements CommandExecutor {
|
||||
if (quester.getCurrentQuests().isEmpty() == false) {
|
||||
final Quest quest = plugin.getQuest(concatArgArray(args, 1, args.length - 1, ' '));
|
||||
if (quest != null) {
|
||||
if (quest.getOptions().getAllowQuitting()) {
|
||||
if (quest.getOptions().canAllowQuitting()) {
|
||||
final QuestQuitEvent event = new QuestQuitEvent(quest, quester);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
|
@ -452,7 +452,7 @@ public class PlayerListener implements Listener {
|
||||
final Quester quester = plugin.getQuester(evt.getPlayer().getUniqueId());
|
||||
if (quester.getCurrentQuests().isEmpty() == false) {
|
||||
for (final Quest quest : quester.getCurrentQuests().keySet()) {
|
||||
if (!quest.getOptions().getAllowCommands()) {
|
||||
if (!quest.getOptions().canAllowCommands()) {
|
||||
if (!evt.getMessage().startsWith("/quest")) {
|
||||
evt.getPlayer().sendMessage(ChatColor.RED + Lang.get(evt.getPlayer(), "optCommandsDenied")
|
||||
.replace("<quest>", ChatColor.DARK_PURPLE + quest.getName() + ChatColor.RED));
|
||||
|
@ -143,6 +143,7 @@ public class CK {
|
||||
// Options
|
||||
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_USE_PARTIES_PLUGIN = "usePartiesPluginOpt";
|
||||
public static final String OPT_SHARE_PROGRESS_LEVEL = "shareProgressLevelOpt";
|
||||
|
@ -477,6 +477,7 @@ optBooleanPrompt: "Enter '<true>' or '<false>', <clear>, <cancel>"
|
||||
optNumberPrompt: "Enter a level (number) for tracking progress, <clear>, <cancel>"
|
||||
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"
|
||||
optUsePartiesPlugin: "Use Parties plugin"
|
||||
@ -773,6 +774,7 @@ requirements: "Requirements"
|
||||
requirementsItemFail: "Unable to collect required item. Is it in your off-hand?"
|
||||
conditionFailQuit: "Condition failed. You have quit <quest>."
|
||||
conditionFailRetry: "Condition not yet met for this stage of <quest>."
|
||||
optionSilkTouchFail: "Unable to progress <quest> with the applied enchantment."
|
||||
money: "Money"
|
||||
with: "with"
|
||||
to: "to"
|
||||
|
Loading…
Reference in New Issue
Block a user