mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-02 14:37:45 +01:00
Refactored Address based rules to a class
Affects issues: - Fixed #1380
This commit is contained in:
parent
278602db36
commit
081f378135
@ -17,13 +17,10 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.settings.ConfigSettingKeyTest;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.key.Setting;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@ -32,9 +29,7 @@ import utilities.mocks.BukkitMockComponent;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
@ -65,21 +60,6 @@ public class BukkitSystemTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void correctWebAddressInDatabaseAfterEnable() throws EnableException {
|
||||
try {
|
||||
system.enable();
|
||||
Database database = system.getDatabaseSystem().getDatabase();
|
||||
String expectedAddress = system.getWebServerSystem().getWebServer().getAccessAddress();
|
||||
Optional<String> found = database.query(ServerQueries.fetchServerMatchingIdentifier(system.getServerInfo().getServerUUID()))
|
||||
.map(Server::getWebAddress);
|
||||
|
||||
assertEquals(expectedAddress, found.orElse(null));
|
||||
} finally {
|
||||
system.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void bukkitSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException {
|
||||
try {
|
||||
|
@ -16,6 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.identification;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
@ -42,6 +43,7 @@ import java.util.concurrent.ExecutionException;
|
||||
public class BungeeServerInfo extends ServerInfo {
|
||||
|
||||
private final DBSystem dbSystem;
|
||||
private final Addresses addresses;
|
||||
private final Lazy<WebServer> webServer;
|
||||
private final PluginLogger logger;
|
||||
|
||||
@ -49,11 +51,13 @@ public class BungeeServerInfo extends ServerInfo {
|
||||
public BungeeServerInfo(
|
||||
ServerProperties serverProperties,
|
||||
DBSystem dbSystem,
|
||||
Addresses addresses,
|
||||
Lazy<WebServer> webServer,
|
||||
PluginLogger logger
|
||||
) {
|
||||
super(serverProperties);
|
||||
this.dbSystem = dbSystem;
|
||||
this.addresses = addresses;
|
||||
this.webServer = webServer;
|
||||
this.logger = logger;
|
||||
}
|
||||
@ -67,7 +71,7 @@ public class BungeeServerInfo extends ServerInfo {
|
||||
Optional<Server> proxyInfo = database.query(ServerQueries.fetchProxyServerInformation());
|
||||
if (proxyInfo.isPresent()) {
|
||||
server = proxyInfo.get();
|
||||
updateServerInfo(database);
|
||||
updateServerInfo();
|
||||
} else {
|
||||
server = registerBungeeInfo(database);
|
||||
}
|
||||
@ -78,26 +82,29 @@ public class BungeeServerInfo extends ServerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateServerInfo(Database db) {
|
||||
String accessAddress = webServer.get().getAccessAddress();
|
||||
private void updateServerInfo() {
|
||||
addresses.getAccessAddress().ifPresent(this::saveAddress);
|
||||
}
|
||||
|
||||
private void saveAddress(String accessAddress) {
|
||||
if (!accessAddress.equals(server.getWebAddress())) {
|
||||
server.setWebAddress(accessAddress);
|
||||
db.executeTransaction(new StoreServerInformationTransaction(server));
|
||||
dbSystem.getDatabase().executeTransaction(new StoreServerInformationTransaction(server));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIfDefaultIP() throws EnableException {
|
||||
String ip = serverProperties.getIp();
|
||||
if ("0.0.0.0".equals(ip)) {
|
||||
logger.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.");
|
||||
logger.error("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
|
||||
logger.info("Player Analytics partially enabled (Use /planbungee to reload config)");
|
||||
throw new EnableException("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.");
|
||||
throw new EnableException("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
|
||||
}
|
||||
}
|
||||
|
||||
private Server registerBungeeInfo(Database db) throws EnableException, ExecutionException, InterruptedException {
|
||||
UUID serverUUID = generateNewUUID();
|
||||
String accessAddress = webServer.get().getAccessAddress();
|
||||
String accessAddress = addresses.getAccessAddress().orElseThrow(() -> new EnableException("BungeeCord can not have '0.0.0.0' or '' as an address. Set up 'Server.IP' setting."));
|
||||
|
||||
Server proxy = new Server(-1, serverUUID, "BungeeCord", accessAddress, serverProperties.getMaxPlayers());
|
||||
db.executeTransaction(new StoreServerInformationTransaction(proxy))
|
||||
@ -107,6 +114,6 @@ public class BungeeServerInfo extends ServerInfo {
|
||||
if (proxyInfo.isPresent()) {
|
||||
return proxyInfo.get();
|
||||
}
|
||||
throw new EnableException("BungeeCord registration failed (DB)");
|
||||
throw new EnableException("BungeeCord registration failed (Was not found in the database after saving)");
|
||||
}
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public class BungeeSystemTest {
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.", thrown.getMessage());
|
||||
assertEquals("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.", thrown.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -22,7 +22,6 @@ import com.djrapitops.plan.delivery.export.ExportSystem;
|
||||
import com.djrapitops.plan.delivery.web.ResolverSvc;
|
||||
import com.djrapitops.plan.delivery.web.ResourceSvc;
|
||||
import com.djrapitops.plan.delivery.webserver.NonProxyWebserverDisableChecker;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServerSystem;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.extension.ExtensionService;
|
||||
@ -30,7 +29,6 @@ import com.djrapitops.plan.extension.ExtensionSvc;
|
||||
import com.djrapitops.plan.gathering.cache.CacheSystem;
|
||||
import com.djrapitops.plan.gathering.importing.ImportSystem;
|
||||
import com.djrapitops.plan.gathering.listeners.ListenerSystem;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.processing.Processing;
|
||||
import com.djrapitops.plan.query.QuerySvc;
|
||||
@ -38,7 +36,6 @@ import com.djrapitops.plan.settings.ConfigSystem;
|
||||
import com.djrapitops.plan.settings.SettingsSvc;
|
||||
import com.djrapitops.plan.settings.locale.LocaleSystem;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import com.djrapitops.plan.version.VersionChecker;
|
||||
import com.djrapitops.plugin.benchmarking.Benchmark;
|
||||
@ -146,14 +143,9 @@ public class PlanSystem implements SubSystem {
|
||||
);
|
||||
}
|
||||
|
||||
public static String getMainAddress(WebServer webServer, DBSystem dbSystem) {
|
||||
return dbSystem.getDatabase().query(ServerQueries.fetchProxyServerInformation())
|
||||
.map(Server::getWebAddress)
|
||||
.orElse(webServer.getAccessAddress());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getMainAddress() {
|
||||
return PlanSystem.getMainAddress(webServerSystem.getWebServer(), databaseSystem);
|
||||
return webServerSystem.getAddresses().getMainAddress().orElse(webServerSystem.getAddresses().getFallbackLocalhostAddress());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -183,7 +175,7 @@ public class PlanSystem implements SubSystem {
|
||||
// Disables Webserver if Proxy is detected in the database
|
||||
if (serverInfo.getServer().isNotProxy()) {
|
||||
processing.submitNonCritical(new NonProxyWebserverDisableChecker(
|
||||
configSystem.getConfig(), databaseSystem, webServerSystem, logger, errorHandler
|
||||
configSystem.getConfig(), webServerSystem.getAddresses(), webServerSystem, logger, errorHandler
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.export.Exporter;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.exceptions.ExportException;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
@ -56,6 +56,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final Exporter exporter;
|
||||
private final Addresses addresses;
|
||||
private final ServerInfo serverInfo;
|
||||
private final WebServer webServer;
|
||||
private final DBSystem dbSystem;
|
||||
@ -66,6 +67,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Exporter exporter,
|
||||
Addresses addresses,
|
||||
ServerInfo serverInfo,
|
||||
WebServer webServer,
|
||||
DBSystem dbSystem,
|
||||
@ -76,6 +78,7 @@ public class AnalyzeCommand extends CommandNode {
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.exporter = exporter;
|
||||
this.addresses = addresses;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
this.dbSystem = dbSystem;
|
||||
@ -110,7 +113,10 @@ public class AnalyzeCommand extends CommandNode {
|
||||
|
||||
private void sendLink(Server server, Sender sender) {
|
||||
String target = "/server/" + Html.encodeToURL(server.getName());
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
||||
return addresses.getFallbackLocalhostAddress();
|
||||
});
|
||||
String url = address + target;
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_ANALYSIS));
|
||||
|
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.identification.UUIDUtility;
|
||||
@ -52,6 +52,7 @@ public class InspectCommand extends CommandNode {
|
||||
private final Locale locale;
|
||||
private final DBSystem dbSystem;
|
||||
private final WebServer webServer;
|
||||
private final Addresses addresses;
|
||||
private final Processing processing;
|
||||
private final UUIDUtility uuidUtility;
|
||||
private final ErrorHandler errorHandler;
|
||||
@ -59,6 +60,7 @@ public class InspectCommand extends CommandNode {
|
||||
@Inject
|
||||
public InspectCommand(
|
||||
Locale locale,
|
||||
Addresses addresses,
|
||||
Processing processing,
|
||||
DBSystem dbSystem,
|
||||
WebServer webServer,
|
||||
@ -66,6 +68,7 @@ public class InspectCommand extends CommandNode {
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("inspect", Permissions.INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
this.addresses = addresses;
|
||||
this.processing = processing;
|
||||
setArguments("<player>");
|
||||
|
||||
@ -132,7 +135,10 @@ public class InspectCommand extends CommandNode {
|
||||
private void sendInspectMsg(Sender sender, String playerName) {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
||||
return addresses.getFallbackLocalhostAddress();
|
||||
});
|
||||
String url = address + "/player/" + Html.encodeToURL(playerName);
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
|
||||
|
@ -16,14 +16,12 @@
|
||||
*/
|
||||
package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.settings.Permissions;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
@ -39,20 +37,17 @@ import javax.inject.Inject;
|
||||
public class ListPlayersCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final DBSystem dbSystem;
|
||||
private final WebServer webServer;
|
||||
private final Addresses addresses;
|
||||
|
||||
@Inject
|
||||
public ListPlayersCommand(
|
||||
Locale locale,
|
||||
DBSystem dbSystem,
|
||||
WebServer webServer
|
||||
Addresses addresses
|
||||
) {
|
||||
super("players|pl|playerlist|list", Permissions.INSPECT_OTHER.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
this.locale = locale;
|
||||
this.dbSystem = dbSystem;
|
||||
this.webServer = webServer;
|
||||
this.addresses = addresses;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.PLAYERS));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.PLAYERS));
|
||||
@ -67,7 +62,10 @@ public class ListPlayersCommand extends CommandNode {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_PLAYERS));
|
||||
|
||||
// Link
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
||||
return addresses.getFallbackLocalhostAddress();
|
||||
});
|
||||
String url = address + "/players";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
|
@ -16,14 +16,12 @@
|
||||
*/
|
||||
package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.settings.Permissions;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
import com.djrapitops.plugin.command.CommandUtils;
|
||||
@ -39,20 +37,17 @@ import javax.inject.Inject;
|
||||
public class NetworkCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final DBSystem dbSystem;
|
||||
private final WebServer webServer;
|
||||
private final Addresses addresses;
|
||||
|
||||
@Inject
|
||||
public NetworkCommand(
|
||||
Locale locale,
|
||||
DBSystem dbSystem,
|
||||
WebServer webServer
|
||||
Addresses addresses
|
||||
) {
|
||||
super("network|n|netw", Permissions.ANALYZE.getPermission(), CommandType.CONSOLE);
|
||||
|
||||
this.locale = locale;
|
||||
this.dbSystem = dbSystem;
|
||||
this.webServer = webServer;
|
||||
this.addresses = addresses;
|
||||
|
||||
setShortHelp(locale.getString(CmdHelpLang.NETWORK));
|
||||
setInDepthHelp(locale.getArray(DeepHelpLang.NETWORK));
|
||||
@ -67,7 +62,10 @@ public class NetworkCommand extends CommandNode {
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_NETWORK));
|
||||
|
||||
// Link
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
||||
return addresses.getFallbackLocalhostAddress();
|
||||
});
|
||||
String url = address + "/network";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
|
@ -16,9 +16,8 @@
|
||||
*/
|
||||
package com.djrapitops.plan.commands.subcommands;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.domain.WebUser;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.processing.Processing;
|
||||
import com.djrapitops.plan.settings.Permissions;
|
||||
@ -62,7 +61,7 @@ public class RegisterCommand extends CommandNode {
|
||||
private final Locale locale;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final WebServer webServer;
|
||||
private final Addresses addresses;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@ -70,8 +69,8 @@ public class RegisterCommand extends CommandNode {
|
||||
public RegisterCommand(
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Addresses addresses,
|
||||
DBSystem dbSystem,
|
||||
WebServer webServer,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
@ -80,7 +79,7 @@ public class RegisterCommand extends CommandNode {
|
||||
|
||||
this.locale = locale;
|
||||
this.processing = processing;
|
||||
this.webServer = webServer;
|
||||
this.addresses = addresses;
|
||||
this.logger = logger;
|
||||
this.dbSystem = dbSystem;
|
||||
this.errorHandler = errorHandler;
|
||||
@ -187,7 +186,10 @@ public class RegisterCommand extends CommandNode {
|
||||
}
|
||||
|
||||
private void sendLink(Sender sender) {
|
||||
String url = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String url = addresses.getMainAddress().orElseGet(() -> {
|
||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
||||
return addresses.getFallbackLocalhostAddress();
|
||||
});
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
// Link
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
|
@ -16,15 +16,13 @@
|
||||
*/
|
||||
package com.djrapitops.plan.commands.subcommands.manage;
|
||||
|
||||
import com.djrapitops.plan.PlanSystem;
|
||||
import com.djrapitops.plan.delivery.rendering.html.Html;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.settings.Permissions;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.locale.lang.CmdHelpLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.CommandLang;
|
||||
import com.djrapitops.plan.settings.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plugin.command.CommandNode;
|
||||
import com.djrapitops.plugin.command.CommandType;
|
||||
@ -44,16 +42,17 @@ import java.util.Arrays;
|
||||
public class ManageRawDataCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final DBSystem dbSystem;
|
||||
private final WebServer webServer;
|
||||
private Addresses addresses;
|
||||
|
||||
@Inject
|
||||
public ManageRawDataCommand(Locale locale, DBSystem dbSystem, WebServer webServer) {
|
||||
public ManageRawDataCommand(
|
||||
Locale locale,
|
||||
Addresses addresses
|
||||
) {
|
||||
super("raw", Permissions.MANAGE.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
|
||||
this.locale = locale;
|
||||
this.dbSystem = dbSystem;
|
||||
this.webServer = webServer;
|
||||
this.addresses = addresses;
|
||||
|
||||
setArguments("<player>");
|
||||
setShortHelp(locale.getString(CmdHelpLang.MANAGE_RAW_DATA));
|
||||
@ -69,7 +68,10 @@ public class ManageRawDataCommand extends CommandNode {
|
||||
|
||||
sender.sendMessage(locale.getString(CommandLang.HEADER_INSPECT, playerName));
|
||||
// Link
|
||||
String address = PlanSystem.getMainAddress(webServer, dbSystem);
|
||||
String address = addresses.getMainAddress().orElseGet(() -> {
|
||||
sender.sendMessage(locale.getString(CommandLang.NO_ADDRESS_NOTIFY));
|
||||
return addresses.getFallbackLocalhostAddress();
|
||||
});
|
||||
String url = address + "/player/" + Html.encodeToURL(playerName) + "/raw";
|
||||
String linkPrefix = locale.getString(CommandLang.LINK_PREFIX);
|
||||
boolean console = !CommandUtils.isPlayer(sender);
|
||||
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* 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.delivery.webserver;
|
||||
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.identification.properties.ServerProperties;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* In charge of address management.
|
||||
* <p>
|
||||
* Possible scenarios (problem domain):
|
||||
* - IP in server properties is 0.0.0.0 which is invalid
|
||||
* - IP in server properties is empty string, which is invalid
|
||||
* - Alternative IP is set in the Plan config
|
||||
* - Proxy server is used as main webserver, this address has highest priority
|
||||
* - Webserver is disabled, external webserver address in config should be used
|
||||
* - Webserver uses either http or https
|
||||
* - Webserver always has a port, but Alternative IP can be used to remove the port from the address
|
||||
* <p>
|
||||
* What are the addresses used in:
|
||||
* - Given as links to commands
|
||||
* - Redirection
|
||||
* - Storing proxy server address in database
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class Addresses {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final Lazy<ServerProperties> serverProperties;
|
||||
private final Lazy<WebServer> webserver;
|
||||
|
||||
@Inject
|
||||
public Addresses(
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
Lazy<ServerProperties> serverProperties,
|
||||
Lazy<WebServer> webserver
|
||||
) {
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverProperties = serverProperties;
|
||||
this.webserver = webserver;
|
||||
}
|
||||
|
||||
public Optional<String> getMainAddress() {
|
||||
Optional<String> proxyServerAddress = getProxyServerAddress();
|
||||
return proxyServerAddress.isPresent() ? proxyServerAddress : getAccessAddress();
|
||||
}
|
||||
|
||||
public Optional<String> getAccessAddress() {
|
||||
WebServer webServer = this.webserver.get();
|
||||
if (!webServer.isEnabled()) {
|
||||
return Optional.of(getFallbackExternalAddress());
|
||||
}
|
||||
return getIP().map(ip -> webServer.getProtocol() + "://" + ip);
|
||||
}
|
||||
|
||||
private Optional<String> getIP() {
|
||||
int port = webserver.get().getPort();
|
||||
return config.isTrue(WebserverSettings.SHOW_ALTERNATIVE_IP)
|
||||
? Optional.of(config.get(WebserverSettings.ALTERNATIVE_IP).replace("%port%", String.valueOf(port)))
|
||||
: getServerPropertyIP().map(ip -> ip + ":" + port);
|
||||
}
|
||||
|
||||
private String getFallbackExternalAddress() {
|
||||
return config.get(WebserverSettings.EXTERNAL_LINK);
|
||||
}
|
||||
|
||||
public String getFallbackLocalhostAddress() {
|
||||
WebServer webServer = this.webserver.get();
|
||||
return webServer.getProtocol() + "://localhost:" + webServer.getPort();
|
||||
}
|
||||
|
||||
public Optional<String> getProxyServerAddress() {
|
||||
return dbSystem.getDatabase().query(ServerQueries.fetchProxyServerInformation()).map(Server::getWebAddress)
|
||||
.filter(this::isValidAddress);
|
||||
}
|
||||
|
||||
private boolean isValidAddress(String address) {
|
||||
return !address.isEmpty() && !address.equals("0.0.0.0");
|
||||
}
|
||||
|
||||
public Optional<String> getServerPropertyIP() {
|
||||
String ip = serverProperties.get().getIp();
|
||||
return isValidAddress(ip) ? Optional.of(ip) : Optional.empty();
|
||||
}
|
||||
}
|
@ -19,8 +19,6 @@ package com.djrapitops.plan.delivery.webserver;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
@ -35,20 +33,20 @@ import java.io.IOException;
|
||||
public class NonProxyWebserverDisableChecker implements Runnable {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final DBSystem dbSystem;
|
||||
private final Addresses addresses;
|
||||
private final WebServerSystem webServerSystem;
|
||||
private final PluginLogger logger;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
public NonProxyWebserverDisableChecker(
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
Addresses addresses,
|
||||
WebServerSystem webServerSystem,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.config = config;
|
||||
this.dbSystem = dbSystem;
|
||||
this.addresses = addresses;
|
||||
this.webServerSystem = webServerSystem;
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
@ -58,8 +56,8 @@ public class NonProxyWebserverDisableChecker implements Runnable {
|
||||
public void run() {
|
||||
if (config.isFalse(PluginSettings.PROXY_COPY_CONFIG)) return;
|
||||
|
||||
dbSystem.getDatabase().query(ServerQueries.fetchProxyServerInformation()).ifPresent(proxy -> {
|
||||
logger.info("Proxy server detected in the database - Proxy Webserver address is '" + proxy.getWebAddress() + "'.");
|
||||
addresses.getProxyServerAddress().ifPresent(address -> {
|
||||
logger.info("Proxy server detected in the database - Proxy Webserver address is '" + address + "'.");
|
||||
WebServer webServer = webServerSystem.getWebServer();
|
||||
|
||||
if (webServer.isEnabled()) {
|
||||
|
@ -23,7 +23,6 @@ import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.PluginSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.settings.locale.Locale;
|
||||
import com.djrapitops.plan.settings.theme.Theme;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
@ -52,8 +51,8 @@ public class RequestHandler implements HttpHandler {
|
||||
|
||||
private final Locale locale;
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
private final DBSystem dbSystem;
|
||||
private final Addresses addresses;
|
||||
private final ResponseResolver responseResolver;
|
||||
private final ResponseFactory responseFactory;
|
||||
private final PluginLogger logger;
|
||||
@ -67,8 +66,8 @@ public class RequestHandler implements HttpHandler {
|
||||
RequestHandler(
|
||||
Locale locale,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
DBSystem dbSystem,
|
||||
Addresses addresses,
|
||||
ResponseResolver responseResolver,
|
||||
ResponseFactory responseFactory,
|
||||
PluginLogger logger,
|
||||
@ -76,8 +75,8 @@ public class RequestHandler implements HttpHandler {
|
||||
) {
|
||||
this.locale = locale;
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
this.dbSystem = dbSystem;
|
||||
this.addresses = addresses;
|
||||
this.responseResolver = responseResolver;
|
||||
this.responseFactory = responseFactory;
|
||||
this.logger = logger;
|
||||
@ -109,7 +108,7 @@ public class RequestHandler implements HttpHandler {
|
||||
response.getHeaders().putIfAbsent("Access-Control-Allow-Origin", config.get(WebserverSettings.CORS_ALLOW_ORIGIN));
|
||||
response.getHeaders().putIfAbsent("Access-Control-Allow-Methods", "GET, OPTIONS");
|
||||
|
||||
ResponseSender sender = new ResponseSender(exchange, response);
|
||||
ResponseSender sender = new ResponseSender(addresses, exchange, response);
|
||||
sender.send();
|
||||
} catch (Exception e) {
|
||||
if (config.isTrue(PluginSettings.DEV_MODE)) {
|
||||
|
@ -33,10 +33,12 @@ import java.util.zip.GZIPOutputStream;
|
||||
*/
|
||||
public class ResponseSender {
|
||||
|
||||
private final Addresses addresses;
|
||||
private final HttpExchange exchange;
|
||||
private final Response response;
|
||||
|
||||
public ResponseSender(HttpExchange exchange, Response response) {
|
||||
public ResponseSender(Addresses addresses, HttpExchange exchange, Response response) {
|
||||
this.addresses = addresses;
|
||||
this.exchange = exchange;
|
||||
this.response = response;
|
||||
}
|
||||
@ -52,11 +54,23 @@ public class ResponseSender {
|
||||
|
||||
private void setResponseHeaders() {
|
||||
Headers headers = exchange.getResponseHeaders();
|
||||
for (Map.Entry<String, String> header : response.getHeaders().entrySet()) {
|
||||
|
||||
Map<String, String> responseHeaders = response.getHeaders();
|
||||
correctRedirect(responseHeaders);
|
||||
|
||||
for (Map.Entry<String, String> header : responseHeaders.entrySet()) {
|
||||
headers.set(header.getKey(), header.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void correctRedirect(Map<String, String> responseHeaders) {
|
||||
String redirect = responseHeaders.get("Location");
|
||||
if (redirect != null) {
|
||||
if (redirect.startsWith("http") || !redirect.startsWith("/")) return;
|
||||
addresses.getAccessAddress().ifPresent(address -> responseHeaders.put("Location", address + redirect));
|
||||
}
|
||||
}
|
||||
|
||||
private void sendCompressed() throws IOException {
|
||||
exchange.getResponseHeaders().set("Content-Encoding", "gzip");
|
||||
beginSend();
|
||||
|
@ -58,6 +58,7 @@ public class WebServer implements SubSystem {
|
||||
private final PlanConfig config;
|
||||
|
||||
private final ServerProperties serverProperties;
|
||||
private Addresses addresses;
|
||||
private final RequestHandler requestHandler;
|
||||
|
||||
private final PluginLogger logger;
|
||||
@ -75,6 +76,7 @@ public class WebServer implements SubSystem {
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
ServerInfo serverInfo,
|
||||
Addresses addresses,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler,
|
||||
RequestHandler requestHandler
|
||||
@ -83,6 +85,7 @@ public class WebServer implements SubSystem {
|
||||
this.files = files;
|
||||
this.config = config;
|
||||
this.serverProperties = serverInfo.getServerProperties();
|
||||
this.addresses = addresses;
|
||||
|
||||
this.requestHandler = requestHandler;
|
||||
|
||||
@ -96,7 +99,7 @@ public class WebServer implements SubSystem {
|
||||
|
||||
initServer();
|
||||
|
||||
if (getAccessAddress().contains("0.0.0.0")) {
|
||||
if (!addresses.getAccessAddress().isPresent()) {
|
||||
logger.warn(locale.getString(PluginLang.ENABLE_NOTIFY_BAD_IP));
|
||||
}
|
||||
|
||||
@ -156,9 +159,11 @@ public class WebServer implements SubSystem {
|
||||
|
||||
enabled = true;
|
||||
|
||||
logger.info(locale.getString(PluginLang.ENABLED_WEB_SERVER, server.getAddress().getPort(), getAccessAddress()));
|
||||
String address = addresses.getAccessAddress().orElse(addresses.getFallbackLocalhostAddress());
|
||||
logger.info(locale.getString(PluginLang.ENABLED_WEB_SERVER, server.getAddress().getPort(), address));
|
||||
|
||||
boolean usingAlternativeIP = config.isTrue(WebserverSettings.SHOW_ALTERNATIVE_IP);
|
||||
if (!usingAlternativeIP && serverProperties.getIp().isEmpty()) {
|
||||
if (!usingAlternativeIP && !addresses.getAccessAddress().isPresent()) {
|
||||
logger.log(L.INFO_COLOR, "§e" + locale.getString(PluginLang.ENABLE_NOTIFY_EMPTY_IP));
|
||||
}
|
||||
} catch (BindException failedToBind) {
|
||||
@ -298,13 +303,7 @@ public class WebServer implements SubSystem {
|
||||
return isUsingHTTPS() && config.isFalse(WebserverSettings.DISABLED_AUTHENTICATION);
|
||||
}
|
||||
|
||||
public String getAccessAddress() {
|
||||
return isEnabled() ? getProtocol() + "://" + getIP() : config.get(WebserverSettings.EXTERNAL_LINK);
|
||||
}
|
||||
|
||||
private String getIP() {
|
||||
return config.isTrue(WebserverSettings.SHOW_ALTERNATIVE_IP)
|
||||
? config.get(WebserverSettings.ALTERNATIVE_IP).replace("%port%", String.valueOf(port))
|
||||
: serverProperties.getIp() + ":" + port;
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
|
@ -30,12 +30,15 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
public class WebServerSystem implements SubSystem {
|
||||
|
||||
private final Addresses addresses;
|
||||
private final WebServer webServer;
|
||||
|
||||
@Inject
|
||||
public WebServerSystem(
|
||||
Addresses addresses,
|
||||
WebServer webServer
|
||||
) {
|
||||
this.addresses = addresses;
|
||||
this.webServer = webServer;
|
||||
}
|
||||
|
||||
@ -55,4 +58,7 @@ public class WebServerSystem implements SubSystem {
|
||||
return webServer;
|
||||
}
|
||||
|
||||
public Addresses getAddresses() {
|
||||
return addresses;
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,10 @@ import com.djrapitops.plan.delivery.web.resolver.request.Request;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.URIPath;
|
||||
import com.djrapitops.plan.delivery.web.resolver.request.WebUser;
|
||||
import com.djrapitops.plan.delivery.webserver.ResponseFactory;
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.identification.ServerInfo;
|
||||
import com.djrapitops.plan.storage.database.DBSystem;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -46,19 +44,16 @@ public class ServerPageResolver implements Resolver {
|
||||
private final ResponseFactory responseFactory;
|
||||
private final DBSystem dbSystem;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Lazy<WebServer> webServer;
|
||||
|
||||
@Inject
|
||||
public ServerPageResolver(
|
||||
ResponseFactory responseFactory,
|
||||
DBSystem dbSystem,
|
||||
ServerInfo serverInfo,
|
||||
Lazy<WebServer> webServer
|
||||
ServerInfo serverInfo
|
||||
) {
|
||||
this.responseFactory = responseFactory;
|
||||
this.dbSystem = dbSystem;
|
||||
this.serverInfo = serverInfo;
|
||||
this.webServer = webServer;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -81,7 +76,7 @@ public class ServerPageResolver implements Resolver {
|
||||
String directTo = serverInfo.getServer().isProxy()
|
||||
? "/network"
|
||||
: "/server/" + Html.encodeToURL(serverInfo.getServer().getIdentifiableName());
|
||||
return Optional.of(responseFactory.redirectResponse(webServer.get().getAccessAddress() + directTo));
|
||||
return Optional.of(responseFactory.redirectResponse(directTo));
|
||||
}
|
||||
|
||||
private Optional<Response> getServerPage(UUID serverUUID) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.identification;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.identification.properties.ServerProperties;
|
||||
@ -29,7 +29,6 @@ import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -53,7 +52,7 @@ public class ServerServerInfo extends ServerInfo {
|
||||
private final PlanConfig config;
|
||||
private final Processing processing;
|
||||
private final DBSystem dbSystem;
|
||||
private final Lazy<WebServer> webServer;
|
||||
private final Addresses addresses;
|
||||
private final ErrorHandler errorHandler;
|
||||
|
||||
@Inject
|
||||
@ -63,14 +62,14 @@ public class ServerServerInfo extends ServerInfo {
|
||||
Processing processing,
|
||||
PlanConfig config,
|
||||
DBSystem dbSystem,
|
||||
Lazy<WebServer> webServer,
|
||||
Addresses addresses,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(serverProperties);
|
||||
this.serverInfoFile = serverInfoFile;
|
||||
this.processing = processing;
|
||||
this.dbSystem = dbSystem;
|
||||
this.webServer = webServer;
|
||||
this.addresses = addresses;
|
||||
this.config = config;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
@ -128,8 +127,7 @@ public class ServerServerInfo extends ServerInfo {
|
||||
String name = config.get(PluginSettings.SERVER_NAME);
|
||||
server.setName("plan".equalsIgnoreCase(name) ? "Server " + server.getId() : name);
|
||||
|
||||
String webAddress = webServer.get().getAccessAddress();
|
||||
server.setWebAddress(webAddress);
|
||||
addresses.getAccessAddress().ifPresent(server::setWebAddress);
|
||||
|
||||
int maxPlayers = serverProperties.getMaxPlayers();
|
||||
server.setMaxPlayers(maxPlayers);
|
||||
@ -161,7 +159,7 @@ public class ServerServerInfo extends ServerInfo {
|
||||
}
|
||||
|
||||
private Server createServerObject(UUID serverUUID) {
|
||||
String webAddress = webServer.get().getAccessAddress();
|
||||
String webAddress = addresses.getAccessAddress().orElse(addresses.getFallbackLocalhostAddress());
|
||||
String name = config.get(PluginSettings.SERVER_NAME);
|
||||
int maxPlayers = serverProperties.getMaxPlayers();
|
||||
return new Server(-1, serverUUID, name, webAddress, maxPlayers);
|
||||
|
@ -73,7 +73,8 @@ public enum CommandLang implements Lang {
|
||||
DISABLE_DISABLED("Cmd Disable - Disabled", "§aPlan systems are now disabled. You can still use /planbungee reload to restart the plugin."),
|
||||
|
||||
RELOAD_COMPLETE("Cmd Info - Reload Complete", "§aReload Complete"),
|
||||
RELOAD_FAILED("Cmd Info - Reload Failed", "§cSomething went wrong during reload of the plugin, a restart is recommended.");
|
||||
RELOAD_FAILED("Cmd Info - Reload Failed", "§cSomething went wrong during reload of the plugin, a restart is recommended."),
|
||||
NO_ADDRESS_NOTIFY("Cmd Notify - No Address", "§eNo address was available - using localhost as fallback. Set up 'Alternative_IP' settings.");
|
||||
|
||||
private final String identifier;
|
||||
private final String defaultValue;
|
||||
|
@ -28,8 +28,8 @@ public enum PluginLang implements Lang {
|
||||
API_ADD_RESOURCE_JS("API - js+", "PageExtension: ${0} added javascript(s) to ${1}, ${2}"),
|
||||
API_ADD_RESOURCE_CSS("API - css+", "PageExtension: ${0} added stylesheet(s) to ${1}, ${2}"),
|
||||
|
||||
ENABLE_NOTIFY_EMPTY_IP("Enable - Notify Empty IP", "IP in server.properties is empty & AlternativeIP is not in use. Incorrect links will be given!"),
|
||||
ENABLE_NOTIFY_BAD_IP("Enable - Notify Bad IP", "0.0.0.0 is not a valid address, set up AlternativeIP settings. Incorrect links will be given!"),
|
||||
ENABLE_NOTIFY_EMPTY_IP("Enable - Notify Empty IP", "IP in server.properties is empty & Alternative_IP is not in use. Incorrect links might be given!"),
|
||||
ENABLE_NOTIFY_BAD_IP("Enable - Notify Bad IP", "0.0.0.0 is not a valid address, set up Alternative_IP settings. Incorrect links might be given!"),
|
||||
ENABLE_NOTIFY_WEB_SERVER_DISABLED("Enable - Notify Webserver disabled", "WebServer was not initialized. (WebServer.DisableWebServer: true)"),
|
||||
ENABLE_NOTIFY_GEOLOCATIONS_INTERNET_REQUIRED("Enable - Notify Geolocations Internet Required", "Plan Requires internet access on first run to download GeoLite2 Geolocation database."),
|
||||
ENABLE_NOTIFY_GEOLOCATIONS_DISABLED("Enable - Notify Geolocations disabled", "Geolocation gathering is not active. (Data.Geolocations: false)"),
|
||||
@ -45,7 +45,7 @@ public enum PluginLang implements Lang {
|
||||
WEB_SERVER_FAIL_EMPTY_FILE("WebServer FAIL - EOF", "WebServer: EOF when reading Certificate file. (Check that the file is not empty)"),
|
||||
WEB_SERVER_NOTIFY_NO_CERT_FILE("WebServer - Notify no Cert file", "WebServer: Certificate KeyStore File not Found: ${0}"),
|
||||
WEB_SERVER_NOTIFY_HTTP("WebServer - Notify HTTP", "WebServer: No Certificate -> Using HTTP-server for Visualization."),
|
||||
WEB_SERVER_NOTIFY_USING_PROXY_MODE("WebServer - Notify Using Proxy", "WebServer: Proxy-mode HTTPS enabled, make sure that your reverse-proxy is routing using HTTPS and Plan AlternativeIP.Link points to the Proxy"),
|
||||
WEB_SERVER_NOTIFY_USING_PROXY_MODE("WebServer - Notify Using Proxy", "WebServer: Proxy-mode HTTPS enabled, make sure that your reverse-proxy is routing using HTTPS and Plan Alternative_IP.Link points to the Proxy"),
|
||||
WEB_SERVER_NOTIFY_HTTP_USER_AUTH("WebServer - Notify HTTP User Auth", "WebServer: User Authorization Disabled! (Not secure over HTTP)"),
|
||||
WEB_SERVER_NOTIFY_HTTPS_USER_AUTH("WebServer - Notify HTTPS User Auth", "WebServer: User Authorization Disabled! (Disabled in config)"),
|
||||
|
||||
|
@ -83,7 +83,7 @@ Disable - Unsaved Session Save || Saving unfinished sessions..
|
||||
Disable - WebServer || Webserver deaktiviert.
|
||||
Enable || Player Analytics eingeschaltet.
|
||||
Enable - Database || ${0}-dDatenbankverbindung hergestellt.
|
||||
Enable - Notify Empty IP || IP in der server.properties ist leer & AlternativeIP ist nicht in Verwendung. Es werden falsche Links verwendet!
|
||||
Enable - Notify Empty IP || IP in der server.properties ist leer & Alternative_IP ist nicht in Verwendung. Es werden falsche Links verwendet!
|
||||
Enable - Notify Geolocations disabled || Geolocation wird nicht aufgezeichnet (Data.Geolocations: false)
|
||||
Enable - Notify Geolocations Internet Required || Plan braucht einen Internetzugang um die GeoLite2 Geolocation Datenbank runterzuladen.
|
||||
Enable - Notify Webserver disabled || WebServer wurde nicht geladen. (WebServer.DisableWebServer: true)
|
||||
|
@ -83,7 +83,7 @@ Disable - Unsaved Session Save || Saving unfinished sessions..
|
||||
Disable - WebServer || Webserver has been disabled.
|
||||
Enable || Player Analytics Enabled.
|
||||
Enable - Database || ${0}-database connection established.
|
||||
Enable - Notify Empty IP || IP in server.properties is empty & AlternativeIP is not in use. Incorrect links will be given!
|
||||
Enable - Notify Empty IP || IP in server.properties is empty & Alternative_IP is not in use. Incorrect links might be given!
|
||||
Enable - Notify Geolocations disabled || Geolocation gathering is not active. (Data.Geolocations: false)
|
||||
Enable - Notify Geolocations Internet Required || Plan Requires internet access on first run to download GeoLite2 Geolocation database.
|
||||
Enable - Notify Webserver disabled || WebServer was not initialized. (WebServer.DisableWebServer: true)
|
||||
|
@ -83,7 +83,7 @@ Disable - Unsaved Session Save || Tallennetaan päättymättöm
|
||||
Disable - WebServer || Web palvelin on sammutettu.
|
||||
Enable || Player Analytics Käynnistetty.
|
||||
Enable - Database || ${0}-tietokanta yhteys luotu.
|
||||
Enable - Notify Empty IP || IP server.properties tiedostossa on tyhjä & AlternativeIP ei ole käytössä. Linkit ovat virheellisiä!
|
||||
Enable - Notify Empty IP || IP server.properties tiedostossa on tyhjä & Alternative_IP ei ole käytössä. Linkit ovat virheellisiä!
|
||||
Enable - Notify Geolocations disabled || Sijaintien keräys ei ole päällä. (Data.Geolocations: false)
|
||||
Enable - Notify Geolocations Internet Required || Plan Vaatii internetin ensimmäisellä käynnistyskerralla GeoLite2 tietokannan lataamiseen.
|
||||
Enable - Notify Webserver disabled || Web Palvelinta ei käynnistetty. (WebServer.DisableWebServer: true)
|
||||
|
@ -84,7 +84,7 @@ Disable - WebServer || Le serveur Web a été désac
|
||||
Enable || Plan a été activé.
|
||||
Enable - Database || Connexion à la base de données établie. (${0})
|
||||
Enable - Notify Bad IP || L'adresse IP située dans le fichier 'server.properties' est érronée. Attention, des liens incorrects seront donnés !
|
||||
Enable - Notify Empty IP || L'adresse IP située dans le fichier 'server.properties' est vide et l'option 'AlternativeIP' n'est pas utilisée. Attention, des liens incorrects seront donnés !
|
||||
Enable - Notify Empty IP || L'adresse IP située dans le fichier 'server.properties' est vide et l'option 'Alternative_IP' n'est pas utilisée. Attention, des liens incorrects seront donnés !
|
||||
Enable - Notify Geolocations disabled || La Géolocalisation n'est pas active. (Data.Geolocations: false)
|
||||
Enable - Notify Geolocations Internet Required || Plan nécessite un accès à Internet lors de sa première utilisation pour télécharger la base de données 'GeoLite2 Geolocation'.
|
||||
Enable - Notify Webserver disabled || Le serveur Web n'a pas été initialisé. (WebServer.DisableWebServer: true)
|
||||
@ -355,7 +355,7 @@ WebServer - Notify HTTP || Serveur Web : Aucun certifica
|
||||
WebServer - Notify HTTP User Auth || Serveur Web : Authentification utilisateur désactivée ! (Non sécurisée avec HTTP)
|
||||
WebServer - Notify HTTPS User Auth || Serveur Web : Authentification d'utilisateur désactivée ! (dans la configuration)
|
||||
WebServer - Notify no Cert file || Serveur Web : Fichier KeyStore du certificat introuvable : ${0}
|
||||
WebServer - Notify Using Proxy || Serveur Web : le Proxy-mode HTTPS est activé, assurez-vous que votre proxy inversé est routé en utilisant HTTPS et Plan AlternativeIP.Link.
|
||||
WebServer - Notify Using Proxy || Serveur Web : le Proxy-mode HTTPS est activé, assurez-vous que votre proxy inversé est routé en utilisant HTTPS et Plan Alternative_IP.Link.
|
||||
WebServer FAIL - Port Bind || Le Serveur Web n'a pas été initialisé avec succès. Le port (${0}) est-il actuellement utilisé ?
|
||||
WebServer FAIL - SSL Context || Serveur Web : Échec d'initialisation du contexte SSL.
|
||||
WebServer FAIL - Store Load || Serveur Web : Échec du chargement du certificat SSL.
|
||||
|
@ -83,7 +83,7 @@ Disable - Unsaved Session Save || Salvano le sessioni..
|
||||
Disable - WebServer || Webserver è stato disabilitato.
|
||||
Enable || Analisi Giocatori Abilitata.
|
||||
Enable - Database || ${0}-connession al database stabilita.
|
||||
Enable - Notify Empty IP || IP in server.properties è vuoto e AlternativeIP non è in uso. Correggi queste informazioni!
|
||||
Enable - Notify Empty IP || IP in server.properties è vuoto e Alternative_IP non è in uso. Correggi queste informazioni!
|
||||
Enable - Notify Geolocations disabled || Geolocalizazione non attiva. (Data.Geolocations: false)
|
||||
Enable - Notify Geolocations Internet Required || Plan richiesta una connessione internet la prima volta per scaricare il database Geolite.
|
||||
Enable - Notify Webserver disabled || WebServer non avviato. (WebServer.DisableWebServer: true)
|
||||
|
@ -17,13 +17,10 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.identification.Server;
|
||||
import com.djrapitops.plan.settings.ConfigSettingKeyTest;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.settings.config.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.settings.config.paths.key.Setting;
|
||||
import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
@ -32,9 +29,7 @@ import utilities.mocks.NukkitMockComponent;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
@ -64,21 +59,6 @@ public class NukkitSystemTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void correctWebAddressInDatabaseAfterEnable() throws EnableException {
|
||||
try {
|
||||
system.enable();
|
||||
Database database = system.getDatabaseSystem().getDatabase();
|
||||
String expectedAddress = system.getWebServerSystem().getWebServer().getAccessAddress();
|
||||
Optional<String> found = database.query(ServerQueries.fetchServerMatchingIdentifier(system.getServerInfo().getServerUUID()))
|
||||
.map(Server::getWebAddress);
|
||||
|
||||
assertEquals(expectedAddress, found.orElse(null));
|
||||
} finally {
|
||||
system.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void nukkitSystemHasDefaultConfigValuesAfterEnable() throws EnableException, IllegalAccessException {
|
||||
try {
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.identification;
|
||||
|
||||
import com.djrapitops.plan.delivery.webserver.WebServer;
|
||||
import com.djrapitops.plan.delivery.webserver.Addresses;
|
||||
import com.djrapitops.plan.exceptions.EnableException;
|
||||
import com.djrapitops.plan.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.identification.properties.ServerProperties;
|
||||
@ -25,7 +25,6 @@ import com.djrapitops.plan.storage.database.Database;
|
||||
import com.djrapitops.plan.storage.database.queries.objects.ServerQueries;
|
||||
import com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import dagger.Lazy;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
@ -42,19 +41,19 @@ import java.util.concurrent.ExecutionException;
|
||||
public class VelocityServerInfo extends ServerInfo {
|
||||
|
||||
private final DBSystem dbSystem;
|
||||
private final Lazy<WebServer> webServer;
|
||||
private final Addresses addresses;
|
||||
private final PluginLogger logger;
|
||||
|
||||
@Inject
|
||||
public VelocityServerInfo(
|
||||
ServerProperties serverProperties,
|
||||
DBSystem dbSystem,
|
||||
Lazy<WebServer> webServer,
|
||||
Addresses addresses,
|
||||
PluginLogger logger
|
||||
) {
|
||||
super(serverProperties);
|
||||
this.dbSystem = dbSystem;
|
||||
this.webServer = webServer;
|
||||
this.addresses = addresses;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@ -67,7 +66,7 @@ public class VelocityServerInfo extends ServerInfo {
|
||||
Optional<Server> proxyInfo = database.query(ServerQueries.fetchProxyServerInformation());
|
||||
if (proxyInfo.isPresent()) {
|
||||
server = proxyInfo.get();
|
||||
updateServerInfo(database);
|
||||
updateServerInfo();
|
||||
} else {
|
||||
server = registerVelocityInfo(database);
|
||||
}
|
||||
@ -78,26 +77,29 @@ public class VelocityServerInfo extends ServerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateServerInfo(Database db) {
|
||||
String accessAddress = webServer.get().getAccessAddress();
|
||||
private void updateServerInfo() {
|
||||
addresses.getAccessAddress().ifPresent(this::saveAddress);
|
||||
}
|
||||
|
||||
private void saveAddress(String accessAddress) {
|
||||
if (!accessAddress.equals(server.getWebAddress())) {
|
||||
server.setWebAddress(accessAddress);
|
||||
db.executeTransaction(new StoreServerInformationTransaction(server));
|
||||
dbSystem.getDatabase().executeTransaction(new StoreServerInformationTransaction(server));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIfDefaultIP() throws EnableException {
|
||||
String ip = serverProperties.getIp();
|
||||
if ("0.0.0.0".equals(ip)) {
|
||||
logger.error("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.");
|
||||
logger.error("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
|
||||
logger.info("Player Analytics partially enabled (Use /planbungee to reload config)");
|
||||
throw new EnableException("IP setting still 0.0.0.0 - Configure AlternativeIP/IP that connects to the Proxy server.");
|
||||
throw new EnableException("IP setting still 0.0.0.0 - Configure Alternative_IP/IP that connects to the Proxy server.");
|
||||
}
|
||||
}
|
||||
|
||||
private Server registerVelocityInfo(Database db) throws EnableException, ExecutionException, InterruptedException {
|
||||
UUID serverUUID = generateNewUUID();
|
||||
String accessAddress = webServer.get().getAccessAddress();
|
||||
String accessAddress = addresses.getAccessAddress().orElseThrow(() -> new EnableException("Velocity can not have '0.0.0.0' or '' as an address. Set up 'Server.IP' setting."));
|
||||
|
||||
// TODO Rework to allow Velocity as name.
|
||||
Server proxy = new Server(-1, serverUUID, "BungeeCord", accessAddress, serverProperties.getMaxPlayers());
|
||||
|
Loading…
Reference in New Issue
Block a user