Skip to content

Commit

Permalink
Added fully CloudNet Support, like CloudPerms
Browse files Browse the repository at this point in the history
  • Loading branch information
Blyrex committed Nov 22, 2020
1 parent 17e87d2 commit cd23d75
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 142 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ subprojects {
newLine = true
}

dependencies {
compile "de.dytanic.cloudnet:cloudnet:3.4.0-SNAPSHOT"
compile "de.dytanic.cloudnet:cloudnet-driver:3.4.0-SNAPSHOT"
compile "de.dytanic.cloudnet:cloudnet-wrapper-jvm:3.4.0-SNAPSHOT"
compile "de.dytanic.cloudnet:cloudnet-bridge:3.4.0-SNAPSHOT"
}

repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://repo.lucko.me/' }
maven {
url "https://repo.cloudnetservice.eu/repository/snapshots/"
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,7 @@ protected void removePlatformHooks() {
private File resolveConfig() {
File configFile = new File(this.bootstrap.getDataFolder(), "config.yml");
if (!configFile.exists()) {
this.bootstrap.getDataFolder().mkdirs();
this.bootstrap.saveResource("config.yml", false);
configFile = this.queryNodeConfig();
}
return configFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ api-version: 1.13
loadbefore: [Vault]

# Soft depend on LilyPad for messaging service impl
softdepend: [LilyPad-Connect]
softdepend: [LilyPad-Connect, CloudNet-Bridge]

commands:
luckperms:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,8 @@ private File resolveConfig() {
File configFile = new File(this.bootstrap.getDataFolder(), "config.yml");

if (!configFile.exists()) {
this.bootstrap.getDataFolder().mkdirs();
try (InputStream is = this.bootstrap.getResourceAsStream("config.yml")) {
Files.copy(is, configFile.toPath());
} catch (IOException e) {
throw new RuntimeException(e);
}
configFile = this.queryNodeConfig();
}

return configFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ version: ${pluginVersion}
description: A permissions plugin
author: Luck
main: me.lucko.luckperms.bungee.LPBungeeBootstrap
softDepends: ["RedisBungee"]
softDepends: ["RedisBungee", "CloudNet-Bridge"]
91 changes: 0 additions & 91 deletions bungee/src/main/resources/config.json

This file was deleted.

29 changes: 22 additions & 7 deletions cloudnet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ plugins {

repositories {
mavenCentral()
maven {
url "https://repo.cloudnetservice.eu/repository/snapshots/"
}
maven {
name 'jitpack'
url 'https://jitpack.io'
}
}

dependencies {

compile project(':common')
compile project(':bukkit')
compile project(':nukkit')
compile project(':bungee')
compile project(':velocity')

compileOnly 'com.imaginarycode.minecraft:RedisBungee:0.4'
compile "de.dytanic.cloudnet:cloudnet:3.4.0-SNAPSHOT"
compile "de.dytanic.cloudnet:cloudnet-driver:3.4.0-SNAPSHOT"
compile "de.dytanic.cloudnet:cloudnet-wrapper-jvm:3.4.0-SNAPSHOT"
compile "de.dytanic.cloudnet:cloudnet-bridge:3.4.0-SNAPSHOT"
compile 'net.md-5:bungeecord-api:1.15-SNAPSHOT'
compile group: 'org.yaml', name: 'snakeyaml', version: '1.27'

Expand All @@ -32,7 +30,24 @@ dependencies {

processResources {
from(sourceSets.main.resources.srcDirs) {
expand 'pluginVersion': sourceSets.main.resources.srcDirs
include 'module.json'
include 'plugin.bukkit.yml'
include 'bungee.yml'
include 'plugin.nukkit.yml'
}
}

sourceSets {
main {
resources {
srcDirs += [
project(':bukkit').sourceSets.main.resources,
project(':nukkit').sourceSets.main.resources,
project(':bungee').sourceSets.main.resources,
project(':velocity').sourceSets.main.resources
]
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
package me.lucko.luckperms.cloudnet;

import com.google.gson.Gson;
import de.dytanic.cloudnet.common.document.gson.JsonDocument;
import de.dytanic.cloudnet.common.logging.LogLevel;
import de.dytanic.cloudnet.driver.CloudNetDriver;
import de.dytanic.cloudnet.driver.channel.ChannelMessage;
import de.dytanic.cloudnet.driver.event.EventListener;
import de.dytanic.cloudnet.driver.event.events.channel.ChannelMessageReceiveEvent;
import de.dytanic.cloudnet.driver.module.ModuleLifeCycle;
import de.dytanic.cloudnet.driver.module.ModuleTask;
import de.dytanic.cloudnet.driver.module.driver.DriverModule;
import de.dytanic.cloudnet.ext.bridge.player.ICloudPlayer;
import de.dytanic.cloudnet.ext.bridge.player.IPlayerManager;
import lombok.Getter;
import lombok.SneakyThrows;
import me.lucko.luckperms.cloudnet.config.LuckPermsNodeConfig;
import me.lucko.luckperms.cloudnet.listener.PluginIncludeListener;
import me.lucko.luckperms.common.dependencies.classloader.PluginClassLoader;
import me.lucko.luckperms.common.dependencies.classloader.ReflectionClassLoader;
import me.lucko.luckperms.common.plugin.bootstrap.LuckPermsBootstrap;
import me.lucko.luckperms.common.plugin.logging.JavaPluginLogger;
import me.lucko.luckperms.common.plugin.logging.PluginLogger;
import me.lucko.luckperms.common.plugin.scheduler.SchedulerAdapter;
import net.luckperms.api.platform.Platform;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.io.InputStream;
import java.io.*;
import java.nio.file.Path;
import java.time.Instant;
import java.util.Collection;
import java.util.Optional;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.logging.Logger;

@Getter
public class LPNodeBootstrap extends DriverModule implements LuckPermsBootstrap {


private PluginLogger logger = null;
private PluginLogger lpLogger = null;
private final SchedulerAdapter schedulerAdapter;
private final PluginClassLoader classLoader;
private final PluginClassLoader lpClassLoader;
private final LPNodePlugin plugin;
private LuckPermsNodeConfig luckPermsNodeConfig;

private Instant startTime;

Expand All @@ -39,36 +47,37 @@ public class LPNodeBootstrap extends DriverModule implements LuckPermsBootstrap

public LPNodeBootstrap() {
this.schedulerAdapter = new NodeSchedulerAdapter(this);
this.classLoader = new ReflectionClassLoader(this);
this.lpClassLoader = new ReflectionClassLoader(this);
this.plugin = new LPNodePlugin(this, this.getDriver());
}

@ModuleTask(event = ModuleLifeCycle.LOADED)
public void onModuleLoad() {
this.logger = new NodeLogger(this.getDriver());

this.getDriver().getEventManager().registerListener(this);
this.luckPermsNodeConfig = this.loadModuleConfig();
this.lpLogger = new NodeLogger(this.getDriver());
this.plugin.load();
this.startTime = Instant.now();
}

@ModuleTask(event = ModuleLifeCycle.STARTED)
public void onStart() {
new PluginIncludeListener(this);
this.plugin.enable();
this.enableLatch.countDown();
}

@ModuleTask(event = ModuleLifeCycle.STOPPED)
public void onStop() {
this.plugin.enable();
this.plugin.disable();
}

@Override
public PluginLogger getPluginLogger() {
if (this.logger == null) {
if (this.lpLogger == null) {
throw new IllegalStateException("Logger has not been initialised yet");
}
return this.logger;
return this.lpLogger;
}

@Override
Expand All @@ -78,7 +87,7 @@ public SchedulerAdapter getScheduler() {

@Override
public PluginClassLoader getPluginClassLoader() {
return this.classLoader;
return this.lpClassLoader;
}

@Override
Expand Down Expand Up @@ -118,13 +127,13 @@ public String getServerVersion() {

@Override
public Path getDataDirectory() {
if(!this.getModuleWrapper().getDataFolder().exists()) this.getModuleWrapper().getDataFolder().mkdirs();
if (!this.getModuleWrapper().getDataFolder().exists()) this.getModuleWrapper().getDataFolder().mkdirs();
return this.getModuleWrapper().getDataFolder().toPath();
}

@Override
public Path getConfigDirectory() {
if(!this.getModuleWrapper().getDataFolder().exists()) this.getModuleWrapper().getDataFolder().mkdirs();
if (!this.getModuleWrapper().getDataFolder().exists()) this.getModuleWrapper().getDataFolder().mkdirs();
return this.getModuleWrapper().getDataFolder().toPath();
}

Expand Down Expand Up @@ -197,4 +206,39 @@ public String getWebsite() {
public String getDescription() {
return super.getDescription();
}

@SneakyThrows
public LuckPermsNodeConfig loadModuleConfig() {
this.getModuleWrapper().getDataFolder().mkdirs();
Gson gson = new Gson();
File configFile = new File(super.getModuleWrapper().getDataFolder() + "//config.json");
if (!configFile.exists()) {
configFile.createNewFile();
List<String> list = new ArrayList<>();
list.add("ExampleGroup");
this.saveContentToFile(configFile, gson.toJson(new LuckPermsNodeConfig(true, list)));
}
return gson.fromJson(new FileReader(configFile), LuckPermsNodeConfig.class);
}

public void saveContentToFile(File file, String content) {
try {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
bufferedWriter.write(content);
bufferedWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}

@EventListener
public void handle(ChannelMessageReceiveEvent event) {

if (event.getMessage() == null || !event.getChannel().equals("luckperms_cloudnet") || !event.getMessage().equals("query_config"))
return;

event.setQueryResponse(ChannelMessage.buildResponseFor(event.getChannelMessage())
.json(JsonDocument.newDocument().append("filePath", new File(this.getModuleWrapper().getDataFolder(), "config.yml").getAbsolutePath()))
.build());
}
}
Loading

0 comments on commit cd23d75

Please sign in to comment.