mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-22 17:18:40 +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 PlatformAbstractionLayer abstractionLayer;
|
||||
private ErrorLogger errorLogger;
|
||||
private PlanBukkitComponent component;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@ -68,7 +69,7 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
PlanBukkitComponent component = DaggerPlanBukkitComponent.builder()
|
||||
component = DaggerPlanBukkitComponent.builder()
|
||||
.plan(this)
|
||||
.abstractionLayer(abstractionLayer)
|
||||
.server(getServer())
|
||||
@ -135,11 +136,18 @@ public class Plan extends JavaPlugin implements PlanPlugin {
|
||||
public void onDisable() {
|
||||
storeSessionsOnShutdown();
|
||||
cancelAllTasks();
|
||||
if (component != null) unregisterPlaceholders(component.placeholders());
|
||||
if (system != null) system.disable();
|
||||
|
||||
pluginLogger.info(Locale.getStringNullSafe(locale, PluginLang.DISABLED));
|
||||
}
|
||||
|
||||
private void unregisterPlaceholders(BukkitPlaceholderRegistrar placeholders) {
|
||||
if (placeholders != null) {
|
||||
placeholders.unregister();
|
||||
}
|
||||
}
|
||||
|
||||
private void storeSessionsOnShutdown() {
|
||||
if (serverShutdownSave != null) {
|
||||
Optional<Future<?>> complete = serverShutdownSave.performSave();
|
||||
|
@ -30,6 +30,8 @@ public class BukkitPlaceholderRegistrar {
|
||||
private final PlanSystem system;
|
||||
private final ErrorLogger errorLogger;
|
||||
|
||||
private PlanPlaceholderExtension placeholderExtension;
|
||||
|
||||
@Inject
|
||||
public BukkitPlaceholderRegistrar(
|
||||
PlanPlaceholders placeholders,
|
||||
@ -42,6 +44,13 @@ public class BukkitPlaceholderRegistrar {
|
||||
}
|
||||
|
||||
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
|
||||
public String onRequest(OfflinePlayer player, @Untrusted String params) {
|
||||
UUID uuid = player != null ? player.getUniqueId() : null;
|
||||
if ("Server thread".equalsIgnoreCase(Thread.currentThread().getName())) {
|
||||
return getCached(params, uuid);
|
||||
try {
|
||||
UUID uuid = player != null ? player.getUniqueId() : null;
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user