mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-29 19:41:35 +01: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;
|
package com.djrapitops.plan;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
|
import com.djrapitops.plan.system.locale.Locale;
|
||||||
import com.djrapitops.plan.utilities.java.Reflection;
|
import com.djrapitops.plan.utilities.java.Reflection;
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
@ -32,16 +33,14 @@ import javax.inject.Singleton;
|
|||||||
@Singleton
|
@Singleton
|
||||||
public class BukkitServerShutdownSave extends ServerShutdownSave {
|
public class BukkitServerShutdownSave extends ServerShutdownSave {
|
||||||
|
|
||||||
private final PluginLogger logger;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BukkitServerShutdownSave(
|
public BukkitServerShutdownSave(
|
||||||
|
Locale locale,
|
||||||
DBSystem dbSystem,
|
DBSystem dbSystem,
|
||||||
PluginLogger logger,
|
PluginLogger logger,
|
||||||
ErrorHandler errorHandler
|
ErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
super(dbSystem, errorHandler);
|
super(locale, dbSystem, logger, errorHandler);
|
||||||
this.logger = logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -91,7 +91,6 @@ public class Plan extends BukkitPlugin implements PlanPlugin {
|
|||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
if (serverShutdownSave != null) {
|
if (serverShutdownSave != null) {
|
||||||
logger.info(locale != null ? locale.getString(PluginLang.DISABLED_UNSAVED_SESSIONS) : PluginLang.DISABLED_UNSAVED_SESSIONS.getDefault());
|
|
||||||
serverShutdownSave.performSave();
|
serverShutdownSave.performSave();
|
||||||
}
|
}
|
||||||
if (system != null) {
|
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.db.access.transactions.events.ServerShutdownTransaction;
|
||||||
import com.djrapitops.plan.system.cache.SessionCache;
|
import com.djrapitops.plan.system.cache.SessionCache;
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
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.L;
|
||||||
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -39,15 +42,21 @@ import java.util.concurrent.ExecutionException;
|
|||||||
*/
|
*/
|
||||||
public abstract class ServerShutdownSave {
|
public abstract class ServerShutdownSave {
|
||||||
|
|
||||||
|
protected final PluginLogger logger;
|
||||||
private final DBSystem dbSystem;
|
private final DBSystem dbSystem;
|
||||||
|
private final Locale locale;
|
||||||
private final ErrorHandler errorHandler;
|
private final ErrorHandler errorHandler;
|
||||||
private boolean shuttingDown = false;
|
private boolean shuttingDown = false;
|
||||||
|
|
||||||
public ServerShutdownSave(
|
public ServerShutdownSave(
|
||||||
|
Locale locale,
|
||||||
DBSystem dbSystem,
|
DBSystem dbSystem,
|
||||||
|
PluginLogger logger,
|
||||||
ErrorHandler errorHandler
|
ErrorHandler errorHandler
|
||||||
) {
|
) {
|
||||||
|
this.locale = locale;
|
||||||
this.dbSystem = dbSystem;
|
this.dbSystem = dbSystem;
|
||||||
|
this.logger = logger;
|
||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +76,11 @@ public abstract class ServerShutdownSave {
|
|||||||
return;
|
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);
|
attemptSave(activeSessions);
|
||||||
|
|
||||||
SessionCache.clear();
|
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.cache.SessionCache;
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
import com.djrapitops.plan.system.database.DBSystem;
|
||||||
import com.djrapitops.plan.system.info.server.Server;
|
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.console.TestPluginLogger;
|
||||||
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
import com.djrapitops.plugin.logging.error.ConsoleErrorLogger;
|
||||||
import extension.PrintExtension;
|
import extension.PrintExtension;
|
||||||
@ -84,7 +85,8 @@ public class ShutdownSaveTest {
|
|||||||
DBSystem dbSystemMock = mock(DBSystem.class);
|
DBSystem dbSystemMock = mock(DBSystem.class);
|
||||||
when(dbSystemMock.getDatabase()).thenReturn(database);
|
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
|
@Override
|
||||||
protected boolean checkServerShuttingDownStatus() {
|
protected boolean checkServerShuttingDownStatus() {
|
||||||
return shutdownStatus;
|
return shutdownStatus;
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
package com.djrapitops.plan;
|
package com.djrapitops.plan;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.database.DBSystem;
|
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 com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||||
import org.spongepowered.api.GameState;
|
import org.spongepowered.api.GameState;
|
||||||
import org.spongepowered.api.event.Listener;
|
import org.spongepowered.api.event.Listener;
|
||||||
@ -37,8 +39,13 @@ public class SpongeServerShutdownSave extends ServerShutdownSave {
|
|||||||
private boolean shuttingDown = false;
|
private boolean shuttingDown = false;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public SpongeServerShutdownSave(DBSystem dbSystem, ErrorHandler errorHandler) {
|
public SpongeServerShutdownSave(
|
||||||
super(dbSystem, errorHandler);
|
Locale locale,
|
||||||
|
DBSystem dbSystem,
|
||||||
|
PluginLogger logger,
|
||||||
|
ErrorHandler errorHandler
|
||||||
|
) {
|
||||||
|
super(locale, dbSystem, logger, errorHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user