2011-05-15 19:33:03 +02:00
|
|
|
package com.Acrobot.ChestShop.Utils;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-06-09 22:54:01 +02:00
|
|
|
import com.Acrobot.ChestShop.Config.Config;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.block.Sign;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
|
|
|
*/
|
|
|
|
public class SignUtil {
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static boolean isSign(Block block) {
|
2011-05-15 18:16:25 +02:00
|
|
|
return (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN);
|
|
|
|
}
|
2011-05-21 19:55:55 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static boolean isAdminShop(String owner) {
|
2011-06-09 22:54:01 +02:00
|
|
|
return owner.toLowerCase().replace(" ", "").equals(Config.getString("adminShopName").toLowerCase().replace(" ", ""));
|
2011-05-21 19:55:55 +02:00
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
|
|
|
public static boolean isValid(Sign sign) {
|
2011-05-15 18:16:25 +02:00
|
|
|
return isValid(sign.getLines());
|
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
|
|
|
public static boolean isValid(String[] line) {
|
|
|
|
try {
|
|
|
|
return isValidPreparedSign(line) && (line[2].contains("B") || line[2].contains("S"));
|
|
|
|
} catch (Exception e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isValidPreparedSign(String[] line) {
|
|
|
|
try {
|
|
|
|
return !line[0].contains("[") && !line[0].contains("]") && !line[3].isEmpty() && !line[3].split(":")[0].isEmpty() && Numerical.isInteger(line[1]) && line[2].split(":").length <= 2;
|
|
|
|
} catch (Exception e) {
|
2011-05-15 18:16:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2011-05-21 19:55:55 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static float buyPrice(String text) {
|
2011-05-21 19:55:55 +02:00
|
|
|
text = text.replace(" ", "").toLowerCase();
|
|
|
|
|
|
|
|
int buyPart = (text.contains("b") ? 0 : -1);
|
2011-05-29 13:25:25 +02:00
|
|
|
if (buyPart == -1) {
|
2011-05-21 19:55:55 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
text = text.replace("b", "").replace("s", "");
|
|
|
|
String[] split = text.split(":");
|
2011-05-29 13:25:25 +02:00
|
|
|
if (Numerical.isFloat(split[0])) {
|
2011-05-21 19:55:55 +02:00
|
|
|
float buyPrice = Float.parseFloat(split[0]);
|
|
|
|
return (buyPrice != 0 ? buyPrice : -1);
|
2011-05-29 13:25:25 +02:00
|
|
|
} else if (split[0].equals("free")) {
|
2011-05-21 19:55:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
2011-05-21 19:55:55 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static float sellPrice(String text) {
|
2011-05-21 19:55:55 +02:00
|
|
|
text = text.replace(" ", "").toLowerCase();
|
|
|
|
|
|
|
|
int sellPart = (text.contains("b") && text.contains("s") ? 1 : (text.contains("s") ? 0 : -1));
|
|
|
|
text = text.replace("b", "").replace("s", "");
|
|
|
|
String[] split = text.split(":");
|
2011-05-29 13:25:25 +02:00
|
|
|
|
|
|
|
if (sellPart == -1 || (sellPart == 1 && split.length < 2)) {
|
2011-05-21 19:55:55 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
if (Numerical.isFloat(split[sellPart])) {
|
2011-05-21 19:55:55 +02:00
|
|
|
Float sellPrice = Float.parseFloat(split[sellPart]);
|
|
|
|
return (sellPrice != 0 ? sellPrice : -1);
|
2011-05-29 13:25:25 +02:00
|
|
|
} else if (split[sellPart].equals("free")) {
|
2011-05-21 19:55:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static int itemAmount(String text) {
|
|
|
|
if (Numerical.isInteger(text)) {
|
2011-05-21 19:55:55 +02:00
|
|
|
return Integer.parseInt(text);
|
2011-05-29 13:25:25 +02:00
|
|
|
} else {
|
2011-05-21 19:55:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|