diff --git a/main/src/main/java/me/blackvein/quests/Quest.java b/main/src/main/java/me/blackvein/quests/Quest.java index b9d7227d5..ced625b46 100644 --- a/main/src/main/java/me/blackvein/quests/Quest.java +++ b/main/src/main/java/me/blackvein/quests/Quest.java @@ -64,7 +64,7 @@ public class Quest implements Comparable { protected String description; protected String finished; protected ItemStack guiDisplay = null; - private final LinkedList orderedStages = new LinkedList(); + private final LinkedList orderedStages = new LinkedList<>(); protected NPC npcStart; protected Location blockStart; protected String regionStart = null; @@ -216,11 +216,11 @@ public class Quest implements Comparable { } // Multiplayer - if (opts.getShareProgressLevel() == 3) { + if (allowSharedProgress && opts.getShareProgressLevel() == 3) { final List 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 { 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 { 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 { } } } - final LinkedList phatLootItems = new LinkedList(); + final LinkedList phatLootItems = new LinkedList<>(); int phatLootExp = 0; - final LinkedList phatLootMessages = new LinkedList(); + final LinkedList 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 { + 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 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 + ":" + 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 + ":" + 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 += " "; + text.append(" "); } - text += ChatColor.GRAY + " x " + i.getAmount(); } + text.append(ChatColor.GRAY).append(" x ").append(i.getAmount()); } else { - text = "- " + ChatColor.DARK_GREEN + ""; - if (i.getEnchantments().isEmpty()) { - text += ChatColor.GRAY + " x " + i.getAmount(); - } else { + text = new StringBuilder("- " + ChatColor.DARK_GREEN + ""); + 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 += " "; + text.append(" "); } } } 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("")) { - if (!plugin.getLocaleManager().sendMessage(p, text, i.getType(), i.getDurability(), + if (plugin.getSettings().canTranslateNames() && text.toString().contains("")) { + if (!plugin.getLocaleManager().sendMessage(p, text.toString(), i.getType(), i.getDurability(), i.getEnchantments())) { for (final Entry e : i.getEnchantments().entrySet()) { - text = text.replaceFirst("", ItemUtil.getPrettyEnchantmentName( - e.getKey())); - text = text.replaceFirst("", RomanNumeral.getNumeral(e.getValue())); + text = new StringBuilder(text.toString().replaceFirst("", ItemUtil.getPrettyEnchantmentName( + e.getKey()))); + text = new StringBuilder(text.toString().replaceFirst("", RomanNumeral.getNumeral(e.getValue()))); } - quester.sendMessage(text.replace("", ItemUtil.getName(i))); + quester.sendMessage(text.toString().replace("", ItemUtil.getName(i))); } } else { for (final Entry e : i.getEnchantments().entrySet()) { - text = text.replaceFirst("", ItemUtil.getPrettyEnchantmentName( - e.getKey())); - text = text.replaceFirst("", RomanNumeral.getNumeral(e.getValue())); + text = new StringBuilder(text.toString().replaceFirst("", ItemUtil.getPrettyEnchantmentName( + e.getKey()))); + text = new StringBuilder(text.toString().replaceFirst("", RomanNumeral.getNumeral(e.getValue()))); } - quester.sendMessage(text.replace("", ItemUtil.getName(i))); + quester.sendMessage(text.toString().replace("", 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 " diff --git a/main/src/main/java/me/blackvein/quests/QuestFactory.java b/main/src/main/java/me/blackvein/quests/QuestFactory.java index 79cf24542..f48fbedb7 100644 --- a/main/src/main/java/me/blackvein/quests/QuestFactory.java +++ b/main/src/main/java/me/blackvein/quests/QuestFactory.java @@ -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 selectedBlockStarts = new HashMap(); - private Map selectedKillLocations = new HashMap(); - private Map selectedReachLocations = new HashMap(); - private Set selectingNpcs = new HashSet(); - private List editingQuestNames = new LinkedList(); + private Map selectedBlockStarts = new HashMap<>(); + private Map selectedKillLocations = new HashMap<>(); + private Map selectedReachLocations = new HashMap<>(); + private Set selectingNpcs = new HashSet<>(); + private List 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 list = new LinkedList(); - final LinkedList> datamapList = new LinkedList>(); + final LinkedList list = new LinkedList<>(); + final LinkedList> datamapList = new LinkedList<>(); for (final Entry> 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(rews.getCustomRewards().keySet())); + context.setSessionData(CK.REW_CUSTOM, new LinkedList<>(rews.getCustomRewards().keySet())); context.setSessionData(CK.REW_CUSTOM_DATA, new LinkedList(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 names = new LinkedList(); - final LinkedList amnts = new LinkedList(); - final LinkedList durab = new LinkedList(); + final LinkedList names = new LinkedList<>(); + final LinkedList amnts = new LinkedList<>(); + final LinkedList 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 names = new LinkedList(); - final LinkedList amnts = new LinkedList(); - final LinkedList durab = new LinkedList(); + final LinkedList names = new LinkedList<>(); + final LinkedList amnts = new LinkedList<>(); + final LinkedList 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 names = new LinkedList(); - final LinkedList amnts = new LinkedList(); - final LinkedList durab = new LinkedList(); + final LinkedList names = new LinkedList<>(); + final LinkedList amnts = new LinkedList<>(); + final LinkedList 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 names = new LinkedList(); - final LinkedList amnts = new LinkedList(); - final LinkedList durab = new LinkedList(); + final LinkedList names = new LinkedList<>(); + final LinkedList amnts = new LinkedList<>(); + final LinkedList 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 names = new LinkedList(); - final LinkedList amnts = new LinkedList(); - final LinkedList durab = new LinkedList(); + final LinkedList names = new LinkedList<>(); + final LinkedList amnts = new LinkedList<>(); + final LinkedList 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 items = new LinkedList(stage.getItemsToCraft()); + final LinkedList items = new LinkedList<>(stage.getItemsToCraft()); context.setSessionData(pref + CK.S_CRAFT_ITEMS, items); } if (!stage.getItemsToSmelt().isEmpty()) { - final LinkedList items = new LinkedList(stage.getItemsToSmelt()); + final LinkedList items = new LinkedList<>(stage.getItemsToSmelt()); context.setSessionData(pref + CK.S_SMELT_ITEMS, items); } if (!stage.getItemsToEnchant().isEmpty()) { - final LinkedList items = new LinkedList(stage.getItemsToEnchant()); + final LinkedList items = new LinkedList<>(stage.getItemsToEnchant()); context.setSessionData(pref + CK.S_ENCHANT_ITEMS, items); } if (!stage.getItemsToBrew().isEmpty()) { - final LinkedList items = new LinkedList(stage.getItemsToBrew()); + final LinkedList items = new LinkedList<>(stage.getItemsToBrew()); context.setSessionData(pref + CK.S_BREW_ITEMS, items); } if (!stage.getItemsToConsume().isEmpty()) { - final LinkedList items = new LinkedList(stage.getItemsToConsume()); + final LinkedList 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 items = new LinkedList(stage.getItemsToDeliver()); - final LinkedList npcs = new LinkedList(stage.getItemDeliveryTargets()); + final LinkedList items = new LinkedList<>(stage.getItemsToDeliver()); + final LinkedList 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 npcs = new LinkedList(stage.getCitizensToInteract()); + final LinkedList npcs = new LinkedList<>(stage.getCitizensToInteract()); context.setSessionData(pref + CK.S_NPCS_TO_TALK_TO, npcs); } if (!stage.getCitizensToKill().isEmpty()) { - final LinkedList npcs = new LinkedList(stage.getCitizensToKill()); + final LinkedList 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 mobs = new LinkedList(); + final LinkedList 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 locs = new LinkedList(); + final LinkedList 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 locs = new LinkedList(); + final LinkedList 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 mobs = new LinkedList(); + final LinkedList mobs = new LinkedList<>(); for (final EntityType e : stage.getMobsToTame()) { mobs.add(MiscUtil.getPrettyMobName(e)); } - final LinkedList amts = new LinkedList(stage.getMobNumToTame()); + final LinkedList 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 colors = new LinkedList(); + final LinkedList colors = new LinkedList<>(); for (final DyeColor d : stage.getSheepToShear()) { colors.add(MiscUtil.getPrettyDyeColorName(d)); } - final LinkedList amts = new LinkedList(stage.sheepNumToShear); + final LinkedList 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 list = new LinkedList(); - final LinkedList countList = new LinkedList(); + final LinkedList list = new LinkedList<>(); + final LinkedList 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> datamapList - = new LinkedList>(stage.getCustomObjectiveData()); + final LinkedList> 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 chatEvents = new LinkedList(); - final LinkedList chatEventTriggers = new LinkedList(); + final LinkedList chatEvents = new LinkedList<>(); + final LinkedList 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 commandEvents = new LinkedList(); - final LinkedList commandEventTriggers = new LinkedList(); + final LinkedList commandEvents = new LinkedList<>(); + final LinkedList 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("", questsFile.getName())); - return; - } catch (final InvalidConfigurationException e) { + } catch (final IOException | InvalidConfigurationException e) { e.printStackTrace(); context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("questErrorReadingFile") .replace("", 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 callback = new ReloadCallback() { - @Override - public void execute(final Boolean response) { - if (!response) { - context.getForWhom().sendRawMessage(ChatColor.RED + Lang.get("unknownError")); - } + final ReloadCallback 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) context.getSessionData(CK.REQ_ITEMS) : null); + ? context.getSessionData(CK.REQ_ITEMS) : null); reqs.set("remove-items", context.getSessionData(CK.REQ_ITEMS_REMOVE) != null - ? (List) context.getSessionData(CK.REQ_ITEMS_REMOVE) : null); + ? context.getSessionData(CK.REQ_ITEMS_REMOVE) : null); reqs.set("permissions", context.getSessionData(CK.REQ_PERMISSION) != null - ? (List) context.getSessionData(CK.REQ_PERMISSION) : null); + ? context.getSessionData(CK.REQ_PERMISSION) : null); reqs.set("quests", context.getSessionData(CK.REQ_QUEST) != null - ? (List) context.getSessionData(CK.REQ_QUEST) : null); + ? context.getSessionData(CK.REQ_QUEST) : null); reqs.set("quest-blocks", context.getSessionData(CK.REQ_QUEST_BLOCK) != null - ? (List) 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) 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) 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 customReqs = context.getSessionData(CK.REQ_CUSTOM) != null ? (LinkedList) context.getSessionData(CK.REQ_CUSTOM) : null; final LinkedList> customReqsData = context.getSessionData(CK.REQ_CUSTOM_DATA) != null ? (LinkedList>) 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)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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) 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) context.getSessionData(pref + CK.S_PASSWORD_PHRASES) : null); + ? context.getSessionData(pref + CK.S_PASSWORD_PHRASES) : null); final LinkedList customObjs = (LinkedList) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES); final LinkedList customObjCounts = (LinkedList) context.getSessionData(pref + CK.S_CUSTOM_OBJECTIVES_COUNT); @@ -761,6 +762,9 @@ public class QuestFactory implements ConversationAbandonedListener { = (LinkedList>) 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 datamap : found.getData()) { for (final Entry 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) 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) 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) 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)context.getSessionData(CK.REW_PERMISSION) : null); + ? context.getSessionData(CK.REW_PERMISSION) : null); rews.set("permission-worlds", context.getSessionData(CK.REW_PERMISSION_WORLDS) != null - ? (List)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) 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) 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) 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) 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) context.getSessionData(CK.REW_PHAT_LOOTS) : null); + ? context.getSessionData(CK.REW_PHAT_LOOTS) : null); final LinkedList customRews = context.getSessionData(CK.REW_CUSTOM) != null ? (LinkedList) context.getSessionData(CK.REW_CUSTOM) : null; final LinkedList> customRewsData = context.getSessionData(CK.REW_CUSTOM_DATA) != null ? (LinkedList>) 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)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); } diff --git a/main/src/main/java/me/blackvein/quests/QuestMob.java b/main/src/main/java/me/blackvein/quests/QuestMob.java index 20722b3df..933b8c116 100644 --- a/main/src/main/java/me/blackvein/quests/QuestMob.java +++ b/main/src/main/java/me/blackvein/quests/QuestMob.java @@ -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; diff --git a/main/src/main/java/me/blackvein/quests/actions/Action.java b/main/src/main/java/me/blackvein/quests/actions/Action.java index 852fabaad..053e81c74 100644 --- a/main/src/main/java/me/blackvein/quests/actions/Action.java +++ b/main/src/main/java/me/blackvein/quests/actions/Action.java @@ -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 { @@ -39,9 +38,9 @@ public class Action implements Comparable { protected String message = null; protected boolean clearInv = false; protected boolean failQuest = false; - protected LinkedList explosions = new LinkedList(); - protected Map effects = new HashMap(); - protected LinkedList items = new LinkedList(); + protected LinkedList explosions = new LinkedList<>(); + protected Map effects = new HashMap<>(); + protected LinkedList items = new LinkedList<>(); protected World stormWorld = null; protected int stormDuration = 0; protected World thunderWorld = null; @@ -62,7 +61,7 @@ public class Action implements Comparable { 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 { return false; } }; - protected LinkedList lightningStrikes = new LinkedList(); - protected LinkedList commands = new LinkedList(); - protected LinkedList potionEffects = new LinkedList(); + protected LinkedList lightningStrikes = new LinkedList<>(); + protected LinkedList commands = new LinkedList<>(); + protected LinkedList potionEffects = new LinkedList<>(); protected int hunger = -1; protected int saturation = -1; protected float health = -1; @@ -278,20 +277,24 @@ public class Action implements Comparable { 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 { 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("", 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 { } } } - if (failQuest == true) { + if (failQuest) { quest.failQuest(quester, true); } if (timer > 0) { @@ -367,38 +372,38 @@ public class Action implements Comparable { .replace("