Skip to content

Commit

Permalink
add bstats
Browse files Browse the repository at this point in the history
  • Loading branch information
powercasgamer committed Dec 2, 2023
1 parent e92cc96 commit 2308fd3
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 57 deletions.
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
}
}
}
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,79 +10,36 @@ 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 dev.mizule.timetriggeredperms.paper.listener.LuckPermsListener
import dev.mizule.timetriggeredperms.core.config.ConfigManager
import dev.mizule.timetriggeredperms.velocity.listener.LuckPermsListener
import org.bstats.velocity.Metrics
import org.slf4j.Logger
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 xyz.jpenilla.gremlin.runtime.DependencyCache
import xyz.jpenilla.gremlin.runtime.DependencyResolver
import xyz.jpenilla.gremlin.runtime.DependencySet
import xyz.jpenilla.gremlin.runtime.platformsupport.PaperClasspathAppender
import xyz.jpenilla.gremlin.runtime.platformsupport.VelocityClasspathAppender
import java.nio.file.Path
import java.util.*
import kotlin.io.path.exists


@Plugin(
name = "TimeTriggeredPerms",
id = "timetriggeredperms",
version = "@version@",
authors = ["powercas_gamer"],
dependencies = [Dependency(id = "luckperms", optional = false)]
)
class TTP @Inject constructor(
logger: Logger,
@DataDirectory val dataPath: Path,
val proxy: ProxyServer,
) : TTPPlugin<TTP> {

init {
val deps = DependencySet.readDefault(this.javaClass.classLoader)
val cache = DependencyCache(dataPath.resolve("libraries"))
DependencyResolver(logger).use { downloader ->
VelocityClasspathAppender(this.proxy, this).append(downloader.resolve(deps, cache).jarFiles())
}
cache.cleanup()
}
val dataPath: Path
) : TTPPlugin<PluginLoader> {

private val configPath = dataPath.resolve("permissions.yml")
private val pluginId = 20405

val configLoader = YamlConfigurationLoader.builder()
.path(configPath)
.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"
}
private lateinit var config: Config

@Subscribe(order = PostOrder.LATE)
fun onProxyInitialize(event: ProxyInitializeEvent) {
if (!configPath.exists()) {
configNode.set(config) // update the backing node to add defaults
configLoader.save(configNode)
}
// Metrics(this, pluginId)
LuckPermsListener(this)
fun enable() {
this.config = ConfigManager.loadConfig(configPath)
LuckPermsListener(PluginLoader.instance)
}

override fun config(): Config {
return config
}

override fun plugin(): TTP {
return this
override fun plugin(): PluginLoader {
return PluginLoader.instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package dev.mizule.timetriggeredperms.paper.listener
package dev.mizule.timetriggeredperms.velocity.listener

import com.google.inject.Inject
import com.velocitypowered.api.proxy.ProxyServer
import dev.mizule.timetriggeredperms.core.TTPPlugin
import dev.mizule.timetriggeredperms.core.config.PermissionThing
import dev.mizule.timetriggeredperms.core.listener.AbstractLuckPermsListener
import dev.mizule.timetriggeredperms.velocity.TTP
import dev.mizule.timetriggeredperms.velocity.PluginLoader
import net.luckperms.api.event.node.NodeRemoveEvent
import net.luckperms.api.model.user.User
import net.luckperms.api.node.types.PermissionNode

class LuckPermsListener(private val plugin: TTPPlugin<TTP>) : AbstractLuckPermsListener(plugin) {
class LuckPermsListener(private val plugin: TTPPlugin<PluginLoader>) : AbstractLuckPermsListener(plugin) {

@Inject lateinit var proxy: ProxyServer

Expand Down

0 comments on commit 2308fd3

Please sign in to comment.