use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class ServerSettingsManager method checkDBForNewConfigSettings.
private void checkDBForNewConfigSettings(Database database) {
File configFile = files.getConfigFile();
long lastModified = configFile.exists() ? configFile.lastModified() : -1;
Optional<ServerUUID> serverUUID = serverInfo.getServerUUIDSafe();
if (!serverUUID.isPresent()) {
return;
}
Optional<Config> foundConfig = database.query(new NewerConfigQuery(serverUUID.get(), lastModified));
if (foundConfig.isPresent()) {
try {
new ConfigWriter(configFile.toPath()).write(foundConfig.get());
logger.info("The Config was updated to match one on the Proxy. Reload for changes to take effect.");
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class PerServerAggregateQueries method lastSeenOnServers.
/**
* Find last seen date on servers.
*
* @param playerUUID UUID of the player.
* @return Map: Server UUID - Last seen epoch ms.
*/
public static Query<Map<ServerUUID, Long>> lastSeenOnServers(UUID playerUUID) {
String sql = SELECT + "MAX(" + SessionsTable.SESSION_END + ") as last_seen, " + SessionsTable.SERVER_UUID + FROM + SessionsTable.TABLE_NAME + WHERE + SessionsTable.USER_UUID + "=?" + GROUP_BY + SessionsTable.SERVER_UUID;
return new QueryStatement<Map<ServerUUID, Long>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, playerUUID.toString());
}
@Override
public Map<ServerUUID, Long> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, Long> lastSeenMap = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(SessionsTable.SERVER_UUID));
long lastSeen = set.getLong("last_seen");
lastSeenMap.put(serverUUID, lastSeen);
}
return lastSeenMap;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class PerServerAggregateQueries method getQueryForCountOf.
private static QueryStatement<Map<ServerUUID, Integer>> getQueryForCountOf(UUID playerUUID, String sql, String column) {
return new QueryStatement<Map<ServerUUID, Integer>>(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, playerUUID.toString());
}
@Override
public Map<ServerUUID, Integer> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, Integer> killCountMap = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(SessionsTable.SERVER_UUID));
int count = set.getInt(column);
killCountMap.put(serverUUID, count);
}
return killCountMap;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class ServerAggregateQueries method serverUserCounts.
/**
* Count how many users are on each server in the network.
* <p>
* Please note that counts can overlap as one user can join multiple servers.
* Use {@link ServerAggregateQueries#baseUserCount()} if you want to count total number of users.
*
* @return Map: Server UUID - Count of users registered to that server
*/
public static Query<Map<ServerUUID, Integer>> serverUserCounts() {
String sql = SELECT + "COUNT(1) as c, " + UserInfoTable.SERVER_UUID + FROM + UserInfoTable.TABLE_NAME + GROUP_BY + UserInfoTable.SERVER_UUID;
return new QueryAllStatement<Map<ServerUUID, Integer>>(sql, 100) {
@Override
public Map<ServerUUID, Integer> processResults(ResultSet set) throws SQLException {
Map<ServerUUID, Integer> ofServer = new HashMap<>();
while (set.next()) {
ServerUUID serverUUID = ServerUUID.fromString(set.getString(UserInfoTable.SERVER_UUID));
int count = set.getInt("c");
ofServer.put(serverUUID, count);
}
return ofServer;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class PageFactory method inspectPluginTabs.
public PlayerPluginTab inspectPluginTabs(UUID playerUUID) {
Database database = dbSystem.get().getDatabase();
Map<ServerUUID, List<ExtensionData>> extensionPlayerData = database.query(new ExtensionPlayerDataQuery(playerUUID));
if (extensionPlayerData.isEmpty()) {
return new PlayerPluginTab("", Collections.emptyList(), formatters.get());
}
List<PlayerPluginTab> playerPluginTabs = new ArrayList<>();
for (Map.Entry<ServerUUID, Server> entry : database.query(ServerQueries.fetchPlanServerInformation()).entrySet()) {
ServerUUID serverUUID = entry.getKey();
String serverName = entry.getValue().getIdentifiableName();
List<ExtensionData> ofServer = extensionPlayerData.get(serverUUID);
if (ofServer == null) {
continue;
}
playerPluginTabs.add(new PlayerPluginTab(serverName, ofServer, formatters.get()));
}
StringBuilder navs = new StringBuilder();
StringBuilder tabs = new StringBuilder();
playerPluginTabs.stream().sorted().forEach(tab -> {
navs.append(tab.getNav());
tabs.append(tab.getTab());
});
return new PlayerPluginTab(navs.toString(), tabs.toString());
}
Aggregations