Refresh placeholders set in the Plan config more often

Affects issue:
- Fixed #2225
This commit is contained in:
Risto Lahtela 2022-02-02 20:03:38 +02:00
parent a8e6ef2944
commit ba24a2f2d9
3 changed files with 72 additions and 1 deletions

View File

@ -0,0 +1,66 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.addons.placeholderapi;
import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.settings.config.PlanConfig;
import me.clip.placeholderapi.PlaceholderAPI;
import net.playeranalytics.plugin.scheduling.RunnableFactory;
import net.playeranalytics.plugin.scheduling.TimeAmount;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Singleton
public class PlaceholderCacheRefreshTask extends TaskSystem.Task {
private final PlanConfig config;
@Inject
public PlaceholderCacheRefreshTask(PlanConfig config) {
this.config = config;
}
@Override
public void register(RunnableFactory runnableFactory) {
runnableFactory.create(this).runTaskTimer(
TimeAmount.toTicks(60, TimeUnit.SECONDS),
TimeAmount.toTicks(15, TimeUnit.SECONDS)
);
}
@Override
public void run() {
if (!config.getNode("Plugins.PlaceholderAPI").isPresent()) {
cancel(); // Cancel the task and don't do anything if PlaceholderAPI is not installed.
return;
}
List<String> placeholders = config.getStringList("Plugins.PlaceholderAPI.Load_these_placeholders_on_join");
if (placeholders.isEmpty() || (placeholders.size() == 1 && placeholders.contains("%plan_server_uuid%"))) {
// Don't do anything if using default settings or placeholder api is not installed
return;
}
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
PlaceholderAPI.setPlaceholders(onlinePlayer, placeholders.toString());
}
}
}

View File

@ -17,6 +17,7 @@
package com.djrapitops.plan.modules.bukkit;
import com.djrapitops.plan.TaskSystem;
import com.djrapitops.plan.addons.placeholderapi.PlaceholderCacheRefreshTask;
import com.djrapitops.plan.delivery.web.ResourceWriteTask;
import com.djrapitops.plan.delivery.web.WebAssetVersionCheckTask;
import com.djrapitops.plan.delivery.webserver.auth.ActiveCookieExpiryCleanupTask;
@ -103,4 +104,8 @@ public interface BukkitTaskModule {
@Binds
@IntoSet
TaskSystem.Task bindExtensionDisableOnGameServerTask(ExtensionDisableOnGameServerTask extensionDisableOnGameServerTask);
@Binds
@IntoSet
TaskSystem.Task bindPlaceholderWarmupTask(PlaceholderCacheRefreshTask placeholderCacheRefreshTask);
}

View File

@ -33,7 +33,7 @@ dependencies {
implementation 'com.djrapitops:Extension-MyPet:3.10-R0.2'
implementation 'com.djrapitops:Extension-Nucleus:2.3.0-R0.1'
implementation 'com.djrapitops:Extension-nuVotifier:2.3.4-R0.3'
implementation 'com.djrapitops:Extension-PlaceholderAPI:2.10.9-R0.4'
implementation 'com.djrapitops:Extension-PlaceholderAPI:2.10.9-R0.5'
implementation 'com.djrapitops:Extension-PlotSquared:5.13.11-R0.2'
implementation 'com.djrapitops:Extension-ProtectionStones:2.8.2-R0.2'
implementation 'com.djrapitops:Extension-ProtocolSupport:1.16.4-R0.1'