sql fixes & more

fixes slconfig sql error
fixes nickclean npe
fixes a few command inconsistensies
This commit is contained in:
speed 2020-11-24 11:53:37 -05:00
parent 495133da1a
commit 6cd995ff52
5 changed files with 71 additions and 69 deletions

View File

@ -79,7 +79,7 @@ public class Command_modifyitem extends FreedomCommand
Enchantment enchantment = Enchantment.getByName(args[1].toUpperCase()); Enchantment enchantment = Enchantment.getByName(args[1].toUpperCase());
if (enchantment == null) if (enchantment == null)
{ {
msg("Invalid enchantment. Please run /enchantments for a list of valid enchantments."); msg("Invalid enchantment. Please run /enchant list for a list of valid enchantments.");
return true; return true;
} }

View File

@ -17,7 +17,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME) @CommandPermissions(level = Rank.ADMIN, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Manage your admin entry.", usage = "/<command> [-o <admin name>] <clearips | clearip <ip> | setlogin <message> | clearlogin | setscformat <format> | clearscformat> | oldtags | logstick | syncroles>") @CommandParameters(description = "Manage your admin entry.", usage = "/<command> [-o <admin name>] <clearips | clearip <ip> | setscformat <format> | clearscformat> | syncroles>")
public class Command_myadmin extends FreedomCommand public class Command_myadmin extends FreedomCommand
{ {
@Override @Override
@ -76,7 +76,7 @@ public class Command_myadmin extends FreedomCommand
} }
else else
{ {
FUtil.staffAction(sender.getName(), "Clearing " + target.getName() + "' IPs", true); FUtil.staffAction(sender.getName(), "Clearing " + target.getName() + "'s IPs", true);
} }
int counter = target.getIps().size() - 1; int counter = target.getIps().size() - 1;
@ -203,7 +203,7 @@ public class Command_myadmin extends FreedomCommand
return Collections.emptyList(); return Collections.emptyList();
} }
List<String> singleArguments = Arrays.asList("clearips", "setscformat"); List<String> singleArguments = Arrays.asList("clearips", "setscformat");
List<String> doubleArguments = Arrays.asList("clearip", "clearscformat", "syncroles"); List<String> doubleArguments = Arrays.asList("clearip", "clearscformat", "syncroles");
if (args.length == 1) if (args.length == 1)
{ {

View File

@ -72,76 +72,78 @@ public class Command_nickclean extends FreedomCommand
final String nickName = plugin.esb.getNickname(playerName); final String nickName = plugin.esb.getNickname(playerName);
StringBuilder newNick = new StringBuilder(); StringBuilder newNick = new StringBuilder();
boolean nickChanged = false; boolean nickChanged = false;
if (nickName != null)
if(nickName.contains("§x"))
{ {
// Detects colors that are similar to blocked codes. if (nickName.contains("§x"))
spliterator:
for (String split : nickName.split("§x"))
{ {
List<Color> colors = new ArrayList<>(); // Detects colors that are similar to blocked codes.
String hexColorSub = null; spliterator:
if (split.length() >= 12 && split.contains("§")) for (String split : nickName.split("§x"))
{ {
hexColorSub = split.substring(0, 12); List<Color> colors = new ArrayList<>();
split = String.valueOf(split.charAt(12)); String hexColorSub = null;
String hexColorString = "#" + hexColorSub.replaceAll("§", ""); if (split.length() >= 12 && split.contains("§"))
java.awt.Color hexColor = java.awt.Color.decode(hexColorString);
// Get a range of nearby colors that are alike to the color blocked.
Color colorFirst;
Color colorSecond;
colorFirst = Color.fromRGB(Math.min(hexColor.getRed() + 20, 255), Math.min(hexColor.getGreen() + 20, 255), Math.min(hexColor.getBlue() + 20, 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed() - 20, 0), Math.max(hexColor.getGreen() - 20, 0), Math.max(hexColor.getBlue() - 20, 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
colorFirst = Color.fromRGB(Math.min(hexColor.getRed() + 20, 255), Math.min(hexColor.getGreen(), 255), Math.min(hexColor.getBlue(), 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed() - 20, 0), Math.max(hexColor.getGreen(), 0), Math.max(hexColor.getBlue(), 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
colorFirst = Color.fromRGB(Math.min(hexColor.getRed(), 255), Math.min(hexColor.getGreen() + 20, 255), Math.min(hexColor.getBlue(), 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed(), 0), Math.max(hexColor.getGreen() - 20, 0), Math.max(hexColor.getBlue(), 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
colorFirst = Color.fromRGB(Math.min(hexColor.getRed(), 255), Math.min(hexColor.getGreen(), 255), Math.min(hexColor.getBlue() + 20, 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed(), 0), Math.max(hexColor.getGreen(), 0), Math.max(hexColor.getBlue() - 20, 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
for (String colorCode : ConfigEntry.BLOCKED_CHATCODES.getString().split(","))
{ {
// Makes sure that there's hex colors in the split. hexColorSub = split.substring(0, 12);
for (Color color : colors) split = String.valueOf(split.charAt(12));
String hexColorString = "#" + hexColorSub.replaceAll("§", "");
java.awt.Color hexColor = java.awt.Color.decode(hexColorString);
// Get a range of nearby colors that are alike to the color blocked.
Color colorFirst;
Color colorSecond;
colorFirst = Color.fromRGB(Math.min(hexColor.getRed() + 20, 255), Math.min(hexColor.getGreen() + 20, 255), Math.min(hexColor.getBlue() + 20, 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed() - 20, 0), Math.max(hexColor.getGreen() - 20, 0), Math.max(hexColor.getBlue() - 20, 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
colorFirst = Color.fromRGB(Math.min(hexColor.getRed() + 20, 255), Math.min(hexColor.getGreen(), 255), Math.min(hexColor.getBlue(), 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed() - 20, 0), Math.max(hexColor.getGreen(), 0), Math.max(hexColor.getBlue(), 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
colorFirst = Color.fromRGB(Math.min(hexColor.getRed(), 255), Math.min(hexColor.getGreen() + 20, 255), Math.min(hexColor.getBlue(), 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed(), 0), Math.max(hexColor.getGreen() - 20, 0), Math.max(hexColor.getBlue(), 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
colorFirst = Color.fromRGB(Math.min(hexColor.getRed(), 255), Math.min(hexColor.getGreen(), 255), Math.min(hexColor.getBlue() + 20, 255));
colorSecond = Color.fromRGB(Math.max(hexColor.getRed(), 0), Math.max(hexColor.getGreen(), 0), Math.max(hexColor.getBlue() - 20, 0));
colors.addAll(FUtil.createColorGradient(colorFirst, colorSecond, 40));
for (String colorCode : ConfigEntry.BLOCKED_CHATCODES.getString().split(","))
{ {
if (colorCodes.get(colorCode) != null && FUtil.colorClose(color, colorCodes.get(colorCode), 40)) // Makes sure that there's hex colors in the split.
for (Color color : colors)
{ {
nickChanged = true; if (colorCodes.get(colorCode) != null && FUtil.colorClose(color, colorCodes.get(colorCode), 40))
newNick.append(split); {
continue spliterator; nickChanged = true;
newNick.append(split);
continue spliterator;
}
} }
} }
newNick.append("§x").append(hexColorSub).append(split);
} }
newNick.append("§x").append(hexColorSub).append(split);
} }
} }
} else
else
{
// Falls back on old code if hex isn't used.
final Pattern REGEX = Pattern.compile(FUtil.colorize(ChatColor.COLOR_CHAR + "[" + StringUtils.join(ConfigEntry.BLOCKED_CHATCODES.getString().split(","), "") + "]"), Pattern.CASE_INSENSITIVE);
if (!nickName.isEmpty() && !nickName.equalsIgnoreCase(playerName))
{ {
final Matcher matcher = REGEX.matcher(nickName); // Falls back on old code if hex isn't used.
if (matcher.find()) final Pattern REGEX = Pattern.compile(FUtil.colorize(ChatColor.COLOR_CHAR + "[" + StringUtils.join(ConfigEntry.BLOCKED_CHATCODES.getString().split(","), "") + "]"), Pattern.CASE_INSENSITIVE);
if (!nickName.isEmpty() && !nickName.equalsIgnoreCase(playerName))
{ {
nickChanged = true; final Matcher matcher = REGEX.matcher(nickName);
newNick.append(matcher.replaceAll("")); if (matcher.find())
{
nickChanged = true;
newNick.append(matcher.replaceAll(""));
}
} }
} }
} }
if(nickChanged) if (nickChanged)
{ {
msg(ChatColor.RESET + playerName + ": \"" + nickName + ChatColor.RESET + "\" -> \"" + newNick.toString() + ChatColor.RESET + "\"."); msg(ChatColor.RESET + playerName + ": \"" + nickName + ChatColor.RESET + "\" -> \"" + newNick.toString() + ChatColor.RESET + "\".");
} }

View File

@ -112,7 +112,7 @@ public class PlayerData
.append("- Tag: ").append(FUtil.colorize(tag)).append(ChatColor.GRAY).append("\n") .append("- Tag: ").append(FUtil.colorize(tag)).append(ChatColor.GRAY).append("\n")
.append("- Ride Mode: ").append(rideMode).append("\n") .append("- Ride Mode: ").append(rideMode).append("\n")
.append("- Backup Codes: ").append(backupCodes.size()).append("/10").append("\n") .append("- Backup Codes: ").append(backupCodes.size()).append("/10").append("\n")
.append("- Reddit Username: ").append(redditUsername) .append("- Reddit Username: ").append(redditUsername).append("\n")
.append("- Login Message: ").append(loginMessage); .append("- Login Message: ").append(loginMessage);
return output.toString(); return output.toString();

View File

@ -247,16 +247,16 @@ public class SQLite extends FreedomService
{ {
try try
{ {
PreparedStatement statement = connection.prepareStatement("INSERT INTO staff VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); PreparedStatement statement = connection.prepareStatement("INSERT INTO staff VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
statement.setString(1, staffMember.getName()); statement.setString(1, staffMember.getName());
statement.setString(2, FUtil.listToString(staffMember.getIps())); statement.setString(2, FUtil.listToString(staffMember.getIps()));
statement.setString(3, staffMember.getRank().toString()); statement.setString(3, staffMember.getRank().toString());
statement.setBoolean(4, staffMember.isActive()); statement.setBoolean(4, staffMember.isActive());
statement.setLong(5, staffMember.getLastLogin().getTime()); statement.setLong(5, staffMember.getLastLogin().getTime());
statement.setBoolean(7, staffMember.getCommandSpy()); statement.setBoolean(6, staffMember.getCommandSpy());
statement.setBoolean(8, staffMember.getPotionSpy()); statement.setBoolean(7, staffMember.getPotionSpy());
statement.setString(9, staffMember.getAcFormat()); statement.setString(8, staffMember.getAcFormat());
statement.setString(10, staffMember.getPteroID()); statement.setString(9, staffMember.getPteroID());
statement.executeUpdate(); statement.executeUpdate();
} }
catch (SQLException e) catch (SQLException e)
@ -270,7 +270,7 @@ public class SQLite extends FreedomService
{ {
try try
{ {
PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); PreparedStatement statement = connection.prepareStatement("INSERT INTO players VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
statement.setString(1, player.getName()); statement.setString(1, player.getName());
statement.setString(2, FUtil.listToString(player.getIps())); statement.setString(2, FUtil.listToString(player.getIps()));
statement.setString(3, FUtil.listToString(player.getNotes())); statement.setString(3, FUtil.listToString(player.getNotes()));
@ -281,11 +281,11 @@ public class SQLite extends FreedomService
statement.setBoolean(8, player.hasVerification()); statement.setBoolean(8, player.hasVerification());
statement.setString(9, player.getRideMode()); statement.setString(9, player.getRideMode());
statement.setInt(10, player.getCoins()); statement.setInt(10, player.getCoins());
statement.setString(12, FUtil.listToString(player.getItems())); statement.setString(11, FUtil.listToString(player.getItems()));
statement.setInt(13, player.getTotalVotes()); statement.setInt(12, player.getTotalVotes());
statement.setBoolean(14, player.doesDisplayDiscord()); statement.setBoolean(13, player.doesDisplayDiscord());
statement.setString(15, player.getRedditUsername()); statement.setString(14, player.getRedditUsername());
statement.setString(16, player.getLoginMessage()); statement.setString(15, player.getLoginMessage());
statement.executeUpdate(); statement.executeUpdate();
} }
catch (SQLException e) catch (SQLException e)