mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
Moved shutdown session save message to ServerShutdownSave
This commit is contained in:
parent
16e6ef1dc7
commit
42464d503e
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.utilities.java.Reflection;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
@ -32,16 +33,14 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
public class BukkitServerShutdownSave extends ServerShutdownSave {
|
||||
|
||||
private final PluginLogger logger;
|
||||
|
||||
@Inject
|
||||
public BukkitServerShutdownSave(
|
||||
Locale locale,
|
||||
DBSystem dbSystem,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(dbSystem, errorHandler);
|
||||
this.logger = logger;
|
||||
super(locale, dbSystem, logger, errorHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,7 +91,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
if (serverShutdownSave != null) {
|
||||
logger.info(locale != null ? locale.getString(PluginLang.DISABLED_UNSAVED_SESSIONS) : PluginLang.DISABLED_UNSAVED_SESSIONS.getDefault());
|
||||
serverShutdownSave.performSave();
|
||||
}
|
||||
if (system != null) {
|
||||
|
@ -24,7 +24,10 @@ import com.djrapitops.plan.db.Database;
|
||||
import com.djrapitops.plan.db.access.transactions.events.ServerShutdownTransaction;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plan.system.locale.lang.PluginLang;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import java.util.Map;
|
||||
@ -39,15 +42,21 @@ import java.util.concurrent.ExecutionException;
|
||||
*/
|
||||
public abstract class ServerShutdownSave {
|
||||
|
||||
protected final PluginLogger logger;
|
||||
private final DBSystem dbSystem;
|
||||
private final Locale locale;
|
||||
private final ErrorHandler errorHandler;
|
||||
private boolean shuttingDown = false;
|
||||
|
||||
public ServerShutdownSave(
|
||||
Locale locale,
|
||||
DBSystem dbSystem,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
this.locale = locale;
|
||||
this.dbSystem = dbSystem;
|
||||
this.logger = logger;
|
||||
this.errorHandler = errorHandler;
|
||||
}
|
||||
|
||||
@ -67,6 +76,11 @@ public abstract class ServerShutdownSave {
|
||||
return;
|
||||
}
|
||||
|
||||
// This check ensures that logging is not attempted on JVM shutdown.
|
||||
// Underlying Logger might not be available leading to an exception.
|
||||
if (!shuttingDown) {
|
||||
logger.info(locale.getString(PluginLang.DISABLED_UNSAVED_SESSIONS));
|
||||
}
|
||||
attemptSave(activeSessions);
|
||||
|
||||
SessionCache.clear();
|
||||
|
@ -27,6 +27,7 @@ import com.djrapitops.plan.db.access.transactions.events.WorldNameStoreTransacti
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plugin.logging.console.TestPluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
||||
import extension.PrintExtension;
|
||||
@ -84,7 +85,8 @@ public class ShutdownSaveTest {
|
||||
DBSystem dbSystemMock = mock(DBSystem.class);
|
||||
when(dbSystemMock.getDatabase()).thenReturn(database);
|
||||
|
||||
underTest = new ServerShutdownSave(dbSystemMock, new ConsoleErrorLogger(new TestPluginLogger())) {
|
||||
TestPluginLogger logger = new TestPluginLogger();
|
||||
underTest = new ServerShutdownSave(new Locale(), dbSystemMock, logger, new ConsoleErrorLogger(logger)) {
|
||||
@Override
|
||||
protected boolean checkServerShuttingDownStatus() {
|
||||
return shutdownStatus;
|
||||
|
@ -17,6 +17,8 @@
|
||||
package com.djrapitops.plan;
|
||||
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.locale.Locale;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import org.spongepowered.api.GameState;
|
||||
import org.spongepowered.api.event.Listener;
|
||||
@ -37,8 +39,13 @@ public class SpongeServerShutdownSave extends ServerShutdownSave {
|
||||
private boolean shuttingDown = false;
|
||||
|
||||
@Inject
|
||||
public SpongeServerShutdownSave(DBSystem dbSystem, ErrorHandler errorHandler) {
|
||||
super(dbSystem, errorHandler);
|
||||
public SpongeServerShutdownSave(
|
||||
Locale locale,
|
||||
DBSystem dbSystem,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(locale, dbSystem, logger, errorHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user