2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
import com.gmail.nossr50.datatypes.party.PartyFeature;
|
2019-01-13 04:56:54 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.Material;
|
2018-07-27 01:53:29 +02:00
|
|
|
import org.bukkit.block.data.Ageable;
|
|
|
|
import org.bukkit.block.data.BlockData;
|
2018-10-13 23:06:54 +02:00
|
|
|
import org.bukkit.entity.EntityType;
|
2013-10-28 18:04:06 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public class StringUtils {
|
2017-06-10 19:47:20 +02:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Gets a capitalized version of the target string.
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param target
|
|
|
|
* String to capitalize
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return the capitalized string
|
|
|
|
*/
|
|
|
|
public static String getCapitalized(String target) {
|
2013-05-21 20:03:00 +02:00
|
|
|
return target.substring(0, 1).toUpperCase() + target.substring(1).toLowerCase();
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getPrettyItemString(Material material) {
|
2018-12-29 14:24:55 +01:00
|
|
|
return createPrettyString(material.toString());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static String getPrettyEntityTypeString(EntityType entity) {
|
2018-12-29 14:24:55 +01:00
|
|
|
return createPrettyString(entity.toString());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2019-01-13 04:56:54 +01:00
|
|
|
public static String getPrettyAbilityString(SuperAbilityType ability) {
|
2018-12-29 14:24:55 +01:00
|
|
|
return createPrettyString(ability.toString());
|
2013-10-28 18:04:06 +01:00
|
|
|
}
|
2017-07-24 00:06:33 +02:00
|
|
|
|
2018-07-27 01:53:29 +02:00
|
|
|
public static String getWildcardConfigBlockDataString(BlockData data) {
|
2018-08-03 02:27:15 +02:00
|
|
|
return getWildcardConfigMaterialString(data.getMaterial());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getWildcardConfigMaterialString(Material data) {
|
|
|
|
return StringUtils.getPrettyItemString(data).replace(" ", "_") + "|*";
|
2017-07-24 00:06:33 +02:00
|
|
|
}
|
2013-12-02 18:08:12 +01:00
|
|
|
|
2018-07-27 01:53:29 +02:00
|
|
|
public static String getFriendlyConfigBlockDataString(BlockData data) {
|
|
|
|
switch(data.getMaterial()){
|
2018-10-13 23:06:54 +02:00
|
|
|
case CHORUS_FLOWER:
|
2018-07-27 01:53:29 +02:00
|
|
|
case COCOA:
|
|
|
|
case WHEAT:
|
|
|
|
case BEETROOTS:
|
|
|
|
case CARROTS:
|
|
|
|
case POTATOES:
|
2018-08-05 16:15:12 +02:00
|
|
|
case NETHER_WART: {
|
2018-07-27 01:53:29 +02:00
|
|
|
if (data instanceof Ageable) {
|
|
|
|
Ageable ageData = (Ageable) data;
|
|
|
|
if (ageData.getAge() == ageData.getMaximumAge()) {
|
|
|
|
return getPrettyItemString(data.getMaterial()).replace(" ", "_") + "_Ripe";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return getPrettyItemString(data.getMaterial()).replace(" ", "_") + "_Ungrown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return getPrettyItemString(data.getMaterial()).replace(" ", "_");
|
2017-06-10 19:47:20 +02:00
|
|
|
}
|
|
|
|
|
2018-08-03 02:27:15 +02:00
|
|
|
public static String getFriendlyConfigMaterialString(Material data) {
|
|
|
|
return getPrettyItemString(data).replace(" ", "_");
|
|
|
|
}
|
|
|
|
|
2018-07-27 01:53:29 +02:00
|
|
|
public static String getExplicitConfigBlockDataString(BlockData data) {
|
2018-08-03 02:27:15 +02:00
|
|
|
return getExplicitConfigMaterialString(data.getMaterial());
|
|
|
|
}
|
|
|
|
|
|
|
|
public static String getExplicitConfigMaterialString(Material data) {
|
|
|
|
return StringUtils.getPrettyItemString(data).replace(" ", "_");
|
2017-06-10 19:47:20 +02:00
|
|
|
}
|
|
|
|
|
2013-11-11 17:42:57 +01:00
|
|
|
public static String getPrettyPartyFeatureString(PartyFeature partyFeature) {
|
2018-12-29 14:24:55 +01:00
|
|
|
return createPrettyString(partyFeature.toString());
|
2013-11-11 17:42:57 +01:00
|
|
|
}
|
|
|
|
|
2018-12-29 14:24:55 +01:00
|
|
|
private static String createPrettyString(String baseString) {
|
2013-03-01 06:52:01 +01:00
|
|
|
String[] substrings = baseString.split("_");
|
|
|
|
String prettyString = "";
|
|
|
|
int size = 1;
|
|
|
|
|
|
|
|
for (String string : substrings) {
|
|
|
|
prettyString = prettyString.concat(getCapitalized(string));
|
|
|
|
|
|
|
|
if (size < substrings.length) {
|
|
|
|
prettyString = prettyString.concat(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return prettyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a string represents an Integer
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param string
|
|
|
|
* String to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the string is an Integer, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isInt(String string) {
|
|
|
|
try {
|
|
|
|
Integer.parseInt(string);
|
|
|
|
return true;
|
2017-06-10 19:47:20 +02:00
|
|
|
} catch (NumberFormatException nFE) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a string represents a Double
|
|
|
|
*
|
2017-06-10 19:47:20 +02:00
|
|
|
* @param string
|
|
|
|
* String to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the string is a Double, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isDouble(String string) {
|
|
|
|
try {
|
|
|
|
Double.parseDouble(string);
|
|
|
|
return true;
|
2017-06-10 19:47:20 +02:00
|
|
|
} catch (NumberFormatException nFE) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2013-11-11 17:42:57 +01:00
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|