forked from ChomeNS/chomens-bot-java
unused (for now)
This commit is contained in:
parent
42cb149e26
commit
a948ef84e2
3 changed files with 56 additions and 17 deletions
|
@ -4,12 +4,8 @@ import com.google.gson.JsonArray;
|
|||
import com.google.gson.JsonElement;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.data.PlayerEntry;
|
||||
import me.chayapak1.chomens_bot.util.ComponentUtilities;
|
||||
import me.chayapak1.chomens_bot.util.PersistentDataUtilities;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
@ -40,21 +36,12 @@ public class IPFilterPlugin extends PlayersPlugin.Listener {
|
|||
}
|
||||
|
||||
private void check (PlayerEntry target) {
|
||||
final CompletableFuture<Component> future = bot.core.runTracked("essentials:seen " + target.profile.getIdAsString());
|
||||
final CompletableFuture<String> future = bot.players.getPlayerIP(target);
|
||||
|
||||
if (future == null) return;
|
||||
|
||||
future.thenApply(output -> {
|
||||
final List<Component> children = output.children();
|
||||
|
||||
String stringified = ComponentUtilities.stringify(Component.join(JoinConfiguration.separator(Component.space()), children));
|
||||
|
||||
if (!stringified.startsWith(" - IP Address: ")) return output;
|
||||
|
||||
stringified = stringified.trim().substring(" - IP Address: ".length());
|
||||
if (stringified.startsWith("/")) stringified = stringified.substring(1);
|
||||
|
||||
handleIP(stringified, target);
|
||||
handleIP(output, target);
|
||||
|
||||
return output;
|
||||
});
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
package me.chayapak1.chomens_bot.plugins;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.data.PlayerEntry;
|
||||
import me.chayapak1.chomens_bot.util.PersistentDataUtilities;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class PlayersPersistentDataPlugin extends PlayersPlugin.Listener {
|
||||
public static JsonObject playersObject = new JsonObject();
|
||||
|
@ -26,12 +29,33 @@ public class PlayersPersistentDataPlugin extends PlayersPlugin.Listener {
|
|||
|
||||
@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());
|
||||
object.add("ips", new JsonObject());
|
||||
|
||||
final CompletableFuture<String> future = bot.players.getPlayerIP(target);
|
||||
|
||||
if (future == null) {
|
||||
setPersistentEntry(target, object);
|
||||
return;
|
||||
}
|
||||
|
||||
future.completeOnTimeout(null, 5, TimeUnit.SECONDS);
|
||||
|
||||
future.thenApply(output -> {
|
||||
if (output != null) {
|
||||
object.getAsJsonObject("ips").addProperty(bot.host + ":" + bot.port, output);
|
||||
}
|
||||
|
||||
setPersistentEntry(target, object);
|
||||
|
||||
return output;
|
||||
});
|
||||
}
|
||||
|
||||
// is this bad?
|
||||
private void setPersistentEntry (PlayerEntry target, JsonObject object) {
|
||||
playersObject.add(getName(target), object);
|
||||
|
||||
PersistentDataUtilities.put("players", playersObject);
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package me.chayapak1.chomens_bot.plugins;
|
||||
|
||||
import me.chayapak1.chomens_bot.util.ComponentUtilities;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import org.geysermc.mcprotocollib.network.Session;
|
||||
import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent;
|
||||
import org.geysermc.mcprotocollib.network.packet.Packet;
|
||||
|
@ -16,6 +18,7 @@ import java.util.ArrayList;
|
|||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class PlayersPlugin extends Bot.Listener {
|
||||
private final Bot bot;
|
||||
|
@ -58,6 +61,31 @@ public class PlayersPlugin extends Bot.Listener {
|
|||
}
|
||||
}
|
||||
|
||||
public CompletableFuture<String> getPlayerIP (PlayerEntry target) {
|
||||
final CompletableFuture<String> outputFuture = new CompletableFuture<>();
|
||||
|
||||
final CompletableFuture<Component> trackedCoreFuture = bot.core.runTracked("essentials:seen " + target.profile.getIdAsString());
|
||||
|
||||
if (trackedCoreFuture == null) return null;
|
||||
|
||||
trackedCoreFuture.thenApply(output -> {
|
||||
final List<Component> children = output.children();
|
||||
|
||||
String stringified = ComponentUtilities.stringify(Component.join(JoinConfiguration.separator(Component.space()), children));
|
||||
|
||||
if (!stringified.startsWith(" - IP Address: ")) return output;
|
||||
|
||||
stringified = stringified.trim().substring(" - IP Address: ".length());
|
||||
if (stringified.startsWith("/")) stringified = stringified.substring(1);
|
||||
|
||||
outputFuture.complete(stringified);
|
||||
|
||||
return output;
|
||||
});
|
||||
|
||||
return outputFuture;
|
||||
}
|
||||
|
||||
public final PlayerEntry getEntry (UUID uuid) {
|
||||
for (PlayerEntry candidate : list) {
|
||||
if (candidate.profile.getId().equals(uuid)) {
|
||||
|
|
Loading…
Reference in a new issue