initial commit
This commit is contained in:
158
src/me/Caesar2011/Mailings/Library/StringOperations.java
Normal file
158
src/me/Caesar2011/Mailings/Library/StringOperations.java
Normal file
@@ -0,0 +1,158 @@
|
||||
package me.Caesar2011.Mailings.Library;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class StringOperations {
|
||||
public static String getStringArr(String[] strArr){
|
||||
String result = "";
|
||||
if (strArr.length > 0) {
|
||||
result = strArr[0]; // start with the first element
|
||||
for (int i=1; i < strArr.length; i++) {
|
||||
result = result + " " + strArr[i];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int getStringPixLen(String string){
|
||||
final String length5 = "()*<>fk{}";
|
||||
final String length4 = " \"I[]t";
|
||||
final String length3 = "´`l";
|
||||
final String length2 = "!',.:;";
|
||||
int result = 0;
|
||||
boolean found = false;
|
||||
char c;
|
||||
|
||||
for (int i = 0; i < string.length(); i++){
|
||||
c = string.charAt(i);
|
||||
found = false;
|
||||
for (int j = 0; j < length5.length() && !found; j++){
|
||||
if (c == length5.charAt(j)){
|
||||
result += 5;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < length4.length() && !found; j++){
|
||||
if (c == length4.charAt(j)){
|
||||
result += 4;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < length3.length() && !found; j++){
|
||||
if (c == length3.charAt(j)){
|
||||
result += 3;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < length2.length() && !found; j++){
|
||||
if (c == length2.charAt(j)){
|
||||
result += 2;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) result += 6;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getSpace(String arg, int pixel){
|
||||
int spaces = getStringPixLen(arg);
|
||||
spaces = pixel - (spaces / 4);
|
||||
String spacesAdd = "";
|
||||
for (;spaces >= 0; spaces--){
|
||||
spacesAdd += " ";
|
||||
}
|
||||
return spacesAdd;
|
||||
}
|
||||
|
||||
public static String getMaterial(String material){
|
||||
if(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack getItemStack(String itemString){
|
||||
Material type = null;
|
||||
int amount = 1;
|
||||
short damage = 0;
|
||||
String[] split = itemString.split(":", 3);
|
||||
if (split.length == 1){
|
||||
try {
|
||||
Material m = Material.matchMaterial(split[0]);
|
||||
if (m != null) {
|
||||
type = m;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else if (split.length == 2) {
|
||||
try {
|
||||
Material m = Material.matchMaterial(split[0]);
|
||||
if (m != null) {
|
||||
type = m;
|
||||
damage = new Short(split[1]);
|
||||
if (!(damage == 0 || dataIsValid(damage, m))) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else if (split.length == 3) {
|
||||
try {
|
||||
amount = new Integer(split[0]);
|
||||
Material m = Material.matchMaterial(split[1]);
|
||||
if (m != null) {
|
||||
type = m;
|
||||
damage = new Short(split[2]);
|
||||
if (!(damage == 0 || dataIsValid(damage, m))) {
|
||||
return null;
|
||||
}
|
||||
if (amount <= 0 || amount > m.getMaxStackSize()){
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return new ItemStack(type, amount, damage);
|
||||
}
|
||||
|
||||
private static boolean dataIsValid(short damage, Material m) {
|
||||
if (damage >= 0) {
|
||||
if (m.equals(Material.WOOD) && damage <= 3) return true;
|
||||
if (m.equals(Material.SAPLING) && damage <= 3) return true;
|
||||
if (m.equals(Material.LOG) && damage <= 3) return true;
|
||||
if (m.equals(Material.LEAVES) && damage <= 3) return true;
|
||||
if (m.equals(Material.SANDSTONE) && damage <= 2) return true;
|
||||
if (m.equals(Material.LONG_GRASS) && damage <= 2) return true;
|
||||
if (m.equals(Material.WOOL) && damage <= 15) return true;
|
||||
if (m.equals(Material.DOUBLE_STEP) && damage <= 6) return true;
|
||||
if (m.equals(Material.STEP) && damage <= 6) return true;
|
||||
if (m.equals(Material.MONSTER_EGGS) && damage <= 3) return true;
|
||||
if (m.equals(Material.SMOOTH_BRICK) && damage <= 3) return true;
|
||||
if (m.equals(Material.WOOD_DOUBLE_STEP) && damage <= 3) return true;
|
||||
if (m.equals(Material.WOOD_STEP) && damage <= 3) return true;
|
||||
//TODO 1.4 if (m.equals(Material.ANVIL) && damage <= 2) return true;
|
||||
if (m.equals(Material.INK_SACK) && damage <= 15) return true;
|
||||
if (m.equals(Material.MONSTER_EGG) && ((damage >= 50 && damage <= 64 && damage != 53) || (damage >= 90 && damage <= 98 && damage != 97) || (damage == 120))) return true;
|
||||
//TODO 1.4 if (m.equals(Material.SKULL_ITEM) && damage <= 4) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user