mirror of https://github.com/PikaMug/Quests.git
NEW while wearing condition, per #1957
This commit is contained in:
parent
64aa1387a0
commit
40b78b68ff
|
@ -44,6 +44,10 @@ public interface ICondition extends Comparable<ICondition> {
|
|||
|
||||
void setItemsWhileHoldingMainHand(final LinkedList<ItemStack> itemsWhileHoldingMainHand);
|
||||
|
||||
LinkedList<ItemStack> getItemsWhileWearing();
|
||||
|
||||
void setItemsWhileWearing(final LinkedList<ItemStack> itemsWhileWearing);
|
||||
|
||||
LinkedList<String> getWorldsWhileStayingWithin();
|
||||
|
||||
void setWorldsWhileStayingWithin(final LinkedList<String> worldsWhileStayingWithin);
|
||||
|
|
|
@ -1683,6 +1683,13 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
.getType().name()));
|
||||
}
|
||||
quester.sendMessage(ChatColor.YELLOW + msg.toString());
|
||||
} else if (!c.getItemsWhileWearing().isEmpty()) {
|
||||
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorItemsWear"));
|
||||
for (final ItemStack is : c.getItemsWhileWearing()) {
|
||||
msg.append(ChatColor.AQUA).append("\n \u2515 ").append(ItemUtil.getPrettyItemName(is
|
||||
.getType().name()));
|
||||
}
|
||||
quester.sendMessage(ChatColor.YELLOW + msg.toString());
|
||||
} else if (!c.getWorldsWhileStayingWithin().isEmpty()) {
|
||||
final StringBuilder msg = new StringBuilder("- " + Lang.get("conditionEditorStayWithinWorld"));
|
||||
for (final String w : c.getWorldsWhileStayingWithin()) {
|
||||
|
@ -4058,6 +4065,19 @@ public class Quests extends JavaPlugin implements QuestsAPI {
|
|||
}
|
||||
condition.setItemsWhileHoldingMainHand(temp);
|
||||
}
|
||||
if (data.contains(conditionKey + "wear")) {
|
||||
final LinkedList<ItemStack> temp = new LinkedList<>();
|
||||
@SuppressWarnings("unchecked")
|
||||
final List<ItemStack> stackList = (List<ItemStack>) data.get(conditionKey + "wear");
|
||||
if (ConfigUtil.checkList(stackList, ItemStack.class)) {
|
||||
for (final ItemStack stack : stackList) {
|
||||
if (stack != null) {
|
||||
temp.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
condition.setItemsWhileWearing(temp);
|
||||
}
|
||||
if (data.contains(conditionKey + "stay-within-world")) {
|
||||
if (ConfigUtil.checkList(data.getList(conditionKey + "stay-within-world"), String.class)) {
|
||||
final LinkedList<String> worlds = new LinkedList<>();
|
||||
|
|
|
@ -108,6 +108,10 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
|
|||
final LinkedList<ItemStack> items = new LinkedList<>(condition.getItemsWhileHoldingMainHand());
|
||||
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, items);
|
||||
}
|
||||
if (condition.getItemsWhileWearing() != null && !condition.getItemsWhileWearing().isEmpty()) {
|
||||
final LinkedList<ItemStack> items = new LinkedList<>(condition.getItemsWhileWearing());
|
||||
context.setSessionData(CK.C_WHILE_WEARING, items);
|
||||
}
|
||||
if (condition.getWorldsWhileStayingWithin() != null && !condition.getWorldsWhileStayingWithin().isEmpty()) {
|
||||
final LinkedList<String> worlds = new LinkedList<>(condition.getBiomesWhileStayingWithin());
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, worlds);
|
||||
|
@ -147,6 +151,7 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
|
|||
context.setSessionData(CK.C_WHILE_RIDING_NPC, null);
|
||||
context.setSessionData(CK.C_WHILE_PERMISSION, null);
|
||||
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, null);
|
||||
context.setSessionData(CK.C_WHILE_WEARING, null);
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, null);
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_START, null);
|
||||
context.setSessionData(CK.C_WHILE_WITHIN_TICKS_END, null);
|
||||
|
@ -236,6 +241,9 @@ public class BukkitConditionFactory implements ConditionFactory, ConversationAba
|
|||
if (context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND) != null) {
|
||||
section.set("hold-main-hand", context.getSessionData(CK.C_WHILE_HOLDING_MAIN_HAND));
|
||||
}
|
||||
if (context.getSessionData(CK.C_WHILE_WEARING) != null) {
|
||||
section.set("wear", context.getSessionData(CK.C_WHILE_WEARING));
|
||||
}
|
||||
if (context.getSessionData(CK.C_WHILE_WITHIN_WORLD) != null) {
|
||||
section.set("stay-within-world", context.getSessionData(CK.C_WHILE_WITHIN_WORLD));
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ public class Condition implements ICondition {
|
|||
private LinkedList<UUID> npcsWhileRiding = new LinkedList<>();
|
||||
private LinkedList<String> permissions = new LinkedList<>();
|
||||
private LinkedList<ItemStack> itemsWhileHoldingMainHand = new LinkedList<>();
|
||||
private LinkedList<ItemStack> itemsWhileWearing = new LinkedList<>();
|
||||
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<>();
|
||||
private int tickStartWhileStayingWithin = -1;
|
||||
private int tickEndWhileStayingWithin = -1;
|
||||
|
@ -111,6 +112,16 @@ public class Condition implements ICondition {
|
|||
this.itemsWhileHoldingMainHand = itemsWhileHoldingMainHand;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedList<ItemStack> getItemsWhileWearing() {
|
||||
return itemsWhileWearing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemsWhileWearing(final LinkedList<ItemStack> itemsWhileWearing) {
|
||||
this.itemsWhileWearing = itemsWhileWearing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedList<String> getWorldsWhileStayingWithin() {
|
||||
return worldsWhileStayingWithin;
|
||||
|
@ -252,6 +263,20 @@ public class Condition implements ICondition {
|
|||
if (!atLeastOne) {
|
||||
failed = true;
|
||||
}
|
||||
} else if (!itemsWhileWearing.isEmpty()) {
|
||||
// Must have ALL listed armor equipped
|
||||
int matches = 0;
|
||||
for (final ItemStack is : itemsWhileWearing) {
|
||||
for (ItemStack armor : player.getInventory().getArmorContents()) {
|
||||
if (ItemUtil.compareItems(armor, is, true, true) == 0) {
|
||||
matches++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matches != itemsWhileWearing.size()) {
|
||||
failed = true;
|
||||
}
|
||||
} else if (!worldsWhileStayingWithin.isEmpty()) {
|
||||
boolean atLeastOne = false;
|
||||
for (final String w : worldsWhileStayingWithin) {
|
||||
|
|
|
@ -1175,11 +1175,11 @@ public class ActionMainPrompt extends ActionsEditorNumericPrompt {
|
|||
|
||||
final StringBuilder text = new StringBuilder(ChatColor.YELLOW + getQueryText(context));
|
||||
if (!modified.isEmpty()) {
|
||||
text.append("\n").append(ChatColor.RED).append(Lang.get("eventEditorModifiedNote"));
|
||||
text.append("\n").append(ChatColor.RED).append(" ").append(Lang.get("eventEditorModifiedNote"));
|
||||
for (final String s : modified) {
|
||||
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.DARK_RED).append(s);
|
||||
}
|
||||
text.append("\n").append(ChatColor.RED).append(Lang.get("eventEditorForcedToQuit"));
|
||||
text.append("\n").append(ChatColor.RED).append(" ").append(Lang.get("eventEditorForcedToQuit"));
|
||||
}
|
||||
for (int i = 1; i <= size; i++) {
|
||||
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
|
||||
|
|
|
@ -544,11 +544,11 @@ public class ConditionMainPrompt extends ConditionsEditorNumericPrompt {
|
|||
|
||||
final StringBuilder text = new StringBuilder(ChatColor.YELLOW + getQueryText(context));
|
||||
if (!modified.isEmpty()) {
|
||||
text.append("\n").append(ChatColor.RED).append(Lang.get("conditionEditorModifiedNote"));
|
||||
text.append("\n").append(ChatColor.RED).append(" ").append(Lang.get("conditionEditorModifiedNote"));
|
||||
for (final String s : modified) {
|
||||
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.DARK_RED).append(s);
|
||||
}
|
||||
text.append("\n").append(ChatColor.RED).append(Lang.get("conditionEditorForcedToQuit"));
|
||||
text.append("\n").append(ChatColor.RED).append(" ").append(Lang.get("conditionEditorForcedToQuit"));
|
||||
}
|
||||
for (int i = 1; i <= size; i++) {
|
||||
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
|
||||
|
|
|
@ -36,7 +36,7 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
|||
super(context);
|
||||
}
|
||||
|
||||
private final int size = 3;
|
||||
private final int size = 4;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
|
@ -53,8 +53,9 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
|||
switch (number) {
|
||||
case 1:
|
||||
case 2:
|
||||
return ChatColor.BLUE;
|
||||
case 3:
|
||||
return ChatColor.BLUE;
|
||||
case 4:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
|
@ -69,6 +70,8 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
|||
case 2:
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorItemsInMainHand");
|
||||
case 3:
|
||||
return ChatColor.YELLOW + Lang.get("conditionEditorItemsWear");
|
||||
case 4:
|
||||
return ChatColor.GREEN + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
|
@ -111,6 +114,22 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
|||
return text.toString();
|
||||
}
|
||||
case 3:
|
||||
if (context.getSessionData(CK.C_WHILE_WEARING) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
final StringBuilder text = new StringBuilder();
|
||||
final LinkedList<ItemStack> whileWearing
|
||||
= (LinkedList<ItemStack>) context.getSessionData(CK.C_WHILE_WEARING);
|
||||
if (whileWearing != null) {
|
||||
for (final ItemStack item : whileWearing) {
|
||||
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
|
||||
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
|
||||
.append(ChatColor.AQUA).append(item.getAmount());
|
||||
}
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
case 4:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
|
@ -155,6 +174,8 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
|||
case 2:
|
||||
return new ItemsInMainHandListPrompt(context);
|
||||
case 3:
|
||||
return new ItemsWearListPrompt(context);
|
||||
case 4:
|
||||
try {
|
||||
return new ConditionMainPrompt(context);
|
||||
} catch (final Exception e) {
|
||||
|
@ -295,7 +316,7 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
|||
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, items);
|
||||
}
|
||||
} else {
|
||||
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
|
||||
final LinkedList<ItemStack> items = new LinkedList<>();
|
||||
items.add((ItemStack) context.getSessionData("tempStack"));
|
||||
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, items);
|
||||
}
|
||||
|
@ -333,4 +354,129 @@ public class PlayerPrompt extends QuestsEditorNumericPrompt {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ItemsWearListPrompt extends QuestsEditorNumericPrompt {
|
||||
|
||||
public ItemsWearListPrompt(final ConversationContext context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private final int size = 3;
|
||||
|
||||
@Override
|
||||
public int getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(final ConversationContext context) {
|
||||
return Lang.get("conditionEditorItemsWear");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatColor getNumberColor(final ConversationContext context, final int number) {
|
||||
switch (number) {
|
||||
case 1:
|
||||
return ChatColor.BLUE;
|
||||
case 2:
|
||||
return ChatColor.RED;
|
||||
case 3:
|
||||
return ChatColor.GREEN;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectionText(final ConversationContext context, final int number) {
|
||||
switch(number) {
|
||||
case 1:
|
||||
return ChatColor.YELLOW + Lang.get("stageEditorDeliveryAddItem");
|
||||
case 2:
|
||||
return ChatColor.RED + Lang.get("clear");
|
||||
case 3:
|
||||
return ChatColor.GREEN + Lang.get("done");
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public String getAdditionalText(final ConversationContext context, final int number) {
|
||||
switch(number) {
|
||||
case 1:
|
||||
if (context.getSessionData(CK.C_WHILE_WEARING) == null) {
|
||||
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
|
||||
} else {
|
||||
final StringBuilder text = new StringBuilder();
|
||||
final List<ItemStack> whileWearing
|
||||
= (List<ItemStack>) context.getSessionData(CK.C_WHILE_WEARING);
|
||||
if (whileWearing != null) {
|
||||
for (final ItemStack is : whileWearing) {
|
||||
text.append("\n").append(ChatColor.GRAY).append(" - ")
|
||||
.append(ItemUtil.getDisplayString(is));
|
||||
}
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
return "";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getBasicPromptText(final ConversationContext context) {
|
||||
// Check/add newly made item
|
||||
if (context.getSessionData("tempStack") != null) {
|
||||
if (context.getSessionData(CK.C_WHILE_WEARING) != null) {
|
||||
final List<ItemStack> items
|
||||
= (List<ItemStack>) context.getSessionData(CK.C_WHILE_WEARING);
|
||||
if (items != null) {
|
||||
items.add((ItemStack) context.getSessionData("tempStack"));
|
||||
context.setSessionData(CK.C_WHILE_WEARING, items);
|
||||
}
|
||||
} else {
|
||||
final LinkedList<ItemStack> items = new LinkedList<>();
|
||||
items.add((ItemStack) context.getSessionData("tempStack"));
|
||||
context.setSessionData(CK.C_WHILE_WEARING, items);
|
||||
}
|
||||
ItemStackPrompt.clearSessionData(context);
|
||||
}
|
||||
|
||||
if (context.getPlugin() != null) {
|
||||
final QuestsEditorPostOpenNumericPromptEvent event
|
||||
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
|
||||
context.getPlugin().getServer().getPluginManager().callEvent(event);
|
||||
}
|
||||
|
||||
final StringBuilder text = new StringBuilder(ChatColor.GOLD + "- " + getTitle(context) + " -");
|
||||
for (int i = 1; i <= size; i++) {
|
||||
text.append("\n").append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i)
|
||||
.append(ChatColor.RESET).append(" - ").append(getSelectionText(context, i)).append(" ")
|
||||
.append(getAdditionalText(context, i));
|
||||
}
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
|
||||
switch(input.intValue()) {
|
||||
case 1:
|
||||
return new ItemStackPrompt(context, ItemsWearListPrompt.this);
|
||||
case 2:
|
||||
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("conditionEditorConditionCleared"));
|
||||
context.setSessionData(CK.C_WHILE_WEARING, null);
|
||||
return new ItemsWearListPrompt(context);
|
||||
case 3:
|
||||
return new PlayerPrompt(context);
|
||||
default:
|
||||
return new ItemsWearListPrompt(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,6 +187,7 @@ public class CK {
|
|||
public static final String C_WHILE_RIDING_NPC = "conRidingNpc";
|
||||
public static final String C_WHILE_PERMISSION = "conPermission";
|
||||
public static final String C_WHILE_HOLDING_MAIN_HAND = "conHoldingMainHand";
|
||||
public static final String C_WHILE_WEARING = "conWearing";
|
||||
public static final String C_WHILE_WITHIN_WORLD = "conWithinWorld";
|
||||
public static final String C_WHILE_WITHIN_TICKS_START = "conWithinTicksStart";
|
||||
public static final String C_WHILE_WITHIN_TICKS_END = "conWithinTicksEnd";
|
||||
|
|
|
@ -398,6 +398,7 @@ conditionEditorNpcsTitle: "- NPCs -"
|
|||
conditionEditorPermissions: "Own permission"
|
||||
conditionEditorPermissionsPrompt: "Enter permission nodes, <space>, <cancel>"
|
||||
conditionEditorItemsInMainHand: "Hold in main hand"
|
||||
conditionEditorItemsWear: "Wear as armor"
|
||||
conditionEditorWorldsTitle: "- Worlds -"
|
||||
conditionEditorWorldsPrompt: "Enter world names, <space>, <cancel>"
|
||||
conditionEditorStayWithinWorld: "Stay within world"
|
||||
|
|
Loading…
Reference in New Issue