mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Ensured that InfoSystem methods are all called from Async threads.
This commit is contained in:
parent
c218627ede
commit
05d8d9fb48
@ -83,19 +83,13 @@ public class AnalyzeCommand extends SubCommand {
|
||||
sender.sendMessage(Locale.get(Msg.CMD_CONSTANT_FOOTER).toString());
|
||||
}
|
||||
|
||||
private void sendWebUserNotificationIfNecessary(ISender sender) {
|
||||
private void sendWebUserNotificationIfNecessary(ISender sender) throws DBException {
|
||||
if (WebServerSystem.getInstance().getWebServer().isAuthRequired() && CommandUtils.isPlayer(sender)) {
|
||||
|
||||
Processor.queue(() -> {
|
||||
try {
|
||||
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
});
|
||||
boolean senderHasWebUser = Database.getActive().check().doesWebUserExists(sender.getName());
|
||||
if (!senderHasWebUser) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[Plan] You might not have a web user, use /plan register <password>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.djrapitops.plan.command.commands.manage;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.locale.Locale;
|
||||
@ -51,27 +52,35 @@ public class ManageSetupCommand extends SubCommand {
|
||||
if (address.endsWith("/")) {
|
||||
address = address.substring(0, address.length() - 1);
|
||||
}
|
||||
try {
|
||||
Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
|
||||
Settings.BUNGEE_COPY_CONFIG.set(true);
|
||||
|
||||
InfoSystem.getInstance().requestSetUp(address);
|
||||
requestSetup(sender, address);
|
||||
|
||||
sender.sendMessage("§aConnection successful, Plan may restart in a few seconds..");
|
||||
} catch (ForbiddenException e) {
|
||||
sender.sendMessage("§eConnection succeeded, but Bungee has set-up mode disabled - use '/planbungee setup' to enable it.");
|
||||
} catch (BadRequestException e) {
|
||||
sender.sendMessage("§eConnection succeeded, but Receiving server was a Bukkit server. Use Bungee address instead.");
|
||||
} catch (UnauthorizedServerException e) {
|
||||
sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support");
|
||||
} catch (ConnectionFailException e) {
|
||||
sender.sendMessage("§eConnection failed: " + e.getMessage());
|
||||
} catch (InternalErrorException e) {
|
||||
sender.sendMessage("§eConnection succeeded. " + e.getMessage() + ", check possible ErrorLog on receiving server's debug page.");
|
||||
} catch (WebException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage("§cConnection to Bungee WebServer failed: More info in the error log.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void requestSetup(ISender sender, String address) {
|
||||
Processor.queue(() -> {
|
||||
try {
|
||||
Settings.BUNGEE_OVERRIDE_STANDALONE_MODE.set(false);
|
||||
Settings.BUNGEE_COPY_CONFIG.set(true);
|
||||
|
||||
InfoSystem.getInstance().requestSetUp(address);
|
||||
|
||||
sender.sendMessage("§aConnection successful, Plan may restart in a few seconds..");
|
||||
} catch (ForbiddenException e) {
|
||||
sender.sendMessage("§eConnection succeeded, but Bungee has set-up mode disabled - use '/planbungee setup' to enable it.");
|
||||
} catch (BadRequestException e) {
|
||||
sender.sendMessage("§eConnection succeeded, but Receiving server was a Bukkit server. Use Bungee address instead.");
|
||||
} catch (UnauthorizedServerException e) {
|
||||
sender.sendMessage("§eConnection succeeded, but Receiving server didn't authorize this server. Contact Discord for support");
|
||||
} catch (ConnectionFailException e) {
|
||||
sender.sendMessage("§eConnection failed: " + e.getMessage());
|
||||
} catch (InternalErrorException e) {
|
||||
sender.sendMessage("§eConnection succeeded. " + e.getMessage() + ", check possible ErrorLog on receiving server's debug page.");
|
||||
} catch (WebException e) {
|
||||
Log.toLog(this.getClass(), e);
|
||||
sender.sendMessage("§cConnection to Bungee WebServer failed: More info in the error log.");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ import com.djrapitops.plan.system.info.request.InfoRequest;
|
||||
import com.djrapitops.plan.system.info.request.SendDBSettingsRequest;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.Processor;
|
||||
import com.djrapitops.plan.system.webserver.WebServerSystem;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
@ -30,6 +31,8 @@ import java.util.UUID;
|
||||
* <p>
|
||||
* Subclasses should decide how InfoRequests are run locally if necessary.
|
||||
*
|
||||
* Everything should be called from an Async thread.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class InfoSystem implements SubSystem {
|
||||
@ -46,6 +49,14 @@ public abstract class InfoSystem implements SubSystem {
|
||||
return infoSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes Player page.
|
||||
* <p>
|
||||
* No calls from non-async thread found on 09.02.2018
|
||||
*
|
||||
* @param player UUID of the player.
|
||||
* @throws WebException If fails.
|
||||
*/
|
||||
public void generateAndCachePlayerPage(UUID player) throws WebException {
|
||||
GenerateInspectPageRequest infoRequest = new GenerateInspectPageRequest(player);
|
||||
try {
|
||||
@ -55,10 +66,14 @@ public abstract class InfoSystem implements SubSystem {
|
||||
}
|
||||
}
|
||||
|
||||
public void generateAnalysisPageOfThisServer() throws WebException {
|
||||
generateAnalysisPage(ServerInfo.getServerUUID());
|
||||
}
|
||||
|
||||
/**
|
||||
* Refreshes Analysis page.
|
||||
*
|
||||
* No calls from non-async thread found on 09.02.2018
|
||||
*
|
||||
* @param serverUUID UUID of the server to analyze
|
||||
* @throws WebException If fails.
|
||||
*/
|
||||
public void generateAnalysisPage(UUID serverUUID) throws WebException {
|
||||
GenerateAnalysisPageRequest request = new GenerateAnalysisPageRequest(serverUUID);
|
||||
if (ServerInfo.getServerUUID().equals(serverUUID)) {
|
||||
@ -68,6 +83,14 @@ public abstract class InfoSystem implements SubSystem {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an InfoRequest to another server or run locally if necessary.
|
||||
*
|
||||
* No calls from non-async thread found on 09.02.2018
|
||||
*
|
||||
* @param infoRequest InfoRequest to send or run.
|
||||
* @throws WebException If fails.
|
||||
*/
|
||||
public void sendRequest(InfoRequest infoRequest) throws WebException {
|
||||
try {
|
||||
if (!connectionSystem.isServerAvailable()) {
|
||||
@ -85,19 +108,29 @@ public abstract class InfoSystem implements SubSystem {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the InfoRequest locally.
|
||||
*
|
||||
* No calls from non-async thread found on 09.02.2018
|
||||
*
|
||||
* @param infoRequest InfoRequest to run.
|
||||
* @throws WebException If fails.
|
||||
*/
|
||||
public abstract void runLocally(InfoRequest infoRequest) throws WebException;
|
||||
|
||||
@Override
|
||||
public void enable() throws EnableException {
|
||||
connectionSystem.enable();
|
||||
try {
|
||||
updateNetworkPage();
|
||||
} catch (NoServersException e) {
|
||||
/* Ignored */
|
||||
} catch (WebException e) {
|
||||
// TODO Exception handling
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
Processor.queue(() -> {
|
||||
try {
|
||||
updateNetworkPage();
|
||||
} catch (NoServersException e) {
|
||||
/* Ignored */
|
||||
} catch (WebException e) {
|
||||
// TODO Exception handling
|
||||
Log.toLog(this.getClass(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,8 +142,23 @@ public abstract class InfoSystem implements SubSystem {
|
||||
return connectionSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates Network page.
|
||||
*
|
||||
* No calls from non-async thread found on 09.02.2018
|
||||
*
|
||||
* @throws WebException If fails.
|
||||
*/
|
||||
public abstract void updateNetworkPage() throws WebException;
|
||||
|
||||
/**
|
||||
* Requests Set up from Bungee.
|
||||
*
|
||||
* No calls from non-async thread found on 09.02.2018
|
||||
*
|
||||
* @param addressToRequestServer Address of Bungee server.
|
||||
* @throws WebException If fails.
|
||||
*/
|
||||
public void requestSetUp(String addressToRequestServer) throws WebException {
|
||||
if (Check.isBungeeAvailable()) {
|
||||
throw new BadRequestException("Method not available on Bungee.");
|
||||
|
@ -4,6 +4,7 @@
|
||||
*/
|
||||
package com.djrapitops.plan.system.info.connection;
|
||||
|
||||
import com.djrapitops.plan.Plan;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.UnsupportedTransferDatabaseException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.WebException;
|
||||
@ -14,6 +15,7 @@ import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.request.*;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -93,6 +95,11 @@ public abstract class ConnectionSystem implements SubSystem {
|
||||
|
||||
protected Optional<UUID> getServerWherePlayerIsOnline(GenerateInspectPageRequest infoRequest) {
|
||||
UUID playerUUID = infoRequest.getPlayerUUID();
|
||||
|
||||
if (Check.isBukkitAvailable() && Plan.getInstance().getServer().getPlayer(playerUUID) != null) {
|
||||
return Optional.of(ServerInfo.getServerUUID());
|
||||
}
|
||||
|
||||
try {
|
||||
return Database.getActive().transfer().getServerPlayerIsOnlineOn(playerUUID);
|
||||
} catch (UnsupportedTransferDatabaseException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user