Improve code syntax, part 1

This commit is contained in:
PikaMug 2021-08-16 04:11:55 -04:00
parent 61f9f2ede2
commit 27b6f97c2b
8 changed files with 651 additions and 561 deletions

View File

@ -64,7 +64,7 @@ public class Quest implements Comparable<Quest> {
protected String description;
protected String finished;
protected ItemStack guiDisplay = null;
private final LinkedList<Stage> orderedStages = new LinkedList<Stage>();
private final LinkedList<Stage> orderedStages = new LinkedList<>();
protected NPC npcStart;
protected Location blockStart;
protected String regionStart = null;
@ -216,11 +216,11 @@ public class Quest implements Comparable<Quest> {
}
// Multiplayer
if (opts.getShareProgressLevel() == 3) {
if (allowSharedProgress && opts.getShareProgressLevel() == 3) {
final List<Quester> mq = quester.getMultiplayerQuesters(this);
for (final Quester qq : mq) {
if (currentStage.equals(qq.getCurrentStage(this))) {
nextStage(qq, allowSharedProgress);
nextStage(qq, true);
}
}
}
@ -303,120 +303,116 @@ public class Quest implements Comparable<Quest> {
return false;
}
final Quest quest = this;
Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override
public void run() {
Location targetLocation = null;
if (stage.citizensToInteract != null && stage.citizensToInteract.size() > 0) {
targetLocation = plugin.getDependencies().getNPCLocation(stage.citizensToInteract.getFirst());
} else if (stage.citizensToKill != null && stage.citizensToKill.size() > 0) {
targetLocation = plugin.getDependencies().getNPCLocation(stage.citizensToKill.getFirst());
} else if (stage.locationsToReach != null && stage.locationsToReach.size() > 0) {
targetLocation = stage.locationsToReach.getFirst();
} else if (stage.itemDeliveryTargets != null && stage.itemDeliveryTargets.size() > 0) {
final NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getById(stage.itemDeliveryTargets
.getFirst());
targetLocation = npc.getStoredLocation();
} else if (stage.playersToKill != null && stage.playersToKill > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
if (source.getWorld() == null) {
return;
Bukkit.getScheduler().runTask(plugin, () -> {
Location targetLocation = null;
if (stage.citizensToInteract != null && stage.citizensToInteract.size() > 0) {
targetLocation = plugin.getDependencies().getNPCLocation(stage.citizensToInteract.getFirst());
} else if (stage.citizensToKill != null && stage.citizensToKill.size() > 0) {
targetLocation = plugin.getDependencies().getNPCLocation(stage.citizensToKill.getFirst());
} else if (stage.locationsToReach != null && stage.locationsToReach.size() > 0) {
targetLocation = stage.locationsToReach.getFirst();
} else if (stage.itemDeliveryTargets != null && stage.itemDeliveryTargets.size() > 0) {
final NPC npc = plugin.getDependencies().getCitizens().getNPCRegistry().getById(stage.itemDeliveryTargets
.getFirst());
targetLocation = npc.getStoredLocation();
} else if (stage.playersToKill != null && stage.playersToKill > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
if (source.getWorld() == null) {
return;
}
for (final Player p : source.getWorld().getPlayers()) {
if (p.getUniqueId().equals(quester.getUUID())) {
continue;
}
for (final Player p : source.getWorld().getPlayers()) {
if (p.getUniqueId().equals(quester.getUUID())) {
continue;
}
final double new_distance = p.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = p.getLocation();
old_distance = new_distance;
}
}
if (nearest != null) {
targetLocation = nearest;
}
} else if (stage.mobsToKill != null && stage.mobsToKill.size() > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
final EntityType et = stage.mobsToKill.getFirst();
if (source.getWorld() == null) {
return;
}
for (final Entity e : source.getWorld().getEntities()) {
if (!e.getType().equals(et)) {
continue;
}
final double new_distance = e.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = e.getLocation();
old_distance = new_distance;
}
}
if (nearest != null) {
targetLocation = nearest;
}
} else if (stage.mobsToTame != null && stage.mobsToTame.size() > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
final EntityType et = stage.mobsToTame.getFirst();
if (source.getWorld() == null) {
return;
}
for (final Entity e : source.getWorld().getEntities()) {
if (!e.getType().equals(et)) {
continue;
}
final double new_distance = e.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = e.getLocation();
old_distance = new_distance;
}
}
if (nearest != null) {
targetLocation = nearest;
}
} else if (stage.sheepToShear != null && stage.sheepToShear.size() > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
final DyeColor dc = stage.sheepToShear.getFirst();
if (source.getWorld() == null) {
return;
}
for (final Entity e : source.getWorld().getEntities()) {
if (!e.getType().equals(EntityType.SHEEP)) {
continue;
}
final Sheep s = (Sheep)e;
if (s.getColor()!= null && s.getColor().equals(dc)) {
continue;
}
final double new_distance = e.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = e.getLocation();
old_distance = new_distance;
}
}
if (nearest != null) {
targetLocation = nearest;
final double new_distance = p.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = p.getLocation();
old_distance = new_distance;
}
}
if (targetLocation != null && targetLocation.getWorld() != null) {
if (targetLocation.getWorld().getName().equals(quester.getPlayer().getWorld().getName())) {
final Location lockedTarget = new Location(targetLocation.getWorld(), targetLocation.getX(),
targetLocation.getY(), targetLocation.getZ());
final QuestUpdateCompassEvent event = new QuestUpdateCompassEvent(quest, quester, lockedTarget);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
quester.getPlayer().setCompassTarget(lockedTarget);
if (nearest != null) {
targetLocation = nearest;
}
} else if (stage.mobsToKill != null && stage.mobsToKill.size() > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
final EntityType et = stage.mobsToKill.getFirst();
if (source.getWorld() == null) {
return;
}
for (final Entity e : source.getWorld().getEntities()) {
if (!e.getType().equals(et)) {
continue;
}
final double new_distance = e.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = e.getLocation();
old_distance = new_distance;
}
}
if (nearest != null) {
targetLocation = nearest;
}
} else if (stage.mobsToTame != null && stage.mobsToTame.size() > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
final EntityType et = stage.mobsToTame.getFirst();
if (source.getWorld() == null) {
return;
}
for (final Entity e : source.getWorld().getEntities()) {
if (!e.getType().equals(et)) {
continue;
}
final double new_distance = e.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = e.getLocation();
old_distance = new_distance;
}
}
if (nearest != null) {
targetLocation = nearest;
}
} else if (stage.sheepToShear != null && stage.sheepToShear.size() > 0) {
final Location source = quester.getPlayer().getLocation();
Location nearest = null;
double old_distance = 30000000;
final DyeColor dc = stage.sheepToShear.getFirst();
if (source.getWorld() == null) {
return;
}
for (final Entity e : source.getWorld().getEntities()) {
if (!e.getType().equals(EntityType.SHEEP)) {
continue;
}
final Sheep s = (Sheep)e;
if (s.getColor()!= null && s.getColor().equals(dc)) {
continue;
}
final double new_distance = e.getLocation().distanceSquared(source);
if (new_distance < old_distance) {
nearest = e.getLocation();
old_distance = new_distance;
}
}
if (nearest != null) {
targetLocation = nearest;
}
}
if (targetLocation != null && targetLocation.getWorld() != null) {
if (targetLocation.getWorld().getName().equals(quester.getPlayer().getWorld().getName())) {
final Location lockedTarget = new Location(targetLocation.getWorld(), targetLocation.getX(),
targetLocation.getY(), targetLocation.getZ());
final QuestUpdateCompassEvent event = new QuestUpdateCompassEvent(quest, quester, lockedTarget);
plugin.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
quester.getPlayer().setCompassTarget(lockedTarget);
}
}
});
@ -574,13 +570,7 @@ public class Quest implements Comparable<Quest> {
final Player p = (Player)player;
final String[] ps = ConfigUtil.parseStringWithPossibleLineBreaks(ChatColor.AQUA
+ finished, this, p);
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
@Override
public void run() {
p.sendMessage(ps);
}
}, 40);
Bukkit.getScheduler().runTaskLater(plugin, () -> p.sendMessage(ps), 40);
}
if (pln.getCooldown() > -1) {
quester.completedTimes.put(this, System.currentTimeMillis());
@ -691,9 +681,9 @@ public class Quest implements Comparable<Quest> {
}
}
}
final LinkedList<ItemStack> phatLootItems = new LinkedList<ItemStack>();
final LinkedList<ItemStack> phatLootItems = new LinkedList<>();
int phatLootExp = 0;
final LinkedList<String> phatLootMessages = new LinkedList<String>();
final LinkedList<String> phatLootMessages = new LinkedList<>();
for (final String s : rews.getPhatLoots()) {
final LootBundle lb = PhatLootsAPI.getPhatLoot(s).rollForLoot();
if (lb.getExp() > 0) {
@ -789,77 +779,72 @@ public class Quest implements Comparable<Quest> {
+ Lang.get(p, "questPoints"));
}
for (final ItemStack i : rews.getItems()) {
String text = "error";
if (i.hasItemMeta() && i.getItemMeta().hasDisplayName()) {
StringBuilder text;
if (i.getItemMeta() != null && i.getItemMeta().hasDisplayName()) {
if (i.getEnchantments().isEmpty()) {
text = "- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName()
+ ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount();
text = new StringBuilder("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName()
+ ChatColor.RESET + ChatColor.GRAY + " x " + i.getAmount());
} else {
text = "- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName()
+ ChatColor.RESET;
text = new StringBuilder("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC + i.getItemMeta().getDisplayName()
+ ChatColor.RESET);
try {
if (!i.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) {
text += ChatColor.GRAY + " " + Lang.get(p, "with") + ChatColor.DARK_PURPLE;
text.append(ChatColor.GRAY).append(" ").append(Lang.get(p, "with")).append(ChatColor.DARK_PURPLE);
for (final Entry<Enchantment, Integer> e : i.getEnchantments().entrySet()) {
text += " " + ItemUtil.getPrettyEnchantmentName(e.getKey()) + ":"
+ e.getValue();
text.append(" ").append(ItemUtil.getPrettyEnchantmentName(e.getKey())).append(":").append(e.getValue());
}
}
} catch (final Throwable tr) {
// Do nothing, hasItemFlag() not introduced until 1.8.6
}
text += ChatColor.GRAY + " x " + i.getAmount();
text.append(ChatColor.GRAY).append(" x ").append(i.getAmount());
}
} else if (i.getDurability() != 0) {
text = "- " + ChatColor.DARK_GREEN + "<item>:" + i.getDurability();
if (i.getEnchantments().isEmpty()) {
text += ChatColor.GRAY + " x " + i.getAmount();
} else {
text += ChatColor.GRAY + " " + Lang.get(p, "with");
text = new StringBuilder("- " + ChatColor.DARK_GREEN + "<item>:" + i.getDurability());
if (!i.getEnchantments().isEmpty()) {
text.append(ChatColor.GRAY).append(" ").append(Lang.get(p, "with"));
for (int iz = 0; iz < i.getEnchantments().size(); iz++) {
text += " <enchantment> <level>";
text.append(" <enchantment> <level>");
}
text += ChatColor.GRAY + " x " + i.getAmount();
}
text.append(ChatColor.GRAY).append(" x ").append(i.getAmount());
} else {
text = "- " + ChatColor.DARK_GREEN + "<item>";
if (i.getEnchantments().isEmpty()) {
text += ChatColor.GRAY + " x " + i.getAmount();
} else {
text = new StringBuilder("- " + ChatColor.DARK_GREEN + "<item>");
if (!i.getEnchantments().isEmpty()) {
try {
if (!i.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) {
text += ChatColor.GRAY + " " + Lang.get(p, "with");
text.append(ChatColor.GRAY).append(" ").append(Lang.get(p, "with"));
for (int iz = 0; iz < i.getEnchantments().size(); iz++) {
text += " <enchantment> <level>";
text.append(" <enchantment> <level>");
}
}
} catch (final Throwable tr) {
// Do nothing, hasItemFlag() not introduced until 1.8.6
}
text += ChatColor.GRAY + " x " + i.getAmount();
}
text.append(ChatColor.GRAY).append(" x ").append(i.getAmount());
}
if (plugin.getSettings().canTranslateNames() && text.contains("<item>")) {
if (!plugin.getLocaleManager().sendMessage(p, text, i.getType(), i.getDurability(),
if (plugin.getSettings().canTranslateNames() && text.toString().contains("<item>")) {
if (!plugin.getLocaleManager().sendMessage(p, text.toString(), i.getType(), i.getDurability(),
i.getEnchantments())) {
for (final Entry<Enchantment, Integer> e : i.getEnchantments().entrySet()) {
text = text.replaceFirst("<enchantment>", ItemUtil.getPrettyEnchantmentName(
e.getKey()));
text = text.replaceFirst("<level>", RomanNumeral.getNumeral(e.getValue()));
text = new StringBuilder(text.toString().replaceFirst("<enchantment>", ItemUtil.getPrettyEnchantmentName(
e.getKey())));
text = new StringBuilder(text.toString().replaceFirst("<level>", RomanNumeral.getNumeral(e.getValue())));
}
quester.sendMessage(text.replace("<item>", ItemUtil.getName(i)));
quester.sendMessage(text.toString().replace("<item>", ItemUtil.getName(i)));
}
} else {
for (final Entry<Enchantment, Integer> e : i.getEnchantments().entrySet()) {
text = text.replaceFirst("<enchantment>", ItemUtil.getPrettyEnchantmentName(
e.getKey()));
text = text.replaceFirst("<level>", RomanNumeral.getNumeral(e.getValue()));
text = new StringBuilder(text.toString().replaceFirst("<enchantment>", ItemUtil.getPrettyEnchantmentName(
e.getKey())));
text = new StringBuilder(text.toString().replaceFirst("<level>", RomanNumeral.getNumeral(e.getValue())));
}
quester.sendMessage(text.replace("<item>", ItemUtil.getName(i)));
quester.sendMessage(text.toString().replace("<item>", ItemUtil.getName(i)));
}
}
for (final ItemStack i : phatLootItems) {
if (i.hasItemMeta() && i.getItemMeta().hasDisplayName()) {
if (i.getItemMeta() != null && i.getItemMeta().hasDisplayName()) {
if (i.getEnchantments().isEmpty()) {
quester.sendMessage("- " + ChatColor.DARK_AQUA + ChatColor.ITALIC
+ i.getItemMeta().getDisplayName() + ChatColor.RESET + ChatColor.GRAY + " x "

View File

@ -18,6 +18,7 @@ import me.blackvein.quests.convo.quests.stages.StageMenuPrompt;
import me.blackvein.quests.interfaces.ReloadCallback;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.FakeConversable;
import me.blackvein.quests.util.Lang;
import me.blackvein.quests.util.MiscUtil;
import org.bukkit.ChatColor;
@ -37,6 +38,7 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
@ -46,6 +48,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
@ -54,23 +57,24 @@ public class QuestFactory implements ConversationAbandonedListener {
private final Quests plugin;
private final ConversationFactory convoCreator;
private Map<UUID, Block> selectedBlockStarts = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedKillLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedReachLocations = new HashMap<UUID, Block>();
private Set<UUID> selectingNpcs = new HashSet<UUID>();
private List<String> editingQuestNames = new LinkedList<String>();
private Map<UUID, Block> selectedBlockStarts = new HashMap<>();
private Map<UUID, Block> selectedKillLocations = new HashMap<>();
private Map<UUID, Block> selectedReachLocations = new HashMap<>();
private Set<UUID> selectingNpcs = new HashSet<>();
private List<String> editingQuestNames = new LinkedList<>();
public QuestFactory(final Quests plugin) {
this.plugin = plugin;
// Ensure to initialize convoCreator last so that 'this' is fully initialized before it is passed
this.convoCreator = new ConversationFactory(plugin).withModality(false).withLocalEcho(false)
.withFirstPrompt(new QuestMenuPrompt(new ConversationContext(plugin, null, null))).withTimeout(3600)
.withFirstPrompt(new QuestMenuPrompt(new ConversationContext(plugin, new FakeConversable(),
new HashMap<>()))).withTimeout(3600)
.withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this);
}
public class LineBreakPrefix implements ConversationPrefix {
public static class LineBreakPrefix implements ConversationPrefix {
@Override
public String getPrefix(final ConversationContext context) {
public @NotNull String getPrefix(final @NotNull ConversationContext context) {
return "\n";
}
}
@ -138,7 +142,7 @@ public class QuestFactory implements ConversationAbandonedListener {
@Override
public void conversationAbandoned(final ConversationAbandonedEvent abandonedEvent) {
if (abandonedEvent.getContext().getSessionData(CK.Q_NAME) != null) {
editingQuestNames.remove(abandonedEvent.getContext().getSessionData(CK.Q_NAME));
editingQuestNames.remove((String) abandonedEvent.getContext().getSessionData(CK.Q_NAME));
}
if (abandonedEvent.getContext().getForWhom() instanceof Player) {
final UUID uuid = ((Player) abandonedEvent.getContext().getForWhom()).getUniqueId();
@ -205,8 +209,8 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(CK.REQ_HEROES_SECONDARY_CLASS, reqs.getHeroesSecondaryClass());
}
if (!reqs.getCustomRequirements().isEmpty()) {
final LinkedList<String> list = new LinkedList<String>();
final LinkedList<Map<String, Object>> datamapList = new LinkedList<Map<String, Object>>();
final LinkedList<String> list = new LinkedList<>();
final LinkedList<Map<String, Object>> datamapList = new LinkedList<>();
for (final Entry<String, Map<String, Object>> entry : reqs.getCustomRequirements().entrySet()) {
list.add(entry.getKey());
datamapList.add(entry.getValue());
@ -257,7 +261,7 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(CK.REW_PHAT_LOOTS, rews.getPhatLoots());
}
if (!rews.getCustomRewards().isEmpty()) {
context.setSessionData(CK.REW_CUSTOM, new LinkedList<String>(rews.getCustomRewards().keySet()));
context.setSessionData(CK.REW_CUSTOM, new LinkedList<>(rews.getCustomRewards().keySet()));
context.setSessionData(CK.REW_CUSTOM_DATA, new LinkedList<Object>(rews.getCustomRewards().values()));
}
if (!rews.getDetailsOverride().isEmpty()) {
@ -294,9 +298,9 @@ public class QuestFactory implements ConversationAbandonedListener {
index++;
context.setSessionData(pref, Boolean.TRUE);
if (!stage.getBlocksToBreak().isEmpty()) {
final LinkedList<String> names = new LinkedList<String>();
final LinkedList<Integer> amnts = new LinkedList<Integer>();
final LinkedList<Short> durab = new LinkedList<Short>();
final LinkedList<String> names = new LinkedList<>();
final LinkedList<Integer> amnts = new LinkedList<>();
final LinkedList<Short> durab = new LinkedList<>();
for (final ItemStack e : stage.getBlocksToBreak()) {
names.add(e.getType().name());
amnts.add(e.getAmount());
@ -307,9 +311,9 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_BREAK_DURABILITY, durab);
}
if (!stage.getBlocksToDamage().isEmpty()) {
final LinkedList<String> names = new LinkedList<String>();
final LinkedList<Integer> amnts = new LinkedList<Integer>();
final LinkedList<Short> durab = new LinkedList<Short>();
final LinkedList<String> names = new LinkedList<>();
final LinkedList<Integer> amnts = new LinkedList<>();
final LinkedList<Short> durab = new LinkedList<>();
for (final ItemStack e : stage.getBlocksToDamage()) {
names.add(e.getType().name());
amnts.add(e.getAmount());
@ -320,9 +324,9 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_DAMAGE_DURABILITY, durab);
}
if (!stage.getBlocksToPlace().isEmpty()) {
final LinkedList<String> names = new LinkedList<String>();
final LinkedList<Integer> amnts = new LinkedList<Integer>();
final LinkedList<Short> durab = new LinkedList<Short>();
final LinkedList<String> names = new LinkedList<>();
final LinkedList<Integer> amnts = new LinkedList<>();
final LinkedList<Short> durab = new LinkedList<>();
for (final ItemStack e : stage.getBlocksToPlace()) {
names.add(e.getType().name());
amnts.add(e.getAmount());
@ -333,9 +337,9 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_PLACE_DURABILITY, durab);
}
if (!stage.getBlocksToUse().isEmpty()) {
final LinkedList<String> names = new LinkedList<String>();
final LinkedList<Integer> amnts = new LinkedList<Integer>();
final LinkedList<Short> durab = new LinkedList<Short>();
final LinkedList<String> names = new LinkedList<>();
final LinkedList<Integer> amnts = new LinkedList<>();
final LinkedList<Short> durab = new LinkedList<>();
for (final ItemStack e : stage.getBlocksToUse()) {
names.add(e.getType().name());
amnts.add(e.getAmount());
@ -346,9 +350,9 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_USE_DURABILITY, durab);
}
if (!stage.getBlocksToCut().isEmpty()) {
final LinkedList<String> names = new LinkedList<String>();
final LinkedList<Integer> amnts = new LinkedList<Integer>();
final LinkedList<Short> durab = new LinkedList<Short>();
final LinkedList<String> names = new LinkedList<>();
final LinkedList<Integer> amnts = new LinkedList<>();
final LinkedList<Short> durab = new LinkedList<>();
for (final ItemStack e : stage.getBlocksToCut()) {
names.add(e.getType().name());
amnts.add(e.getAmount());
@ -359,23 +363,23 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_CUT_DURABILITY, durab);
}
if (!stage.getItemsToCraft().isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>(stage.getItemsToCraft());
final LinkedList<ItemStack> items = new LinkedList<>(stage.getItemsToCraft());
context.setSessionData(pref + CK.S_CRAFT_ITEMS, items);
}
if (!stage.getItemsToSmelt().isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>(stage.getItemsToSmelt());
final LinkedList<ItemStack> items = new LinkedList<>(stage.getItemsToSmelt());
context.setSessionData(pref + CK.S_SMELT_ITEMS, items);
}
if (!stage.getItemsToEnchant().isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>(stage.getItemsToEnchant());
final LinkedList<ItemStack> items = new LinkedList<>(stage.getItemsToEnchant());
context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items);
}
if (!stage.getItemsToBrew().isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>(stage.getItemsToBrew());
final LinkedList<ItemStack> items = new LinkedList<>(stage.getItemsToBrew());
context.setSessionData(pref + CK.S_BREW_ITEMS, items);
}
if (!stage.getItemsToConsume().isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>(stage.getItemsToConsume());
final LinkedList<ItemStack> items = new LinkedList<>(stage.getItemsToConsume());
context.setSessionData(pref + CK.S_CONSUME_ITEMS, items);
}
if (stage.getCowsToMilk() != null) {
@ -388,30 +392,30 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_PLAYER_KILL, stage.getPlayersToKill());
}
if (!stage.getItemsToDeliver().isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>(stage.getItemsToDeliver());
final LinkedList<Integer> npcs = new LinkedList<Integer>(stage.getItemDeliveryTargets());
final LinkedList<ItemStack> items = new LinkedList<>(stage.getItemsToDeliver());
final LinkedList<Integer> npcs = new LinkedList<>(stage.getItemDeliveryTargets());
context.setSessionData(pref + CK.S_DELIVERY_ITEMS, items);
context.setSessionData(pref + CK.S_DELIVERY_NPCS, npcs);
context.setSessionData(pref + CK.S_DELIVERY_MESSAGES, stage.getDeliverMessages());
}
if (!stage.getCitizensToInteract().isEmpty()) {
final LinkedList<Integer> npcs = new LinkedList<Integer>(stage.getCitizensToInteract());
final LinkedList<Integer> npcs = new LinkedList<>(stage.getCitizensToInteract());
context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs);
}
if (!stage.getCitizensToKill().isEmpty()) {
final LinkedList<Integer> npcs = new LinkedList<Integer>(stage.getCitizensToKill());
final LinkedList<Integer> npcs = new LinkedList<>(stage.getCitizensToKill());
context.setSessionData(pref + CK.S_NPCS_TO_KILL, npcs);
context.setSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS, stage.getCitizenNumToKill());
}
if (!stage.getMobsToKill().isEmpty()) {
final LinkedList<String> mobs = new LinkedList<String>();
final LinkedList<String> mobs = new LinkedList<>();
for (final EntityType et : stage.getMobsToKill()) {
mobs.add(MiscUtil.getPrettyMobName(et));
}
context.setSessionData(pref + CK.S_MOB_TYPES, mobs);
context.setSessionData(pref + CK.S_MOB_AMOUNTS, stage.getMobNumToKill());
if (!stage.getLocationsToKillWithin().isEmpty()) {
final LinkedList<String> locs = new LinkedList<String>();
final LinkedList<String> locs = new LinkedList<>();
for (final Location l : stage.getLocationsToKillWithin()) {
locs.add(ConfigUtil.getLocationInfo(l));
}
@ -421,7 +425,7 @@ public class QuestFactory implements ConversationAbandonedListener {
}
}
if (!stage.getLocationsToReach().isEmpty()) {
final LinkedList<String> locs = new LinkedList<String>();
final LinkedList<String> locs = new LinkedList<>();
for (final Location l : stage.getLocationsToReach()) {
locs.add(ConfigUtil.getLocationInfo(l));
}
@ -430,21 +434,21 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_REACH_LOCATIONS_NAMES, stage.getLocationNames());
}
if (!stage.getMobsToTame().isEmpty()) {
final LinkedList<String> mobs = new LinkedList<String>();
final LinkedList<String> mobs = new LinkedList<>();
for (final EntityType e : stage.getMobsToTame()) {
mobs.add(MiscUtil.getPrettyMobName(e));
}
final LinkedList<Integer> amts = new LinkedList<Integer>(stage.getMobNumToTame());
final LinkedList<Integer> amts = new LinkedList<>(stage.getMobNumToTame());
context.setSessionData(pref + CK.S_TAME_TYPES, mobs);
context.setSessionData(pref + CK.S_TAME_AMOUNTS, amts);
}
if (!stage.getSheepToShear().isEmpty()) {
final LinkedList<String> colors = new LinkedList<String>();
final LinkedList<String> colors = new LinkedList<>();
for (final DyeColor d : stage.getSheepToShear()) {
colors.add(MiscUtil.getPrettyDyeColorName(d));
}
final LinkedList<Integer> amts = new LinkedList<Integer>(stage.sheepNumToShear);
final LinkedList<Integer> amts = new LinkedList<>(stage.sheepNumToShear);
context.setSessionData(pref + CK.S_SHEAR_COLORS, colors);
context.setSessionData(pref + CK.S_SHEAR_AMOUNTS, amts);
}
@ -453,14 +457,13 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_PASSWORD_PHRASES, stage.getPasswordPhrases());
}
if (!stage.getCustomObjectives().isEmpty()) {
final LinkedList<String> list = new LinkedList<String>();
final LinkedList<Integer> countList = new LinkedList<Integer>();
final LinkedList<String> list = new LinkedList<>();
final LinkedList<Integer> countList = new LinkedList<>();
for (int i = 0; i < stage.getCustomObjectives().size(); i++) {
list.add(stage.getCustomObjectives().get(i).getName());
countList.add(stage.getCustomObjectiveCounts().get(i));
}
final LinkedList<Entry<String, Object>> datamapList
= new LinkedList<Entry<String, Object>>(stage.getCustomObjectiveData());
final LinkedList<Entry<String, Object>> datamapList = new LinkedList<>(stage.getCustomObjectiveData());
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES, list);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT, countList);
context.setSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA, datamapList);
@ -481,8 +484,8 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_DISCONNECT_EVENT, stage.getDisconnectAction().getName());
}
if (!stage.getChatActions().isEmpty()) {
final LinkedList<String> chatEvents = new LinkedList<String>();
final LinkedList<String> chatEventTriggers = new LinkedList<String>();
final LinkedList<String> chatEvents = new LinkedList<>();
final LinkedList<String> chatEventTriggers = new LinkedList<>();
for (final String s : stage.getChatActions().keySet()) {
chatEventTriggers.add(s);
chatEvents.add(stage.getChatActions().get(s).getName());
@ -491,8 +494,8 @@ public class QuestFactory implements ConversationAbandonedListener {
context.setSessionData(pref + CK.S_CHAT_EVENT_TRIGGERS, chatEventTriggers);
}
if (!stage.getCommandActions().isEmpty()) {
final LinkedList<String> commandEvents = new LinkedList<String>();
final LinkedList<String> commandEventTriggers = new LinkedList<String>();
final LinkedList<String> commandEvents = new LinkedList<>();
final LinkedList<String> commandEventTriggers = new LinkedList<>();
for (final String s : stage.getCommandActions().keySet()) {
commandEventTriggers.add(s);
commandEvents.add(stage.getCommandActions().get(s).getName());
@ -529,12 +532,7 @@ public class QuestFactory implements ConversationAbandonedListener {
final File questsFile = new File(plugin.getDataFolder(), "quests.yml");
try {
data.load(questsFile);
} catch (final IOException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<quest>", questsFile.getName()));
return;
} catch (final InvalidConfigurationException e) {
} catch (final IOException | InvalidConfigurationException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<quest>", questsFile.getName()));
@ -542,10 +540,13 @@ public class QuestFactory implements ConversationAbandonedListener {
}
final String quest = (String) context.getSessionData(CK.ED_QUEST_DELETE);
final ConfigurationSection sec = data.getConfigurationSection("quests");
for (final String key : sec.getKeys(false)) {
if (sec.getString(key + ".name").equalsIgnoreCase(quest)) {
sec.set(key, null);
break;
if (sec != null) {
for (final String key : sec.getKeys(false)) {
if (sec.getString(key + ".name") != null
&& Objects.requireNonNull(sec.getString(key + ".name")).equalsIgnoreCase(quest)) {
sec.set(key, null);
break;
}
}
}
try {
@ -554,12 +555,9 @@ public class QuestFactory implements ConversationAbandonedListener {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questSaveError"));
return;
}
final ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
@Override
public void execute(final Boolean response) {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
final ReloadCallback<Boolean> callback = response -> {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
};
plugin.reload(callback);
@ -578,32 +576,35 @@ public class QuestFactory implements ConversationAbandonedListener {
}
if (edit != null) {
final ConfigurationSection questList = section.getParent();
for (final String key : questList.getKeys(false)) {
final String name = questList.getString(key + ".name");
if (name != null) {
if (name.equalsIgnoreCase(edit)) {
questList.set(key, null);
break;
if (questList != null) {
for (final String key : questList.getKeys(false)) {
final String name = questList.getString(key + ".name");
if (name != null) {
if (name.equalsIgnoreCase(edit)) {
questList.set(key, null);
break;
}
}
}
}
}
section.set("name", context.getSessionData(CK.Q_NAME) != null
? (String) context.getSessionData(CK.Q_NAME) : null);
? context.getSessionData(CK.Q_NAME) : null);
section.set("ask-message", context.getSessionData(CK.Q_ASK_MESSAGE) != null
? (String) context.getSessionData(CK.Q_ASK_MESSAGE) : null);
? context.getSessionData(CK.Q_ASK_MESSAGE) : null);
section.set("finish-message", context.getSessionData(CK.Q_FINISH_MESSAGE) != null
? (String) context.getSessionData(CK.Q_FINISH_MESSAGE) : null);
? context.getSessionData(CK.Q_FINISH_MESSAGE) : null);
section.set("npc-giver-id", context.getSessionData(CK.Q_START_NPC) != null
? (Integer) context.getSessionData(CK.Q_START_NPC) : null);
? context.getSessionData(CK.Q_START_NPC) : null);
section.set("block-start", context.getSessionData(CK.Q_START_BLOCK) != null
? ConfigUtil.getLocationInfo((Location) context.getSessionData(CK.Q_START_BLOCK)) : null);
? ConfigUtil.getLocationInfo((Location) Objects.requireNonNull(context
.getSessionData(CK.Q_START_BLOCK))) : null);
section.set("event", context.getSessionData(CK.Q_INITIAL_EVENT) != null
? (String) context.getSessionData(CK.Q_INITIAL_EVENT) : null);
? context.getSessionData(CK.Q_INITIAL_EVENT) : null);
section.set("region", context.getSessionData(CK.Q_REGION) != null
? (String) context.getSessionData(CK.Q_REGION) : null);
? context.getSessionData(CK.Q_REGION) : null);
section.set("gui-display", context.getSessionData(CK.Q_GUIDISPLAY) != null
? (ItemStack) context.getSessionData(CK.Q_GUIDISPLAY) : null);
? context.getSessionData(CK.Q_GUIDISPLAY) : null);
saveRequirements(context, section);
saveStages(context, section);
saveRewards(context, section);
@ -612,7 +613,7 @@ public class QuestFactory implements ConversationAbandonedListener {
if (plugin.getSettings().getConsoleLogging() > 0) {
final String identifier = context.getForWhom() instanceof Player ?
"Player " + ((Player)context.getForWhom()).getUniqueId() : "CONSOLE";
plugin.getLogger().info(identifier + " saved quest " + (String) context.getSessionData(CK.Q_NAME));
plugin.getLogger().info(identifier + " saved quest " + context.getSessionData(CK.Q_NAME));
}
}
@ -620,32 +621,32 @@ public class QuestFactory implements ConversationAbandonedListener {
private void saveRequirements(final ConversationContext context, final ConfigurationSection section) {
final ConfigurationSection reqs = section.createSection("requirements");
reqs.set("money", context.getSessionData(CK.REQ_MONEY) != null
? (Integer) context.getSessionData(CK.REQ_MONEY) : null);
? context.getSessionData(CK.REQ_MONEY) : null);
reqs.set("quest-points", context.getSessionData(CK.REQ_QUEST_POINTS) != null
? (Integer) context.getSessionData(CK.REQ_QUEST_POINTS) : null);
? context.getSessionData(CK.REQ_QUEST_POINTS) : null);
reqs.set("items", context.getSessionData(CK.REQ_ITEMS) != null
? (List<ItemStack>) context.getSessionData(CK.REQ_ITEMS) : null);
? context.getSessionData(CK.REQ_ITEMS) : null);
reqs.set("remove-items", context.getSessionData(CK.REQ_ITEMS_REMOVE) != null
? (List<Boolean>) context.getSessionData(CK.REQ_ITEMS_REMOVE) : null);
? context.getSessionData(CK.REQ_ITEMS_REMOVE) : null);
reqs.set("permissions", context.getSessionData(CK.REQ_PERMISSION) != null
? (List<String>) context.getSessionData(CK.REQ_PERMISSION) : null);
? context.getSessionData(CK.REQ_PERMISSION) : null);
reqs.set("quests", context.getSessionData(CK.REQ_QUEST) != null
? (List<String>) context.getSessionData(CK.REQ_QUEST) : null);
? context.getSessionData(CK.REQ_QUEST) : null);
reqs.set("quest-blocks", context.getSessionData(CK.REQ_QUEST_BLOCK) != null
? (List<String>) context.getSessionData(CK.REQ_QUEST_BLOCK) : null);
? context.getSessionData(CK.REQ_QUEST_BLOCK) : null);
reqs.set("mcmmo-skills", context.getSessionData(CK.REQ_MCMMO_SKILLS) != null
? (List<String>) context.getSessionData(CK.REQ_MCMMO_SKILLS) : null);
? context.getSessionData(CK.REQ_MCMMO_SKILLS) : null);
reqs.set("mcmmo-amounts", context.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS) != null
? (List<Integer>) context.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS) : null);
? context.getSessionData(CK.REQ_MCMMO_SKILL_AMOUNTS) : null);
reqs.set("heroes-primary-class", context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) != null
? (String) context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) : null);
? context.getSessionData(CK.REQ_HEROES_PRIMARY_CLASS) : null);
reqs.set("heroes-secondary-class", context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) != null
? (String) context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) : null);
? context.getSessionData(CK.REQ_HEROES_SECONDARY_CLASS) : null);
final LinkedList<String> customReqs = context.getSessionData(CK.REQ_CUSTOM) != null
? (LinkedList<String>) context.getSessionData(CK.REQ_CUSTOM) : null;
final LinkedList<Map<String, Object>> customReqsData = context.getSessionData(CK.REQ_CUSTOM_DATA) != null
? (LinkedList<Map<String, Object>>) context.getSessionData(CK.REQ_CUSTOM_DATA) : null;
if (customReqs != null) {
if (customReqs != null && customReqsData != null) {
final ConfigurationSection customReqsSec = reqs.createSection("custom-requirements");
for (int i = 0; i < customReqs.size(); i++) {
final ConfigurationSection customReqSec = customReqsSec.createSection("req" + (i + 1));
@ -654,7 +655,7 @@ public class QuestFactory implements ConversationAbandonedListener {
}
}
reqs.set("fail-requirement-message", context.getSessionData(CK.REQ_FAIL_MESSAGE) != null
? (List<String>)context.getSessionData(CK.REQ_FAIL_MESSAGE) : null);
? context.getSessionData(CK.REQ_FAIL_MESSAGE) : null);
if (reqs.getKeys(false).isEmpty()) {
section.set("requirements", null);
}
@ -669,91 +670,91 @@ public class QuestFactory implements ConversationAbandonedListener {
pref = "stage" + i;
final ConfigurationSection stage = ordered.createSection("" + i);
stage.set("break-block-names", context.getSessionData(pref + CK.S_BREAK_NAMES) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_BREAK_NAMES) : null);
? context.getSessionData(pref + CK.S_BREAK_NAMES) : null);
stage.set("break-block-amounts", context.getSessionData(pref + CK.S_BREAK_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_BREAK_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_BREAK_AMOUNTS) : null);
stage.set("break-block-durability", context.getSessionData(pref + CK.S_BREAK_DURABILITY) != null
? (LinkedList<Short>) context.getSessionData(pref + CK.S_BREAK_DURABILITY) : null);
? context.getSessionData(pref + CK.S_BREAK_DURABILITY) : null);
stage.set("damage-block-names", context.getSessionData(pref + CK.S_DAMAGE_NAMES) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_DAMAGE_NAMES) : null);
? context.getSessionData(pref + CK.S_DAMAGE_NAMES) : null);
stage.set("damage-block-amounts", context.getSessionData(pref + CK.S_DAMAGE_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_DAMAGE_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_DAMAGE_AMOUNTS) : null);
stage.set("damage-block-durability", context.getSessionData(pref + CK.S_DAMAGE_DURABILITY) != null
? (LinkedList<Short>) context.getSessionData(pref + CK.S_DAMAGE_DURABILITY) : null);
? context.getSessionData(pref + CK.S_DAMAGE_DURABILITY) : null);
stage.set("place-block-names", context.getSessionData(pref + CK.S_PLACE_NAMES) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_PLACE_NAMES) : null);
? context.getSessionData(pref + CK.S_PLACE_NAMES) : null);
stage.set("place-block-amounts", context.getSessionData(pref + CK.S_PLACE_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_PLACE_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_PLACE_AMOUNTS) : null);
stage.set("place-block-durability", context.getSessionData(pref + CK.S_PLACE_DURABILITY) != null
? (LinkedList<Short>) context.getSessionData(pref + CK.S_PLACE_DURABILITY) : null);
? context.getSessionData(pref + CK.S_PLACE_DURABILITY) : null);
stage.set("use-block-names", context.getSessionData(pref + CK.S_USE_NAMES) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_USE_NAMES) : null);
? context.getSessionData(pref + CK.S_USE_NAMES) : null);
stage.set("use-block-amounts", context.getSessionData(pref + CK.S_USE_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_USE_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_USE_AMOUNTS) : null);
stage.set("use-block-durability", context.getSessionData(pref + CK.S_USE_DURABILITY) != null
? (LinkedList<Short>) context.getSessionData(pref + CK.S_USE_DURABILITY) : null);
? context.getSessionData(pref + CK.S_USE_DURABILITY) : null);
stage.set("cut-block-names", context.getSessionData(pref + CK.S_CUT_NAMES) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUT_NAMES) : null);
? context.getSessionData(pref + CK.S_CUT_NAMES) : null);
stage.set("cut-block-amounts", context.getSessionData(pref + CK.S_CUT_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUT_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_CUT_AMOUNTS) : null);
stage.set("cut-block-durability", context.getSessionData(pref + CK.S_CUT_DURABILITY) != null
? (LinkedList<Short>) context.getSessionData(pref + CK.S_CUT_DURABILITY) : null);
? context.getSessionData(pref + CK.S_CUT_DURABILITY) : null);
stage.set("items-to-craft", context.getSessionData(pref + CK.S_CRAFT_ITEMS) != null
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CRAFT_ITEMS) : null);
? context.getSessionData(pref + CK.S_CRAFT_ITEMS) : null);
stage.set("items-to-smelt", context.getSessionData(pref + CK.S_SMELT_ITEMS) != null
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_SMELT_ITEMS) : null);
? context.getSessionData(pref + CK.S_SMELT_ITEMS) : null);
stage.set("items-to-enchant", context.getSessionData(pref + CK.S_ENCHANT_ITEMS) != null
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_ENCHANT_ITEMS) : null);
? context.getSessionData(pref + CK.S_ENCHANT_ITEMS) : null);
stage.set("items-to-brew", context.getSessionData(pref + CK.S_BREW_ITEMS) != null
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_BREW_ITEMS) : null);
? context.getSessionData(pref + CK.S_BREW_ITEMS) : null);
stage.set("items-to-consume", context.getSessionData(pref + CK.S_CONSUME_ITEMS) != null
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_CONSUME_ITEMS) : null);
? context.getSessionData(pref + CK.S_CONSUME_ITEMS) : null);
stage.set("cows-to-milk", context.getSessionData(pref + CK.S_COW_MILK) != null
? (Integer) context.getSessionData(pref + CK.S_COW_MILK) : null);
? context.getSessionData(pref + CK.S_COW_MILK) : null);
stage.set("fish-to-catch", context.getSessionData(pref + CK.S_FISH) != null
? (Integer) context.getSessionData(pref + CK.S_FISH) : null);
? context.getSessionData(pref + CK.S_FISH) : null);
stage.set("players-to-kill", context.getSessionData(pref + CK.S_PLAYER_KILL) != null
? (Integer) context.getSessionData(pref + CK.S_PLAYER_KILL) : null);
? context.getSessionData(pref + CK.S_PLAYER_KILL) : null);
stage.set("items-to-deliver", context.getSessionData(pref + CK.S_DELIVERY_ITEMS) != null
? (LinkedList<ItemStack>) context.getSessionData(pref + CK.S_DELIVERY_ITEMS) : null);
? context.getSessionData(pref + CK.S_DELIVERY_ITEMS) : null);
stage.set("npc-delivery-ids", context.getSessionData(pref + CK.S_DELIVERY_NPCS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_DELIVERY_NPCS) : null);
? context.getSessionData(pref + CK.S_DELIVERY_NPCS) : null);
stage.set("delivery-messages", context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) : null);
? context.getSessionData(pref + CK.S_DELIVERY_MESSAGES) : null);
stage.set("npc-ids-to-talk-to", context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) : null);
? context.getSessionData(pref + CK.S_NPCS_TO_TALK_TO) : null);
stage.set("npc-ids-to-kill", context.getSessionData(pref + CK.S_NPCS_TO_KILL) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL) : null);
? context.getSessionData(pref + CK.S_NPCS_TO_KILL) : null);
stage.set("npc-kill-amounts", context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_NPCS_TO_KILL_AMOUNTS) : null);
stage.set("mobs-to-kill", context.getSessionData(pref + CK.S_MOB_TYPES) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_TYPES) : null);
? context.getSessionData(pref + CK.S_MOB_TYPES) : null);
stage.set("mob-amounts", context.getSessionData(pref + CK.S_MOB_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_MOB_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_MOB_AMOUNTS) : null);
stage.set("locations-to-kill", context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) : null);
? context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS) : null);
stage.set("kill-location-radii", context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS) : null);
? context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_RADIUS) : null);
stage.set("kill-location-names", context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES) : null);
? context.getSessionData(pref + CK.S_MOB_KILL_LOCATIONS_NAMES) : null);
stage.set("locations-to-reach", context.getSessionData(pref + CK.S_REACH_LOCATIONS) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_REACH_LOCATIONS) : null);
? context.getSessionData(pref + CK.S_REACH_LOCATIONS) : null);
stage.set("reach-location-radii", context.getSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS) : null);
? context.getSessionData(pref + CK.S_REACH_LOCATIONS_RADIUS) : null);
stage.set("reach-location-names", context.getSessionData(pref + CK.S_REACH_LOCATIONS_NAMES) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_REACH_LOCATIONS_NAMES) : null);
? context.getSessionData(pref + CK.S_REACH_LOCATIONS_NAMES) : null);
stage.set("mobs-to-tame", context.getSessionData(pref + CK.S_TAME_TYPES) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_TAME_TYPES) : null);
? context.getSessionData(pref + CK.S_TAME_TYPES) : null);
stage.set("mob-tame-amounts", context.getSessionData(pref + CK.S_TAME_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_TAME_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_TAME_AMOUNTS) : null);
stage.set("sheep-to-shear", context.getSessionData(pref + CK.S_SHEAR_COLORS) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_SHEAR_COLORS) : null);
? context.getSessionData(pref + CK.S_SHEAR_COLORS) : null);
stage.set("sheep-amounts", context.getSessionData(pref + CK.S_SHEAR_AMOUNTS) != null
? (LinkedList<Integer>) context.getSessionData(pref + CK.S_SHEAR_AMOUNTS) : null);
? context.getSessionData(pref + CK.S_SHEAR_AMOUNTS) : null);
stage.set("password-displays", context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS) : null);
? context.getSessionData(pref + CK.S_PASSWORD_DISPLAYS) : null);
stage.set("password-phrases", context.getSessionData(pref + CK.S_PASSWORD_PHRASES) != null
? (LinkedList<String>) context.getSessionData(pref + CK.S_PASSWORD_PHRASES) : null);
? context.getSessionData(pref + CK.S_PASSWORD_PHRASES) : null);
final LinkedList<String> customObjs = (LinkedList<String>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES);
final LinkedList<Integer> customObjCounts
= (LinkedList<Integer>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT);
@ -761,6 +762,9 @@ public class QuestFactory implements ConversationAbandonedListener {
= (LinkedList<Entry<String, Object>>) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_DATA);
if (context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES) != null) {
final ConfigurationSection sec = stage.createSection("custom-objectives");
if (customObjs == null || customObjCounts == null || customObjsData == null) {
continue;
}
for (int index = 0; index < customObjs.size(); index++) {
final ConfigurationSection sec2 = sec.createSection("custom" + (index + 1));
sec2.set("name", customObjs.get(index));
@ -772,6 +776,9 @@ public class QuestFactory implements ConversationAbandonedListener {
break;
}
}
if (found == null) {
continue;
}
final ConfigurationSection sec3 = sec2.createSection("data");
for (final Entry<String, Object> datamap : found.getData()) {
for (final Entry<String, Object> e : customObjsData) {
@ -829,38 +836,38 @@ public class QuestFactory implements ConversationAbandonedListener {
private void saveRewards(final ConversationContext context, final ConfigurationSection section) {
final ConfigurationSection rews = section.createSection("rewards");
rews.set("items", context.getSessionData(CK.REW_ITEMS) != null
? (List<ItemStack>) context.getSessionData(CK.REW_ITEMS) : null);
? context.getSessionData(CK.REW_ITEMS) : null);
rews.set("money", context.getSessionData(CK.REW_MONEY) != null
? (Integer) context.getSessionData(CK.REW_MONEY) : null);
? context.getSessionData(CK.REW_MONEY) : null);
rews.set("quest-points", context.getSessionData(CK.REW_QUEST_POINTS) != null
? (Integer) context.getSessionData(CK.REW_QUEST_POINTS) : null);
? context.getSessionData(CK.REW_QUEST_POINTS) : null);
rews.set("exp", context.getSessionData(CK.REW_EXP) != null
? (Integer) context.getSessionData(CK.REW_EXP) : null);
? context.getSessionData(CK.REW_EXP) : null);
rews.set("commands", context.getSessionData(CK.REW_COMMAND) != null
? (List<String>) context.getSessionData(CK.REW_COMMAND) : null);
? context.getSessionData(CK.REW_COMMAND) : null);
rews.set("commands-override-display", context.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY) != null
? (List<String>) context.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY) : null);
? context.getSessionData(CK.REW_COMMAND_OVERRIDE_DISPLAY) : null);
rews.set("permissions", context.getSessionData(CK.REW_PERMISSION) != null
? (List<String>)context.getSessionData(CK.REW_PERMISSION) : null);
? context.getSessionData(CK.REW_PERMISSION) : null);
rews.set("permission-worlds", context.getSessionData(CK.REW_PERMISSION_WORLDS) != null
? (List<String>)context.getSessionData(CK.REW_PERMISSION_WORLDS) : null);
? context.getSessionData(CK.REW_PERMISSION_WORLDS) : null);
rews.set("mcmmo-skills", context.getSessionData(CK.REW_MCMMO_SKILLS) != null
? (List<String>) context.getSessionData(CK.REW_MCMMO_SKILLS) : null);
? context.getSessionData(CK.REW_MCMMO_SKILLS) : null);
rews.set("mcmmo-levels", context.getSessionData(CK.REW_MCMMO_AMOUNTS) != null
? (List<Integer>) context.getSessionData(CK.REW_MCMMO_AMOUNTS) : null);
? context.getSessionData(CK.REW_MCMMO_AMOUNTS) : null);
rews.set("heroes-exp-classes", context.getSessionData(CK.REW_HEROES_CLASSES) != null
? (List<String>) context.getSessionData(CK.REW_HEROES_CLASSES) : null);
? context.getSessionData(CK.REW_HEROES_CLASSES) : null);
rews.set("heroes-exp-amounts", context.getSessionData(CK.REW_HEROES_AMOUNTS) != null
? (List<Double>) context.getSessionData(CK.REW_HEROES_AMOUNTS) : null);
? context.getSessionData(CK.REW_HEROES_AMOUNTS) : null);
rews.set("parties-experience", context.getSessionData(CK.REW_PARTIES_EXPERIENCE) != null
? (Integer) context.getSessionData(CK.REW_PARTIES_EXPERIENCE) : null);
? context.getSessionData(CK.REW_PARTIES_EXPERIENCE) : null);
rews.set("phat-loots", context.getSessionData(CK.REW_PHAT_LOOTS) != null
? (List<String>) context.getSessionData(CK.REW_PHAT_LOOTS) : null);
? context.getSessionData(CK.REW_PHAT_LOOTS) : null);
final LinkedList<String> customRews = context.getSessionData(CK.REW_CUSTOM) != null
? (LinkedList<String>) context.getSessionData(CK.REW_CUSTOM) : null;
final LinkedList<Map<String, Object>> customRewsData = context.getSessionData(CK.REW_CUSTOM_DATA) != null
? (LinkedList<Map<String, Object>>) context.getSessionData(CK.REW_CUSTOM_DATA) : null;
if (customRews != null) {
if (customRews != null && customRewsData != null) {
final ConfigurationSection customRewsSec = rews.createSection("custom-rewards");
for (int i = 0; i < customRews.size(); i++) {
final ConfigurationSection customRewSec = customRewsSec.createSection("req" + (i + 1));
@ -869,7 +876,7 @@ public class QuestFactory implements ConversationAbandonedListener {
}
}
rews.set("details-override", context.getSessionData(CK.REW_DETAILS_OVERRIDE) != null
? (List<String>)context.getSessionData(CK.REW_DETAILS_OVERRIDE) : null);
? context.getSessionData(CK.REW_DETAILS_OVERRIDE) : null);
if (rews.getKeys(false).isEmpty()) {
section.set("rewards", null);
}
@ -878,15 +885,15 @@ public class QuestFactory implements ConversationAbandonedListener {
private void savePlanner(final ConversationContext context, final ConfigurationSection section) {
final ConfigurationSection pln = section.createSection("planner");
pln.set("start", context.getSessionData(CK.PLN_START_DATE) != null
? (String) context.getSessionData(CK.PLN_START_DATE) : null);
? context.getSessionData(CK.PLN_START_DATE) : null);
pln.set("end", context.getSessionData(CK.PLN_END_DATE) != null
? (String) context.getSessionData(CK.PLN_END_DATE) : null);
pln.set("repeat", context.getSessionData(CK.PLN_REPEAT_CYCLE) != null
? ((Long) context.getSessionData(CK.PLN_REPEAT_CYCLE) / 1000L) : null);
pln.set("cooldown", context.getSessionData(CK.PLN_COOLDOWN) != null
? ((Long) context.getSessionData(CK.PLN_COOLDOWN) / 1000L) : null);
? context.getSessionData(CK.PLN_END_DATE) : null);
final Long repeatCycle = (Long) context.getSessionData(CK.PLN_REPEAT_CYCLE);
pln.set("repeat", repeatCycle != null ? (repeatCycle / 1000L) : null);
final Long cooldown = (Long) context.getSessionData(CK.PLN_COOLDOWN);
pln.set("cooldown", cooldown != null ? (cooldown / 1000L) : null);
pln.set("override", context.getSessionData(CK.PLN_OVERRIDE) != null
? (Boolean) context.getSessionData(CK.PLN_OVERRIDE) : null);
? context.getSessionData(CK.PLN_OVERRIDE) : null);
if (pln.getKeys(false).isEmpty()) {
section.set("planner", null);
}
@ -895,23 +902,23 @@ public class QuestFactory implements ConversationAbandonedListener {
private void saveOptions(final ConversationContext context, final ConfigurationSection section) {
final ConfigurationSection opts = section.createSection("options");
opts.set("allow-commands", context.getSessionData(CK.OPT_ALLOW_COMMANDS) != null
? (Boolean) context.getSessionData(CK.OPT_ALLOW_COMMANDS) : null);
? context.getSessionData(CK.OPT_ALLOW_COMMANDS) : null);
opts.set("allow-quitting", context.getSessionData(CK.OPT_ALLOW_QUITTING) != null
? (Boolean) context.getSessionData(CK.OPT_ALLOW_QUITTING) : null);
? context.getSessionData(CK.OPT_ALLOW_QUITTING) : null);
opts.set("ignore-silk-touch", context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) != null
? (Boolean) context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) : null);
? context.getSessionData(CK.OPT_IGNORE_SILK_TOUCH) : null);
opts.set("use-dungeonsxl-plugin", context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) != null
? (Boolean) context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) : null);
? context.getSessionData(CK.OPT_USE_DUNGEONSXL_PLUGIN) : null);
opts.set("use-parties-plugin", context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) != null
? (Boolean) context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) : null);
? context.getSessionData(CK.OPT_USE_PARTIES_PLUGIN) : null);
opts.set("share-progress-level", context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) != null
? (Integer) context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) : null);
? context.getSessionData(CK.OPT_SHARE_PROGRESS_LEVEL) : null);
opts.set("same-quest-only", context.getSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY) != null
? (Boolean) context.getSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY) : null);
? context.getSessionData(CK.OPT_SHARE_SAME_QUEST_ONLY) : null);
opts.set("share-distance", context.getSessionData(CK.OPT_SHARE_DISTANCE) != null
? (Double) context.getSessionData(CK.OPT_SHARE_DISTANCE) : null);
? context.getSessionData(CK.OPT_SHARE_DISTANCE) : null);
opts.set("handle-offline-players", context.getSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS) != null
? (Boolean) context.getSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS) : null);
? context.getSessionData(CK.OPT_HANDLE_OFFLINE_PLAYERS) : null);
if (opts.getKeys(false).isEmpty()) {
section.set("options", null);
}

View File

@ -118,6 +118,9 @@ public class QuestMob {
@SuppressWarnings("deprecation")
public void spawn() {
final World world = spawnLocation.getWorld();
if (world == null) {
return;
}
for (int i = 0; i < spawnAmounts; i++) {
final LivingEntity entity = (LivingEntity) world.spawnEntity(spawnLocation, entityType);
if (name != null) {
@ -125,6 +128,9 @@ public class QuestMob {
entity.setCustomNameVisible(true);
}
final EntityEquipment eq = entity.getEquipment();
if (eq == null) {
return;
}
eq.setItemInHand(inventory[0]);
eq.setBoots(inventory[1]);
eq.setLeggings(inventory[2]);
@ -252,7 +258,7 @@ public class QuestMob {
}
}
}
final QuestMob qm = new QuestMob(entityType, loc, amounts);
final QuestMob qm = new QuestMob(entityType, loc, amounts != null ? amounts : 1);
qm.setName(name);
qm.inventory = inventory;
qm.dropChances = dropChances;

View File

@ -11,18 +11,6 @@
*/
package me.blackvein.quests.actions;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import me.blackvein.quests.Quest;
import me.blackvein.quests.QuestMob;
import me.blackvein.quests.Quester;
@ -31,6 +19,17 @@ import me.blackvein.quests.tasks.ActionTimer;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.InventoryUtil;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
public class Action implements Comparable<Action> {
@ -39,9 +38,9 @@ public class Action implements Comparable<Action> {
protected String message = null;
protected boolean clearInv = false;
protected boolean failQuest = false;
protected LinkedList<Location> explosions = new LinkedList<Location>();
protected Map<Location, Effect> effects = new HashMap<Location, Effect>();
protected LinkedList<ItemStack> items = new LinkedList<ItemStack>();
protected LinkedList<Location> explosions = new LinkedList<>();
protected Map<Location, Effect> effects = new HashMap<>();
protected LinkedList<ItemStack> items = new LinkedList<>();
protected World stormWorld = null;
protected int stormDuration = 0;
protected World thunderWorld = null;
@ -62,7 +61,7 @@ public class Action implements Comparable<Action> {
return false;
}
for (int i = 0; i < size(); i++) {
if (get(i).equals(other.get(i)) == false) {
if (!get(i).equals(other.get(i))) {
return false;
}
}
@ -70,9 +69,9 @@ public class Action implements Comparable<Action> {
return false;
}
};
protected LinkedList<Location> lightningStrikes = new LinkedList<Location>();
protected LinkedList<String> commands = new LinkedList<String>();
protected LinkedList<PotionEffect> potionEffects = new LinkedList<PotionEffect>();
protected LinkedList<Location> lightningStrikes = new LinkedList<>();
protected LinkedList<String> commands = new LinkedList<>();
protected LinkedList<PotionEffect> potionEffects = new LinkedList<>();
protected int hunger = -1;
protected int saturation = -1;
protected float health = -1;
@ -278,20 +277,24 @@ public class Action implements Comparable<Action> {
if (message != null) {
player.sendMessage(ConfigUtil.parseStringWithPossibleLineBreaks(message, quest, player));
}
if (clearInv == true) {
if (clearInv) {
player.getInventory().clear();
}
if (explosions.isEmpty() == false) {
if (!explosions.isEmpty()) {
for (final Location l : explosions) {
l.getWorld().createExplosion(l, 4F, false);
if (l.getWorld() != null) {
l.getWorld().createExplosion(l, 4F, false);
}
}
}
if (effects.isEmpty() == false) {
if (!effects.isEmpty()) {
for (final Location l : effects.keySet()) {
l.getWorld().playEffect(l, effects.get(l), 1);
if (l.getWorld() != null) {
l.getWorld().playEffect(l, effects.get(l), 1);
}
}
}
if (items.isEmpty() == false) {
if (!items.isEmpty()) {
for (final ItemStack is : items) {
try {
InventoryUtil.addItem(player, is);
@ -311,23 +314,25 @@ public class Action implements Comparable<Action> {
thunderWorld.setThundering(true);
thunderWorld.setThunderDuration(thunderDuration);
}
if (mobSpawns.isEmpty() == false) {
if (!mobSpawns.isEmpty()) {
for (final QuestMob questMob : mobSpawns) {
questMob.spawn();
}
}
if (lightningStrikes.isEmpty() == false) {
if (!lightningStrikes.isEmpty()) {
for (final Location l : lightningStrikes) {
l.getWorld().strikeLightning(l);
if (l.getWorld() != null) {
l.getWorld().strikeLightning(l);
}
}
}
if (commands.isEmpty() == false) {
if (!commands.isEmpty()) {
for (final String s : commands) {
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(),
s.replace("<player>", quester.getPlayer().getName()));
}
}
if (potionEffects.isEmpty() == false) {
if (!potionEffects.isEmpty()) {
for (final PotionEffect p : potionEffects) {
player.addPotionEffect(p);
}
@ -359,7 +364,7 @@ public class Action implements Comparable<Action> {
}
}
}
if (failQuest == true) {
if (failQuest) {
quest.failQuest(quester, true);
}
if (timer > 0) {
@ -367,38 +372,38 @@ public class Action implements Comparable<Action> {
.replace("<time>", ChatColor.RED + String.valueOf(timer) + ChatColor.GREEN));
if (timer > 60) {
quester.getTimers().put(new ActionTimer(quester, quest, 60, false)
.runTaskLater(plugin, (timer-60)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 60) * 20L).getTaskId(), quest);
}
if (timer > 30) {
quester.getTimers().put(new ActionTimer(quester, quest, 30, false)
.runTaskLater(plugin, (timer-30)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 30) * 20L).getTaskId(), quest);
}
if (timer > 10) {
quester.getTimers().put(new ActionTimer(quester, quest, 10, false)
.runTaskLater(plugin, (timer-10)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 10) * 20L).getTaskId(), quest);
}
if (timer > 5) {
quester.getTimers().put(new ActionTimer(quester, quest, 5, false)
.runTaskLater(plugin, (timer-5)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 5) * 20L).getTaskId(), quest);
}
if (timer > 4) {
quester.getTimers().put(new ActionTimer(quester, quest, 4, false)
.runTaskLater(plugin, (timer-4)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 4) * 20L).getTaskId(), quest);
}
if (timer > 3) {
quester.getTimers().put(new ActionTimer(quester, quest, 3, false)
.runTaskLater(plugin, (timer-3)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 3) * 20L).getTaskId(), quest);
}
if (timer > 2) {
quester.getTimers().put(new ActionTimer(quester, quest, 2, false)
.runTaskLater(plugin, (timer-2)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 2) * 20L).getTaskId(), quest);
}
if (timer > 1) {
quester.getTimers().put(new ActionTimer(quester, quest, 1, false)
.runTaskLater(plugin, (timer-1)*20).getTaskId(), quest);
.runTaskLater(plugin, (timer - 1) * 20L).getTaskId(), quest);
}
quester.getTimers().put(new ActionTimer(quester, quest, 0, true)
.runTaskLater(plugin, timer*20).getTaskId(), quest);
.runTaskLater(plugin, timer * 20L).getTaskId(), quest);
}
if (cancelTimer) {
for (final Map.Entry<Integer, Quest> entry : quester.getTimers().entrySet()) {

View File

@ -12,16 +12,18 @@
package me.blackvein.quests.actions;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import me.blackvein.quests.Quest;
import me.blackvein.quests.QuestMob;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.actions.main.ActionMainPrompt;
import me.blackvein.quests.convo.actions.menu.ActionMenuPrompt;
import me.blackvein.quests.interfaces.ReloadCallback;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.FakeConversable;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.Effect;
import org.bukkit.Location;
@ -38,41 +40,42 @@ import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.jetbrains.annotations.NotNull;
import me.blackvein.quests.Quest;
import me.blackvein.quests.QuestMob;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.actions.main.ActionMainPrompt;
import me.blackvein.quests.convo.actions.menu.ActionMenuPrompt;
import me.blackvein.quests.interfaces.ReloadCallback;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.ConfigUtil;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.Lang;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.UUID;
public class ActionFactory implements ConversationAbandonedListener {
private final Quests plugin;
private final ConversationFactory convoCreator;
private Map<UUID, Block> selectedExplosionLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedEffectLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedMobLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedLightningLocations = new HashMap<UUID, Block>();
private Map<UUID, Block> selectedTeleportLocations = new HashMap<UUID, Block>();
private List<String> editingActionNames = new LinkedList<String>();
private Map<UUID, Block> selectedExplosionLocations = new HashMap<>();
private Map<UUID, Block> selectedEffectLocations = new HashMap<>();
private Map<UUID, Block> selectedMobLocations = new HashMap<>();
private Map<UUID, Block> selectedLightningLocations = new HashMap<>();
private Map<UUID, Block> selectedTeleportLocations = new HashMap<>();
private List<String> editingActionNames = new LinkedList<>();
public ActionFactory(final Quests plugin) {
this.plugin = plugin;
// Ensure to initialize convoCreator last so that 'this' is fully initialized before it is passed
this.convoCreator = new ConversationFactory(plugin).withModality(false).withLocalEcho(false)
.withFirstPrompt(new ActionMenuPrompt(new ConversationContext(plugin, null, null))).withTimeout(3600)
.withFirstPrompt(new ActionMenuPrompt(new ConversationContext(plugin, new FakeConversable(),
new HashMap<>()))).withTimeout(3600)
.withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this);
}
public class LineBreakPrefix implements ConversationPrefix {
public static class LineBreakPrefix implements ConversationPrefix {
@Override
public String getPrefix(final ConversationContext context) {
public @NotNull String getPrefix(final @NotNull ConversationContext context) {
return "\n";
}
}
@ -152,31 +155,30 @@ public class ActionFactory implements ConversationAbandonedListener {
if (event.message != null) {
context.setSessionData(CK.E_MESSAGE, event.message);
}
if (event.clearInv == true) {
if (event.clearInv) {
context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("yesWord"));
} else {
context.setSessionData(CK.E_CLEAR_INVENTORY, Lang.get("noWord"));
}
if (event.failQuest == true) {
if (event.failQuest) {
context.setSessionData(CK.E_FAIL_QUEST, Lang.get("yesWord"));
} else {
context.setSessionData(CK.E_FAIL_QUEST, Lang.get("noWord"));
}
if (event.items != null && event.items.isEmpty() == false) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
items.addAll(event.items);
if (event.items != null && !event.items.isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<>(event.items);
context.setSessionData(CK.E_ITEMS, items);
}
if (event.explosions != null && event.explosions.isEmpty() == false) {
final LinkedList<String> locs = new LinkedList<String>();
if (event.explosions != null && !event.explosions.isEmpty()) {
final LinkedList<String> locs = new LinkedList<>();
for (final Location loc : event.explosions) {
locs.add(ConfigUtil.getLocationInfo(loc));
}
context.setSessionData(CK.E_EXPLOSIONS, locs);
}
if (event.effects != null && event.effects.isEmpty() == false) {
final LinkedList<String> locs = new LinkedList<String>();
final LinkedList<String> effs = new LinkedList<String>();
if (event.effects != null && !event.effects.isEmpty()) {
final LinkedList<String> locs = new LinkedList<>();
final LinkedList<String> effs = new LinkedList<>();
for (final Entry<Location, Effect> e : event.effects.entrySet()) {
locs.add(ConfigUtil.getLocationInfo(e.getKey()));
effs.add(e.getValue().toString());
@ -192,24 +194,24 @@ public class ActionFactory implements ConversationAbandonedListener {
context.setSessionData(CK.E_WORLD_THUNDER, event.thunderWorld.getName());
context.setSessionData(CK.E_WORLD_THUNDER_DURATION, event.thunderDuration);
}
if (event.mobSpawns != null && event.mobSpawns.isEmpty() == false) {
final LinkedList<String> questMobs = new LinkedList<String>();
if (event.mobSpawns != null && !event.mobSpawns.isEmpty()) {
final LinkedList<String> questMobs = new LinkedList<>();
for (final QuestMob questMob : event.mobSpawns) {
questMobs.add(questMob.serialize());
}
context.setSessionData(CK.E_MOB_TYPES, questMobs);
}
if (event.lightningStrikes != null && event.lightningStrikes.isEmpty() == false) {
final LinkedList<String> locs = new LinkedList<String>();
if (event.lightningStrikes != null && !event.lightningStrikes.isEmpty()) {
final LinkedList<String> locs = new LinkedList<>();
for (final Location loc : event.lightningStrikes) {
locs.add(ConfigUtil.getLocationInfo(loc));
}
context.setSessionData(CK.E_LIGHTNING, locs);
}
if (event.potionEffects != null && event.potionEffects.isEmpty() == false) {
final LinkedList<String> types = new LinkedList<String>();
final LinkedList<Long> durations = new LinkedList<Long>();
final LinkedList<Integer> mags = new LinkedList<Integer>();
if (event.potionEffects != null && !event.potionEffects.isEmpty()) {
final LinkedList<String> types = new LinkedList<>();
final LinkedList<Long> durations = new LinkedList<>();
final LinkedList<Integer> mags = new LinkedList<>();
for (final PotionEffect pe : event.potionEffects) {
types.add(pe.getType().getName());
durations.add((long) pe.getDuration());
@ -276,12 +278,7 @@ public class ActionFactory implements ConversationAbandonedListener {
final File actionsFile = new File(plugin.getDataFolder(), "actions.yml");
try {
data.load(actionsFile);
} catch (final IOException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", actionsFile.getName()));
return;
} catch (final InvalidConfigurationException e) {
} catch (final IOException | InvalidConfigurationException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", actionsFile.getName()));
@ -294,19 +291,18 @@ public class ActionFactory implements ConversationAbandonedListener {
key = "events";
sec = data.getConfigurationSection(key);
}
sec.set(action, null);
if (sec != null && action != null) {
sec.set(action, null);
}
try {
data.save(actionsFile);
} catch (final IOException e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questSaveError"));
return;
}
final ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
@Override
public void execute(final Boolean response) {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
final ReloadCallback<Boolean> callback = response -> {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
};
plugin.reload(callback);
@ -330,43 +326,37 @@ public class ActionFactory implements ConversationAbandonedListener {
final File actionsFile = new File(plugin.getDataFolder(), "actions.yml");
try {
data.load(actionsFile);
} catch (final IOException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", actionsFile.getName()));
return;
} catch (final InvalidConfigurationException e) {
} catch (final IOException | InvalidConfigurationException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", actionsFile.getName()));
return;
}
String key = "actions";
ConfigurationSection sec = data.getConfigurationSection(key);
if (sec == null) {
if (data.getConfigurationSection(key) == null) {
key = "events";
sec = data.getConfigurationSection(key);
}
if (((String) context.getSessionData(CK.E_OLD_EVENT)).isEmpty() == false) {
data.set(key + "." + (String) context.getSessionData(CK.E_OLD_EVENT), null);
if (context.getSessionData(CK.E_OLD_EVENT) != null
&& !((String) Objects.requireNonNull(context.getSessionData(CK.E_OLD_EVENT))).isEmpty()) {
data.set(key + "." + context.getSessionData(CK.E_OLD_EVENT), null);
final Collection<Action> temp = plugin.getLoadedActions();
temp.remove(plugin.getAction((String) context.getSessionData(CK.E_OLD_EVENT)));
plugin.setLoadedActions(temp);
}
final ConfigurationSection section = data.createSection(key + "." + (String) context.getSessionData(CK.E_NAME));
editingActionNames.remove(context.getSessionData(CK.E_NAME));
final ConfigurationSection section = data.createSection(key + "." + context.getSessionData(CK.E_NAME));
editingActionNames.remove((String) context.getSessionData(CK.E_NAME));
if (context.getSessionData(CK.E_MESSAGE) != null) {
section.set("message", context.getSessionData(CK.E_MESSAGE));
}
if (context.getSessionData(CK.E_CLEAR_INVENTORY) != null) {
final String s = (String) context.getSessionData(CK.E_CLEAR_INVENTORY);
if (s.equalsIgnoreCase(Lang.get("yesWord"))) {
if (s != null && s.equalsIgnoreCase(Lang.get("yesWord"))) {
section.set("clear-inventory", true);
}
}
if (context.getSessionData(CK.E_FAIL_QUEST) != null) {
final String s = (String) context.getSessionData(CK.E_FAIL_QUEST);
if (s.equalsIgnoreCase(Lang.get("yesWord"))) {
if (s != null && s.equalsIgnoreCase(Lang.get("yesWord"))) {
section.set("fail-quest", true);
}
}
@ -391,13 +381,14 @@ public class ActionFactory implements ConversationAbandonedListener {
try {
if (context.getSessionData(CK.E_MOB_TYPES) != null) {
int count = 0;
for (final String s : (LinkedList<String>) context.getSessionData(CK.E_MOB_TYPES)) {
for (final String s : (LinkedList<String>) Objects.requireNonNull(context
.getSessionData(CK.E_MOB_TYPES))) {
ConfigurationSection ss = section.getConfigurationSection("mob-spawns." + count);
if (ss == null) {
ss = section.createSection("mob-spawns." + count);
}
final QuestMob questMob = QuestMob.fromString(s);
if (questMob == null) {
if (questMob.getName() == null) {
continue;
}
ss.set("name", questMob.getName());
@ -425,7 +416,7 @@ public class ActionFactory implements ConversationAbandonedListener {
}
if (context.getSessionData(CK.E_COMMANDS) != null) {
final LinkedList<String> commands = (LinkedList<String>) context.getSessionData(CK.E_COMMANDS);
if (commands.isEmpty() == false) {
if (commands != null && !commands.isEmpty()) {
section.set("commands", commands);
}
}
@ -446,12 +437,15 @@ public class ActionFactory implements ConversationAbandonedListener {
if (context.getSessionData(CK.E_TELEPORT) != null) {
section.set("teleport-location", context.getSessionData(CK.E_TELEPORT));
}
if (context.getSessionData(CK.E_TIMER) != null && (int) context.getSessionData(CK.E_TIMER) > 0) {
section.set("timer", context.getSessionData(CK.E_TIMER));
if (context.getSessionData(CK.E_TIMER) != null) {
final Integer i = (Integer) context.getSessionData(CK.E_TIMER);
if (i != null && i > 0) {
section.set("timer", context.getSessionData(CK.E_TIMER));
}
}
if (context.getSessionData(CK.E_CANCEL_TIMER) != null) {
final String s = (String) context.getSessionData(CK.E_CANCEL_TIMER);
if (s.equalsIgnoreCase(Lang.get("yesWord"))) {
if (s != null && s.equalsIgnoreCase(Lang.get("yesWord"))) {
section.set("cancel-timer", true);
}
}
@ -464,12 +458,9 @@ public class ActionFactory implements ConversationAbandonedListener {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questSaveError"));
return;
}
final ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
@Override
public void execute(final Boolean response) {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
final ReloadCallback<Boolean> callback = response -> {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
};
plugin.reload(callback);
@ -477,7 +468,7 @@ public class ActionFactory implements ConversationAbandonedListener {
if (plugin.getSettings().getConsoleLogging() > 0) {
final String identifier = context.getForWhom() instanceof Player ?
"Player " + ((Player)context.getForWhom()).getUniqueId() : "CONSOLE";
plugin.getLogger().info(identifier + " saved action " + (String) context.getSessionData(CK.E_NAME));
plugin.getLogger().info(identifier + " saved action " + context.getSessionData(CK.E_NAME));
}
for (final Quester q : plugin.getOfflineQuesters()) {
for (final Quest quest : q.getCurrentQuests().keySet()) {

View File

@ -12,32 +12,32 @@
package me.blackvein.quests.conditions;
import java.util.LinkedList;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.util.ItemUtil;
import me.blackvein.quests.util.MiscUtil;
import me.clip.placeholderapi.PlaceholderAPI;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.LinkedList;
import java.util.Objects;
public class Condition implements Comparable<Condition> {
private final Quests plugin;
private String name = "";
private boolean failQuest = false;
private LinkedList<String> entitiesWhileRiding = new LinkedList<String>();
private LinkedList<Integer> npcsWhileRiding = new LinkedList<Integer>();
private LinkedList<String> permissions = new LinkedList<String>();
private LinkedList<ItemStack> itemsWhileHoldingMainHand = new LinkedList<ItemStack>();
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<String>();
private LinkedList<String> biomesWhileStayingWithin = new LinkedList<String>();
private LinkedList<String> regionsWhileStayingWithin = new LinkedList<String>();
private LinkedList<String> placeholdersCheckIdentifier = new LinkedList<String>();
private LinkedList<String> placeholdersCheckValue = new LinkedList<String>();
private LinkedList<String> entitiesWhileRiding = new LinkedList<>();
private LinkedList<Integer> npcsWhileRiding = new LinkedList<>();
private LinkedList<String> permissions = new LinkedList<>();
private LinkedList<ItemStack> itemsWhileHoldingMainHand = new LinkedList<>();
private LinkedList<String> worldsWhileStayingWithin = new LinkedList<>();
private LinkedList<String> biomesWhileStayingWithin = new LinkedList<>();
private LinkedList<String> regionsWhileStayingWithin = new LinkedList<>();
private LinkedList<String> placeholdersCheckIdentifier = new LinkedList<>();
private LinkedList<String> placeholdersCheckValue = new LinkedList<>();
public Condition(final Quests plugin) {
this.plugin = plugin;
@ -141,7 +141,7 @@ public class Condition implements Comparable<Condition> {
final Player player = quester.getPlayer();
if (!entitiesWhileRiding.isEmpty()) {
for (final String e : entitiesWhileRiding) {
if (player.isInsideVehicle() && player.getVehicle().getType().equals(MiscUtil.getProperMobType(e))) {
if (player.getVehicle() != null && player.getVehicle().getType().equals(MiscUtil.getProperMobType(e))) {
return true;
} else if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition entity mismatch for " + player.getName() + ": " + e);
@ -150,7 +150,7 @@ public class Condition implements Comparable<Condition> {
} else if (!npcsWhileRiding.isEmpty()) {
for (final int n : npcsWhileRiding) {
if (plugin.getDependencies().getCitizens() != null) {
if (player.isInsideVehicle() && player.getVehicle()
if (player.getVehicle() != null && player.getVehicle()
.equals(plugin.getDependencies().getCitizens().getNPCRegistry().getById(n).getEntity())) {
return true;
} else if (plugin.getSettings().getConsoleLogging() > 2) {
@ -189,8 +189,11 @@ public class Condition implements Comparable<Condition> {
}
} else if (!biomesWhileStayingWithin.isEmpty()) {
for (final String b : biomesWhileStayingWithin) {
if (MiscUtil.getProperBiome(b) == null) {
continue;
}
if (player.getWorld().getBiome(player.getLocation().getBlockX(), player.getLocation().getBlockZ())
.name().equalsIgnoreCase(MiscUtil.getProperBiome(b).name())) {
.name().equalsIgnoreCase(Objects.requireNonNull(MiscUtil.getProperBiome(b)).name())) {
return true;
} else if (plugin.getSettings().getConsoleLogging() > 2) {
plugin.getLogger().info("DEBUG: Condition biome mismatch for " + player.getName() + ": "

View File

@ -12,12 +12,15 @@
package me.blackvein.quests.conditions;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.conditions.main.ConditionMainPrompt;
import me.blackvein.quests.convo.conditions.menu.ConditionMenuPrompt;
import me.blackvein.quests.interfaces.ReloadCallback;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.FakeConversable;
import me.blackvein.quests.util.Lang;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.InvalidConfigurationException;
@ -30,33 +33,34 @@ import org.bukkit.conversations.ConversationPrefix;
import org.bukkit.conversations.Prompt;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import me.blackvein.quests.Quest;
import me.blackvein.quests.Quester;
import me.blackvein.quests.Quests;
import me.blackvein.quests.convo.conditions.main.ConditionMainPrompt;
import me.blackvein.quests.convo.conditions.menu.ConditionMenuPrompt;
import me.blackvein.quests.interfaces.ReloadCallback;
import me.blackvein.quests.util.CK;
import me.blackvein.quests.util.Lang;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
public class ConditionFactory implements ConversationAbandonedListener {
private final Quests plugin;
private final ConversationFactory convoCreator;
private List<String> editingConditionNames = new LinkedList<String>();
private List<String> editingConditionNames = new LinkedList<>();
public ConditionFactory(final Quests plugin) {
this.plugin = plugin;
// Ensure to initialize convoCreator last so that 'this' is fully initialized before it is passed
this.convoCreator = new ConversationFactory(plugin).withModality(false).withLocalEcho(false)
.withFirstPrompt(new ConditionMenuPrompt(new ConversationContext(plugin, null, null))).withTimeout(3600)
.withFirstPrompt(new ConditionMenuPrompt(new ConversationContext(plugin, new FakeConversable(),
new HashMap<>()))).withTimeout(3600)
.withPrefix(new LineBreakPrefix()).addConversationAbandonedListener(this);
}
public class LineBreakPrefix implements ConversationPrefix {
public static class LineBreakPrefix implements ConversationPrefix {
@Override
public String getPrefix(final ConversationContext context) {
public @NotNull String getPrefix(final @NotNull ConversationContext context) {
return "\n";
}
}
@ -74,7 +78,7 @@ public class ConditionFactory implements ConversationAbandonedListener {
}
@Override
public void conversationAbandoned(final ConversationAbandonedEvent abandonedEvent) {
public void conversationAbandoned(final @NotNull ConversationAbandonedEvent abandonedEvent) {
}
public Prompt returnToMenu(final ConversationContext context) {
@ -82,63 +86,46 @@ public class ConditionFactory implements ConversationAbandonedListener {
}
public void loadData(final Condition condition, final ConversationContext context) {
if (condition.isFailQuest() == true) {
if (condition.isFailQuest()) {
context.setSessionData(CK.C_FAIL_QUEST, Lang.get("yesWord"));
} else {
context.setSessionData(CK.C_FAIL_QUEST, Lang.get("noWord"));
}
if (condition.getEntitiesWhileRiding() != null
&& condition.getEntitiesWhileRiding().isEmpty() == false) {
final LinkedList<String> entities = new LinkedList<String>();
entities.addAll(condition.getEntitiesWhileRiding());
if (condition.getEntitiesWhileRiding() != null && !condition.getEntitiesWhileRiding().isEmpty()) {
final LinkedList<String> entities = new LinkedList<>(condition.getEntitiesWhileRiding());
context.setSessionData(CK.C_WHILE_RIDING_ENTITY, entities);
}
if (condition.getNpcsWhileRiding() != null
&& condition.getNpcsWhileRiding().isEmpty() == false) {
final LinkedList<Integer> npcs = new LinkedList<Integer>();
npcs.addAll(condition.getNpcsWhileRiding());
if (condition.getNpcsWhileRiding() != null && !condition.getNpcsWhileRiding().isEmpty()) {
final LinkedList<Integer> npcs = new LinkedList<>(condition.getNpcsWhileRiding());
context.setSessionData(CK.C_WHILE_RIDING_NPC, npcs);
}
if (condition.getPermissions() != null
&& condition.getPermissions().isEmpty() == false) {
final LinkedList<String> permissions = new LinkedList<String>();
permissions.addAll(condition.getPermissions());
if (condition.getPermissions() != null && !condition.getPermissions().isEmpty()) {
final LinkedList<String> permissions = new LinkedList<>(condition.getPermissions());
context.setSessionData(CK.C_WHILE_PERMISSION, permissions);
}
if (condition.getItemsWhileHoldingMainHand() != null
&& condition.getItemsWhileHoldingMainHand().isEmpty() == false) {
final LinkedList<ItemStack> items = new LinkedList<ItemStack>();
items.addAll(condition.getItemsWhileHoldingMainHand());
if (condition.getItemsWhileHoldingMainHand() != null && !condition.getItemsWhileHoldingMainHand().isEmpty()) {
final LinkedList<ItemStack> items = new LinkedList<>(condition.getItemsWhileHoldingMainHand());
context.setSessionData(CK.C_WHILE_HOLDING_MAIN_HAND, items);
}
if (condition.getWorldsWhileStayingWithin() != null
&& condition.getWorldsWhileStayingWithin().isEmpty() == false) {
final LinkedList<String> worlds = new LinkedList<String>();
worlds.addAll(condition.getBiomesWhileStayingWithin());
if (condition.getWorldsWhileStayingWithin() != null && !condition.getWorldsWhileStayingWithin().isEmpty()) {
final LinkedList<String> worlds = new LinkedList<>(condition.getBiomesWhileStayingWithin());
context.setSessionData(CK.C_WHILE_WITHIN_WORLD, worlds);
}
if (condition.getBiomesWhileStayingWithin() != null
&& condition.getBiomesWhileStayingWithin().isEmpty() == false) {
final LinkedList<String> biomes = new LinkedList<String>();
biomes.addAll(condition.getBiomesWhileStayingWithin());
if (condition.getBiomesWhileStayingWithin() != null && !condition.getBiomesWhileStayingWithin().isEmpty()) {
final LinkedList<String> biomes = new LinkedList<>(condition.getBiomesWhileStayingWithin());
context.setSessionData(CK.C_WHILE_WITHIN_BIOME, biomes);
}
if (condition.getRegionsWhileStayingWithin() != null
&& condition.getRegionsWhileStayingWithin().isEmpty() == false) {
final LinkedList<String> regions = new LinkedList<String>();
regions.addAll(condition.getRegionsWhileStayingWithin());
if (condition.getRegionsWhileStayingWithin() != null && !condition.getRegionsWhileStayingWithin().isEmpty()) {
final LinkedList<String> regions = new LinkedList<>(condition.getRegionsWhileStayingWithin());
context.setSessionData(CK.C_WHILE_WITHIN_REGION, regions);
}
if (condition.getPlaceholdersCheckIdentifier() != null
&& condition.getPlaceholdersCheckIdentifier().isEmpty() == false) {
final LinkedList<String> identifiers = new LinkedList<String>();
identifiers.addAll(condition.getPlaceholdersCheckIdentifier());
if (condition.getPlaceholdersCheckIdentifier() != null
&& !condition.getPlaceholdersCheckIdentifier().isEmpty()) {
final LinkedList<String> identifiers = new LinkedList<>(condition.getPlaceholdersCheckIdentifier());
context.setSessionData(CK.C_WHILE_PLACEHOLDER_ID, identifiers);
}
if (condition.getPlaceholdersCheckValue() != null
&& condition.getPlaceholdersCheckValue().isEmpty() == false) {
final LinkedList<String> values = new LinkedList<String>();
values.addAll(condition.getPlaceholdersCheckValue());
if (condition.getPlaceholdersCheckValue() != null && !condition.getPlaceholdersCheckValue().isEmpty()) {
final LinkedList<String> values = new LinkedList<>(condition.getPlaceholdersCheckValue());
context.setSessionData(CK.C_WHILE_PLACEHOLDER_VAL, values);
}
}
@ -163,12 +150,7 @@ public class ConditionFactory implements ConversationAbandonedListener {
final File conditionsFile = new File(plugin.getDataFolder(), "conditions.yml");
try {
data.load(conditionsFile);
} catch (final IOException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", conditionsFile.getName()));
return;
} catch (final InvalidConfigurationException e) {
} catch (final IOException | InvalidConfigurationException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", conditionsFile.getName()));
@ -176,19 +158,18 @@ public class ConditionFactory implements ConversationAbandonedListener {
}
final String condition = (String) context.getSessionData(CK.ED_CONDITION_DELETE);
final ConfigurationSection sec = data.getConfigurationSection("conditions");
sec.set(condition, null);
if (sec != null && condition != null) {
sec.set(condition, null);
}
try {
data.save(conditionsFile);
} catch (final IOException e) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questSaveError"));
return;
}
final ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
@Override
public void execute(final Boolean response) {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
final ReloadCallback<Boolean> callback = response -> {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
};
plugin.reload(callback);
@ -211,28 +192,24 @@ public class ConditionFactory implements ConversationAbandonedListener {
final File conditionsFile = new File(plugin.getDataFolder(), "conditions.yml");
try {
data.load(conditionsFile);
} catch (final IOException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", conditionsFile.getName()));
return;
} catch (final InvalidConfigurationException e) {
} catch (final IOException | InvalidConfigurationException e) {
e.printStackTrace();
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile")
.replace("<file>", conditionsFile.getName()));
return;
}
if (((String) context.getSessionData(CK.C_OLD_CONDITION)).isEmpty() == false) {
data.set("conditions." + (String) context.getSessionData(CK.C_OLD_CONDITION), null);
if (context.getSessionData(CK.C_OLD_CONDITION) != null
&& !((String) Objects.requireNonNull(context.getSessionData(CK.C_OLD_CONDITION))).isEmpty()) {
data.set("conditions." + context.getSessionData(CK.C_OLD_CONDITION), null);
final Collection<Condition> temp = plugin.getLoadedConditions();
temp.remove(plugin.getCondition((String) context.getSessionData(CK.C_OLD_CONDITION)));
plugin.setLoadedConditions(temp);
}
final ConfigurationSection section = data.createSection("conditions." + (String) context.getSessionData(CK.C_NAME));
editingConditionNames.remove(context.getSessionData(CK.C_NAME));
final ConfigurationSection section = data.createSection("conditions." + context.getSessionData(CK.C_NAME));
editingConditionNames.remove((String) context.getSessionData(CK.C_NAME));
if (context.getSessionData(CK.C_FAIL_QUEST) != null) {
final String s = (String) context.getSessionData(CK.C_FAIL_QUEST);
if (s.equalsIgnoreCase(Lang.get("yesWord"))) {
if (s != null && s.equalsIgnoreCase(Lang.get("yesWord"))) {
section.set("fail-quest", true);
}
}
@ -278,12 +255,9 @@ public class ConditionFactory implements ConversationAbandonedListener {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questSaveError"));
return;
}
final ReloadCallback<Boolean> callback = new ReloadCallback<Boolean>() {
@Override
public void execute(final Boolean response) {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
final ReloadCallback<Boolean> callback = response -> {
if (!response) {
context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError"));
}
};
plugin.reload(callback);
@ -291,7 +265,7 @@ public class ConditionFactory implements ConversationAbandonedListener {
if (plugin.getSettings().getConsoleLogging() > 0) {
final String identifier = context.getForWhom() instanceof Player ?
"Player " + ((Player)context.getForWhom()).getUniqueId() : "CONSOLE";
plugin.getLogger().info(identifier + " saved condition " + (String) context.getSessionData(CK.C_NAME));
plugin.getLogger().info(identifier + " saved condition " + context.getSessionData(CK.C_NAME));
}
for (final Quester q : plugin.getOfflineQuesters()) {
for (final Quest quest : q.getCurrentQuests().keySet()) {

View File

@ -0,0 +1,119 @@
/*
* Copyright (c) 2014 PikaMug and contributors. All rights reserved.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package me.blackvein.quests.util;
import org.bukkit.Server;
import org.bukkit.conversations.Conversable;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
/**
* For use when creating a new ConversationContext
*/
public class FakeConversable implements Conversable {
public String lastSentMessage;
public Conversation begunConversation;
public Conversation abandonedConverstion;
public ConversationAbandonedEvent abandonedConversationEvent;
public boolean isConversing() {
return false;
}
public void acceptConversationInput(@NotNull String input) {
}
public boolean beginConversation(Conversation conversation) {
begunConversation = conversation;
conversation.outputNextPrompt();
return true;
}
public void abandonConversation(@NotNull Conversation conversation) {
abandonedConverstion = conversation;
}
public void abandonConversation(@NotNull Conversation conversation, @NotNull ConversationAbandonedEvent details) {
abandonedConverstion = conversation;
abandonedConversationEvent = details;
}
public void sendRawMessage(@NotNull String message) {
lastSentMessage = message;
}
public Server getServer() {
return null;
}
public String getName() {
return null;
}
public boolean isPermissionSet(String name) {
return false;
}
public boolean isPermissionSet(Permission perm) {
return false;
}
public boolean hasPermission(String name) {
return false;
}
public boolean hasPermission(Permission perm) {
return false;
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
return null;
}
public PermissionAttachment addAttachment(Plugin plugin) {
return null;
}
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
return null;
}
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
return null;
}
public void removeAttachment(PermissionAttachment attachment) {
}
public void recalculatePermissions() {
}
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
return null;
}
public boolean isOp() {
return false;
}
public void setOp(boolean value) {
}
}