Compare commits

..

No commits in common. "743072d8e31bc946118055f3a4edc30c84cbe9ad" and "a948ef84e257ee8cb936c03a8427de2747a39aa3" have entirely different histories.

4 changed files with 5 additions and 94 deletions

View file

@ -1,88 +0,0 @@
package me.chayapak1.chomens_bot.commands;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.command.Command;
import me.chayapak1.chomens_bot.command.CommandContext;
import me.chayapak1.chomens_bot.command.CommandException;
import me.chayapak1.chomens_bot.command.TrustLevel;
import me.chayapak1.chomens_bot.data.PlayerEntry;
import me.chayapak1.chomens_bot.plugins.PlayersPersistentDataPlugin;
import me.chayapak1.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
public class FindAltsCommand extends Command {
public FindAltsCommand() {
super(
"findalts",
"Finds players with the same IP address",
new String[] { "<player>", "<ip>" },
new String[] { "alts", "sameip" },
TrustLevel.PUBLIC,
false
);
}
@Override
public Component execute(CommandContext context) throws Exception {
final Bot bot = context.bot;
String targetIP;
final String player = context.getString(true, true);
final PlayerEntry playerEntry = bot.players.getEntry(player);
if (playerEntry == null) targetIP = player;
else {
final CompletableFuture<String> future = bot.players.getPlayerIP(playerEntry);
targetIP = future.get(5, TimeUnit.SECONDS);
}
if (targetIP == null) throw new CommandException(Component.text("Could not find player's IP address"));
final Stream<String> matches = PlayersPersistentDataPlugin.playersObject.deepCopy().entrySet() // is calling deepCopy necessary?
.stream()
.filter(
entry -> {
final JsonObject ipsObject = entry
.getValue().getAsJsonObject().getAsJsonObject("ips");
if (ipsObject == null) return false;
final JsonElement currentServerIP = ipsObject.get(bot.host + ":" + bot.port);
if (currentServerIP == null) return false;
return currentServerIP.getAsString().equals(targetIP);
}
)
.map(Map.Entry::getKey);
Component component = Component
.translatable("Possible alts for the player %s:")
.color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor))
.arguments(Component.text(player).color(ColorUtilities.getColorByString(bot.config.colorPalette.username)))
.appendNewline();
int i = 0;
for (String name : matches.toList()) {
component = component
.append(
Component
.text(name)
.color((i++ & 1) == 0 ? ColorUtilities.getColorByString(bot.config.colorPalette.primary) : ColorUtilities.getColorByString(bot.config.colorPalette.secondary))
)
.appendSpace();
}
return component;
}
}

View file

@ -43,16 +43,16 @@ public class SeenCommand extends Command {
}
final JsonElement playerElement = PlayersPersistentDataPlugin.playersObject.get(player);
if (playerElement == null) throw new CommandException(Component.translatable(
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("This player does not have the `lastSeen.time` entry in the database for some reason."));
if (time == null) throw new CommandException(Component.text("time is null.. (possible invalid entry)"));
final DateTime dateTime = new DateTime(time.getAsLong(), DateTimeZone.UTC);

View file

@ -58,7 +58,6 @@ public class CommandHandlerPlugin {
registerCommand(new IPFilterCommand());
registerCommand(new StopCommand());
registerCommand(new GrepLogCommand());
registerCommand(new FindAltsCommand());
}
public boolean disabled = false;

View file

@ -31,8 +31,8 @@ public class PlayersPersistentDataPlugin extends PlayersPlugin.Listener {
public void playerJoined(PlayerEntry target) {
final JsonObject object = new JsonObject();
object.addProperty("uuid", target.profile.getIdAsString());
if (!object.has("lastSeen")) object.add("lastSeen", new JsonObject());
if (!object.has("ips")) object.add("ips", new JsonObject());
object.add("lastSeen", new JsonObject());
object.add("ips", new JsonObject());
final CompletableFuture<String> future = bot.players.getPlayerIP(target);