From 2f2edece1491fd6b4b2d0459ee4c24904c967cb8 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 5 Aug 2023 14:47:33 +0700 Subject: [PATCH] remove seen rip rip rip also the reason why is that the persistent data gets too big and it fails to load now https://i.imgur.com/XOOkKAB.png --- .../chomens_bot/commands/SeenCommand.java | 70 ------------------- .../plugins/CommandHandlerPlugin.java | 1 - .../chomens_bot/plugins/PlayersPlugin.java | 39 +---------- 3 files changed, 3 insertions(+), 107 deletions(-) delete mode 100644 src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java deleted file mode 100644 index 3b7233e..0000000 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/SeenCommand.java +++ /dev/null @@ -1,70 +0,0 @@ -package land.chipmunk.chayapak.chomens_bot.commands; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import land.chipmunk.chayapak.chomens_bot.Bot; -import land.chipmunk.chayapak.chomens_bot.command.Command; -import land.chipmunk.chayapak.chomens_bot.command.CommandContext; -import land.chipmunk.chayapak.chomens_bot.command.TrustLevel; -import land.chipmunk.chayapak.chomens_bot.plugins.PlayersPlugin; -import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; -import org.joda.time.DateTime; -import org.joda.time.DateTimeZone; -import org.joda.time.format.DateTimeFormat; -import org.joda.time.format.DateTimeFormatter; - -public class SeenCommand extends Command { - public SeenCommand () { - super( - "seen", - "Shows the last seen of a player", - new String[] { "<{player}>" }, - new String[] { "lastseen" }, - TrustLevel.PUBLIC, - false - ); - } - - @Override - public Component execute(CommandContext context, String[] args, String[] fullArgs) { - final Bot bot = context.bot; - - final String player = String.join(" ", args); - - for (Bot eachBot : bot.bots) { - if (eachBot.players.getEntry(player) != null) return Component.empty() - .append(Component.text(player)) - .append(Component.text(" is currently online on ")) - .append(Component.text(eachBot.host + ":" + eachBot.port)) - .color(NamedTextColor.RED); - } - - final JsonElement playerElement = PlayersPlugin.playersObject.get(player); - if (playerElement == null) return Component.translatable( - "%s was never seen", - Component.text(player) - ).color(NamedTextColor.RED); - - final JsonObject lastSeen = playerElement.getAsJsonObject().get("lastSeen").getAsJsonObject(); - - final JsonElement time = lastSeen.get("time"); - - if (time == null) return null; - - final DateTime dateTime = new DateTime(time.getAsLong(), DateTimeZone.UTC); - - final DateTimeFormatter formatter = DateTimeFormat.forPattern("EEEE, MMMM d, YYYY, hh:mm:ss a z"); - final String formattedTime = formatter.print(dateTime); - - final String server = lastSeen.get("server").getAsString(); - - return Component.translatable( - "%s was last seen at %s on %s", - Component.text(player).color(ColorUtilities.getColorByString(bot.config.colorPalette.username)), - Component.text(formattedTime).color(ColorUtilities.getColorByString(bot.config.colorPalette.string)), - Component.text(server).color(ColorUtilities.getColorByString(bot.config.colorPalette.string)) - ).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)); - } -} diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java index 196b7dd..bdf438d 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java @@ -53,7 +53,6 @@ public class CommandHandlerPlugin { registerCommand(new ClearChatQueueCommand()); registerCommand(new FilterCommand()); registerCommand(new MailCommand()); - registerCommand(new SeenCommand()); registerCommand(new EvalCommand()); registerCommand(new InfoCommand()); registerCommand(new ConsoleServerCommand()); diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java index 2166019..15d8f45 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/PlayersPlugin.java @@ -8,13 +8,10 @@ import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPl import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.packet.Packet; -import com.google.gson.JsonObject; import land.chipmunk.chayapak.chomens_bot.Bot; import land.chipmunk.chayapak.chomens_bot.data.chat.PlayerEntry; -import land.chipmunk.chayapak.chomens_bot.util.PersistentDataUtilities; import net.kyori.adventure.text.Component; -import java.time.Instant; import java.util.ArrayList; import java.util.EnumSet; import java.util.List; @@ -27,14 +24,6 @@ public class PlayersPlugin extends Bot.Listener { private final List listeners = new ArrayList<>(); - public static JsonObject playersObject = new JsonObject(); - - static { - if (PersistentDataUtilities.jsonObject.has("players")) { - playersObject = PersistentDataUtilities.jsonObject.get("players").getAsJsonObject(); - } - } - public PlayersPlugin (Bot bot) { this.bot = bot; @@ -133,18 +122,9 @@ public class PlayersPlugin extends Bot.Listener { if (duplicate == null) { for (Listener listener : listeners) { listener.playerJoined(target); } - - // should this be here? - if (playersObject.has(getName(target))) return; - - final JsonObject object = new JsonObject(); - object.addProperty("uuid", target.profile.getIdAsString()); - object.add("lastSeen", new JsonObject()); - - playersObject.add(getName(target), object); - - PersistentDataUtilities.put("players", playersObject); - } else for (Listener listener : listeners) { listener.playerUnVanished(target); } + } else { + for (Listener listener : listeners) { listener.playerUnVanished(target); } + } } private void updateGamemode (PlayerListEntry newEntry) { @@ -200,19 +180,6 @@ public class PlayersPlugin extends Bot.Listener { for (Listener listener : listeners) { listener.playerLeft(target); } - // should this be here? - if (!playersObject.has(getName(target))) return packet; - - final JsonObject player = playersObject.get(getName(target)).getAsJsonObject(); - - final JsonObject object = new JsonObject(); - object.addProperty("time", Instant.now().toEpochMilli()); - object.addProperty("server", bot.host + ":" + bot.port); - - player.add("lastSeen", object); - - PersistentDataUtilities.put("players", playersObject); - return packet; }); }