refactor: store player ip in PlayerEntry, so we don't have to query them in stuff like IP filter which spams console
This commit is contained in:
parent
5834a0584a
commit
8a9b123f49
5 changed files with 25 additions and 11 deletions
build-number.txt
src/main/java/me/chayapak1/chomens_bot
|
@ -1 +1 @@
|
|||
2046
|
||||
2048
|
|
@ -46,8 +46,11 @@ public class FindAltsCommand extends Command {
|
|||
|
||||
final PlayerEntry playerEntry = bot.players.getEntry(player);
|
||||
|
||||
if (playerEntry == null) return handle(bot, player, true, player, allServer);
|
||||
else {
|
||||
if (playerEntry == null) {
|
||||
return handle(bot, player, true, player, allServer);
|
||||
} else if (playerEntry.ip != null) {
|
||||
return handle(bot, playerEntry.ip, false, player, allServer);
|
||||
} else {
|
||||
final CompletableFuture<String> future = bot.players.getPlayerIP(playerEntry);
|
||||
|
||||
if (future == null) return null;
|
||||
|
|
|
@ -19,6 +19,7 @@ public class PlayerEntry {
|
|||
public PublicKey publicKey;
|
||||
public final byte[] keySignature;
|
||||
public boolean listed;
|
||||
public String ip;
|
||||
|
||||
public PlayerEntry(
|
||||
GameProfile profile,
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.sql.ResultSet;
|
|||
import java.sql.SQLException;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class IPFilterPlugin extends PlayersPlugin.Listener {
|
||||
|
@ -67,15 +66,11 @@ public class IPFilterPlugin extends PlayersPlugin.Listener {
|
|||
private void check (PlayerEntry target) {
|
||||
if (bot.options.useCorePlaceBlock) return; // it will spam the place block core so i ignored this
|
||||
|
||||
final CompletableFuture<String> future = bot.players.getPlayerIP(target);
|
||||
final String ip = target.ip;
|
||||
|
||||
if (future == null) return;
|
||||
if (ip == null) return;
|
||||
|
||||
future.thenApply(output -> {
|
||||
handleFilterManager(output, target);
|
||||
|
||||
return output;
|
||||
});
|
||||
handleFilterManager(ip, target);
|
||||
}
|
||||
|
||||
public static Map<String, String> list () {
|
||||
|
|
|
@ -36,6 +36,7 @@ public class PlayersPlugin extends Bot.Listener {
|
|||
|
||||
bot.addListener(this);
|
||||
|
||||
bot.executor.scheduleAtFixedRate(this::queryPlayersIP, 0, 1, TimeUnit.SECONDS);
|
||||
bot.executor.scheduleAtFixedRate(this::onLastKnownNameTick, 0, 5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
@ -67,6 +68,15 @@ public class PlayersPlugin extends Bot.Listener {
|
|||
}
|
||||
}
|
||||
|
||||
private void queryPlayersIP () { for (PlayerEntry target : list) queryPlayersIP(target); }
|
||||
private void queryPlayersIP (PlayerEntry target) {
|
||||
if (target.ip != null) return;
|
||||
|
||||
final CompletableFuture<String> future = getPlayerIP(target, true);
|
||||
|
||||
future.thenApply(ip -> target.ip = ip);
|
||||
}
|
||||
|
||||
public CompletableFuture<String> getPlayerIP (PlayerEntry target) { return getPlayerIP(target, false); }
|
||||
public CompletableFuture<String> getPlayerIP (PlayerEntry target, boolean forceSeen) {
|
||||
final CompletableFuture<String> outputFuture = new CompletableFuture<>();
|
||||
|
@ -185,6 +195,7 @@ public class PlayersPlugin extends Bot.Listener {
|
|||
target.listed = true;
|
||||
|
||||
target.usernames.addAll(duplicate.usernames);
|
||||
target.ip = duplicate.ip;
|
||||
|
||||
list.add(target);
|
||||
|
||||
|
@ -192,6 +203,8 @@ public class PlayersPlugin extends Bot.Listener {
|
|||
} else {
|
||||
list.add(target);
|
||||
|
||||
queryPlayersIP(target);
|
||||
|
||||
for (Listener listener : listeners) listener.playerJoined(target);
|
||||
}
|
||||
}
|
||||
|
@ -261,6 +274,8 @@ public class PlayersPlugin extends Bot.Listener {
|
|||
newTarget.usernames.addAll(target.usernames);
|
||||
newTarget.usernames.addLast(target.profile.getName());
|
||||
|
||||
newTarget.ip = target.ip;
|
||||
|
||||
list.add(newTarget);
|
||||
|
||||
list.remove(target);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue