sub-project rename, added velocity (unfihsed) + config api and the velocity implemntation of the config

This commit is contained in:
2021-12-14 18:47:17 +04:00
parent a4fc072dde
commit 4d19f68a28
11 changed files with 242 additions and 23 deletions

37
gal-velocity/pom.xml Normal file
View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>GreenAppleLogin</artifactId>
<groupId>net.limework.plugins</groupId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gal-velocity</artifactId>
<repositories>
<repository>
<id>velocitypowered</id>
<url>https://nexus.velocitypowered.com/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>gal-api</artifactId>
<groupId>net.limework.plugins</groupId>
<version>${version}</version>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,34 @@
package net.limework.gal;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import net.limework.gal.utils.config.AntiBot;
import net.limework.gal.utils.config.Configuration;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.concurrent.TimeUnit;
public class ConfigLoader implements Configuration {
private final String crackedChar;
private final AntiBot antiBot;
public ConfigLoader(File file) throws FileNotFoundException {
JsonObject jsonObject = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
this.crackedChar = jsonObject.get("default-cracked-char").getAsString();
JsonObject antiBotJson = jsonObject.getAsJsonObject("simple-anti-bot");
this.antiBot = new AntiBot(antiBotJson.get("max-connections").getAsInt(), antiBotJson.get("reset").getAsLong(), TimeUnit.MINUTES);
}
@Override
public String getCrackedChar() {
return this.crackedChar;
}
@Override
public AntiBot getAntiBot() {
return this.antiBot;
}
}

View File

@@ -0,0 +1,65 @@
package net.limework.gal;
import com.google.inject.Inject;
import com.velocitypowered.api.plugin.Plugin;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.ProxyServer;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Objects;
import java.util.logging.Logger;
@Plugin(name = "GreenAppleLogin", id = "greenapplelogin", version = "1.0.0", description = "Plugin that handle cracked + premium")
public class VelocityGalPlugin {
private final ProxyServer proxyServer;
private final Logger logger;
private final File dataFolder;
private final ConfigLoader config;
@Inject
public VelocityGalPlugin(ProxyServer proxyServer, Logger logger, @DataDirectory Path dataDirectory) {
this.proxyServer = proxyServer;
this.logger = logger;
this.dataFolder = dataDirectory.toFile();
if (this.dataFolder.mkdir()) {
getLogger().info("Created Plugin data folder.");
}
File file = new File(getDataFolder(), "config.json");
if (!file.exists()) {
try (InputStream in = getClass().getClassLoader().getResourceAsStream("config.json")) {
Files.copy(Objects.requireNonNull(in), file.toPath());
} catch (NullPointerException | IOException e) {
throw new RuntimeException("unable to load config file", e);
}
}
try {
this.config = new ConfigLoader(file);
} catch (FileNotFoundException e) {
throw new RuntimeException("unable to load config file", e);
}
}
public ProxyServer getProxyServer() {
return proxyServer;
}
public Logger getLogger() {
return logger;
}
public File getDataFolder() {
return dataFolder;
}
}