Properly handle loading of dual-word sheep shear colors, fixes #1178

This commit is contained in:
PikaMug 2020-04-07 18:25:06 -04:00
parent b705c4bddb
commit 68e99ac96f
2 changed files with 16 additions and 69 deletions

View File

@ -541,12 +541,9 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
questsSection = config.getConfigurationSection("quests"); questsSection = config.getConfigurationSection("quests");
for (String questKey : questsSection.getKeys(false)) { for (String questKey : questsSection.getKeys(false)) {
try { try {
Quest quest = new Quest();
failedToLoad = false; failedToLoad = false;
if (config.contains("quests." + questKey + ".name")) { if (config.contains("quests." + questKey)) {
quest = getQuest(ConfigUtil.parseString(config.getString("quests." + questKey + ".name"), loadCustomSections(getQuestById(questKey), config, questKey);
quest));
loadCustomSections(quest, config, questKey);
} else { } else {
throw new QuestFormatException("Quest block is missing", questKey); throw new QuestFormatException("Quest block is missing", questKey);
} }
@ -1295,7 +1292,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
return; return;
} }
for (String questKey : questsSection.getKeys(false)) { for (String questKey : questsSection.getKeys(false)) {
try { // main "skip quest" try/catch block try {
Quest quest = new Quest(); Quest quest = new Quest();
failedToLoad = false; failedToLoad = false;
quest.id = questKey; quest.id = questKey;
@ -1418,8 +1415,10 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
getLogger().log(Level.SEVERE, "Failed to load Quest \"" + questKey + "\". Skipping."); getLogger().log(Level.SEVERE, "Failed to load Quest \"" + questKey + "\". Skipping.");
} }
} catch (QuestFormatException ex) { } catch (QuestFormatException ex) {
ex.printStackTrace();
continue; continue;
} catch (StageFormatException ex) { } catch (StageFormatException ex) {
ex.printStackTrace();
continue; continue;
} }
} }
@ -2581,9 +2580,11 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
List<Integer> shearAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered." List<Integer> shearAmounts = config.getIntegerList("quests." + questKey + ".stages.ordered."
+ stageNum + ".sheep-amounts"); + stageNum + ".sheep-amounts");
for (String color : sheep) { for (String color : sheep) {
DyeColor dc = null; DyeColor dc = MiscUtil.getProperDyeColor(color);
try { try {
dc = DyeColor.valueOf(color.toUpperCase()); if (dc == null) {
dc = DyeColor.valueOf(color.toUpperCase());
}
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Fail silently // Fail silently
} }
@ -3092,8 +3093,7 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (id == null) { if (id == null) {
return null; return null;
} }
LinkedList<Quest> qs = quests; for (Quest q : quests) {
for (Quest q : qs) {
if (q.getId().equals(id)) { if (q.getId().equals(id)) {
return q; return q;
} }
@ -3111,18 +3111,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (name == null) { if (name == null) {
return null; return null;
} }
LinkedList<Quest> qs = quests; for (Quest q : quests) {
for (Quest q : qs) {
if (q.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) { if (q.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) {
return q; return q;
} }
} }
for (Quest q : qs) { for (Quest q : quests) {
if (q.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { if (q.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
return q; return q;
} }
} }
for (Quest q : qs) { for (Quest q : quests) {
if (q.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { if (q.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
return q; return q;
} }
@ -3140,18 +3139,17 @@ public class Quests extends JavaPlugin implements ConversationAbandonedListener
if (name == null) { if (name == null) {
return null; return null;
} }
LinkedList<Action> as = actions; for (Action a : actions) {
for (Action a : as) {
if (a.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) { if (a.getName().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', name))) {
return a; return a;
} }
} }
for (Action a : as) { for (Action a : actions) {
if (a.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { if (a.getName().toLowerCase().startsWith(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
return a; return a;
} }
} }
for (Action a : as) { for (Action a : actions) {
if (a.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) { if (a.getName().toLowerCase().contains(ChatColor.translateAlternateColorCodes('&', name).toLowerCase())) {
return a; return a;
} }

View File

@ -15,7 +15,6 @@ package me.blackvein.quests.util;
import java.util.LinkedList; import java.util.LinkedList;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
@ -186,60 +185,10 @@ public class MiscUtil {
if (dc.name().replace("_", "").equalsIgnoreCase(properName)) { if (dc.name().replace("_", "").equalsIgnoreCase(properName)) {
return dc; return dc;
} }
if (getDyeColorLegacy(properName) != null) {
return dc;
}
} }
return null; return null;
} }
/**
* Gets DyeColor from name as it appears in lang file
*
* @deprecated Use {@link #getProperDyeColor(String)}
* @param s Name to match lang value to
* @return DyeColor or null if invalid
*/
public static DyeColor getDyeColorLegacy(String s) {
if (s.equalsIgnoreCase("Black") || s.equalsIgnoreCase(Lang.get("COLOR_BLACK"))) {
return DyeColor.BLACK;
} else if (s.equalsIgnoreCase("Blue") || s.equalsIgnoreCase(Lang.get("COLOR_BLUE"))) {
return DyeColor.BLUE;
} else if (s.equalsIgnoreCase("Brown") || s.equalsIgnoreCase(Lang.get("COLOR_BROWN"))) {
return DyeColor.BROWN;
} else if (s.equalsIgnoreCase("Cyan") || s.equalsIgnoreCase(Lang.get("COLOR_CYAN"))) {
return DyeColor.CYAN;
} else if (s.equalsIgnoreCase("Gray") || s.equalsIgnoreCase(Lang.get("COLOR_GRAY"))) {
return DyeColor.GRAY;
} else if (s.equalsIgnoreCase("Green") || s.equalsIgnoreCase(Lang.get("COLOR_GREEN"))) {
return DyeColor.GREEN;
} else if (s.equalsIgnoreCase("LightBlue") || s.equalsIgnoreCase(Lang.get("COLOR_LIGHT_BLUE"))) {
return DyeColor.LIGHT_BLUE;
} else if (s.equalsIgnoreCase("Lime") || s.equalsIgnoreCase(Lang.get("COLOR_LIME"))) {
return DyeColor.LIME;
} else if (s.equalsIgnoreCase("Magenta") || s.equalsIgnoreCase(Lang.get("COLOR_MAGENTA"))) {
return DyeColor.MAGENTA;
} else if (s.equalsIgnoreCase("Orange") || s.equalsIgnoreCase(Lang.get("COLOR_ORAGE"))) {
return DyeColor.ORANGE;
} else if (s.equalsIgnoreCase("Pink") || s.equalsIgnoreCase(Lang.get("COLOR_PINK"))) {
return DyeColor.PINK;
} else if (s.equalsIgnoreCase("Purple") || s.equalsIgnoreCase(Lang.get("COLOR_PURPLE"))) {
return DyeColor.PURPLE;
} else if (s.equalsIgnoreCase("Red") || s.equalsIgnoreCase(Lang.get("COLOR_RED"))) {
return DyeColor.RED;
// 1.13 changed DyeColor.SILVER -> DyeColor.LIGHT_GRAY
} else if (s.equalsIgnoreCase("Silver") || s.equalsIgnoreCase("LightGray")
|| s.equalsIgnoreCase(Lang.get("COLOR_SILVER"))) {
return DyeColor.getByColor(Color.SILVER);
} else if (s.equalsIgnoreCase("White") || s.equalsIgnoreCase(Lang.get("COLOR_WHITE"))) {
return DyeColor.WHITE;
} else if (s.equalsIgnoreCase("Yellow") || s.equalsIgnoreCase(Lang.get("COLOR_YELLOW"))) {
return DyeColor.YELLOW;
} else {
return null;
}
}
/** /**
* Split text into multiple lines * Split text into multiple lines
* *