mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-06 15:44:49 +08:00
Fixed lag from host name lookup
This commit is contained in:
parent
cf3fe26b8a
commit
2e01758fd6
@ -50,6 +50,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import javax.inject.Inject;
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Event Listener for PlayerJoin, PlayerQuit and PlayerKickEvents.
|
||||
@ -156,12 +157,12 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
String world = player.getWorld().getName();
|
||||
String gm = player.getGameMode().name();
|
||||
String hostname = player.getAddress().getHostName();
|
||||
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
|
||||
|
||||
InetAddress address = player.getAddress().getAddress();
|
||||
Supplier<String> getHostName = address::getHostName;
|
||||
|
||||
String playerName = player.getName();
|
||||
String displayName = player.getDisplayName();
|
||||
@ -174,7 +175,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
}
|
||||
|
||||
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID,
|
||||
player::getFirstPlayed, playerName, serverUUID, hostname));
|
||||
player::getFirstPlayed, playerName, serverUUID, getHostName));
|
||||
|
||||
ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
|
||||
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
|
||||
|
@ -23,6 +23,7 @@ import com.djrapitops.plan.storage.database.queries.PlayerFetchQueries;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.LongSupplier;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Transaction for registering player's BaseUser and UserInfo to the database.
|
||||
@ -32,10 +33,10 @@ import java.util.function.LongSupplier;
|
||||
public class PlayerServerRegisterTransaction extends PlayerRegisterTransaction {
|
||||
|
||||
private final ServerUUID serverUUID;
|
||||
private final String hostname;
|
||||
private final Supplier<String> hostname;
|
||||
|
||||
public PlayerServerRegisterTransaction(UUID playerUUID, LongSupplier registered,
|
||||
String playerName, ServerUUID serverUUID, String hostname) {
|
||||
String playerName, ServerUUID serverUUID, Supplier<String> hostname) {
|
||||
super(playerUUID, registered, playerName);
|
||||
this.serverUUID = serverUUID;
|
||||
this.hostname = hostname;
|
||||
@ -46,7 +47,7 @@ public class PlayerServerRegisterTransaction extends PlayerRegisterTransaction {
|
||||
super.performOperations();
|
||||
long registerDate = registered.getAsLong();
|
||||
if (Boolean.FALSE.equals(query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID)))) {
|
||||
execute(DataStoreQueries.registerUserInfo(playerUUID, registerDate, serverUUID, hostname));
|
||||
execute(DataStoreQueries.registerUserInfo(playerUUID, registerDate, serverUUID, hostname.get()));
|
||||
}
|
||||
|
||||
// Updates register date to smallest possible value.
|
||||
|
@ -49,8 +49,10 @@ import com.djrapitops.plan.utilities.logging.ErrorContext;
|
||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.net.InetAddress;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Event Listener for PlayerJoin, PlayerQuit and PlayerKickEvents.
|
||||
@ -154,12 +156,12 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
String world = player.getLevel().getName();
|
||||
String gm = GMTimes.magicNumberToGMName(player.getGamemode());
|
||||
String hostname = player.getAddress();
|
||||
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
|
||||
|
||||
String address = player.getAddress();
|
||||
InetAddress address = player.getSocketAddress().getAddress();
|
||||
Supplier<String> getHostName = address::getHostName;
|
||||
|
||||
String playerName = player.getName();
|
||||
String displayName = player.getDisplayName();
|
||||
@ -173,7 +175,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
long registerDate = TimeUnit.SECONDS.toMillis(player.getFirstPlayed());
|
||||
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate,
|
||||
playerName, serverUUID, hostname));
|
||||
playerName, serverUUID, getHostName));
|
||||
ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
|
||||
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
|
||||
session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName()));
|
||||
|
@ -54,6 +54,7 @@ import javax.inject.Inject;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Listener for Player Join/Leave on Sponge.
|
||||
@ -159,12 +160,12 @@ public class PlayerOnlineListener {
|
||||
String world = player.getWorld().getName();
|
||||
Optional<GameMode> gameMode = player.getGameModeData().get(Keys.GAME_MODE);
|
||||
String gm = gameMode.map(mode -> mode.getName().toUpperCase()).orElse("ADVENTURE");
|
||||
String hostname = player.getConnection().getVirtualHost().getHostString();
|
||||
|
||||
Database database = dbSystem.getDatabase();
|
||||
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
|
||||
|
||||
InetAddress address = player.getConnection().getAddress().getAddress();
|
||||
Supplier<String> getHostName = () -> player.getConnection().getVirtualHost().getHostString();
|
||||
|
||||
String playerName = player.getName();
|
||||
String displayName = player.getDisplayNameData().displayName().get().toPlain();
|
||||
@ -177,7 +178,7 @@ public class PlayerOnlineListener {
|
||||
}
|
||||
|
||||
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time,
|
||||
playerName, serverUUID, hostname));
|
||||
playerName, serverUUID, getHostName));
|
||||
ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
|
||||
session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
|
||||
session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName()));
|
||||
|
Loading…
Reference in New Issue
Block a user