mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-11 02:48:22 +01:00
Write new html customized Plan web files when Plan enables (no overwrite)
Affects issues: - Close #1745
This commit is contained in:
parent
bcbbcff724
commit
cd2d0fcb0f
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.modules.bukkit;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.web.ResourceWriteTask;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONFileStorage;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.ShutdownDataPreservation;
|
||||
@ -83,4 +84,8 @@ public interface BukkitTaskModule {
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindOldDependencyCacheDeletion(OldDependencyCacheDeletionTask deletionTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindResourceWriteTask(ResourceWriteTask resourceWriteTask);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.modules.bungee;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.web.ResourceWriteTask;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONFileStorage;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.timed.BungeePingCounter;
|
||||
@ -72,4 +73,8 @@ public interface BungeeTaskModule {
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindOldDependencyCacheDeletion(OldDependencyCacheDeletionTask deletionTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindResourceWriteTask(ResourceWriteTask resourceWriteTask);
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package com.djrapitops.plan.delivery.web;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.settings.config.ConfigNode;
|
||||
import com.djrapitops.plan.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.storage.file.PlanFiles;
|
||||
import net.playeranalytics.plugin.scheduling.RunnableFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Task in charge of writing html customized files on enable when they don't exist yet.
|
||||
*
|
||||
* @author AuroraLS3
|
||||
*/
|
||||
@Singleton
|
||||
public class ResourceWriteTask extends TaskSystem.Task {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final PlanFiles files;
|
||||
|
||||
@Inject
|
||||
public ResourceWriteTask(PlanConfig config, PlanFiles files) {
|
||||
this.config = config;
|
||||
this.files = files;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(RunnableFactory runnableFactory) {
|
||||
runnableFactory.create(this).runTaskLaterAsynchronously(3, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ResourceService resourceService = ResourceService.getInstance();
|
||||
Optional<ConfigNode> planCustomizationNode = getPlanCustomizationNode();
|
||||
if (planCustomizationNode.isPresent()) {
|
||||
for (ConfigNode child : planCustomizationNode.get().getChildren()) {
|
||||
if (child.getBoolean()) {
|
||||
String resource = child.getKey(false).replace(',', '.');
|
||||
resourceService.getResource("Plan", resource, () -> files.getResourceFromJar("web/" + resource).asWebResource());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Optional<ConfigNode> getPlanCustomizationNode() {
|
||||
return config.getResourceSettings().getCustomizationConfigNode().getNode("Plan");
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ public class ResourceSettings {
|
||||
}
|
||||
|
||||
public boolean shouldBeCustomized(String plugin, String fileName) {
|
||||
ConfigNode fileCustomization = config.getNode("Customized_files").orElseGet(() -> config.addNode("Customized_files"));
|
||||
ConfigNode fileCustomization = getCustomizationConfigNode();
|
||||
fileCustomization.setComment(Collections.singletonList("The files are placed in /Plan/web/ if the setting is 'true' when accessed."));
|
||||
|
||||
ConfigNode pluginCustomization = fileCustomization.getNode(plugin).orElseGet(() -> fileCustomization.addNode(plugin));
|
||||
@ -53,4 +53,8 @@ public class ResourceSettings {
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigNode getCustomizationConfigNode() {
|
||||
return config.getNode("Customized_files").orElseGet(() -> config.addNode("Customized_files"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.djrapitops.plan.modules.nukkit;
|
||||
|
||||
import cn.nukkit.level.Level;
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.web.ResourceWriteTask;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONFileStorage;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.ShutdownDataPreservation;
|
||||
@ -83,4 +84,8 @@ public interface NukkitTaskModule {
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindOldDependencyCacheDeletion(OldDependencyCacheDeletionTask deletionTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindResourceWriteTask(ResourceWriteTask resourceWriteTask);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.modules.sponge;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.web.ResourceWriteTask;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONFileStorage;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.ShutdownDataPreservation;
|
||||
@ -83,4 +84,8 @@ public interface SpongeTaskModule {
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindOldDependencyCacheDeletion(OldDependencyCacheDeletionTask deletionTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindResourceWriteTask(ResourceWriteTask resourceWriteTask);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.modules.velocity;
|
||||
|
||||
import com.djrapitops.plan.TaskSystem;
|
||||
import com.djrapitops.plan.delivery.web.ResourceWriteTask;
|
||||
import com.djrapitops.plan.delivery.webserver.cache.JSONFileStorage;
|
||||
import com.djrapitops.plan.extension.ExtensionServerDataUpdater;
|
||||
import com.djrapitops.plan.gathering.timed.ProxyTPSCounter;
|
||||
@ -72,4 +73,8 @@ public interface VelocityTaskModule {
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindOldDependencyCacheDeletion(OldDependencyCacheDeletionTask deletionTask);
|
||||
|
||||
@Binds
|
||||
@IntoSet
|
||||
TaskSystem.Task bindResourceWriteTask(ResourceWriteTask resourceWriteTask);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user