Merge pull request #10 from 4drian3d/configuration
Improved plugin usage
This commit is contained in:
commit
2a9ff63ce0
22
.gitignore
vendored
22
.gitignore
vendored
@ -1,3 +1,19 @@
|
||||
.idea
|
||||
target
|
||||
*.iml
|
||||
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
# Visual Studio Code
|
||||
|
||||
.settings/
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.vscode/
|
@ -2,12 +2,12 @@
|
||||
This plugin adds the support for [Velocity](https://velocitypowered.com/) to [AuthMeReloaded](https://github.com/AuthMe/AuthMeReloaded)
|
||||
|
||||
## Requirements
|
||||
- Spigot, Paper, Tuinity, Airplane or Purpur
|
||||
- Velocity 1.1.x or 3.0.0
|
||||
- Java 8/11/16 (Java 11 recommended)
|
||||
- Paper, Tuinity, Airplane or Purpur
|
||||
- Velocity 3.0.0+
|
||||
- Java 16
|
||||
|
||||
## Setup
|
||||
1. Download the latest release of the plugin [link](https://github.com/Glyart/AuthMeVelocity/releases)
|
||||
1. Download the latest release of the plugin [link](https://github.com/4drian3d/AuthMeVelocity/releases)
|
||||
2. Put the jar that ends with "-proxy" in Velocity's plugins folder
|
||||
3. Put the jar that ends with "-spigot" in the Spigot servers that contains AuthMe
|
||||
4. Start the Velocity proxy and set up the config.yml with the auth servers
|
||||
|
27
pom.xml
27
pom.xml
@ -7,18 +7,20 @@
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0.1</version>
|
||||
<version>1.1.0</version>
|
||||
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>apache.snapshots</id>
|
||||
<url>https://repository.apache.org/snapshots/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
|
||||
<modules>
|
||||
<module>spigot</module>
|
||||
<module>proxy</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>AuthMeVelocity-${project.name}</finalName>
|
||||
<plugins>
|
||||
@ -26,14 +28,14 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>11</source>
|
||||
<target>11</target>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.3.0-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@ -42,6 +44,13 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>de.leonhard</pattern>
|
||||
<shadedPattern>com.glyart.authmevelocity.libs.simplixstorage</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
|
@ -5,45 +5,35 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>proxy</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>velocity</id>
|
||||
<url>https://nexus.velocitypowered.com/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.12.5</version>
|
||||
<groupId>com.github.simplix-softworks</groupId>
|
||||
<artifactId>SimplixStorage</artifactId>
|
||||
<version>3.1.9</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -5,51 +5,42 @@ import com.glyart.authmevelocity.proxy.listener.ProxyListener;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import lombok.Getter;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import de.leonhard.storage.Yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class AuthMeVelocityPlugin {
|
||||
|
||||
private final ProxyServer server;
|
||||
public final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Path dataFolder;
|
||||
static Yaml config = new Yaml("config", "plugins/AuthmeVelocity");
|
||||
|
||||
private final List<UUID> loggedPlayers = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
private AuthMeConfig config;
|
||||
public final List<UUID> loggedPlayers = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
@Inject
|
||||
public AuthMeVelocityPlugin(ProxyServer server, Logger logger, @DataDirectory Path dataFolder) {
|
||||
public AuthMeVelocityPlugin(ProxyServer server, Logger logger) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
this.dataFolder = dataFolder;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialize(ProxyInitializeEvent event) {
|
||||
try {
|
||||
config = AuthMeConfig.loadConfig(dataFolder);
|
||||
} catch (IOException e) {
|
||||
logger.error("An error occurred while enabling AuthMeVelocity.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
public void onProxyInitialize(ProxyInitializeEvent event) throws IOException {
|
||||
server.getChannelRegistrar().register(new LegacyChannelIdentifier("authmevelocity:main"), MinecraftChannelIdentifier.create("authmevelocity", "main"));
|
||||
server.getEventManager().register(this, new ProxyListener(this));
|
||||
AuthMeConfig.defaultConfig();
|
||||
logger.info("AuthMeVelocity enabled.");
|
||||
logger.info("AuthServers:" + config.getList("authservers"));
|
||||
}
|
||||
|
||||
public static Yaml getConfig(){
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +1,11 @@
|
||||
package com.glyart.authmevelocity.proxy.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
public class AuthMeConfig {
|
||||
import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin;
|
||||
|
||||
private List<String> authServers = Arrays.asList("auth-1", "auth-2");
|
||||
|
||||
public static AuthMeConfig loadConfig(Path folder) throws IOException {
|
||||
File folderFile = folder.toFile();
|
||||
File file = new File(folderFile, "config.yml");
|
||||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
|
||||
if (!folderFile.exists())
|
||||
folderFile.mkdir();
|
||||
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
|
||||
AuthMeConfig config = new AuthMeConfig();
|
||||
mapper.writeValue(file, config);
|
||||
return config;
|
||||
public interface AuthMeConfig {
|
||||
public static void defaultConfig(){
|
||||
AuthMeVelocityPlugin.getConfig().setDefault("authservers", List.of("auth1", "auth2"));
|
||||
}
|
||||
|
||||
return mapper.readValue(file, AuthMeConfig.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.glyart.authmevelocity.proxy.listener;
|
||||
|
||||
import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin;
|
||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.command.CommandExecuteEvent;
|
||||
@ -21,66 +20,74 @@ public class ProxyListener {
|
||||
|
||||
private final AuthMeVelocityPlugin plugin;
|
||||
private final ProxyServer server;
|
||||
private final AuthMeConfig config;
|
||||
|
||||
public ProxyListener(AuthMeVelocityPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
server = plugin.getServer();
|
||||
config = plugin.getConfig();
|
||||
server = plugin.server;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
if (!(event.getSource() instanceof ServerConnection))
|
||||
public void onPluginMessage(final PluginMessageEvent event) {
|
||||
if (!(event.getSource() instanceof ServerConnection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!event.getIdentifier().getId().equals("authmevelocity:main"))
|
||||
if (!event.getIdentifier().getId().equals("authmevelocity:main")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ByteArrayDataInput input = event.dataAsDataStream();
|
||||
String sChannel = input.readUTF();
|
||||
if (!sChannel.equals("LOGIN"))
|
||||
if (!sChannel.equals("LOGIN")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String user = input.readUTF();
|
||||
Optional<Player> player = server.getPlayer(UUID.fromString(user));
|
||||
if (!player.isPresent())
|
||||
if (!player.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
plugin.getLoggedPlayers().add(player.get().getUniqueId());
|
||||
plugin.loggedPlayers.add(player.get().getUniqueId());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onDisconnect(DisconnectEvent event) {
|
||||
plugin.getLoggedPlayers().remove(event.getPlayer().getUniqueId());
|
||||
public void onDisconnect(final DisconnectEvent event) {
|
||||
plugin.loggedPlayers.remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onCommandExecute(CommandExecuteEvent event) {
|
||||
public void onCommandExecute(final CommandExecuteEvent event) {
|
||||
if (!(event.getCommandSource() instanceof Player))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getCommandSource();
|
||||
if (plugin.getLoggedPlayers().contains(player.getUniqueId()))
|
||||
final var player = (Player) event.getCommandSource();
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
Optional<ServerConnection> server = player.getCurrentServer();
|
||||
boolean isAuthServer = server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName());
|
||||
if (isAuthServer)
|
||||
boolean isAuthServer =
|
||||
server.isPresent() &&
|
||||
AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName());
|
||||
|
||||
if (isAuthServer) {
|
||||
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||
else
|
||||
}
|
||||
else {
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
public void onPlayerChat(final PlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.getLoggedPlayers().contains(player.getUniqueId()))
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
Optional<ServerConnection> server = player.getCurrentServer();
|
||||
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName()))
|
||||
if (server.isPresent() && AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setResult(PlayerChatEvent.ChatResult.denied());
|
||||
}
|
||||
@ -88,14 +95,14 @@ public class ProxyListener {
|
||||
@Subscribe
|
||||
public void onServerPreConnect(ServerPreConnectEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.getLoggedPlayers().contains(player.getUniqueId()))
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
Optional<RegisteredServer> server = event.getResult().getServer();
|
||||
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName()))
|
||||
if (server.isPresent() && AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,15 +5,15 @@
|
||||
<parent>
|
||||
<artifactId>parent</artifactId>
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<version>1.0.1</version>
|
||||
<version>1.1.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spigot</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>16</maven.compiler.source>
|
||||
<maven.compiler.target>16</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@ -35,7 +35,6 @@
|
||||
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>fr.xephi</groupId>
|
||||
<artifactId>authme</artifactId>
|
||||
@ -43,5 +42,4 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -28,5 +28,4 @@ public class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
|
||||
player.sendPluginMessage(this, "authmevelocity:main", out.toByteArray());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user