Add Plan version to /plan servers

Affects issues:
- Resolve #2245
This commit is contained in:
Aurora Lahtela 2022-04-07 18:24:40 +03:00
parent 17096a46c7
commit 604bfd9e67
38 changed files with 143 additions and 70 deletions

View File

@ -28,6 +28,7 @@ import com.djrapitops.plan.settings.locale.lang.PluginLang;
import net.playeranalytics.plugin.server.PluginLogger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
/**
@ -38,6 +39,7 @@ import javax.inject.Singleton;
@Singleton
public class BungeeServerInfo extends ServerInfo {
private final String currentVersion;
private final ServerLoader fromFile;
private final ServerLoader fromDatabase;
@ -49,6 +51,7 @@ public class BungeeServerInfo extends ServerInfo {
@Inject
public BungeeServerInfo(
@Named("currentVersion") String currentVersion,
ServerProperties serverProperties,
ServerFileLoader fromFile,
ServerDBLoader fromDatabase,
@ -58,6 +61,7 @@ public class BungeeServerInfo extends ServerInfo {
PluginLogger logger
) {
super(serverProperties);
this.currentVersion = currentVersion;
this.fromFile = fromFile;
this.fromDatabase = fromDatabase;
this.processing = processing;
@ -89,7 +93,7 @@ public class BungeeServerInfo extends ServerInfo {
}
/**
* @throws EnableException
* @throws EnableException If IP setting is unset
*/
private void checkIfDefaultIP() {
String ip = serverProperties.getIp();
@ -101,7 +105,7 @@ public class BungeeServerInfo extends ServerInfo {
}
/**
* @throws EnableException
* @throws EnableException If IP setting is unset
*/
private Server registerServer() {
Server proxy = createServerObject();
@ -115,11 +119,11 @@ public class BungeeServerInfo extends ServerInfo {
}
/**
* @throws EnableException
* @throws EnableException If IP setting is unset
*/
private Server createServerObject() {
ServerUUID serverUUID = generateNewUUID();
String accessAddress = addresses.getAccessAddress().orElseThrow(() -> new EnableException("Velocity can not have '0.0.0.0' or '' as an address. Set up 'Server.IP' setting."));
return new Server(-1, serverUUID, "BungeeCord", accessAddress, true);
return new Server(-1, serverUUID, "BungeeCord", accessAddress, true, currentVersion);
}
}

View File

@ -125,7 +125,7 @@ public class LinkCommands {
String serversListed = dbSystem.getDatabase()
.query(ServerQueries.fetchPlanServerInformationCollection())
.stream().sorted()
.map(server -> m + server.getId().orElse(0) + "::" + t + server.getName() + "::" + s + server.getUuid() + "\n")
.map(server -> m + server.getId().orElse(0) + "::" + t + server.getName() + "::" + s + server.getUuid() + "::" + s + server.getPlanVersion() + "\n")
.collect(StringBuilder::new, StringBuilder::append, StringBuilder::append)
.toString();
sender.buildMessage()

View File

@ -31,16 +31,19 @@ public class Server implements Comparable<Server> {
private String webAddress;
private boolean proxy;
public Server(ServerUUID uuid, String name, String webAddress) {
this(null, uuid, name, webAddress, false);
private final String planVersion;
public Server(ServerUUID uuid, String name, String webAddress, String planVersion) {
this(null, uuid, name, webAddress, false, planVersion);
}
public Server(Integer id, ServerUUID uuid, String name, String webAddress, boolean proxy) {
public Server(Integer id, ServerUUID uuid, String name, String webAddress, boolean proxy, String planVersion) {
this.id = id;
this.uuid = uuid;
this.name = name;
this.webAddress = webAddress;
this.proxy = proxy;
this.planVersion = planVersion;
}
public Optional<Integer> getId() {
@ -79,6 +82,10 @@ public class Server implements Comparable<Server> {
this.webAddress = webAddress;
}
public String getPlanVersion() {
return planVersion;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -30,6 +30,7 @@ import com.djrapitops.plan.settings.locale.lang.PluginLang;
import net.playeranalytics.plugin.server.PluginLogger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.util.Optional;
@ -43,6 +44,8 @@ import java.util.Optional;
@Singleton
public class ServerServerInfo extends ServerInfo {
private final String currentVersion;
private final ServerLoader fromFile;
private final ServerLoader fromDatabase;
@ -55,6 +58,7 @@ public class ServerServerInfo extends ServerInfo {
@Inject
public ServerServerInfo(
@Named("currentVersion") String currentVersion,
ServerProperties serverProperties,
ServerFileLoader fromFile,
ServerDBLoader fromDatabase,
@ -65,6 +69,7 @@ public class ServerServerInfo extends ServerInfo {
PluginLogger logger
) {
super(serverProperties);
this.currentVersion = currentVersion;
this.fromFile = fromFile;
this.fromDatabase = fromDatabase;
this.processing = processing;
@ -112,6 +117,6 @@ public class ServerServerInfo extends ServerInfo {
private Server createServerObject(ServerUUID serverUUID) {
String webAddress = addresses.getAccessAddress().orElseGet(addresses::getFallbackLocalhostAddress);
String name = config.get(PluginSettings.SERVER_NAME);
return new Server(serverUUID, name, webAddress);
return new Server(serverUUID, name, webAddress, currentVersion);
}
}

View File

@ -27,6 +27,7 @@ import com.djrapitops.plan.settings.config.paths.PluginSettings;
import com.djrapitops.plan.storage.file.PlanFiles;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.Objects;
@ -35,6 +36,7 @@ import java.util.Optional;
@Singleton
public class ServerFileLoader extends Config implements ServerLoader {
private final String currentVersion;
private final PlanFiles files;
private final PlanConfig config;
@ -42,10 +44,12 @@ public class ServerFileLoader extends Config implements ServerLoader {
@Inject
public ServerFileLoader(
@Named("currentVersion") String currentVersion,
PlanFiles files,
PlanConfig config
) {
super(files.getFileFromPluginFolder("ServerInfoFile.yml"));
this.currentVersion = currentVersion;
this.files = files;
this.config = config;
@ -76,7 +80,7 @@ public class ServerFileLoader extends Config implements ServerLoader {
.orElse("Proxy");
String address = getString("Server.Web_address");
return Optional.of(new Server(id, serverUUID, name, address, false));
return Optional.of(new Server(id, serverUUID, name, address, false, currentVersion));
} catch (IOException e) {
throw new EnableException("Failed to read ServerInfoFile.yml: " + e.getMessage());
}

View File

@ -81,7 +81,7 @@ public enum CommandLang implements Lang {
HEADER_PLAYERS("command.header.players", "Cmd Header - Players", "> §2Players"),
HEADER_WEB_USERS("command.header.webUsers", "Cmd Header - Web Users", "> §2${0} Web Users"),
HEADER_NETWORK("command.header.network", "Cmd Header - Network", "> §2Network Page"),
HEADER_SERVER_LIST("command.header.serverList", "Cmd Header - server list", "id::name::uuid"),
HEADER_SERVER_LIST("command.header.serverList", "Cmd Header - server list", "id::name::uuid::version"),
HEADER_WEB_USER_LIST("command.header.webUserList", "Cmd Header - web user list", "username::linked to::permission level"),
INFO_VERSION("command.subcommand.info.version", "Cmd Info - Version", " §2Version: §f${0}"),

View File

@ -218,7 +218,8 @@ public abstract class SQLDB extends AbstractDatabase {
new PlayerTableRowPatch(),
new ExtensionTableProviderValuesForPatch(),
new RemoveIncorrectTebexPackageDataPatch(),
new ExtensionTableProviderFormattersPatch()
new ExtensionTableProviderFormattersPatch(),
new ServerPlanVersionPatch()
};
}

View File

@ -62,8 +62,8 @@ public class ServerQueries {
ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)),
set.getString(ServerTable.NAME),
set.getString(ServerTable.WEB_ADDRESS),
set.getBoolean(ServerTable.PROXY)
));
set.getBoolean(ServerTable.PROXY),
set.getString(ServerTable.PLAN_VERSION)));
}
return servers;
}
@ -94,8 +94,8 @@ public class ServerQueries {
serverUUID,
set.getString(ServerTable.NAME),
set.getString(ServerTable.WEB_ADDRESS),
set.getBoolean(ServerTable.PROXY)
));
set.getBoolean(ServerTable.PROXY),
set.getString(ServerTable.PLAN_VERSION)));
}
return servers;
}
@ -137,8 +137,8 @@ public class ServerQueries {
ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)),
set.getString(ServerTable.NAME),
set.getString(ServerTable.WEB_ADDRESS),
set.getBoolean(ServerTable.PROXY)
));
set.getBoolean(ServerTable.PROXY),
set.getString(ServerTable.PLAN_VERSION)));
}
return Optional.empty();
}
@ -165,8 +165,8 @@ public class ServerQueries {
ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)),
set.getString(ServerTable.NAME),
set.getString(ServerTable.WEB_ADDRESS),
set.getBoolean(ServerTable.PROXY)
));
set.getBoolean(ServerTable.PROXY),
set.getString(ServerTable.PLAN_VERSION)));
}
return Optional.empty();
}
@ -239,8 +239,8 @@ public class ServerQueries {
ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID)),
set.getString(ServerTable.NAME),
set.getString(ServerTable.WEB_ADDRESS),
set.getBoolean(ServerTable.PROXY)
));
set.getBoolean(ServerTable.PROXY),
set.getString(ServerTable.PLAN_VERSION)));
}
return matches;
}

View File

@ -45,19 +45,19 @@ public class ServerTable {
public static final String WEB_ADDRESS = "web_address";
public static final String INSTALLED = "is_installed";
public static final String PROXY = "is_proxy";
@Deprecated
public static final String MAX_PLAYERS = "max_players";
public static final String PLAN_VERSION = "plan_version";
public static final String INSERT_STATEMENT = Insert.values(TABLE_NAME,
SERVER_UUID, NAME,
WEB_ADDRESS, INSTALLED, PROXY);
WEB_ADDRESS, INSTALLED, PROXY, PLAN_VERSION);
public static final String UPDATE_STATEMENT = Update.values(TABLE_NAME,
SERVER_UUID,
NAME,
WEB_ADDRESS,
INSTALLED,
PROXY)
SERVER_UUID,
NAME,
WEB_ADDRESS,
INSTALLED,
PROXY,
PLAN_VERSION)
.where(SERVER_UUID + "=?")
.toString();
@ -78,7 +78,7 @@ public class ServerTable {
.column(WEB_ADDRESS, Sql.varchar(100))
.column(INSTALLED, Sql.BOOL).notNull().defaultValue(true)
.column(PROXY, Sql.BOOL).notNull().defaultValue(false)
.column(MAX_PLAYERS, Sql.INT).notNull().defaultValue("-1")
.column(PLAN_VERSION, Sql.varchar(18))
.toString();
}

View File

@ -54,7 +54,8 @@ public class StoreServerInformationTransaction extends Transaction {
statement.setString(3, server.getWebAddress());
statement.setBoolean(4, true);
statement.setBoolean(5, server.isProxy());
statement.setString(6, serverUUIDString);
statement.setString(6, server.getPlanVersion());
statement.setString(7, serverUUIDString);
}
};
}
@ -68,6 +69,7 @@ public class StoreServerInformationTransaction extends Transaction {
statement.setString(3, server.getWebAddress());
statement.setBoolean(4, true);
statement.setBoolean(5, server.isProxy());
statement.setString(6, server.getPlanVersion());
}
};
}

View File

@ -0,0 +1,33 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.storage.database.transactions.patches;
import com.djrapitops.plan.storage.database.sql.building.Sql;
import com.djrapitops.plan.storage.database.sql.tables.ServerTable;
public class ServerPlanVersionPatch extends Patch {
@Override
public boolean hasBeenApplied() {
return hasColumn(ServerTable.TABLE_NAME, ServerTable.PLAN_VERSION);
}
@Override
protected void applyPatch() {
addColumn(ServerTable.TABLE_NAME, ServerTable.PLAN_VERSION + " " + Sql.varchar(18) + " DEFAULT 'Old'");
}
}

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} 帮助"
servers: "> §2全部服务器"
search: "> §2${0} 对于 §f${1}§2 的结果:"
serverList: "id::名称::uuid"
serverList: "id::名称::uuid::version"
inspect: "> §2玩家: §f${0}"
network: "> §2群组网络页面"
webUsers: "> §2${0} 网页用户"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Pomoc"
servers: "> §2Servery"
search: "> §2${0} Výsledky pro §f${1}§2:"
serverList: "id::jméno::uuid"
serverList: "id::jméno::uuid::version"
inspect: "> §2Hráč: §f${0}"
network: "> §2Stránka Sítě"
webUsers: "> §2${0} Web uživatelé"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Hilfe"
servers: "> §2Server"
search: "> §2${0} Ergebnisse für §f${1}§2:"
serverList: "id::name::uuid"
serverList: "id::name::uuid::version"
inspect: "> §2Benutzer: §f${0}"
network: "> §2Netzwerkseite"
webUsers: "> §2${0} Accounts"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Help"
servers: "> §2Servers"
search: "> §2${0} Results for §f${1}§2:"
serverList: "id::name::uuid"
serverList: "id::name::uuid::version"
inspect: "> §2Player: §f${0}"
network: "> §2Network Page"
webUsers: "> §2${0} Web Users"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Ayuda"
servers: "> §2Servidores"
search: "> §2${0} Resultados para §f${1}§2:"
serverList: "id::name::uuid"
serverList: "id::name::uuid::version"
inspect: "> §2Jugador: §f${0}"
network: "> §2Página de red"
webUsers: "> §2${0} Usuarios web"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Apu"
servers: "> §2Palvelimet"
search: "> §2${0} Tulosta haulle §f${1}§2:"
serverList: "id::nimi::uuid"
serverList: "id::nimi::uuid::version"
inspect: "> §2Pelaaja: §f${0}"
network: "> §2Verkoston Sivu"
webUsers: "> §2${0} Web Käyttäjät"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Help"
servers: "> §2Serveurs"
search: "> §2${0} Résultats pour §f${1}§2 :"
serverList: "id::nom d'utilisateur::uuid"
serverList: "id::nom d'utilisateur::uuid::version"
inspect: "> §2Joueur : §f${0}"
network: "> §2Page du réseau"
webUsers: "> §2${0} Utilisateurs Web"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Help"
servers: "> §2Servers"
search: "> §2${0} Risultati per §f${1}§2:"
serverList: "id::name::uuid"
serverList: "id::name::uuid::version"
inspect: "> §2Nome: §f${0}"
network: "> §2Pagina Network"
webUsers: "> §2${0} Utenti Web"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0}の詳細"
servers: "> §2サーバー"
search: "> §2${0} §f${1}§2 の結果:"
serverList: "Minecraft id::名前::uuid"
serverList: "Minecraft id::名前::uuid::version"
inspect: "> §2プレイヤー: §f${0}"
network: "> §2ネットワークページ"
webUsers: "> §2${0} ウェブユーザー"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Help"
servers: "> §2서버 목록"
search: "> §2${0} Results for §f${1}§2:"
serverList: "id::name::uuid"
serverList: "id::name::uuid::version"
inspect: "> §2플레이어: §f${0}"
network: "> §2네트워크 페이지"
webUsers: "> §2${0} 웹 사용자"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Hulp"
servers: "> §2Servers"
search: "> §2${0} Resultaten voor §f${1}§2:"
serverList: "id::name::uuid"
serverList: "id::name::uuid::version"
inspect: "> §2Speler: §f${0}"
network: "> §2Netwerkpagina"
webUsers: "> §2${0} Webgebruikers"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Help"
servers: "> §2Servidores"
search: "> §2${0} Resultados para §f${1}§2:"
serverList: "id::name::uuid"
serverList: "id::name::uuid::version"
inspect: "> §2Jogador: §f${0}"
network: "> §2Página da Network"
webUsers: "> §2${0} Usuários da Web"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Помощь"
servers: "> §2Серверы"
search: "> §2${0} Результаты для §f${1}§2:"
serverList: "id::название::uuid"
serverList: "id::название::uuid::version"
inspect: "> §2Игрок: §f${0}"
network: "> §2Сетевая страница"
webUsers: "> §2${0} Веб-пользователи"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} Help"
servers: "> §2Sunucular"
search: "> §2${0} §f${1} §2için sonuçlar:"
serverList: "id::isim::uuid"
serverList: "id::isim::uuid::version"
inspect: "> §2Oyuncu: §f${0}"
network: "> §2Ağ Sayfası"
webUsers: "> §2${0} Web kullanıcıları"

View File

@ -253,7 +253,7 @@ command:
help: "> §2/${0} 幫助"
servers: "> §2全部伺服器"
search: "> §2${0} 對於 §f${1}§2 的結果:"
serverList: "id::名稱::uuid"
serverList: "id::名稱::uuid::version"
inspect: "> §2玩家: §f${0}"
network: "> §2群組網路頁面"
webUsers: "> §2${0} 網頁使用者"

View File

@ -108,8 +108,8 @@ class AccessControlTest {
system.getDatabaseSystem().getDatabase().executeTransaction(new StoreServerInformationTransaction(new Server(
TestConstants.SERVER_UUID,
TestConstants.SERVER_NAME,
address
)));
address,
TestConstants.VERSION)));
Caller caller = system.getExtensionService().register(new ExtensionsDatabaseTest.PlayerExtension())
.orElseThrow(AssertionError::new);

View File

@ -103,7 +103,7 @@ class ShutdownSaveTest {
UUID playerUUID = TestConstants.PLAYER_ONE_UUID;
String worldName = TestConstants.WORLD_ONE_NAME;
database.executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID, "-", "")));
database.executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID, "-", "", TestConstants.VERSION)));
database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> 0L, TestConstants.PLAYER_ONE_NAME));
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, worldName))
.get();
@ -152,7 +152,7 @@ class ShutdownSaveTest {
long endTime = System.currentTimeMillis();
Collection<ActiveSession> activeSessions = SessionCache.getActiveSessions();
for (FinishedSession session : underTest.finishSessions(activeSessions, endTime)) {
assertEquals(endTime, session.getEnd(), () -> "One of the sessions had differing end time");
assertEquals(endTime, session.getEnd(), "One of the sessions had differing end time");
}
}

View File

@ -69,7 +69,7 @@ class MySQLTest implements DatabaseTest, QueriesTestAggregate {
private static DBPreparer preparer;
@BeforeAll
static void setupDatabase(@TempDir Path temp) throws Exception {
static void setupDatabase(@TempDir Path temp) {
component = DaggerDatabaseTestComponent.builder()
.bindTemporaryDirectory(temp)
.build();
@ -100,7 +100,7 @@ class MySQLTest implements DatabaseTest, QueriesTestAggregate {
db().executeTransaction(new CreateTablesTransaction());
db().executeTransaction(new RemoveEverythingTransaction());
db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), TestConstants.SERVER_NAME, "")));
db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), TestConstants.SERVER_NAME, "", TestConstants.VERSION)));
assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}

View File

@ -38,6 +38,7 @@ import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import utilities.DBPreparer;
import utilities.RandomData;
import utilities.TestConstants;
import utilities.TestErrorLogger;
import java.nio.file.Path;
@ -62,7 +63,7 @@ public class SQLiteTest implements DatabaseTest, QueriesTestAggregate {
private static DBPreparer preparer;
@BeforeAll
static void setupDatabase(@TempDir Path temp) throws Exception {
static void setupDatabase(@TempDir Path temp) {
component = DaggerDatabaseTestComponent.builder()
.bindTemporaryDirectory(temp)
.build();
@ -92,7 +93,7 @@ public class SQLiteTest implements DatabaseTest, QueriesTestAggregate {
db().executeTransaction(new CreateTablesTransaction());
db().executeTransaction(new RemoveEverythingTransaction());
db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), "ServerName", "")));
db().executeTransaction(new StoreServerInformationTransaction(new Server(serverUUID(), "ServerName", "", TestConstants.VERSION)));
assertEquals(serverUUID(), ((SQLDB) db()).getServerUUIDSupplier().get());
}

View File

@ -25,6 +25,7 @@ import com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythi
import com.djrapitops.plan.storage.database.transactions.commands.SetServerAsUninstalledTransaction;
import org.junit.jupiter.api.Test;
import utilities.OptionalAssert;
import utilities.TestConstants;
import java.util.Collection;
import java.util.Map;
@ -56,7 +57,7 @@ public interface ServerQueriesTest extends DatabaseTestPreparer {
assertFalse(bungeeInfo.isPresent());
ServerUUID bungeeUUID = ServerUUID.randomUUID();
Server bungeeCord = new Server(bungeeUUID, "BungeeCord", "Random:1234");
Server bungeeCord = new Server(bungeeUUID, "BungeeCord", "Random:1234", TestConstants.VERSION);
bungeeCord.setProxy(true);
db().executeTransaction(new StoreServerInformationTransaction(bungeeCord));

View File

@ -152,7 +152,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
List<FinishedSession> allSessions = db().query(SessionQueries.fetchAllSessions());
assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class).get());
assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class)
.orElseThrow(AssertionError::new));
}
@Test
@ -180,7 +181,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
List<FinishedSession> allSessions = db().query(SessionQueries.fetchAllSessions());
assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class).get());
assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class)
.orElseThrow(AssertionError::new));
}
@Test
@ -240,7 +242,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
prepareForSessionSave();
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
List<PlayerKill> expected = session.getExtraData(PlayerKills.class).map(PlayerKills::asList).get();
List<PlayerKill> expected = session.getExtraData(PlayerKills.class).map(PlayerKills::asList)
.orElseThrow(AssertionError::new);
execute(DataStoreQueries.storeSession(session));
forcePersistenceCheck();
@ -250,7 +253,8 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
assertNotNull(savedSessions);
assertFalse(savedSessions.isEmpty());
List<PlayerKill> got = savedSessions.get(0).getExtraData(PlayerKills.class).map(PlayerKills::asList).get();
List<PlayerKill> got = savedSessions.get(0).getExtraData(PlayerKills.class).map(PlayerKills::asList)
.orElseThrow(AssertionError::new);
assertEquals(expected, got);
}
@ -366,7 +370,7 @@ public interface SessionQueriesTest extends DatabaseTestPreparer {
server1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
ServerUUID serverTwoUuid = TestConstants.SERVER_TWO_UUID;
executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "")));
executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "", TestConstants.VERSION)));
db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[1]));
List<FinishedSession> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID);

View File

@ -80,7 +80,7 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), () -> null));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
db().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_TWO_UUID, TestConstants.SERVER_TWO_NAME, "")));
db().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_TWO_UUID, TestConstants.SERVER_TWO_NAME, "", TestConstants.VERSION)));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, TestConstants.SERVER_TWO_UUID, () -> "example.join.address"));
Set<UserInfo> userInfo = db().query(UserInfoQueries.fetchUserInformationOfUser(playerUUID));
@ -301,7 +301,7 @@ public interface UserInfoQueriesTest extends DatabaseTestPreparer {
@Test
default void joinAddressQueryHasDistinctPlayers() {
db().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_TWO_UUID, TestConstants.SERVER_TWO_NAME, "")));
db().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_TWO_UUID, TestConstants.SERVER_TWO_NAME, "", TestConstants.VERSION)));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, () -> TestConstants.REGISTER_TIME, TestConstants.PLAYER_ONE_NAME, TestConstants.SERVER_TWO_UUID, TestConstants.GET_PLAYER_HOSTNAME));

View File

@ -39,7 +39,7 @@ class CreateTableBuilderTest {
.column(ServerTable.NAME, Sql.varchar(100))
.column(ServerTable.WEB_ADDRESS, Sql.varchar(100))
.column(ServerTable.INSTALLED, Sql.BOOL).notNull().defaultValue(true)
.column(ServerTable.MAX_PLAYERS, Sql.INT).notNull().defaultValue("-1")
.column("max_players", Sql.INT).notNull().defaultValue("-1")
.toString();
assertEquals(expected, result);
}

View File

@ -29,6 +29,7 @@ import java.util.function.Supplier;
public class TestConstants {
private TestConstants() {
/* Static variable class */
}
@ -57,4 +58,6 @@ public class TestConstants {
public static final int SERVER_MAX_PLAYERS = 20;
public static final int BUNGEE_MAX_PLAYERS = 100;
public static final String VERSION = "1.0.0";
}

View File

@ -98,8 +98,8 @@ public class TestData {
return new Transaction() {
@Override
protected void performOperations() {
executeOther(new StoreServerInformationTransaction(new Server(serverUUID, "Server 1", "")));
executeOther(new StoreServerInformationTransaction(new Server(server2UUID, "Server 2", "")));
executeOther(new StoreServerInformationTransaction(new Server(serverUUID, "Server 1", "", TestConstants.VERSION)));
executeOther(new StoreServerInformationTransaction(new Server(server2UUID, "Server 2", "", TestConstants.VERSION)));
for (String worldName : serverWorldNames) {
executeOther(new WorldNameStoreTransaction(serverUUID, worldName));

View File

@ -31,6 +31,7 @@ import com.djrapitops.plan.settings.locale.lang.PluginLang;
import net.playeranalytics.plugin.server.PluginLogger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
/**
@ -41,6 +42,7 @@ import javax.inject.Singleton;
@Singleton
public class ProxyServerInfo extends ServerInfo {
private final String currentVersion;
private final ServerLoader fromFile;
private final ServerLoader fromDatabase;
@ -52,6 +54,7 @@ public class ProxyServerInfo extends ServerInfo {
@Inject
public ProxyServerInfo(
@Named("currentVersion") String currentVersion,
ServerProperties serverProperties,
ServerFileLoader fromFile,
ServerDBLoader fromDatabase,
@ -61,6 +64,7 @@ public class ProxyServerInfo extends ServerInfo {
PluginLogger logger
) {
super(serverProperties);
this.currentVersion = currentVersion;
this.fromFile = fromFile;
this.fromDatabase = fromDatabase;
this.processing = processing;
@ -114,6 +118,6 @@ public class ProxyServerInfo extends ServerInfo {
private Server createServerObject() {
ServerUUID serverUUID = generateNewUUID();
String accessAddress = addresses.getAccessAddress().orElseThrow(() -> new EnableException("Velocity can not have '0.0.0.0' or '' as an address. Set up 'Server.IP' setting."));
return new Server(-1, serverUUID, "BungeeCord", accessAddress, true);
return new Server(-1, serverUUID, "BungeeCord", accessAddress, true, currentVersion);
}
}

View File

@ -28,6 +28,7 @@ import com.djrapitops.plan.settings.locale.lang.PluginLang;
import net.playeranalytics.plugin.server.PluginLogger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
/**
@ -38,6 +39,7 @@ import javax.inject.Singleton;
@Singleton
public class VelocityServerInfo extends ServerInfo {
private final String currentVersion;
private final ServerLoader fromFile;
private final ServerLoader fromDatabase;
@ -49,6 +51,7 @@ public class VelocityServerInfo extends ServerInfo {
@Inject
public VelocityServerInfo(
@Named("currentVersion") String currentVersion,
ServerProperties serverProperties,
ServerFileLoader fromFile,
ServerDBLoader fromDatabase,
@ -58,6 +61,7 @@ public class VelocityServerInfo extends ServerInfo {
PluginLogger logger
) {
super(serverProperties);
this.currentVersion = currentVersion;
this.fromFile = fromFile;
this.fromDatabase = fromDatabase;
this.processing = processing;
@ -89,7 +93,7 @@ public class VelocityServerInfo extends ServerInfo {
}
/**
* @throws EnableException
* @throws EnableException If IP setting is unset
*/
private void checkIfDefaultIP() {
String ip = serverProperties.getIp();
@ -112,12 +116,12 @@ public class VelocityServerInfo extends ServerInfo {
}
/**
* @throws EnableException
* @throws EnableException If IP setting is unset
*/
private Server createServerObject() {
ServerUUID serverUUID = generateNewUUID();
String accessAddress = addresses.getAccessAddress().orElseThrow(() -> new EnableException("Velocity can not have '0.0.0.0' or '' as an address. Set up 'Server.IP' setting."));
return new Server(-1, serverUUID, "Velocity", accessAddress, true);
return new Server(-1, serverUUID, "Velocity", accessAddress, true, currentVersion);
}
}