-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e92cc96
commit 2308fd3
Showing
4 changed files
with
129 additions
and
57 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
core/src/main/kotlin/dev/mizule/timetriggeredperms/core/config/ConfigManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package dev.mizule.timetriggeredperms.core.config | ||
|
||
import org.spongepowered.configurate.kotlin.extensions.get | ||
import org.spongepowered.configurate.kotlin.objectMapperFactory | ||
import org.spongepowered.configurate.yaml.NodeStyle | ||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader | ||
import java.nio.file.Path | ||
import kotlin.io.path.exists | ||
|
||
class ConfigManager { | ||
|
||
companion object { | ||
|
||
fun loadConfig(path: Path): Config { | ||
val configLoader = YamlConfigurationLoader.builder() | ||
.path(path) | ||
.nodeStyle(NodeStyle.BLOCK) | ||
.indent(2) | ||
.defaultOptions { options -> | ||
options.shouldCopyDefaults(true) | ||
options.serializers { builder -> | ||
builder.registerAnnotatedObjects(objectMapperFactory()) | ||
} | ||
} | ||
.build() | ||
var configNode = configLoader.load() | ||
var config = requireNotNull(configNode.get<Config>()) { | ||
"Could not read configuration" | ||
} | ||
|
||
if (!path.exists()) { | ||
configNode.set(config) // update the backing node to add defaults | ||
configLoader.save(configNode) | ||
} | ||
|
||
return config | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
velocity/src/main/java/dev/mizule/timetriggeredperms/velocity/PluginLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package dev.mizule.timetriggeredperms.velocity; | ||
|
||
import com.google.inject.Inject; | ||
import com.velocitypowered.api.event.PostOrder; | ||
import com.velocitypowered.api.event.Subscribe; | ||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; | ||
import com.velocitypowered.api.plugin.Dependency; | ||
import com.velocitypowered.api.plugin.Plugin; | ||
import com.velocitypowered.api.plugin.annotation.DataDirectory; | ||
import com.velocitypowered.api.proxy.ProxyServer; | ||
import dev.mizule.timetriggeredperms.core.TTPPlugin; | ||
import dev.mizule.timetriggeredperms.core.config.Config; | ||
import org.bstats.velocity.Metrics; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.slf4j.Logger; | ||
import xyz.jpenilla.gremlin.runtime.DependencyCache; | ||
import xyz.jpenilla.gremlin.runtime.DependencyResolver; | ||
import xyz.jpenilla.gremlin.runtime.DependencySet; | ||
import xyz.jpenilla.gremlin.runtime.platformsupport.VelocityClasspathAppender; | ||
|
||
import java.nio.file.Path; | ||
|
||
@Plugin( | ||
name = "TimeTriggeredPerms", | ||
id = "timetriggeredperms", | ||
version = "@version@", | ||
authors = "powercas_gamer", | ||
dependencies = {@Dependency(id = "luckperms")} | ||
) | ||
public class PluginLoader implements TTPPlugin<PluginLoader> { | ||
|
||
final Path path; | ||
final Logger logger; | ||
final ProxyServer server; | ||
final Metrics.Factory metricsFactory; | ||
|
||
public static PluginLoader instance; | ||
TTP ttp; | ||
|
||
@Inject | ||
public PluginLoader(@DataDirectory Path dataPath, Logger logger, ProxyServer proxy, Metrics.Factory metricsFactory) { | ||
this.path = dataPath; | ||
this.logger = logger; | ||
this.server = proxy; | ||
this.metricsFactory = metricsFactory; | ||
instance = this; | ||
|
||
} | ||
|
||
@Subscribe(order = PostOrder.LATE) | ||
public void onInit(final ProxyInitializeEvent event) { | ||
var deps = DependencySet.readDefault(this.getClass().getClassLoader()); | ||
var cache = new DependencyCache(path.resolve("libraries")); | ||
try (DependencyResolver resolver = new DependencyResolver(logger)) { | ||
var files = resolver.resolve(deps, cache).jarFiles(); | ||
VelocityClasspathAppender appender = new VelocityClasspathAppender(server, PluginLoader.this); | ||
appender.append(files); | ||
} | ||
cache.cleanup(); | ||
Metrics metrics = metricsFactory.make(this, 20405); | ||
|
||
this.ttp = new TTP(logger, server, path); | ||
this.ttp.enable(); | ||
} | ||
|
||
@Override | ||
public @NotNull Config config() { | ||
return this.ttp.config(); | ||
} | ||
|
||
@Override | ||
public PluginLoader plugin() { | ||
return this; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters