mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-15 15:16:41 +01:00
Improve handling of dye color names
This commit is contained in:
parent
024e455698
commit
081e14dc64
@ -3057,7 +3057,7 @@ public class Quester {
|
|||||||
List<String> colors = questSec.getStringList("sheep-to-shear");
|
List<String> colors = questSec.getStringList("sheep-to-shear");
|
||||||
List<Integer> amounts = questSec.getIntegerList("sheep-sheared");
|
List<Integer> amounts = questSec.getIntegerList("sheep-sheared");
|
||||||
for (String color : colors) {
|
for (String color : colors) {
|
||||||
getQuestData(quest).sheepSheared.put(MiscUtil.getDyeColor(color), amounts.get(colors
|
getQuestData(quest).sheepSheared.put(MiscUtil.getProperDyeColor(color), amounts.get(colors
|
||||||
.indexOf(color)));
|
.indexOf(color)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -815,9 +815,9 @@ public class MobsPrompt extends FixedSetPrompt {
|
|||||||
final DyeColor[] colArr = DyeColor.values();
|
final DyeColor[] colArr = DyeColor.values();
|
||||||
for (int i = 0; i < colArr.length; i++) {
|
for (int i = 0; i < colArr.length; i++) {
|
||||||
if (i < (colArr.length - 1)) {
|
if (i < (colArr.length - 1)) {
|
||||||
cols += MiscUtil.getDyeString(colArr[i]) + ", ";
|
cols += MiscUtil.snakeCaseToUpperCamelCase(colArr[i].name()) + ", ";
|
||||||
} else {
|
} else {
|
||||||
cols += MiscUtil.getDyeString(colArr[i]) + "\n";
|
cols += MiscUtil.snakeCaseToUpperCamelCase(colArr[i].name()) + "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return cols + ChatColor.YELLOW + Lang.get("stageEditorShearColorsPrompt");
|
return cols + ChatColor.YELLOW + Lang.get("stageEditorShearColorsPrompt");
|
||||||
@ -829,8 +829,8 @@ public class MobsPrompt extends FixedSetPrompt {
|
|||||||
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
if (input.equalsIgnoreCase(Lang.get("cmdCancel")) == false) {
|
||||||
LinkedList<String> colors = new LinkedList<String>();
|
LinkedList<String> colors = new LinkedList<String>();
|
||||||
for (String s : input.split(" ")) {
|
for (String s : input.split(" ")) {
|
||||||
if (MiscUtil.getDyeColor(s) != null) {
|
if (MiscUtil.getProperDyeColor(s) != null) {
|
||||||
colors.add(MiscUtil.getDyeString(MiscUtil.getDyeColor(s)));
|
colors.add(s);
|
||||||
context.setSessionData(pref + CK.S_SHEAR_COLORS, colors);
|
context.setSessionData(pref + CK.S_SHEAR_COLORS, colors);
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
|
player.sendMessage(ChatColor.LIGHT_PURPLE + s + " " + ChatColor.RED
|
||||||
|
@ -615,22 +615,6 @@ public class ItemUtil {
|
|||||||
return prettyString;
|
return prettyString;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets name of enchantment exactly as it appears in lang file
|
|
||||||
*
|
|
||||||
* @param e Enchantment to get localized name of
|
|
||||||
* @return localized name
|
|
||||||
*/
|
|
||||||
/*private static String getEnchantmentName(Enchantment e) {
|
|
||||||
try {
|
|
||||||
return (Lang.get("ENCHANTMENT_" + e.getName()));
|
|
||||||
} catch (NullPointerException ne) {
|
|
||||||
Bukkit.getLogger().warning(e.getName() + " was not found in Lang.yml, please ask the developer to "
|
|
||||||
+ "update the file or simply add an entry for the enchantment");
|
|
||||||
return e.getName().toLowerCase().replace("_", " ");
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets enchantment from name
|
* Gets enchantment from name
|
||||||
*
|
*
|
||||||
|
@ -21,6 +21,12 @@ import org.bukkit.entity.EntityType;
|
|||||||
|
|
||||||
public class MiscUtil {
|
public class MiscUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a human-readable date and time from milliseconds
|
||||||
|
*
|
||||||
|
* @param milliseconds Total amount of time to convert
|
||||||
|
* @return Converted time in text
|
||||||
|
*/
|
||||||
public static String getTime(long milliseconds) {
|
public static String getTime(long milliseconds) {
|
||||||
String message = "";
|
String message = "";
|
||||||
long days = milliseconds / 86400000;
|
long days = milliseconds / 86400000;
|
||||||
@ -73,8 +79,8 @@ public class MiscUtil {
|
|||||||
/**
|
/**
|
||||||
* Capitalize first letter of text and set remainder to lowercase
|
* Capitalize first letter of text and set remainder to lowercase
|
||||||
*
|
*
|
||||||
* @param input
|
* @param input To convert
|
||||||
* @return
|
* @return Converted text
|
||||||
*/
|
*/
|
||||||
public static String getCapitalized(String input) {
|
public static String getCapitalized(String input) {
|
||||||
if (input.isEmpty()) {
|
if (input.isEmpty()) {
|
||||||
@ -157,22 +163,42 @@ public class MiscUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets player-friendly name from type. 'LIGHT_BLUE' becomes 'Light Blue'
|
||||||
|
*
|
||||||
|
* @param type any dye type, ideally
|
||||||
|
* @return cleaned-up string
|
||||||
|
*/
|
||||||
public static String getPrettyDyeColorName(DyeColor color) {
|
public static String getPrettyDyeColorName(DyeColor color) {
|
||||||
return Lang.get("COLOR_" + color.name());
|
return Lang.get("COLOR_" + color.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DyeColor getDyeColor(String s) {
|
/**
|
||||||
String col = Lang.getKey(getCapitalized(s));
|
* Gets DyeColor from name
|
||||||
col = col.replace("COLOR_", "");
|
*
|
||||||
DyeColor color = null;
|
* @param properName Name to get type from
|
||||||
try {
|
* @return DyeColor or null if invalid
|
||||||
color = DyeColor.valueOf(col);
|
*/
|
||||||
} catch (IllegalArgumentException e) {
|
public static DyeColor getProperDyeColor(String properName) {
|
||||||
// Do nothing
|
properName = properName.replace("_", "").replace(" ", "").toUpperCase();
|
||||||
|
for (DyeColor dc : DyeColor.values()) {
|
||||||
|
if (dc.name().replace("_", "").equalsIgnoreCase(properName)) {
|
||||||
|
return dc;
|
||||||
|
}
|
||||||
|
if (getDyeColorLegacy(properName) != null) {
|
||||||
|
return dc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return color != null ? color : getDyeColorLegacy(s);
|
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) {
|
public static DyeColor getDyeColorLegacy(String s) {
|
||||||
if (s.equalsIgnoreCase("Black") || s.equalsIgnoreCase(Lang.get("COLOR_BLACK"))) {
|
if (s.equalsIgnoreCase("Black") || s.equalsIgnoreCase(Lang.get("COLOR_BLACK"))) {
|
||||||
return DyeColor.BLACK;
|
return DyeColor.BLACK;
|
||||||
@ -213,25 +239,18 @@ public class MiscUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDyeString(DyeColor dc) {
|
|
||||||
return Lang.get("COLOR_" + dc.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Will be removed in a future version of Quests
|
* Split text into multiple lines
|
||||||
|
*
|
||||||
|
* @param input Text to convert
|
||||||
|
* @param wordDelimiter Character(s) used to split up text
|
||||||
|
* @param lineLength Maximum number of characters per line
|
||||||
|
* @param lineColor Color to use at start of each new line
|
||||||
|
* @return Converted text
|
||||||
*/
|
*/
|
||||||
public static String concatArgArray(String[] args, int startingIndex, int endingIndex, char delimiter) {
|
public static LinkedList<String> makeLines(String input, String wordDelimiter, int lineLength, ChatColor lineColor) {
|
||||||
String s = "";
|
|
||||||
for (int i = startingIndex; i <= endingIndex; i++) {
|
|
||||||
s += args[i] + delimiter;
|
|
||||||
}
|
|
||||||
s = s.substring(0, s.length());
|
|
||||||
return s.trim().equals("") ? null : s.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static LinkedList<String> makeLines(String s, String wordDelimiter, int lineLength, ChatColor lineColor) {
|
|
||||||
LinkedList<String> toReturn = new LinkedList<String>();
|
LinkedList<String> toReturn = new LinkedList<String>();
|
||||||
String[] split = s.split(wordDelimiter);
|
String[] split = input.split(wordDelimiter);
|
||||||
String line = "";
|
String line = "";
|
||||||
int currentLength = 0;
|
int currentLength = 0;
|
||||||
for (String piece : split) {
|
for (String piece : split) {
|
||||||
@ -265,16 +284,16 @@ public class MiscUtil {
|
|||||||
* @param s string to process
|
* @param s string to process
|
||||||
* @return processed string
|
* @return processed string
|
||||||
*/
|
*/
|
||||||
public static String capitalsToSpaces(String s) {
|
public static String capitalsToSpaces(String input) {
|
||||||
int max = s.length();
|
int max = input.length();
|
||||||
for (int i = 1; i < max; i++) {
|
for (int i = 1; i < max; i++) {
|
||||||
if (Character.isUpperCase(s.charAt(i))) {
|
if (Character.isUpperCase(input.charAt(i))) {
|
||||||
s = s.substring(0, i) + " " + s.substring(i);
|
input = input.substring(0, i) + " " + input.substring(i);
|
||||||
i++;
|
i++;
|
||||||
max++;
|
max++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -283,13 +302,14 @@ public class MiscUtil {
|
|||||||
* @param s string to process
|
* @param s string to process
|
||||||
* @return processed string
|
* @return processed string
|
||||||
*/
|
*/
|
||||||
public static String spaceToCapital(String s) {
|
public static String spaceToCapital(String input) {
|
||||||
int index = s.indexOf(' ');
|
int index = input.indexOf(' ');
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
s = s.substring(0, (index + 1)) + Character.toUpperCase(s.charAt(index + 1)) + s.substring(index + 2);
|
input = input.substring(0, (index + 1)) + Character.toUpperCase(input.charAt(index + 1))
|
||||||
s = s.replaceFirst(" ", "");
|
+ input.substring(index + 2);
|
||||||
return s;
|
input = input.replaceFirst(" ", "");
|
||||||
|
return input;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -701,22 +701,6 @@ journalAlreadyHave: "You already have your Quest Journal out."
|
|||||||
journalNoRoom: "You have no room in your inventory for your Quest Journal!"
|
journalNoRoom: "You have no room in your inventory for your Quest Journal!"
|
||||||
journalNoQuests: "You have no accepted quests!"
|
journalNoQuests: "You have no accepted quests!"
|
||||||
journalDenied: "You cannot do that with your Quest Journal."
|
journalDenied: "You cannot do that with your Quest Journal."
|
||||||
COLOR_BLACK: "Black"
|
|
||||||
COLOR_BLUE: "Blue"
|
|
||||||
COLOR_BROWN: "Brown"
|
|
||||||
COLOR_CYAN: "Cyan"
|
|
||||||
COLOR_GRAY: "Gray"
|
|
||||||
COLOR_GREEN: "Green"
|
|
||||||
COLOR_LIGHT_BLUE: "LightBlue"
|
|
||||||
COLOR_LIME: "Lime"
|
|
||||||
COLOR_MAGENTA: "Magenta"
|
|
||||||
COLOR_ORANGE: "Orange"
|
|
||||||
COLOR_PINK: "Pink"
|
|
||||||
COLOR_PURPLE: "Purple"
|
|
||||||
COLOR_RED: "Red"
|
|
||||||
COLOR_SILVER: "Silver"
|
|
||||||
COLOR_WHITE: "White"
|
|
||||||
COLOR_YELLOW: "Yellow"
|
|
||||||
timeZone: "Time zone"
|
timeZone: "Time zone"
|
||||||
timeDay: "Day"
|
timeDay: "Day"
|
||||||
timeDays: "Days"
|
timeDays: "Days"
|
||||||
|
Loading…
Reference in New Issue
Block a user