@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onSignChange(SignChangeEvent e){
Player player = e.getPlayer();
Sign sign = (Sign) e.getBlock().getState();
String[] lines = e.getLines();
String function = lines[0].toLowerCase();
if (function.equals("[balance]")){
if (Permissions.checkPerms(player, "cex.sign.create.balance")){
if (!lines[1].equals("") || !lines[2].equals("") || !lines[3].equals("")){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
} else {
LogHelper.showInfo("commandSignBalance", player, ChatColor.GREEN);
}
} else {
sign.getBlock().breakNaturally();
}
} else if (function.equals("[pay]")){
if (Permissions.checkPerms(player, "cex.sign.create.pay")){
if (lines[1].equals("")){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
} else {
if (lines[2].equals("")){
e.setLine(2, player.getName());
}
try {
double amount = Double.parseDouble(lines[1]);
e.setLine(1, Economy.fixDecimals(amount));
LogHelper.showInfo("commandSignPay", player, ChatColor.GREEN);
} catch (NumberFormatException ex){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
}
}
}
} else if (function.equals("[item]")){
if (Permissions.checkPerms(player, "cex.sign.create.item")){
if (lines[1].equals("")){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
} else {
String[] data = lines[1].split(":");
List<Material> matches = ClosestMatches.material(data[0]);
Material material = (matches.size() > 0 ? matches.get(0) : null);
if (material == null){
LogHelper.showWarning("itemNotFound", player);
sign.getBlock().breakNaturally();
} else {
if (data.length > 0){
if (data.length != 2){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
} else {
if (material == Material.WOOL || material == Material.INK_SACK){
List<DyeColor> dyeMatches = ClosestMatches.dyeColor(data[1]);
DyeColor dye = (dyeMatches.size() > 0 ? dyeMatches.get(0) : null);
if (dye == null){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
return;
} else {
e.setLine(1, WordUtils.capitalize(material.name().toLowerCase().replaceAll("_", "")) + ":" + WordUtils.capitalize(dye.toString().toLowerCase().replaceAll("_", "")));
}
} else {
if (!data[1].matches(CommandsEX.intRegex)){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
return;
} else {
e.setLine(1, WordUtils.capitalize(material.name().toLowerCase().replaceAll("_", "")));
}
}
}
}
if (lines[2].equals("")){
e.setLine(2, String.valueOf(1));
} else {
try {
Integer.parseInt(lines[2]);
if (!lines[3].equals("")){
try {
double amount = Double.parseDouble(lines[3]);
e.setLine(3, Economy.fixDecimals(amount));
} catch (NumberFormatException ex1){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
return;
}
}
} catch (NumberFormatException ex){
LogHelper.showWarning("commandSignInvalid", player);
sign.getBlock().breakNaturally();
return;
}
}
LogHelper.showInfo("commandSignItem", player, ChatColor.GREEN);