Improve code syntax, part 4

This commit is contained in:
PikaMug 2021-09-04 22:23:33 -04:00
parent e3b449ed8b
commit df04c72c99
18 changed files with 2077 additions and 1508 deletions

View File

@ -290,14 +290,15 @@ public class EffectPrompt extends ActionsEditorNumericPrompt {
case 4:
final int one;
final int two;
if (context.getSessionData(CK.E_EFFECTS) != null) {
one = ((List<String>) Objects.requireNonNull(context.getSessionData(CK.E_EFFECTS))).size();
final List<String> effects = (List<String>) context.getSessionData(CK.E_EFFECTS);
final List<String> locations = (List<String>) context.getSessionData(CK.E_EFFECTS_LOCATIONS);
if (effects != null) {
one = effects.size();
} else {
one = 0;
}
if (context.getSessionData(CK.E_EFFECTS_LOCATIONS) != null) {
two = ((List<String>) Objects.requireNonNull(context.getSessionData(CK.E_EFFECTS_LOCATIONS)))
.size();
if (locations != null) {
two = locations.size();
} else {
two = 0;
}

View File

@ -579,19 +579,21 @@ public class PlayerPrompt extends ActionsEditorNumericPrompt {
final int one;
final int two;
final int three;
if (context.getSessionData(CK.E_POTION_TYPES) != null) {
one = ((List<String>) Objects.requireNonNull(context.getSessionData(CK.E_POTION_TYPES))).size();
final List<String> types = (List<String>) context.getSessionData(CK.E_POTION_TYPES);
final List<Long> durations = (List<Long>) context.getSessionData(CK.E_POTION_DURATIONS);
final List<Integer> strength = (List<Integer>) context.getSessionData(CK.E_POTION_STRENGTH);
if (types != null) {
one = types.size();
} else {
one = 0;
}
if (context.getSessionData(CK.E_POTION_DURATIONS) != null) {
two = ((List<Long>) Objects.requireNonNull(context.getSessionData(CK.E_POTION_DURATIONS))).size();
if (durations != null) {
two = durations.size();
} else {
two = 0;
}
if (context.getSessionData(CK.E_POTION_STRENGTH) != null) {
three = ((List<Integer>) Objects.requireNonNull(context.getSessionData(CK.E_POTION_STRENGTH)))
.size();
if (strength != null) {
three = strength.size();
} else {
three = 0;
}

View File

@ -25,7 +25,7 @@ public abstract class QuestsEditorNumericPrompt extends QuestsNumericPrompt {
public QuestsEditorNumericPrompt(final ConversationContext context) {
this.context = context;
if (context != null) {
if (context != null && context.getPlugin() != null) {
factory = ((Quests)context.getPlugin()).getQuestFactory();
}
}

View File

@ -24,7 +24,7 @@ public abstract class QuestsEditorStringPrompt extends QuestsStringPrompt {
public QuestsEditorStringPrompt(final ConversationContext context) {
this.context = context;
if (context != null) {
if (context != null && context.getPlugin() != null) {
factory = ((Quests)context.getPlugin()).getQuestFactory();
}
}

View File

@ -28,7 +28,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
public class BlocksPrompt extends QuestsEditorNumericPrompt {
private final int stageNum;
@ -349,35 +348,33 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
case 5:
final int one;
final int two;
if (context.getSessionData(pref + CK.S_BREAK_NAMES) != null) {
one = ((List<Integer>) Objects.requireNonNull(context.getSessionData(pref + CK.S_BREAK_NAMES)))
.size();
final List<Integer> names = (List<Integer>) context.getSessionData(pref + CK.S_BREAK_NAMES);
final List<Integer> amounts = (List<Integer>) context.getSessionData(pref + CK.S_BREAK_AMOUNTS);
if (names != null) {
one = names.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_BREAK_AMOUNTS) != null) {
two = ((List<Integer>) Objects.requireNonNull(context.getSessionData(pref + CK.S_BREAK_AMOUNTS)))
.size();
if (amounts != null) {
two = amounts.size();
} else {
two = 0;
}
if (one == two) {
final int missing;
final LinkedList<Short> elements;
if (context.getSessionData(pref + CK.S_BREAK_DURABILITY) != null) {
missing = one - ((List<Short>) Objects.requireNonNull(context
.getSessionData(pref + CK.S_BREAK_DURABILITY))).size();
elements = (LinkedList<Short>) context.getSessionData(pref + CK.S_BREAK_DURABILITY);
final LinkedList<Short> durability
= (LinkedList<Short>) context.getSessionData(pref + CK.S_BREAK_DURABILITY);
if (durability != null) {
missing = one - durability.size();
} else {
missing = one;
elements = new LinkedList<>();
}
for (int i = 0; i < missing; i++) {
if (elements != null) {
elements.add((short) 0);
if (durability != null) {
durability.add((short) 0);
}
}
context.setSessionData(pref + CK.S_BREAK_DURABILITY, elements);
context.setSessionData(pref + CK.S_BREAK_DURABILITY, durability);
return new BlocksPrompt(stageNum, context);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
@ -722,35 +719,33 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
case 5:
final int one;
final int two;
if (context.getSessionData(pref + CK.S_DAMAGE_NAMES) != null) {
one = ((List<String>) Objects.requireNonNull(context.getSessionData(pref + CK.S_DAMAGE_NAMES)))
.size();
final List<Integer> names = (List<Integer>) context.getSessionData(pref + CK.S_DAMAGE_NAMES);
final List<Integer> amounts = (List<Integer>) context.getSessionData(pref + CK.S_DAMAGE_AMOUNTS);
if (names != null) {
one = names.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_DAMAGE_AMOUNTS) != null) {
two = ((List<Integer>) Objects.requireNonNull(context.getSessionData(pref + CK.S_DAMAGE_AMOUNTS)))
.size();
if (amounts != null) {
two = amounts.size();
} else {
two = 0;
}
if (one == two) {
final int missing;
final LinkedList<Short> elements;
if (context.getSessionData(pref + CK.S_DAMAGE_DURABILITY) != null) {
missing = one - ((List<Short>) Objects.requireNonNull(context
.getSessionData(pref + CK.S_DAMAGE_DURABILITY))).size();
elements = (LinkedList<Short>) context.getSessionData(pref + CK.S_DAMAGE_DURABILITY);
final LinkedList<Short> durability
= (LinkedList<Short>) context.getSessionData(pref + CK.S_DAMAGE_DURABILITY);
if (durability != null) {
missing = one - durability.size();
} else {
missing = one;
elements = new LinkedList<>();
}
for (int i = 0; i < missing; i++) {
if (elements != null) {
elements.add((short) 0);
if (durability != null) {
durability.add((short) 0);
}
}
context.setSessionData(pref + CK.S_DAMAGE_DURABILITY, elements);
context.setSessionData(pref + CK.S_DAMAGE_DURABILITY, durability);
return new BlocksPrompt(stageNum, context);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
@ -1093,35 +1088,33 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
case 5:
final int one;
final int two;
if (context.getSessionData(pref + CK.S_PLACE_NAMES) != null) {
one = ((List<String>) Objects.requireNonNull(context.getSessionData(pref + CK.S_PLACE_NAMES)))
.size();
final List<Integer> names = (List<Integer>) context.getSessionData(pref + CK.S_PLACE_NAMES);
final List<Integer> amounts = (List<Integer>) context.getSessionData(pref + CK.S_PLACE_AMOUNTS);
if (names != null) {
one = names.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_PLACE_AMOUNTS) != null) {
two = ((List<Integer>) Objects.requireNonNull(context.getSessionData(pref + CK.S_PLACE_AMOUNTS)))
.size();
if (amounts != null) {
two = amounts.size();
} else {
two = 0;
}
if (one == two) {
final int missing;
final LinkedList<Short> elements;
if (context.getSessionData(pref + CK.S_PLACE_DURABILITY) != null) {
missing = one - ((List<Short>) Objects.requireNonNull(context
.getSessionData(pref + CK.S_PLACE_DURABILITY))).size();
elements = (LinkedList<Short>) context.getSessionData(pref + CK.S_PLACE_DURABILITY);
final LinkedList<Short> durability
= (LinkedList<Short>) context.getSessionData(pref + CK.S_PLACE_DURABILITY);
if (durability != null) {
missing = one - durability.size();
} else {
missing = one;
elements = new LinkedList<>();
}
for (int i = 0; i < missing; i++) {
if (elements != null) {
elements.add((short) 0);
if (durability != null) {
durability.add((short) 0);
}
}
context.setSessionData(pref + CK.S_PLACE_DURABILITY, elements);
context.setSessionData(pref + CK.S_PLACE_DURABILITY, durability);
return new BlocksPrompt(stageNum, context);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));
@ -1462,34 +1455,33 @@ public class BlocksPrompt extends QuestsEditorNumericPrompt {
case 5:
final int one;
final int two;
if (context.getSessionData(pref + CK.S_USE_NAMES) != null) {
one = ((List<String>) Objects.requireNonNull(context.getSessionData(pref + CK.S_USE_NAMES))).size();
final List<Integer> names = (List<Integer>) context.getSessionData(pref + CK.S_USE_NAMES);
final List<Integer> amounts = (List<Integer>) context.getSessionData(pref + CK.S_USE_AMOUNTS);
if (names != null) {
one = names.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_USE_AMOUNTS) != null) {
two = ((List<Integer>) Objects.requireNonNull(context.getSessionData(pref + CK.S_USE_AMOUNTS)))
.size();
if (amounts != null) {
two = amounts.size();
} else {
two = 0;
}
if (one == two) {
final int missing;
final LinkedList<Short> elements;
if (context.getSessionData(pref + CK.S_USE_DURABILITY) != null) {
missing = one - ((List<Short>) Objects.requireNonNull(context
.getSessionData(pref + CK.S_USE_DURABILITY))).size();
elements = (LinkedList<Short>) context.getSessionData(pref + CK.S_USE_DURABILITY);
final LinkedList<Short> durability
= (LinkedList<Short>) context.getSessionData(pref + CK.S_USE_DURABILITY);
if (durability != null) {
missing = one - durability.size();
} else {
missing = one;
elements = new LinkedList<>();
}
for (int i = 0; i < missing; i++) {
if (elements != null) {
elements.add((short) 0);
if (durability != null) {
durability.add((short) 0);
}
}
context.setSessionData(pref + CK.S_USE_DURABILITY, elements);
context.setSessionData(pref + CK.S_USE_DURABILITY, durability);
return new BlocksPrompt(stageNum, context);
} else {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("listsNotSameSize"));

View File

@ -12,14 +12,6 @@
package me.blackvein.quests.convo.quests.objectives;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.inventory.ItemStack;
import me.blackvein.quests.convo.generic.ItemStackPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.stages.StageMainPrompt;
@ -27,6 +19,14 @@ import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromp
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.LinkedList;
import java.util.List;
public class ItemsPrompt extends QuestsEditorNumericPrompt {
private final int stageNum;
@ -94,61 +94,79 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
for (int i = 0; i < items.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i))
+ ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount()).append("\n");
}
}
return text;
return text.toString();
}
case 2:
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
for (int i = 0; i < items.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i))
+ ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount()).append("\n");
}
}
return text;
return text.toString();
}
case 3:
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS);
for (int i = 0; i < items.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i))
+ ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + "\n";
if (items != null) {
for (final ItemStack item : items) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount()).append("\n");
}
}
return text;
return text.toString();
}
case 4:
if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
for (int i = 0; i < items.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i))
+ ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + "\n";
if (items != null) {
for (final ItemStack item : items) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount()).append("\n");
}
}
return text;
return text.toString();
}
case 5:
if (context.getSessionData(pref + CK.S_CONSUME_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final LinkedList<ItemStack> items = (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS);
for (int i = 0; i < items.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i))
+ ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS);
if (items != null) {
for (final ItemStack item : items) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(item)).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(item.getAmount()).append("\n");
}
}
return text;
return text.toString();
}
case 6:
return "";
@ -159,34 +177,42 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
}
} else if (context.getSessionData(pref + CK.S_SMELT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
}
}
ItemStackPrompt.clearSessionData(context);
}
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + 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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemsCraftListPrompt(context);
@ -264,11 +290,16 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
final StringBuilder text = new StringBuilder("\n");
final List<ItemStack> craftItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
if (craftItems != null) {
for (final ItemStack is : craftItems) {
text.append(ChatColor.GRAY).append(" - ").append(ItemUtil.getDisplayString(is))
.append("\n");
}
}
return text;
return text.toString();
}
case 2:
case 3:
@ -280,34 +311,40 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.GOLD + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsCraftListPrompt.this);
@ -315,8 +352,6 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_CRAFT_ITEMS, null);
return new ItemsCraftListPrompt(context);
case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context);
}
@ -377,11 +412,16 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
final StringBuilder text = new StringBuilder("\n");
final List<ItemStack> smeltItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
if (smeltItems != null) {
for (final ItemStack is : smeltItems) {
text.append(ChatColor.GRAY).append(" - ").append(ItemUtil.getDisplayString(is))
.append("\n");
}
}
return text;
return text.toString();
}
case 2:
case 3:
@ -393,35 +433,40 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_SMELT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.GOLD + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsSmeltListPrompt.this);
@ -429,8 +474,6 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_SMELT_ITEMS, null);
return new ItemsSmeltListPrompt(context);
case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context);
}
@ -491,11 +534,16 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
final StringBuilder text = new StringBuilder("\n");
final List<ItemStack> enchantItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS);
if (enchantItems != null) {
for (final ItemStack is : enchantItems) {
text.append(ChatColor.GRAY).append(" - ").append(ItemUtil.getDisplayString(is))
.append("\n");
}
}
return text;
return text.toString();
}
case 2:
case 3:
@ -507,35 +555,40 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_ENCHANT_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.GOLD + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsEnchantListPrompt.this);
@ -543,8 +596,6 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, null);
return new ItemsEnchantListPrompt(context);
case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context);
}
@ -605,11 +656,14 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_BREW_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
final StringBuilder text = new StringBuilder("\n");
final List<ItemStack> brewItems = (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
if (brewItems != null) {
for (final ItemStack is : brewItems) {
text.append(ChatColor.GRAY).append(" - ").append(ItemUtil.getDisplayString(is)).append("\n");
}
}
return text;
return text.toString();
}
case 2:
case 3:
@ -621,35 +675,38 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_BREW_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_BREW_ITEMS, items);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_BREW_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_BREW_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.GOLD + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsBrewListPrompt.this);
@ -657,8 +714,6 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_BREW_ITEMS, null);
return new ItemsBrewListPrompt(context);
case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context);
}
@ -719,11 +774,16 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_CONSUME_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
final StringBuilder text = new StringBuilder("\n");
final List<ItemStack> consumeItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS);
if (consumeItems != null) {
for (final ItemStack is : consumeItems) {
text.append(ChatColor.GRAY).append(" - ").append(ItemUtil.getDisplayString(is))
.append("\n");
}
}
return text;
return text.toString();
}
case 2:
case 3:
@ -735,35 +795,40 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_CONSUME_ITEMS) != null) {
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS);
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, items);
if (items != null) {
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, items);
}
} else {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
final LinkedList<ItemStack> items = new LinkedList<>();
items.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, items);
}
ItemStackPrompt.clearSessionData(context);
}
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.GOLD + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, ItemsConsumeListPrompt.this);
@ -771,8 +836,6 @@ public class ItemsPrompt extends QuestsEditorNumericPrompt {
context.getForWhom().sendRawMessage(ChatColor.YELLOW + Lang.get("stageEditorObjectiveCleared"));
context.setSessionData(pref + CK.S_CONSUME_ITEMS, null);
return new ItemsConsumeListPrompt(context);
case 3:
return new ItemsPrompt(stageNum, context);
default:
return new ItemsPrompt(stageNum, context);
}

View File

@ -12,23 +12,6 @@
package me.blackvein.quests.convo.quests.objectives;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
@ -39,6 +22,25 @@ import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import org.bukkit.ChatColor;
import org.bukkit.DyeColor;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.entity.Tameable;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
public class MobsPrompt extends QuestsEditorNumericPrompt {
private final Quests plugin;
@ -108,45 +110,57 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_MOB_TYPES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
final StringBuilder text = new StringBuilder();
final LinkedList<String> mobs = (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_TYPES);
final LinkedList<Integer> amnts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_MOB_AMOUNTS);
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) {
for (int i = 0; i < mobs.size(); i++) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA
+ MiscUtil.getPrettyMobName(MiscUtil.getProperMobType(mobs.get(i))) + ChatColor.GRAY
+ " x " + ChatColor.DARK_AQUA + amnts.get(i);
}
} else {
final LinkedList<String> locs
= (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS);
final LinkedList<Integer> radii
= (LinkedList<Integer>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS);
final LinkedList<String> names
= (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES);
for (int i = 0; i < mobs.size(); i++) {
String msg = Lang.get("blocksWithin");
msg = msg.replace("<amount>", ChatColor.DARK_PURPLE + "" + radii.get(i) + ChatColor.GRAY);
text += "\n" + ChatColor.GRAY + " - " + ChatColor.BLUE
+ MiscUtil.getPrettyMobName(MiscUtil.getProperMobType(mobs.get(i))) + ChatColor.GRAY
+ " x " + ChatColor.DARK_AQUA + amnts.get(i) + ChatColor.GRAY + msg + ChatColor.YELLOW
+ names.get(i) + " (" + locs.get(i) + ")";
final LinkedList<Integer> amounts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_MOB_AMOUNTS);
if (mobs != null && amounts != null) {
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) {
for (int i = 0; i < mobs.size(); i++) {
if (MiscUtil.getProperMobType(mobs.get(i)) != null) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA)
.append(MiscUtil.getPrettyMobName(Objects.requireNonNull(MiscUtil
.getProperMobType(mobs.get(i))))).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.DARK_AQUA).append(amounts.get(i));
}
}
} else {
final LinkedList<String> locations
= (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS);
final LinkedList<Integer> radii
= (LinkedList<Integer>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS);
final LinkedList<String> names
= (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES);
if (locations != null && radii != null && names != null) {
for (int i = 0; i < mobs.size(); i++) {
String msg = Lang.get("blocksWithin");
msg = msg.replace("<amount>", ChatColor.DARK_PURPLE + "" + radii.get(i) + ChatColor.GRAY);
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(MiscUtil.getPrettyMobName(Objects.requireNonNull(MiscUtil
.getProperMobType(mobs.get(i))))).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.DARK_AQUA).append(amounts.get(i)).append(ChatColor.GRAY).append(msg)
.append(ChatColor.YELLOW).append(names.get(i)).append(" (").append(locations.get(i))
.append(")");
}
}
}
}
return text;
return text.toString();
}
case 2:
if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
final StringBuilder text = new StringBuilder();
final LinkedList<String> mobs = (LinkedList<String>) context.getSessionData(pref + CK.S_TAME_TYPES);
final LinkedList<Integer> amounts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_TAME_AMOUNTS);
for (int i = 0; i < mobs.size(); i++) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.BLUE + mobs.get(i) + ChatColor.GRAY + " x "
+ ChatColor.AQUA + amounts.get(i);
if (mobs != null && amounts != null) {
for (int i = 0; i < mobs.size(); i++) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(mobs.get(i)).append(ChatColor.GRAY).append(" x ").append(ChatColor.AQUA)
.append(amounts.get(i));
}
}
return text;
return text.toString();
}
case 3:
if (context.getSessionData(pref + CK.S_FISH) == null) {
@ -168,14 +182,18 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_SHEAR_COLORS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
final StringBuilder text = new StringBuilder();
final LinkedList<String> colors = (LinkedList<String>) context.getSessionData(pref + CK.S_SHEAR_COLORS);
final LinkedList<Integer> amounts = (LinkedList<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS);
for (int i = 0; i < colors.size(); i++) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.BLUE + colors.get(i) + ChatColor.GRAY + " x "
+ ChatColor.AQUA + amounts.get(i);
final LinkedList<Integer> amounts
= (LinkedList<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS);
if (colors != null && amounts != null) {
for (int i = 0; i < colors.size(); i++) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(colors.get(i)).append(ChatColor.GRAY).append(" x ").append(ChatColor.AQUA)
.append(amounts.get(i));
}
}
return text;
return text.toString();
}
case 6:
return "";
@ -185,22 +203,26 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
context.setSessionData(pref, Boolean.TRUE);
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + 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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new MobsKillListPrompt(context);
@ -247,6 +269,8 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
switch (number) {
case 1:
case 2:
case 4:
case 5:
return ChatColor.BLUE;
case 3:
if (context.getForWhom() instanceof Player) {
@ -254,9 +278,6 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
} else {
return ChatColor.GRAY;
}
case 4:
case 5:
return ChatColor.BLUE;
case 6:
return ChatColor.RED;
case 7:
@ -300,51 +321,69 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_MOB_TYPES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final String s : (List<String>) context.getSessionData(pref + CK.S_MOB_TYPES)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + s;
final StringBuilder text = new StringBuilder();
final List<String> mobTypes = (List<String>) context.getSessionData(pref + CK.S_MOB_TYPES);
if (mobTypes != null) {
for (final String s : mobTypes) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s);
}
}
return text;
return text.toString();
}
case 2:
if (context.getSessionData(pref + CK.S_MOB_AMOUNTS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final Integer i : (List<Integer>) context.getSessionData(pref + CK.S_MOB_AMOUNTS)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + i;
final StringBuilder text = new StringBuilder();
final List<Integer> mobAmounts = (List<Integer>) context.getSessionData(pref + CK.S_MOB_AMOUNTS);
if (mobAmounts != null) {
for (final Integer i : mobAmounts) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i);
}
}
return text;
return text.toString();
}
case 3:
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final String s : (List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + s;
final StringBuilder text = new StringBuilder();
final List<String> mobsKillLocations
= (List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS);
if (mobsKillLocations != null) {
for (final String s : mobsKillLocations) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s);
}
}
return text;
return text.toString();
}
case 4:
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final int i : (List<Integer>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + i;
final StringBuilder text = new StringBuilder();
final List<Integer> mobKillLocationsRadius
= (List<Integer>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS);
if (mobKillLocationsRadius != null) {
for (final int i : mobKillLocationsRadius) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i);
}
}
return text;
return text.toString();
}
case 5:
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final String s : (List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + s;
final StringBuilder text = new StringBuilder();
final List<String> mobKillLocationsNames
= (List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES);
if (mobKillLocationsNames != null) {
for (final String s : mobKillLocationsNames) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s);
}
}
return text;
return text.toString();
}
case 6:
case 7:
@ -355,21 +394,24 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + 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();
}
@SuppressWarnings("unchecked")
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new MobsTypesPrompt(context);
@ -398,33 +440,39 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, null);
return new MobsKillListPrompt(context);
case 7:
int one;
int two;
int three;
int four;
int five;
if (context.getSessionData(pref + CK.S_MOB_TYPES) != null) {
one = ((List<String>) context.getSessionData(pref + CK.S_MOB_TYPES)).size();
final int one;
final int two;
final int three;
final int four;
final int five;
final List<String> types = (List<String>) context.getSessionData(pref + CK.S_MOB_TYPES);
final List<Integer> amounts = (List<Integer>) context.getSessionData(pref + CK.S_MOB_AMOUNTS);
final List<String> locations = (List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS);
final List<Integer> radii
= (List<Integer>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS);
final List<String> names = (List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES);
if (types != null) {
one = types.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_MOB_AMOUNTS) != null) {
two = ((List<Integer>) context.getSessionData(pref + CK.S_MOB_AMOUNTS)).size();
if (amounts != null) {
two = amounts.size();
} else {
two = 0;
}
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) != null) {
three = ((List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS)).size();
if (locations != null) {
three = locations.size();
} else {
three = 0;
}
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS) != null) {
four = ((List<Integer>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS)).size();
if (radii != null) {
four = radii.size();
} else {
four = 0;
}
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES) != null) {
five = ((List<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES)).size();
if (names != null) {
five = names.size();
} else {
five = 0;
}
@ -466,35 +514,40 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
String mobs = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n";
final StringBuilder mobs = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
final List<EntityType> mobArr = new LinkedList<>(Arrays.asList(EntityType.values()));
final List<EntityType> toRemove = new LinkedList<EntityType>();
for (int i = 0; i < mobArr.size(); i++) {
final EntityType type = mobArr.get(i);
if (type.isAlive() == false || type.name().equals("PLAYER")) {
final List<EntityType> toRemove = new LinkedList<>();
for (final EntityType type : mobArr) {
if (!type.isAlive() || type.name().equals("PLAYER")) {
toRemove.add(type);
}
}
mobArr.removeAll(toRemove);
mobArr.sort(Comparator.comparing(EntityType::name));
for (int i = 0; i < mobArr.size(); i++) {
mobs += ChatColor.AQUA + MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name());
mobs.append(ChatColor.AQUA).append(MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()));
if (i < (mobArr.size() - 1)) {
mobs += ChatColor.GRAY + ", ";
mobs.append(ChatColor.GRAY).append(", ");
}
}
mobs += "\n" + ChatColor.YELLOW + getQueryText(context);
return mobs;
mobs.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return mobs.toString();
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<String> mobTypes = new LinkedList<String>();
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<String> mobTypes = new LinkedList<>();
for (final String s : input.split(" ")) {
if (MiscUtil.getProperMobType(s) != null) {
mobTypes.add(s);
@ -527,17 +580,23 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<Integer> mobAmounts = new LinkedList<Integer>();
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<Integer> mobAmounts = new LinkedList<>();
for (final String s : input.split(" ")) {
try {
final int i = Integer.parseInt(s);
@ -575,29 +634,37 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@SuppressWarnings("unchecked")
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
final Player player = (Player) context.getForWhom();
if (input.equalsIgnoreCase(Lang.get("cmdAdd"))) {
final Block block = plugin.getQuestFactory().getSelectedKillLocations().get(player.getUniqueId());
if (block != null) {
final Location loc = block.getLocation();
LinkedList<String> locs;
final LinkedList<String> locations;
if (context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) != null) {
locs = (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS);
locations = (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS);
} else {
locs = new LinkedList<String>();
locations = new LinkedList<>();
}
locs.add(ConfigUtil.getLocationInfo(loc));
context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locs);
if (locations != null) {
locations.add(ConfigUtil.getLocationInfo(loc));
}
context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS, locations);
final Map<UUID, Block> temp = plugin.getQuestFactory().getSelectedKillLocations();
temp.remove(player.getUniqueId());
plugin.getQuestFactory().setSelectedKillLocations(temp);
@ -634,17 +701,22 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<Integer> radii = new LinkedList<Integer>();
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<Integer> radii = new LinkedList<>();
for (final String s : input.split(" ")) {
try {
final int i = Integer.parseInt(s);
@ -683,18 +755,23 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<String> locNames = new LinkedList<String>();
locNames.addAll(Arrays.asList(input.split(Lang.get("charSemi"))));
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<String> locNames = new LinkedList<>(Arrays.asList(input.split(Lang.get("charSemi"))));
context.setSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES, locNames);
}
return new MobsKillListPrompt(context);
@ -718,17 +795,22 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
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"))) {
try {
final int i = Integer.parseInt(input);
if (i < 0) {
@ -766,17 +848,22 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
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"))) {
try {
final int i = Integer.parseInt(input);
if (i < 0) {
@ -854,21 +941,27 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_TAME_TYPES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final String s : (List<String>) context.getSessionData(pref + CK.S_TAME_TYPES)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + s;
final StringBuilder text = new StringBuilder();
final List<String> tameTypes = (List<String>) context.getSessionData(pref + CK.S_TAME_TYPES);
if (tameTypes != null) {
for (final String s : tameTypes) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s);
}
}
return text;
return text.toString();
}
case 2:
if (context.getSessionData(pref + CK.S_TAME_AMOUNTS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final Integer i : (List<Integer>) context.getSessionData(pref + CK.S_TAME_AMOUNTS)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + i;
final StringBuilder text = new StringBuilder();
final List<Integer> tameAmounts = (List<Integer>) context.getSessionData(pref + CK.S_TAME_AMOUNTS);
if (tameAmounts != null) {
for (final Integer i : tameAmounts) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i);
}
}
return text;
return text.toString();
}
case 3:
case 4:
@ -879,21 +972,24 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -\n";
for (int i = 1; i <= size; i++) {
text += getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i) + "\n";
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + getTitle(context) + " -\n");
for (int i = 1; i <= size; i++) {
text.append(getNumberColor(context, i)).append(ChatColor.BOLD).append(i).append(ChatColor.RESET)
.append(" - ").append(getSelectionText(context, i)).append(" ")
.append(getAdditionalText(context, i)).append("\n");
}
return text.toString();
}
@SuppressWarnings("unchecked")
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new MobsTameTypesPrompt(context);
@ -905,15 +1001,17 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData(pref + CK.S_TAME_AMOUNTS, null);
return new MobsTameListPrompt(context);
case 4:
int one;
int two;
if (context.getSessionData(pref + CK.S_TAME_TYPES) != null) {
one = ((List<String>) context.getSessionData(pref + CK.S_TAME_TYPES)).size();
final int one;
final int two;
final List<String> types = (List<String>) context.getSessionData(pref + CK.S_TAME_TYPES);
final List<Integer> amounts = (List<Integer>) context.getSessionData(pref + CK.S_TAME_AMOUNTS);
if (types != null) {
one = types.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_TAME_AMOUNTS) != null) {
two = ((List<Integer>) context.getSessionData(pref + CK.S_TAME_AMOUNTS)).size();
if (amounts != null) {
two = amounts.size();
} else {
two = 0;
}
@ -946,45 +1044,54 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
String mobs = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n";
final StringBuilder mobs = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
final List<EntityType> mobArr = new LinkedList<>(Arrays.asList(EntityType.values()));
final List<EntityType> toRemove = new LinkedList<EntityType>();
for (int i = 0; i < mobArr.size(); i++) {
final EntityType type = mobArr.get(i);
if (type.isAlive() == false || Tameable.class.isAssignableFrom(type.getEntityClass()) == false) {
final List<EntityType> toRemove = new LinkedList<>();
for (final EntityType type : mobArr) {
final Class<? extends Entity> ec = type.getEntityClass();
if (!type.isAlive() || (ec != null && !Tameable.class.isAssignableFrom(ec))) {
toRemove.add(type);
}
}
mobArr.removeAll(toRemove);
mobArr.sort(Comparator.comparing(EntityType::name));
for (int i = 0; i < mobArr.size(); i++) {
mobs += ChatColor.AQUA + MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name());
mobs.append(ChatColor.AQUA).append(MiscUtil.snakeCaseToUpperCamelCase(mobArr.get(i).name()));
if (i < (mobArr.size() - 1)) {
mobs += ChatColor.GRAY + ", ";
mobs.append(ChatColor.GRAY).append(", ");
}
}
mobs += "\n" + ChatColor.YELLOW + getQueryText(context);
return mobs;
mobs.append("\n").append(ChatColor.YELLOW).append(getQueryText(context));
return mobs.toString();
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<String> mobTypes = new LinkedList<String>();
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<String> mobTypes = new LinkedList<>();
for (final String s : input.split(" ")) {
if (MiscUtil.getProperMobType(s) != null) {
final EntityType type = MiscUtil.getProperMobType(s);
if (type.isAlive() || Tameable.class.isAssignableFrom(type.getEntityClass())) {
mobTypes.add(s);
context.setSessionData(pref + CK.S_TAME_TYPES, mobTypes);
} else {
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
+ Lang.get("stageEditorInvalidMob"));
return new MobsTameTypesPrompt(context);
if (type != null) {
final Class<? extends Entity> ec = type.getEntityClass();
if (type.isAlive() || (ec != null && Tameable.class.isAssignableFrom(ec))) {
mobTypes.add(s);
context.setSessionData(pref + CK.S_TAME_TYPES, mobTypes);
} else {
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
+ Lang.get("stageEditorInvalidMob"));
return new MobsTameTypesPrompt(context);
}
}
} else {
context.getForWhom().sendRawMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
@ -1014,17 +1121,23 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<Integer> mobAmounts = new LinkedList<Integer>();
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<Integer> mobAmounts = new LinkedList<>();
for (final String s : input.split(" ")) {
try {
final int i = Integer.parseInt(s);
@ -1103,21 +1216,27 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_SHEAR_COLORS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final String s : (List<String>) context.getSessionData(pref + CK.S_SHEAR_COLORS)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + s;
final StringBuilder text = new StringBuilder();
final List<String> shearColors = (List<String>) context.getSessionData(pref + CK.S_SHEAR_COLORS);
if (shearColors != null) {
for (final String s : shearColors) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(s);
}
}
return text;
return text.toString();
}
case 2:
if (context.getSessionData(pref + CK.S_SHEAR_AMOUNTS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "";
for (final Integer i : (List<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS)) {
text += "\n" + ChatColor.GRAY + " - " + ChatColor.AQUA + i;
final StringBuilder text = new StringBuilder();
final List<Integer> shearAmounts = (List<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS);
if (shearAmounts != null) {
for (final Integer i : shearAmounts) {
text.append("\n").append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i);
}
}
return text;
return text.toString();
}
case 3:
case 4:
@ -1128,21 +1247,25 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + 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();
}
@SuppressWarnings("unchecked")
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new MobsShearColorsPrompt(context);
@ -1154,15 +1277,17 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData(pref + CK.S_SHEAR_AMOUNTS, null);
return new MobsShearListPrompt(context);
case 4:
int one;
int two;
if (context.getSessionData(pref + CK.S_SHEAR_COLORS) != null) {
one = ((List<String>) context.getSessionData(pref + CK.S_SHEAR_COLORS)).size();
final int one;
final int two;
final List<String> colors = (List<String>) context.getSessionData(pref + CK.S_SHEAR_COLORS);
final List<Integer> amounts = (List<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS);
if (colors != null) {
one = colors.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_SHEAR_AMOUNTS) != null) {
two = ((List<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS)).size();
if (amounts != null) {
two = amounts.size();
} else {
two = 0;
}
@ -1195,26 +1320,32 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
String cols = ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " - \n";
final StringBuilder cols = new StringBuilder(ChatColor.LIGHT_PURPLE + "- " + getTitle(context) + " - \n");
final DyeColor[] colArr = DyeColor.values();
for (int i = 0; i < colArr.length; i++) {
if (i < (colArr.length - 1)) {
cols += MiscUtil.snakeCaseToUpperCamelCase(colArr[i].name()) + ", ";
cols.append(MiscUtil.snakeCaseToUpperCamelCase(colArr[i].name())).append(", ");
} else {
cols += MiscUtil.snakeCaseToUpperCamelCase(colArr[i].name()) + "\n";
cols.append(MiscUtil.snakeCaseToUpperCamelCase(colArr[i].name())).append("\n");
}
}
return cols + ChatColor.YELLOW + getQueryText(context);
return cols.toString() + ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<String> colors = new LinkedList<String>();
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<String> colors = new LinkedList<>();
for (final String s : input.split(" ")) {
if (MiscUtil.getProperDyeColor(s) != null) {
colors.add(s);
@ -1247,17 +1378,23 @@ public class MobsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
final LinkedList<Integer> shearAmounts = new LinkedList<Integer>();
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final LinkedList<Integer> shearAmounts = new LinkedList<>();
for (final String s : input.split(" ")) {
try {
final int i = Integer.parseInt(s);

View File

@ -26,6 +26,7 @@ import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.LinkedList;
@ -96,18 +97,21 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<Integer> npcs = (LinkedList<Integer>) context.getSessionData(pref + CK.S_DELIVERY_NPCS);
final LinkedList<ItemStack> items
= (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS);
for (int i = 0; i < npcs.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE + ItemUtil.getName(items.get(i))
+ ChatColor.GRAY + " x " + ChatColor.AQUA + items.get(i).getAmount() + ChatColor.GRAY
+ " " + Lang.get("to") + " " + ChatColor.DARK_AQUA
+ plugin.getDependencies().getCitizens().getNPCRegistry().getById(npcs.get(i)).getName()
+ "\n";
if (npcs != null && items != null) {
for (int i = 0; i < npcs.size(); i++) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(ItemUtil.getName(items.get(i))).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(items.get(i).getAmount()).append(ChatColor.GRAY)
.append(" ").append(Lang.get("to")).append(" ").append(ChatColor.DARK_AQUA)
.append(plugin.getDependencies().getCitizens().getNPCRegistry()
.getById(npcs.get(i)).getName()).append("\n");
}
}
return text;
return text.toString();
}
} else {
return ChatColor.GRAY + " (" + Lang.get("notInstalled") + ")";
@ -117,15 +121,17 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<Integer> npcs
= (LinkedList<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO);
for (int i = 0; i < npcs.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE
+ plugin.getDependencies().getCitizens().getNPCRegistry().getById(npcs.get(i)).getName()
+ "\n";
if (npcs != null) {
for (final Integer npc : npcs) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(plugin.getDependencies().getCitizens().getNPCRegistry()
.getById(npc).getName()).append("\n");
}
}
return text;
return text.toString();
}
} else {
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
@ -135,16 +141,19 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
final StringBuilder text = new StringBuilder("\n");
final LinkedList<Integer> npcs = (LinkedList<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL);
final LinkedList<Integer> amounts
= (LinkedList<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS);
for (int i = 0; i < npcs.size(); i++) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE
+ plugin.getDependencies().getCitizens().getNPCRegistry().getById(npcs.get(i)).getName()
+ ChatColor.GRAY + " x " + ChatColor.AQUA + amounts.get(i) + "\n";
if (npcs != null && amounts != null) {
for (int i = 0; i < npcs.size(); i++) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE)
.append(plugin.getDependencies().getCitizens().getNPCRegistry()
.getById(npcs.get(i)).getName()).append(ChatColor.GRAY).append(" x ")
.append(ChatColor.AQUA).append(amounts.get(i)).append("\n");
}
}
return text;
return text.toString();
}
} else {
return ChatColor.GRAY + "(" + Lang.get("notInstalled") + ")";
@ -157,22 +166,26 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
context.setSessionData(pref, Boolean.TRUE);
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + 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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
if (plugin.getDependencies().getCitizens() != null) {
@ -267,32 +280,46 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final ItemStack is : (List<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS)) {
text += ChatColor.GRAY + " - " + ItemUtil.getDisplayString(is) + "\n";
final StringBuilder text = new StringBuilder("\n");
final List<ItemStack> deliveryItems
= (List<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS);
if (deliveryItems != null) {
for (final ItemStack is : deliveryItems) {
text.append(ChatColor.GRAY).append(" - ").append(ItemUtil.getDisplayString(is))
.append("\n");
}
}
return text;
return text.toString();
}
case 2:
if (context.getSessionData(pref + CK.S_DELIVERY_NPCS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final int i : (List<Integer>) context.getSessionData(pref + CK.S_DELIVERY_NPCS)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + i + " ("
+ plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName() + ")\n";
final StringBuilder text = new StringBuilder("\n");
final List<Integer> deliveryNpcs = (List<Integer>) context.getSessionData(pref + CK.S_DELIVERY_NPCS);
if (deliveryNpcs != null) {
for (final int i : deliveryNpcs) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append(i).append(" (")
.append(plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName())
.append(")\n");
}
}
return text;
return text.toString();
}
case 3:
if (context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final String s : (List<String>) context.getSessionData(pref + CK.S_DELIVERY_MESSAGES)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA + "\"" + s + "\"\n";
final StringBuilder text = new StringBuilder("\n");
final List<String> deliveryMessages
= (List<String>) context.getSessionData(pref + CK.S_DELIVERY_MESSAGES);
if (deliveryMessages != null) {
for (final String s : deliveryMessages) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA).append("\"").append(s)
.append("\"\n");
}
}
return text;
return text.toString();
}
case 4:
case 5:
@ -304,36 +331,42 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
@SuppressWarnings("unchecked")
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
// Check/add newly made item
if (context.getSessionData("tempStack") != null) {
if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null) {
final List<ItemStack> itemRews = (List<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS);
itemRews.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_DELIVERY_ITEMS, itemRews);
final List<ItemStack> itemRew
= (List<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS);
if (itemRew != null) {
itemRew.add((ItemStack) context.getSessionData("tempStack"));
}
context.setSessionData(pref + CK.S_DELIVERY_ITEMS, itemRew);
} else {
final LinkedList<ItemStack> itemRews = new LinkedList<ItemStack>();
final LinkedList<ItemStack> itemRews = new LinkedList<>();
itemRews.add((ItemStack) context.getSessionData("tempStack"));
context.setSessionData(pref + CK.S_DELIVERY_ITEMS, itemRews);
}
ItemStackPrompt.clearSessionData(context);
}
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + 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();
}
@SuppressWarnings("unchecked")
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new ItemStackPrompt(context, NpcsDeliveryListPrompt.this);
@ -348,15 +381,17 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, null);
return new NpcsDeliveryListPrompt(context);
case 5:
int one;
int two;
if (context.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null) {
one = ((List<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS)).size();
final int one;
final int two;
final List<ItemStack> items = (List<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS);
final List<Integer> npcs = (List<Integer>) context.getSessionData(pref + CK.S_DELIVERY_NPCS);
if (items != null) {
one = items.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_DELIVERY_NPCS) != null) {
two = ((List<Integer>) context.getSessionData(pref + CK.S_DELIVERY_NPCS)).size();
if (npcs != null) {
two = npcs.size();
} else {
two = 0;
}
@ -394,7 +429,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
final Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.add(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp);
@ -402,13 +437,16 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final String[] args = input.split(" ");
final LinkedList<Integer> npcs = new LinkedList<Integer>();
final LinkedList<Integer> npcs = new LinkedList<>();
for (final String s : args) {
try {
final Integer i = Integer.parseInt(s);
final int i = Integer.parseInt(s);
if (plugin.getDependencies().getCitizens().getNPCRegistry().getById(i) != null) {
npcs.add(i);
} else {
@ -447,16 +485,18 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
return Lang.get("stageEditorDeliveryMessagesPrompt");
}
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
return ChatColor.YELLOW + getQueryText(context) + "\n" + ChatColor.GOLD + Lang.get("stageEditorNPCNote");
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final String[] args = input.split(Lang.get("charSemi"));
final LinkedList<String> messages = new LinkedList<String>();
messages.addAll(Arrays.asList(args));
final LinkedList<String> messages = new LinkedList<>(Arrays.asList(args));
context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, messages);
}
return new NpcsDeliveryListPrompt(context);
@ -480,7 +520,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
final Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.add(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp);
@ -489,14 +529,16 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
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"))) {
final String[] args = input.split(" ");
final LinkedList<Integer> npcs = new LinkedList<Integer>();
final LinkedList<Integer> npcs = new LinkedList<>();
for (final String s : args) {
try {
final Integer i = Integer.parseInt(s);
final int i = Integer.parseInt(s);
if (plugin.getDependencies().getCitizens().getNPCRegistry().getById(i) != null) {
npcs.add(i);
} else {
@ -581,13 +623,17 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final Integer i : (List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL)) {
text += ChatColor.GRAY + " - " + ChatColor.AQUA
+ plugin.getDependencies().getCitizens().getNPCRegistry().getById(i).getName()
+ ChatColor.DARK_AQUA + " (" + i + ")\n";
final StringBuilder text = new StringBuilder("\n");
final List<Integer> npcsToKill = (List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL);
if (npcsToKill != null) {
for (final Integer i : npcsToKill) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.AQUA)
.append(plugin.getDependencies().getCitizens().getNPCRegistry()
.getById(i).getName()).append(ChatColor.DARK_AQUA).append(" (").append(i)
.append(")\n");
}
}
return text;
return text.toString();
}
} else {
return ChatColor.GRAY + " (" + Lang.get("notInstalled") + ")";
@ -596,11 +642,15 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
if (context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
String text = "\n";
for (final Integer i : (List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS)) {
text += ChatColor.GRAY + " - " + ChatColor.BLUE + i + "\n";
final StringBuilder text = new StringBuilder("\n");
final List<Integer> npcsToKillAmounts
= (List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS);
if (npcsToKillAmounts != null) {
for (final Integer i : npcsToKillAmounts) {
text.append(ChatColor.GRAY).append(" - ").append(ChatColor.BLUE).append(i).append("\n");
}
}
return text;
return text.toString();
}
case 3:
case 4:
@ -611,21 +661,25 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.AQUA + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.AQUA + "- " + 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();
}
@SuppressWarnings("unchecked")
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 1:
return new NpcIdsToKillPrompt(context);
@ -637,15 +691,18 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, null);
return new NpcsKillListPrompt(context);
case 4:
int one;
int two;
if (context.getSessionData(pref + CK.S_NPCS_TO_KILL) != null) {
one = ((List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL)).size();
final int one;
final int two;
final List<Integer> kill = (List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL);
final List<Integer> killAmounts
= (List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS);
if (kill != null) {
one = kill.size();
} else {
one = 0;
}
if (context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) != null) {
two = ((List<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS)).size();
if (killAmounts != null) {
two = killAmounts.size();
} else {
two = 0;
}
@ -678,7 +735,7 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final ConversationContext context) {
final Set<UUID> temp = plugin.getQuestFactory().getSelectingNpcs();
temp.add(((Player) context.getForWhom()).getUniqueId());
plugin.getQuestFactory().setSelectingNpcs(temp);
@ -686,13 +743,16 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final String[] args = input.split(" ");
final LinkedList<Integer> npcs = new LinkedList<Integer>();
final LinkedList<Integer> npcs = new LinkedList<>();
for (final String s : args) {
try {
final Integer i = Integer.parseInt(s);
final int i = Integer.parseInt(s);
if (plugin.getDependencies().getCitizens().getNPCRegistry().getById(i) != null) {
npcs.add(i);
} else {
@ -732,15 +792,18 @@ public class NpcsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
final String[] args = input.split(" ");
final LinkedList<Integer> amounts = new LinkedList<Integer>();
final LinkedList<Integer> amounts = new LinkedList<>();
for (final String s : args) {
try {
if (Integer.parseInt(s) > 0) {

View File

@ -24,6 +24,9 @@ import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromp
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.Lang;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
public class OptionsPrompt extends QuestsEditorNumericPrompt {
@ -45,14 +48,14 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("optionsTitle").replace("<quest>", (String) context.getSessionData(CK.Q_NAME));
return Lang.get("optionsTitle").replace("<quest>", (String) Objects
.requireNonNull(context.getSessionData(CK.Q_NAME)));
}
@Override
public ChatColor getNumberColor(final ConversationContext context, final int number) {
switch (number) {
case 1:
return ChatColor.BLUE;
case 2:
return ChatColor.BLUE;
case 3:
@ -82,22 +85,25 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.DARK_GREEN + getTitle(context)
.replace((String) context.getSessionData(CK.Q_NAME), ChatColor.AQUA
+ (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_GREEN);
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.DARK_GREEN + getTitle(context)
.replace((String) Objects.requireNonNull(context.getSessionData(CK.Q_NAME)), ChatColor.AQUA
+ (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_GREEN));
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));
}
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch (input.intValue()) {
case 1:
return new OptionsGeneralPrompt(context);
@ -148,18 +154,22 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + Lang.get("optBooleanPrompt").replace("<true>", Lang.get("true"))
.replace("<false>", Lang.get("false"));
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
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.startsWith("t") || input.equalsIgnoreCase(Lang.get("true"))
|| input.equalsIgnoreCase(Lang.get("yesWord"))) {
context.setSessionData(tempKey, true);
@ -229,7 +239,6 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
case 4:
return ChatColor.GRAY + Lang.get("quests");
case 5:
return "";
case 6:
return "";
default:
@ -238,9 +247,12 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
String text = Lang.get("optNumberPrompt");
text += "\n" + ChatColor.GRAY + "\u2515 " + ChatColor.GOLD + "1" + ChatColor.RESET + " = " + ChatColor.GRAY
@ -255,9 +267,11 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
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"))) {
try {
final int i = Integer.parseInt(input);
context.setSessionData(tempKey, i);
@ -289,17 +303,22 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
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"))) {
try {
final double d = Double.parseDouble(input);
context.setSessionData(tempKey, d);
@ -366,40 +385,40 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
public String getAdditionalText(final ConversationContext context, final int number) {
switch (number) {
case 1:
if (context.getSessionData(CK.OPT_ALLOW_COMMANDS) == null) {
final Boolean commandsOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_COMMANDS);
if (commandsOpt == null) {
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 + ")";
} else {
final boolean commandsOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_COMMANDS);
return ChatColor.GRAY + "(" + (commandsOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(commandsOpt)) : ChatColor.RED
return ChatColor.GRAY + "(" + (commandsOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(commandsOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(commandsOpt))) + ChatColor.GRAY + ")";
}
case 2:
if (context.getSessionData(CK.OPT_ALLOW_QUITTING) == null) {
final Boolean quittingOpt = (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING);
if (quittingOpt == null) {
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);
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 ignoreOpt = (Boolean) context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH);
if (ignoreOpt == 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 + ")";
return ChatColor.GRAY + "(" + (ignoreOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(ignoreOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(ignoreOpt))) + ChatColor.GRAY + ")";
}
case 4:
return "";
@ -409,20 +428,24 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.DARK_GREEN + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.DARK_GREEN + "- " + 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
public Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
public Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch (input.intValue()) {
case 1:
tempKey = CK.OPT_ALLOW_COMMANDS;
@ -472,15 +495,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.BLUE;
case 5:
return ChatColor.BLUE;
case 6:
return ChatColor.BLUE;
case 7:
@ -516,65 +534,65 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
public String getAdditionalText(final ConversationContext context, final int number) {
switch (number) {
case 1:
if (context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) == null) {
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 + ")";
} else {
final boolean dungeonsOpt = (Boolean) context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN);
return ChatColor.GRAY + "(" + (dungeonsOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(dungeonsOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(dungeonsOpt))) + ChatColor.GRAY + ")";
}
case 2:
if (context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) == null) {
final Boolean partiesOpt = (Boolean) context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN);
if (partiesOpt == null) {
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 + ")";
} else {
final boolean partiesOpt = (Boolean) context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN);
return ChatColor.GRAY + "(" + (partiesOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(partiesOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(partiesOpt))) + ChatColor.GRAY + ")";
}
case 3:
if (context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) == null) {
final Integer shareOpt = (Integer) context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL);
if (shareOpt == null) {
final int defaultOpt = new Options().getShareProgressLevel();
return ChatColor.GRAY + "(" + ChatColor.AQUA + String.valueOf(defaultOpt) + ChatColor.GRAY + ")";
return ChatColor.GRAY + "(" + ChatColor.AQUA + defaultOpt + ChatColor.GRAY + ")";
} else {
final int shareOpt = (Integer) context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL);
return ChatColor.GRAY + "(" + ChatColor.AQUA + String.valueOf(shareOpt) + ChatColor.GRAY + ")";
return ChatColor.GRAY + "(" + ChatColor.AQUA + shareOpt + ChatColor.GRAY + ")";
}
case 4:
if (context.getSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY) == null) {
final Boolean requireOpt = (Boolean) context.getSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY);
if (requireOpt == null) {
final boolean defaultOpt = new Options().canShareSameQuestOnly();
return ChatColor.GRAY + "(" + (defaultOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
} else {
final boolean requireOpt = (Boolean) context.getSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY);
return ChatColor.GRAY + "(" + (requireOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(requireOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(requireOpt))) + ChatColor.GRAY + ")";
}
case 5:
if (context.getSessionData(CK.OPT_SHARE_DISTANCE) == null) {
final Double distanceOpt = (Double) context.getSessionData(CK.OPT_SHARE_DISTANCE);
if (distanceOpt == null) {
final double defaultOpt = new Options().getShareDistance();
return ChatColor.GRAY + "(" + ChatColor.AQUA + String.valueOf(defaultOpt) + ChatColor.GRAY + ")";
return ChatColor.GRAY + "(" + ChatColor.AQUA + defaultOpt + ChatColor.GRAY + ")";
} else {
final double shareOpt = (Double) context.getSessionData(CK.OPT_SHARE_DISTANCE);
return ChatColor.GRAY + "(" + ChatColor.AQUA + String.valueOf(shareOpt) + ChatColor.GRAY + ")";
return ChatColor.GRAY + "(" + ChatColor.AQUA + distanceOpt + ChatColor.GRAY + ")";
}
case 6:
if (context.getSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS) == null) {
final Boolean handleOpt = (Boolean) context.getSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS);
if (handleOpt == null) {
final boolean defaultOpt = new Options().canHandleOfflinePlayers();
return ChatColor.GRAY + "("+ (defaultOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(defaultOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(defaultOpt))) + ChatColor.GRAY + ")";
} else {
final boolean handleOpt = (Boolean) context.getSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS);
return ChatColor.GRAY + "(" + (handleOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(handleOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(handleOpt))) + ChatColor.GRAY + ")";
@ -587,20 +605,24 @@ public class OptionsPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.DARK_GREEN + "- " + getTitle(context) + " -";
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() == null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final StringBuilder text = new StringBuilder(ChatColor.DARK_GREEN + "- " + 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
public Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
public Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch (input.intValue()) {
case 1:
tempKey = CK.OPT_USE_DUNGEONSXL_PLUGIN;

View File

@ -12,26 +12,26 @@
package me.blackvein.quests.convo.quests.planner;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
import me.blackvein.quests.convo.quests.QuestsEditorStringPrompt;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenNumericPromptEvent;
import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPromptEvent;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.jetbrains.annotations.NotNull;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
public class DateTimePrompt extends QuestsEditorNumericPrompt {
private final Prompt oldPrompt;
private String source = "";
private final String source;
public DateTimePrompt(final ConversationContext context, final Prompt old, final String origin) {
super(context);
@ -53,31 +53,30 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
public String getDataText(final ConversationContext context) {
String dateData = "";
if (context.getSessionData("tempYear") == null
|| context.getSessionData("tempMonth") == null
|| context.getSessionData("tempDay") == null
|| context.getSessionData("tempHour") == null
|| context.getSessionData("tempMinute") == null
|| context.getSessionData("tempSecond") == null) {
final Integer year = (Integer) context.getSessionData("tempYear");
final Integer month = (Integer) context.getSessionData("tempMonth");
final Integer day = (Integer) context.getSessionData("tempDay");
final Integer hour = (Integer) context.getSessionData("tempHour");
final Integer minute = (Integer) context.getSessionData("tempMinute");
final Integer second = (Integer) context.getSessionData("tempSecond");
if (year == null || month == null || day == null || hour == null || minute == null || second == null) {
return dateData;
}
final Calendar cal = Calendar.getInstance();
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/dd/MM");
final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
cal.set((Integer) context.getSessionData("tempYear"), (Integer) context.getSessionData("tempMonth"),
(Integer) context.getSessionData("tempDay"), (Integer) context.getSessionData("tempHour"),
(Integer) context.getSessionData("tempMinute"), (Integer) context.getSessionData("tempSecond"));
cal.set(year, month, day, hour, minute, second);
dateData += ChatColor.DARK_AQUA + dateFormat.format(cal.getTime()) + " ";
dateData += ChatColor.AQUA + timeFormat.format(cal.getTime()) + " ";
cal.setTimeZone(TimeZone.getTimeZone((String) context.getSessionData("tempZone")));
final String[] iso = Lang.getISO().split("-");
final Locale loc = new Locale(iso[0], iso[1]);
final Double hour = (double) (cal.getTimeZone().getRawOffset() / 60 / 60 / 1000);
final String[] sep = String.valueOf(hour).replace("-", "").split("\\.");
final Double zonedHour = (double) (cal.getTimeZone().getRawOffset() / 60 / 60 / 1000);
final String[] sep = String.valueOf(zonedHour).replace("-", "").split("\\.");
final DecimalFormat zoneFormat = new DecimalFormat("00");
dateData += ChatColor.LIGHT_PURPLE + "UTC" + (hour < 0 ? "-":"+") + zoneFormat.format(Integer.valueOf(sep[0]))
dateData += ChatColor.LIGHT_PURPLE + "UTC" + (zonedHour < 0 ? "-":"+") + zoneFormat.format(Integer.valueOf(sep[0]))
+ ":" + zoneFormat.format(Integer.valueOf(sep[1])) + ChatColor.GREEN + " ("
+ cal.getTimeZone().getDisplayName(loc) + ")";
return dateData;
@ -144,9 +143,9 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
+ ChatColor.GRAY + ")";
}
case 2:
if (context.getSessionData("tempMonth") != null) {
return ChatColor.GRAY + "(" + ChatColor.AQUA
+ ((Integer) context.getSessionData("tempMonth") + 1) + ChatColor.GRAY + ")";
final Integer month = (Integer) context.getSessionData("tempMonth");
if (month != null) {
return ChatColor.GRAY + "(" + ChatColor.AQUA + (month + 1) + ChatColor.GRAY + ")";
}
case 3:
if (context.getSessionData("tempDay") != null) {
@ -183,26 +182,28 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
String text = ChatColor.AQUA + getTitle(context) + "\n";
final StringBuilder text = new StringBuilder(ChatColor.AQUA + getTitle(context) + "\n");
if (context.getSessionData("tempYear") != null && context.getSessionData("tempMonth") != null
&& context.getSessionData("tempDay") != null && context.getSessionData("tempHour") != null
&& context.getSessionData("tempMinute") != null && context.getSessionData("tempSecond") != null
&& context.getSessionData("tempZone") != null) {
text += getDataText(context);
text.append(getDataText(context));
}
for (int i = 0; i <= size - 1; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, 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;
return text.toString();
}
@Override
protected Prompt acceptValidatedInput(final ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch(input.intValue()) {
case 0:
final Calendar cal = Calendar.getInstance();
@ -242,12 +243,12 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
&& context.getSessionData("tempDay") != null && context.getSessionData("tempHour") != null
&& context.getSessionData("tempMinute") != null && context.getSessionData("tempSecond") != null
&& context.getSessionData("tempZone") != null) {
final int year = (Integer) context.getSessionData("tempYear");
final int month = (Integer) context.getSessionData("tempMonth");
final int day = (Integer) context.getSessionData("tempDay");
final int hour = (Integer) context.getSessionData("tempHour");
final int minute = (Integer) context.getSessionData("tempMinute");
final int second = (Integer) context.getSessionData("tempSecond");
final Integer year = (Integer) context.getSessionData("tempYear");
final Integer month = (Integer) context.getSessionData("tempMonth");
final Integer day = (Integer) context.getSessionData("tempDay");
final Integer hour = (Integer) context.getSessionData("tempHour");
final Integer minute = (Integer) context.getSessionData("tempMinute");
final Integer second = (Integer) context.getSessionData("tempSecond");
final String zone = (String) context.getSessionData("tempZone");
final String date = day + ":" + month + ":" + year + ":"
+ hour + ":" + minute + ":" + second + ":" + zone;
@ -297,16 +298,22 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int amt = Integer.parseInt(input);
if (amt < 1000 || amt > 9999) {
@ -344,16 +351,22 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int amt = Integer.parseInt(input);
if (amt < 1 || amt > 12) {
@ -391,16 +404,22 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int amt = Integer.parseInt(input);
if (amt < 1 || amt > 31) {
@ -438,16 +457,22 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int amt = Integer.parseInt(input);
if (amt < 0 || amt > 23) {
@ -485,16 +510,22 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int amt = Integer.parseInt(input);
if (amt < 0 || amt > 59) {
@ -532,16 +563,22 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final int amt = Integer.parseInt(input);
if (amt < 0 || amt > 59) {
@ -579,16 +616,22 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
try {
final double amt = Double.parseDouble(input.replace("UTC", "").replace(":", "."));
if (amt < -12.0 || amt > 14.0) {
@ -636,21 +679,27 @@ public class DateTimePrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.LIGHT_PURPLE + getTitle(context) + "\n";
for (final String z : zones) {
text += ChatColor.GREEN + z + ", ";
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);
}
text = text.substring(0, text.length() - 2);
StringBuilder text = new StringBuilder(ChatColor.LIGHT_PURPLE + getTitle(context) + "\n");
for (final String z : zones) {
text.append(ChatColor.GREEN).append(z).append(", ");
}
text = new StringBuilder(text.substring(0, text.length() - 2));
return text + "\n" + ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (!input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
for (final String z : zones) {
if (z.toLowerCase().startsWith(input.toLowerCase())) {
context.setSessionData("tempZone", z);

View File

@ -12,16 +12,6 @@
package me.blackvein.quests.convo.quests.planner;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import me.blackvein.quests.Planner;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.quests.QuestsEditorNumericPrompt;
@ -31,6 +21,17 @@ import me.blackvein.quests.events.editor.quests.QuestsEditorPostOpenStringPrompt
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import org.bukkit.ChatColor;
import org.bukkit.conversations.ConversationContext;
import org.bukkit.conversations.Prompt;
import org.jetbrains.annotations.NotNull;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.util.Objects;
import java.util.TimeZone;
public class PlannerPrompt extends QuestsEditorNumericPrompt {
@ -50,7 +51,8 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
@Override
public String getTitle(final ConversationContext context) {
return Lang.get("plannerTitle").replace("<quest>", (String) context.getSessionData(CK.Q_NAME));
return Lang.get("plannerTitle").replace("<quest>", (String) Objects
.requireNonNull(context.getSessionData(CK.Q_NAME)));
}
@Override
@ -58,6 +60,8 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
switch (number) {
case 1:
case 2:
case 4:
case 5:
return ChatColor.BLUE;
case 3:
if (context.getSessionData(CK.PLN_START_DATE) == null || context.getSessionData(CK.PLN_END_DATE) == null) {
@ -65,9 +69,6 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
} else {
return ChatColor.BLUE;
}
case 4:
case 5:
return ChatColor.BLUE;
case 6:
return ChatColor.GREEN;
default:
@ -103,48 +104,49 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
public String getAdditionalText(final ConversationContext context, final int number) {
switch (number) {
case 1:
if (context.getSessionData(CK.PLN_START_DATE) == null) {
final String start = (String) context.getSessionData(CK.PLN_START_DATE);
if (start == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
return "\n" + ChatColor.YELLOW + " - " + getPrettyDate((String) context.getSessionData(CK.PLN_START_DATE));
return "\n" + ChatColor.YELLOW + " - " + getPrettyDate(start);
}
case 2:
if (context.getSessionData(CK.PLN_END_DATE) == null) {
final String end = (String) context.getSessionData(CK.PLN_END_DATE);
if (end == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
return "\n" + ChatColor.YELLOW + " - "
+ getPrettyDate((String) context.getSessionData(CK.PLN_END_DATE));
+ getPrettyDate(end);
}
case 3:
final Long repeat = (Long) context.getSessionData(CK.PLN_REPEAT_CYCLE);
if (context.getSessionData(CK.PLN_START_DATE) == null || context.getSessionData(CK.PLN_END_DATE) == null) {
return ChatColor.GRAY + "(" + Lang.get("stageEditorOptional") + ")";
} else {
if (context.getSessionData(CK.PLN_REPEAT_CYCLE) == null) {
if (repeat == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
return ChatColor.YELLOW + "("
+ MiscUtil.getTime((Long) context.getSessionData(CK.PLN_REPEAT_CYCLE))
+ ChatColor.RESET + ChatColor.YELLOW + ")";
return ChatColor.YELLOW + "(" + MiscUtil.getTime(repeat) + ChatColor.RESET + ChatColor.YELLOW + ")";
}
}
case 4:
if (context.getSessionData(CK.PLN_COOLDOWN) == null) {
final Long cooldown = (Long) context.getSessionData(CK.PLN_COOLDOWN);
if (cooldown == null) {
return ChatColor.GRAY + "(" + Lang.get("noneSet") + ")";
} else {
return ChatColor.YELLOW + "(" + MiscUtil.getTime((Long) context.getSessionData(CK.PLN_COOLDOWN))
+ ChatColor.RESET + ChatColor.YELLOW + ")";
return ChatColor.YELLOW + "(" + MiscUtil.getTime(cooldown) + ChatColor.RESET + ChatColor.YELLOW + ")";
}
case 5:
if (context.getSessionData(CK.PLN_OVERRIDE) == null) {
final Boolean override = (Boolean) context.getSessionData(CK.PLN_OVERRIDE);
if (override == null) {
final boolean defaultOpt = new Planner().getOverride();
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.PLN_OVERRIDE);
return ChatColor.GRAY + "(" + (quittingOpt ? ChatColor.GREEN
+ Lang.get(String.valueOf(quittingOpt)) : ChatColor.RED
+ Lang.get(String.valueOf(quittingOpt))) + ChatColor.GRAY + ")";
return ChatColor.GRAY + "(" + (override ? ChatColor.GREEN
+ Lang.get(String.valueOf(override)) : ChatColor.RED
+ Lang.get(String.valueOf(override))) + ChatColor.GRAY + ")";
}
case 6:
return "";
@ -154,22 +156,26 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenNumericPromptEvent event = new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
String text = ChatColor.DARK_AQUA + getTitle(context).replace((String) context
.getSessionData(CK.Q_NAME), ChatColor.AQUA + (String) context.getSessionData(CK.Q_NAME)
+ ChatColor.DARK_AQUA);
for (int i = 1; i <= size; i++) {
text += "\n" + getNumberColor(context, i) + "" + ChatColor.BOLD + i + ChatColor.RESET + " - "
+ getSelectionText(context, i) + " " + getAdditionalText(context, i);
public @NotNull String getPromptText(final @NotNull ConversationContext context) {
if (context.getPlugin() != null) {
final QuestsEditorPostOpenNumericPromptEvent event
= new QuestsEditorPostOpenNumericPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
}
return text;
final String name = Objects.requireNonNull((String) context.getSessionData(CK.Q_NAME));
final StringBuilder text = new StringBuilder(ChatColor.DARK_AQUA + getTitle(context)
.replace(name, ChatColor.AQUA + (String) context.getSessionData(CK.Q_NAME) + ChatColor.DARK_AQUA));
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 ConversationContext context, final Number input) {
protected Prompt acceptValidatedInput(final @NotNull ConversationContext context, final Number input) {
switch (input.intValue()) {
case 1:
return new DateTimePrompt(context, PlannerPrompt.this, "start");
@ -210,15 +216,21 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new PlannerPrompt(context);
}
@ -226,7 +238,7 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
context.setSessionData(CK.PLN_REPEAT_CYCLE, null);
return new PlannerPrompt(context);
}
long delay;
final long delay;
try {
final long l = Long.parseLong(input);
delay = l * 1000;
@ -261,15 +273,21 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
return ChatColor.YELLOW + getQueryText(context);
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
public Prompt acceptInput(final @NotNull ConversationContext context, final String input) {
if (input == null) {
return null;
}
if (input.equalsIgnoreCase(Lang.get("cmdCancel"))) {
return new PlannerPrompt(context);
}
@ -277,7 +295,7 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
context.setSessionData(CK.PLN_COOLDOWN, null);
return new PlannerPrompt(context);
}
long delay;
final long delay;
try {
final long l = Long.parseLong(input);
delay = l * 1000;
@ -335,9 +353,12 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
}
@Override
public String getPromptText(final ConversationContext context) {
final QuestsEditorPostOpenStringPromptEvent event = new QuestsEditorPostOpenStringPromptEvent(context, this);
context.getPlugin().getServer().getPluginManager().callEvent(event);
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);
}
String text = Lang.get("optBooleanPrompt");
text = text.replace("<true>", Lang.get("true"));
@ -346,9 +367,11 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
}
@Override
public Prompt acceptInput(final ConversationContext context, final String input) {
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false
&& input.equalsIgnoreCase(Lang.get("cmdClear")) == false) {
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.startsWith("t") || input.equalsIgnoreCase(Lang.get("true"))
|| input.equalsIgnoreCase(Lang.get("yesWord"))) {
context.setSessionData(CK.PLN_OVERRIDE, true);
@ -372,12 +395,12 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/dd/MM");
final SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
final String[] date = formattedDate.split(":");
final int day = Integer.valueOf(date[0]);
final int month = Integer.valueOf(date[1]);
final int year = Integer.valueOf(date[2]);
final int hour = Integer.valueOf(date[3]);
final int minute = Integer.valueOf(date[4]);
final int second = Integer.valueOf(date[5]);
final int day = Integer.parseInt(date[0]);
final int month = Integer.parseInt(date[1]);
final int year = Integer.parseInt(date[2]);
final int hour = Integer.parseInt(date[3]);
final int minute = Integer.parseInt(date[4]);
final int second = Integer.parseInt(date[5]);
cal.set(year, month, day, hour, minute, second);
String output = ChatColor.DARK_AQUA + dateFormat.format(cal.getTime());
@ -387,10 +410,10 @@ public class PlannerPrompt extends QuestsEditorNumericPrompt {
cal.setTimeZone(tz);
final String[] iso = Lang.getISO().split("-");
final Locale loc = iso.length > 1 ? new Locale(iso[0], iso[1]) : new Locale(iso[0]);
final Double zhour = (double) (cal.getTimeZone().getRawOffset() / 60 / 60 / 1000);
final String[] sep = String.valueOf(zhour).replace("-", "").split("\\.");
final Double zonehour = (double) (cal.getTimeZone().getRawOffset() / 60 / 60 / 1000);
final String[] sep = String.valueOf(zonehour).replace("-", "").split("\\.");
final DecimalFormat zoneFormat = new DecimalFormat("00");
output += ChatColor.LIGHT_PURPLE + " UTC" + (zhour < 0 ? "-":"+") + zoneFormat.format(Integer.valueOf(sep[0]))
output += ChatColor.LIGHT_PURPLE + " UTC" + (zonehour < 0 ? "-":"+") + zoneFormat.format(Integer.valueOf(sep[0]))
+ ":" + zoneFormat.format(Integer.valueOf(sep[1])) + ChatColor.GREEN + " ("
+ cal.getTimeZone().getDisplayName(loc) + ")";
return output;

View File

@ -40,11 +40,11 @@ public enum ObjectiveType {
PASSWORD(21, "Password"),
CUSTOM(127, "Custom");
private String name;
private byte typeId;
private final String name;
private final byte typeId;
private static final Map<String, ObjectiveType> NAME_MAP = new HashMap<String, ObjectiveType>();
private static final Map<Byte, ObjectiveType> ID_MAP = new HashMap<Byte, ObjectiveType>();
private static final Map<String, ObjectiveType> NAME_MAP = new HashMap<>();
private static final Map<Byte, ObjectiveType> ID_MAP = new HashMap<>();
static {
for (final ObjectiveType type : values()) {

View File

@ -16,6 +16,7 @@ import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quester;
import me.blackvein.quests.events.QuestsEvent;
import org.jetbrains.annotations.NotNull;
/**
* Represents a Quests command-related event
@ -43,7 +44,7 @@ public abstract class QuestsCommandEvent extends QuestsEvent {
}
@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return HANDLERS;
}

View File

@ -17,6 +17,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quester;
import org.jetbrains.annotations.NotNull;
/**
* Called when the /quests editor command is run by a player
@ -42,7 +43,7 @@ public class QuestsCommandPreQuestsEditorEvent extends QuestsCommandEvent implem
}
@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

View File

@ -16,6 +16,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quester;
import org.jetbrains.annotations.NotNull;
/**
* Called when the /quests journal command is run by a player
@ -39,7 +40,7 @@ public class QuestsCommandPreQuestsJournalEvent extends QuestsCommandEvent imple
}
@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}

View File

@ -16,6 +16,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import me.blackvein.quests.Quester;
import org.jetbrains.annotations.NotNull;
/**
* Called when the /quests list command is run by a player
@ -41,7 +42,7 @@ public class QuestsCommandPreQuestsListEvent extends QuestsCommandEvent implemen
}
@Override
public HandlerList getHandlers() {
public @NotNull HandlerList getHandlers() {
return handlers;
}