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
This commit is contained in:
parent
3ac0e8745f
commit
2f2edece14
3 changed files with 3 additions and 107 deletions
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
|
|
|
@ -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<Listener> 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;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue