use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.
the class NicknameLastSeenPatch method updateLastUsed.
private void updateLastUsed(Map<ServerUUID, Integer> serverIDsByUUID, Map<Integer, Set<Nickname>> nicknames) {
String updateSQL = "UPDATE " + NicknamesTable.TABLE_NAME + " SET " + NicknamesTable.LAST_USED + "=?" + WHERE + NicknamesTable.NICKNAME + "=?" + AND + "user_id=?" + AND + "server_id=?";
execute(new ExecBatchStatement(updateSQL) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (Map.Entry<Integer, Set<Nickname>> entry : nicknames.entrySet()) {
Integer userId = entry.getKey();
Set<Nickname> nicks = entry.getValue();
for (Nickname nick : nicks) {
Integer serverID = serverIDsByUUID.get(nick.getServerUUID());
statement.setLong(1, nick.getDate());
statement.setString(2, nick.getName());
statement.setInt(3, userId);
statement.setInt(4, serverID);
statement.addBatch();
}
}
}
});
}
use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.
the class SpongeChatListener method actOnChatEvent.
private void actOnChatEvent(@First Player player) {
long time = System.currentTimeMillis();
UUID uuid = player.getUniqueId();
String displayName = player.getDisplayNameData().displayName().get().toPlain();
dbSystem.getDatabase().executeTransaction(new NicknameStoreTransaction(uuid, new Nickname(displayName, time, serverInfo.getServerUUID()), (playerUUID, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
}
use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnJoinEvent.
private void actOnJoinEvent(ServerPlayerEntity player) {
UUID playerUUID = player.getUuid();
ServerUUID serverUUID = serverInfo.getServerUUID();
long time = System.currentTimeMillis();
FabricAFKListener.afkTracker.performedAction(playerUUID, time);
String world = player.getServerWorld().getRegistryKey().getValue().toString();
String gm = player.interactionManager.getGameMode().name();
Database database = dbSystem.getDatabase();
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
InetSocketAddress socketAddress = (InetSocketAddress) player.networkHandler.connection.getAddress();
InetAddress address = InetAddresses.forString(socketAddress.getAddress().toString().replace("/", ""));
Supplier<String> getHostName = () -> getHostname(player);
String playerName = player.getEntityName();
String displayName = player.getDisplayName().asString();
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
}
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, System::currentTimeMillis, playerName, serverUUID, getHostName));
database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, server.getPlayerManager().getOpList().isOp(player.getGameProfile())));
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()));
sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
database.executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname(displayName, time, serverUUID), (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
}
use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.
the class NicknameQueries method fetchLastSeenNicknameOfPlayer.
public static Query<Optional<Nickname>> fetchLastSeenNicknameOfPlayer(UUID playerUUID, ServerUUID serverUUID) {
String subQuery = SELECT + "MAX(" + NicknamesTable.LAST_USED + ") FROM " + NicknamesTable.TABLE_NAME + WHERE + NicknamesTable.USER_UUID + "=?" + AND + NicknamesTable.SERVER_UUID + "=?" + GROUP_BY + NicknamesTable.USER_UUID;
String sql = SELECT + NicknamesTable.LAST_USED + ',' + NicknamesTable.NICKNAME + FROM + NicknamesTable.TABLE_NAME + WHERE + NicknamesTable.USER_UUID + "=?" + AND + NicknamesTable.SERVER_UUID + "=?" + AND + NicknamesTable.LAST_USED + "=(" + subQuery + ')';
return new QueryStatement<Optional<Nickname>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, playerUUID.toString());
statement.setString(2, serverUUID.toString());
statement.setString(3, playerUUID.toString());
statement.setString(4, serverUUID.toString());
}
@Override
public Optional<Nickname> processResults(ResultSet set) throws SQLException {
if (set.next()) {
return Optional.of(new Nickname(set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID));
}
return Optional.empty();
}
};
}
use of com.djrapitops.plan.delivery.domain.Nickname in project Plan by plan-player-analytics.
the class NicknameQueries method fetchAllNicknameData.
/**
* Query database for all nickname data.
*
* @return Multimap: Server UUID - (Player UUID - List of nicknames)
*/
public static Query<Map<ServerUUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.USER_UUID + ',' + NicknamesTable.SERVER_UUID + FROM + NicknamesTable.TABLE_NAME;
return new QueryAllStatement<Map<ServerUUID, Map<UUID, List<Nickname>>>>(sql, 5000) {
@Override
public Map<ServerUUID, Map<UUID, List<Nickname>>> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, Map<UUID, List<Nickname>>> map = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
UUID uuid = UUID.fromString(set.getString(NicknamesTable.USER_UUID));
Map<UUID, List<Nickname>> serverMap = map.computeIfAbsent(serverUUID, Maps::create);
List<Nickname> nicknames = serverMap.computeIfAbsent(uuid, Lists::create);
nicknames.add(new Nickname(set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID));
}
return map;
}
};
}
Aggregations