refactor: remove jackson annotations from some classes that don't need them anymore

This commit is contained in:
ChomeNS
2025-04-15 08:21:24 +07:00
parent 5cd1cc8976
commit f2250c656e
4 changed files with 20 additions and 59 deletions

View File

@@ -63,7 +63,7 @@ public class FilterCommand extends Command {
if (
PlayerFilterPlugin.localList.stream()
.map(filteredPlayer -> filteredPlayer.playerName)
.map(filteredPlayer -> filteredPlayer.playerName())
.toList()
.contains(player)
) {
@@ -116,11 +116,11 @@ public class FilterCommand extends Command {
if (player == null) throw new CommandException(Component.text("Invalid index"));
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.playerFilter.remove(player.playerName));
DatabasePlugin.EXECUTOR_SERVICE.submit(() -> bot.playerFilter.remove(player.playerName()));
return Component.translatable(
"Removed %s from the filters",
Component.text(player.playerName).color(bot.colorPalette.username)
Component.text(player.playerName()).color(bot.colorPalette.username)
).color(bot.colorPalette.defaultColor);
}
case "clear" -> {
@@ -138,11 +138,11 @@ public class FilterCommand extends Command {
for (final FilteredPlayer player : PlayerFilterPlugin.localList) {
Component options = Component.empty().color(NamedTextColor.DARK_GRAY);
if (player.ignoreCase || player.regex) {
if (player.ignoreCase() || player.regex()) {
final List<Component> args = new ArrayList<>();
if (player.ignoreCase) args.add(Component.text("ignore case"));
if (player.regex) args.add(Component.text("regex"));
if (player.ignoreCase()) args.add(Component.text("ignore case"));
if (player.regex()) args.add(Component.text("regex"));
options = options
.append(Component.text("("))
@@ -158,13 +158,13 @@ public class FilterCommand extends Command {
.append(Component.space());
}
if (!player.reason.isEmpty()) {
if (!player.reason().isEmpty()) {
options = options
.append(Component.text("("))
.append(Component.text("reason: ").color(NamedTextColor.GRAY))
.append(
Component
.text(player.reason)
.text(player.reason())
.color(bot.colorPalette.string)
)
.append(Component.text(")"));
@@ -174,7 +174,7 @@ public class FilterCommand extends Command {
Component.translatable(
"%s %s %s",
Component.text(index).color(bot.colorPalette.number),
Component.text(player.playerName).color(bot.colorPalette.username),
Component.text(player.playerName()).color(bot.colorPalette.username),
options
).color(NamedTextColor.DARK_GRAY)
);

View File

@@ -1,27 +1,6 @@
package me.chayapak1.chomens_bot.data.filter;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public class FilteredPlayer {
public final String playerName;
public final String reason;
public final boolean regex;
public final boolean ignoreCase;
@JsonCreator
public FilteredPlayer (
@JsonProperty("playerName") final String playerName,
@JsonProperty("reason") final String reason,
@JsonProperty("regex") final boolean regex,
@JsonProperty("ignoreCase") final boolean ignoreCase
) {
this.playerName = playerName;
this.reason = reason;
this.regex = regex;
this.ignoreCase = ignoreCase;
}
public record FilteredPlayer(String playerName, String reason, boolean regex, boolean ignoreCase) {
@Override
public String toString () {
return "FilteredPlayer{" +

View File

@@ -1,24 +1,6 @@
package me.chayapak1.chomens_bot.data.mail;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
public record Mail(String sentBy, String sentTo, long timeSent, String server, String contents) {
@JsonCreator
public Mail (
@JsonProperty("sentBy") final String sentBy,
@JsonProperty("sentTo") final String sentTo,
@JsonProperty("timeSent") final long timeSent,
@JsonProperty("server") final String server,
@JsonProperty("contents") final String contents
) {
this.sentBy = sentBy;
this.sentTo = sentTo;
this.timeSent = timeSent;
this.server = server;
this.contents = contents;
}
@Override
public String toString () {
return "Mail{" +

View File

@@ -95,7 +95,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
}
private boolean matchesPlayer (final String name, final FilteredPlayer player) {
if (player.regex) {
if (player.regex()) {
final Pattern pattern = compilePattern(player);
return pattern != null && pattern.matcher(name).find();
@@ -106,19 +106,19 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
private Pattern compilePattern (final FilteredPlayer player) {
try {
final int flags = player.ignoreCase ? Pattern.CASE_INSENSITIVE : 0;
final int flags = player.ignoreCase() ? Pattern.CASE_INSENSITIVE : 0;
return Pattern.compile(player.playerName, flags);
return Pattern.compile(player.playerName(), flags);
} catch (final Exception e) {
bot.logger.error("Error compiling player filter regex " + player.playerName + " (this shouldn't happen):");
bot.logger.error("Error compiling player filter regex " + player.playerName() + " (this shouldn't happen):");
bot.logger.error(e);
return null;
}
}
private boolean compareNames (final String name, final FilteredPlayer player) {
final String playerName = player.ignoreCase ? player.playerName.toLowerCase() : player.playerName;
final String targetName = player.ignoreCase ? name.toLowerCase() : name;
final String playerName = player.ignoreCase() ? player.playerName().toLowerCase() : player.playerName();
final String targetName = player.ignoreCase() ? name.toLowerCase() : name;
return playerName.equals(targetName);
}
@@ -130,7 +130,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
if (player == null) return;
bot.filterManager.add(target, player.reason);
bot.filterManager.add(target, player.reason());
});
}
@@ -155,11 +155,11 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
// loop through all the servers too
for (final Bot bot : bot.bots) {
for (final FilteredPlayer match : matches) {
final PlayerEntry entry = bot.players.getEntry(match.playerName);
final PlayerEntry entry = bot.players.getEntry(match.playerName());
if (entry == null) continue;
bot.filterManager.add(entry, match.reason);
bot.filterManager.add(entry, match.reason());
}
}
}
@@ -181,7 +181,7 @@ public class PlayerFilterPlugin implements PlayersPlugin.Listener {
}
public void clear () {
for (final FilteredPlayer player : localList) bot.filterManager.remove(player.playerName);
for (final FilteredPlayer player : localList) bot.filterManager.remove(player.playerName());
try {
Main.database.update(CLEAR_FILTER);