bring back *seen + mabe fix filter clear
This commit is contained in:
parent
b9a0f55b1d
commit
e56b6533a1
5 changed files with 133 additions and 3 deletions
|
@ -80,6 +80,7 @@ public class Bot {
|
||||||
public ScreensharePlugin screenshare;
|
public ScreensharePlugin screenshare;
|
||||||
public FormatCheckerPlugin formatChecker;
|
public FormatCheckerPlugin formatChecker;
|
||||||
public WhitelistPlugin whitelist;
|
public WhitelistPlugin whitelist;
|
||||||
|
public PlayersPersistentDataPlugin playersPersistent;
|
||||||
|
|
||||||
public Bot (Configuration.BotOption botOption, List<Bot> bots, Configuration config) {
|
public Bot (Configuration.BotOption botOption, List<Bot> bots, Configuration config) {
|
||||||
this.host = botOption.host;
|
this.host = botOption.host;
|
||||||
|
@ -131,6 +132,7 @@ public class Bot {
|
||||||
// this.screenshare = new ScreensharePlugin(this);
|
// this.screenshare = new ScreensharePlugin(this);
|
||||||
this.formatChecker = new FormatCheckerPlugin(this);
|
this.formatChecker = new FormatCheckerPlugin(this);
|
||||||
this.whitelist = new WhitelistPlugin(this);
|
this.whitelist = new WhitelistPlugin(this);
|
||||||
|
this.playersPersistent = new PlayersPersistentDataPlugin(this);
|
||||||
|
|
||||||
for (Listener listener : listeners) listener.loadedPlugins();
|
for (Listener listener : listeners) listener.loadedPlugins();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
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.CommandException;
|
||||||
|
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
|
||||||
|
import land.chipmunk.chayapak.chomens_bot.plugins.PlayersPersistentDataPlugin;
|
||||||
|
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) throws Exception {
|
||||||
|
final Bot bot = context.bot;
|
||||||
|
|
||||||
|
final String player = context.getString(true, true);
|
||||||
|
|
||||||
|
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 = PlayersPersistentDataPlugin.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) throw new CommandException(Component.text("time is null.. (possible invalid entry)"));
|
||||||
|
|
||||||
|
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,6 +53,7 @@ public class CommandHandlerPlugin {
|
||||||
registerCommand(new PCrashCommand());
|
registerCommand(new PCrashCommand());
|
||||||
// registerCommand(new ScreenshareCommand());
|
// registerCommand(new ScreenshareCommand());
|
||||||
registerCommand(new WhitelistCommand());
|
registerCommand(new WhitelistCommand());
|
||||||
|
registerCommand(new SeenCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean disabled = false;
|
public boolean disabled = false;
|
||||||
|
|
|
@ -186,9 +186,7 @@ public class FilterPlugin extends PlayersPlugin.Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear () {
|
public void clear () {
|
||||||
for (int i = 0; i <= filteredPlayers.size(); i++) {
|
while (!filteredPlayers.isEmpty()) filteredPlayers.remove(0);
|
||||||
filteredPlayers.remove(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
PersistentDataUtilities.put("filters", filteredPlayers);
|
PersistentDataUtilities.put("filters", filteredPlayers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||||
|
|
||||||
|
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 java.time.Instant;
|
||||||
|
|
||||||
|
public class PlayersPersistentDataPlugin extends PlayersPlugin.Listener {
|
||||||
|
public static JsonObject playersObject = new JsonObject();
|
||||||
|
|
||||||
|
static {
|
||||||
|
if (PersistentDataUtilities.jsonObject.has("players")) {
|
||||||
|
playersObject = PersistentDataUtilities.jsonObject.get("players").getAsJsonObject();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Bot bot;
|
||||||
|
|
||||||
|
public PlayersPersistentDataPlugin (Bot bot) {
|
||||||
|
this.bot = bot;
|
||||||
|
|
||||||
|
bot.players.addListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playerJoined(PlayerEntry target) {
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getName(PlayerEntry target) {
|
||||||
|
return bot.options.creayun ? target.profile.getName().replaceAll("§.", "") : target.profile.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void playerLeft(PlayerEntry target) {
|
||||||
|
if (!playersObject.has(getName(target))) return;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue