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

View File

@ -15,7 +15,6 @@ package me.blackvein.quests.util;
import java.util.LinkedList;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.entity.EntityType;
@ -186,60 +185,10 @@ public class MiscUtil {
if (dc.name().replace("_", "").equalsIgnoreCase(properName)) {
return dc;
}
if (getDyeColorLegacy(properName) != null) {
return dc;
}
}
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
*