Skip to content

Commit

Permalink
Fix some issues with data registering for new users
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraLS3 committed Apr 11, 2022
1 parent 4bbc641 commit 69c54fb
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,32 +177,34 @@ private void actOnJoinEvent(PlayerJoinEvent event) {
String playerName = player.getName();
String displayName = player.getDisplayName();

boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID,
player::getFirstPlayed, playerName, serverUUID, getHostName));
database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, player.isOp()));

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));
}
player::getFirstPlayed, playerName, serverUUID, getHostName))
.thenRunAsync(() -> {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, player.isOp()));

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));
}
});
}

private String getHostname(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,20 @@ private void actOnLogin(PostLoginEvent event) {
sessionCache.cacheSession(playerUUID, session);
Database database = dbSystem.getDatabase();

boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName))
.thenRunAsync(() -> {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
});
}

@EventHandler(priority = EventPriority.NORMAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public static DBOpException forCause(String sql, SQLException e) {
context.related("Error code: " + errorCode)
.related(sql);
switch (errorCode) {
case 0:
context.related("Connection aquisition error")
.whatToDo("Failed to aquire connection. Try increasing 'Database.MySQL.Max_connections' setting.");
break;
// SQLite Corrupt
case 10:
case 523:
Expand Down Expand Up @@ -129,6 +133,11 @@ public static DBOpException forCause(String sql, SQLException e) {
context.related("Incorrect character encoding in MySQL")
.whatToDo("Convert your MySQL database and tables to use utf8mb4: https://www.a2hosting.com/kb/developer-corner/mysql/convert-mysql-database-utf-8");
break;
case 1048:
// MySQL
context.related("Not null constraint violation")
.whatToDo("Report this error. NOT NULL constraint violation occurred.");
break;
default:
context.related("Unknown SQL Error code");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.djrapitops.plan.storage.database.sql.building.Sql;
import com.djrapitops.plan.storage.database.transactions.Transaction;

import java.util.concurrent.Future;
import java.util.concurrent.CompletableFuture;

/**
* Interface for interacting with a Plan SQL database.
Expand Down Expand Up @@ -58,7 +58,7 @@ public interface Database {
* @param transaction Transaction to execute.
* @return Future that is finished when the transaction has been executed.
*/
Future<?> executeTransaction(Transaction transaction);
CompletableFuture<?> executeTransaction(Transaction transaction);

/**
* Used to get the {@code DBType} of the Database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;

Expand Down Expand Up @@ -305,7 +308,7 @@ public <T> T query(Query<T> query) {
}

@Override
public Future<?> executeTransaction(Transaction transaction) {
public CompletableFuture<?> executeTransaction(Transaction transaction) {
if (getState() == State.CLOSED) {
throw new DBOpException("Transaction tried to execute although database is closed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public static Query<Integer> newPlayerCount(long after, long before) {
}

public static Query<Map<ServerUUID, Integer>> newPlayerCounts(long after, long before) {
String sql = SELECT + ServerTable.SERVER_UUID + ",COUNT(1) as player_count" +
String sql = SELECT + "s." + ServerTable.SERVER_UUID + ",COUNT(1) as player_count" +
FROM + UserInfoTable.TABLE_NAME +
INNER_JOIN + ServerTable.TABLE_NAME + " s on s." + ServerTable.ID + '=' + UserInfoTable.TABLE_NAME + '.' + UserInfoTable.SERVER_ID +
WHERE + UserInfoTable.REGISTERED + "<=?" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,32 +188,35 @@ private void actOnJoinEvent(ServerPlayerEntity 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));
}
System::currentTimeMillis, playerName, serverUUID, getHostName))
.thenRunAsync(() -> {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

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));
}
});
}

private String getHostname(ServerPlayerEntity player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,33 +167,35 @@ private void actOnJoinEvent(PlayerJoinEvent event) {
String playerName = player.getName();
String displayName = player.getDisplayName();

boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

long registerDate = TimeUnit.SECONDS.toMillis(player.getFirstPlayed());
database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> registerDate,
playerName, serverUUID, getHostName));
dbSystem.getDatabase().executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, player.isOp()));

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));
}
playerName, serverUUID, getHostName))
.thenRunAsync(() -> {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

dbSystem.getDatabase().executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, player.isOp()));

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));
}
});
}

@EventHandler(priority = EventPriority.NORMAL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,30 +170,32 @@ private void actOnJoinEvent(ClientConnectionEvent.Join event) {
String playerName = player.getName();
String displayName = player.getDisplayNameData().displayName().get().toPlain();

boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> time,
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()));
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));
}
playerName, serverUUID, getHostName))
.thenRunAsync(() -> {
boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
if (gatheringGeolocations) {
database.executeTransaction(
new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry)
);
}

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));
}
});
}

@Listener(order = Order.DEFAULT)
Expand Down
Loading

0 comments on commit 69c54fb

Please sign in to comment.