mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-13 15:20:14 +01:00
Unregister placeholder extension when Plan disables
Affects issues: - Fixed #2833
This commit is contained in:
parent
75e9057919
commit
1f1a8e0de2
@ -58,6 +58,7 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
|||||||
private RunnableFactory runnableFactory;
|
private RunnableFactory runnableFactory;
|
||||||
private PlatformAbstractionLayer abstractionLayer;
|
private PlatformAbstractionLayer abstractionLayer;
|
||||||
private ErrorLogger errorLogger;
|
private ErrorLogger errorLogger;
|
||||||
|
private PlanBukkitComponent component;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
@ -68,7 +69,7 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
PlanBukkitComponent component = DaggerPlanBukkitComponent.builder()
|
component = DaggerPlanBukkitComponent.builder()
|
||||||
.plan(this)
|
.plan(this)
|
||||||
.abstractionLayer(abstractionLayer)
|
.abstractionLayer(abstractionLayer)
|
||||||
.server(getServer())
|
.server(getServer())
|
||||||
@ -135,11 +136,18 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
|||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
storeSessionsOnShutdown();
|
storeSessionsOnShutdown();
|
||||||
cancelAllTasks();
|
cancelAllTasks();
|
||||||
|
if (component != null) unregisterPlaceholders(component.placeholders());
|
||||||
if (system != null) system.disable();
|
if (system != null) system.disable();
|
||||||
|
|
||||||
pluginLogger.info(Locale.getStringNullSafe(locale, PluginLang.DISABLED));
|
pluginLogger.info(Locale.getStringNullSafe(locale, PluginLang.DISABLED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void unregisterPlaceholders(BukkitPlaceholderRegistrar placeholders) {
|
||||||
|
if (placeholders != null) {
|
||||||
|
placeholders.unregister();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void storeSessionsOnShutdown() {
|
private void storeSessionsOnShutdown() {
|
||||||
if (serverShutdownSave != null) {
|
if (serverShutdownSave != null) {
|
||||||
Optional<Future<?>> complete = serverShutdownSave.performSave();
|
Optional<Future<?>> complete = serverShutdownSave.performSave();
|
||||||
|
@ -30,6 +30,8 @@ public class BukkitPlaceholderRegistrar {
|
|||||||
private final PlanSystem system;
|
private final PlanSystem system;
|
||||||
private final ErrorLogger errorLogger;
|
private final ErrorLogger errorLogger;
|
||||||
|
|
||||||
|
private PlanPlaceholderExtension placeholderExtension;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BukkitPlaceholderRegistrar(
|
public BukkitPlaceholderRegistrar(
|
||||||
PlanPlaceholders placeholders,
|
PlanPlaceholders placeholders,
|
||||||
@ -42,6 +44,13 @@ public class BukkitPlaceholderRegistrar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void register() {
|
public void register() {
|
||||||
new PlanPlaceholderExtension(placeholders, system, errorLogger).register();
|
placeholderExtension = new PlanPlaceholderExtension(placeholders, system, errorLogger);
|
||||||
|
placeholderExtension.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregister() {
|
||||||
|
if (placeholderExtension != null) {
|
||||||
|
placeholderExtension.unregister();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,11 +91,19 @@ public class PlanPlaceholderExtension extends PlaceholderExpansion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String onRequest(OfflinePlayer player, @Untrusted String params) {
|
public String onRequest(OfflinePlayer player, @Untrusted String params) {
|
||||||
UUID uuid = player != null ? player.getUniqueId() : null;
|
try {
|
||||||
if ("Server thread".equalsIgnoreCase(Thread.currentThread().getName())) {
|
UUID uuid = player != null ? player.getUniqueId() : null;
|
||||||
return getCached(params, uuid);
|
if ("Server thread".equalsIgnoreCase(Thread.currentThread().getName())) {
|
||||||
|
return getCached(params, uuid);
|
||||||
|
}
|
||||||
|
return getPlaceholderValue(params, uuid);
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
if ("zip file closed".equals(e.getMessage())) {
|
||||||
|
return null; // Plan is disabled.
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getPlaceholderValue(params, uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPlaceholderValue(@Untrusted String params, UUID uuid) {
|
private String getPlaceholderValue(@Untrusted String params, UUID uuid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user