Improved plugin usage

- Reduced jar file size
- Changed some things
This commit is contained in:
4drian3d 2021-09-05 16:02:16 -05:00
parent 379a44d2a5
commit b00a0d310b
10 changed files with 125 additions and 140 deletions

22
.gitignore vendored
View File

@ -1,3 +1,19 @@
.idea
target target/
*.iml 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/

View File

@ -2,12 +2,12 @@
This plugin adds the support for [Velocity](https://velocitypowered.com/) to [AuthMeReloaded](https://github.com/AuthMe/AuthMeReloaded) This plugin adds the support for [Velocity](https://velocitypowered.com/) to [AuthMeReloaded](https://github.com/AuthMe/AuthMeReloaded)
## Requirements ## Requirements
- Spigot, Paper, Tuinity, Airplane or Purpur - Paper, Tuinity, Airplane or Purpur
- Velocity 1.1.x or 3.0.0 - Velocity 3.0.0+
- Java 8/11/16 (Java 11 recommended) - Java 16
## Setup ## 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 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 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 4. Start the Velocity proxy and set up the config.yml with the auth servers

27
pom.xml
View File

@ -7,18 +7,20 @@
<groupId>com.glyart.authmevelocity</groupId> <groupId>com.glyart.authmevelocity</groupId>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<packaging>pom</packaging> <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> <modules>
<module>spigot</module> <module>spigot</module>
<module>proxy</module> <module>proxy</module>
</modules> </modules>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build> <build>
<finalName>AuthMeVelocity-${project.name}</finalName> <finalName>AuthMeVelocity-${project.name}</finalName>
<plugins> <plugins>
@ -26,14 +28,14 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<configuration> <configuration>
<source>11</source> <source>16</source>
<target>11</target> <target>16</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.3.0-SNAPSHOT</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@ -42,6 +44,13 @@
</goals> </goals>
<configuration> <configuration>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<relocations>
<relocation>
<pattern>de.leonhard</pattern>
<shadedPattern>com.glyart.authmevelocity.libs.simplixstorage</shadedPattern>
</relocation>
</relocations>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>

View File

@ -5,45 +5,35 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId> <groupId>com.glyart.authmevelocity</groupId>
<version>1.0.1</version> <version>1.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>proxy</artifactId> <artifactId>proxy</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<repositories> <repositories>
<repository> <repository>
<id>velocity</id> <id>velocity</id>
<url>https://nexus.velocitypowered.com/repository/maven-public/</url> <url>https://nexus.velocitypowered.com/repository/maven-public/</url>
</repository> </repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.velocitypowered</groupId> <groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId> <artifactId>velocity-api</artifactId>
<version>3.0.0</version> <version>3.0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>com.github.simplix-softworks</groupId>
<artifactId>lombok</artifactId> <artifactId>SimplixStorage</artifactId>
<version>1.18.20</version> <version>3.1.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.12.4</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -5,51 +5,42 @@ import com.glyart.authmevelocity.proxy.listener.ProxyListener;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; 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.ProxyServer;
import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier; import com.velocitypowered.api.proxy.messages.LegacyChannelIdentifier;
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier; import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
import lombok.Getter;
import org.slf4j.Logger; import org.slf4j.Logger;
import de.leonhard.storage.Yaml;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@Getter
public class AuthMeVelocityPlugin { public class AuthMeVelocityPlugin {
public final ProxyServer server;
private final ProxyServer server;
private final Logger logger; 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<>()); public final List<UUID> loggedPlayers = Collections.synchronizedList(new ArrayList<>());
private AuthMeConfig config;
@Inject @Inject
public AuthMeVelocityPlugin(ProxyServer server, Logger logger, @DataDirectory Path dataFolder) { public AuthMeVelocityPlugin(ProxyServer server, Logger logger) {
this.server = server; this.server = server;
this.logger = logger; this.logger = logger;
this.dataFolder = dataFolder;
} }
@Subscribe @Subscribe
public void onProxyInitialize(ProxyInitializeEvent event) { public void onProxyInitialize(ProxyInitializeEvent event) throws IOException {
try {
config = AuthMeConfig.loadConfig(dataFolder);
} catch (IOException e) {
logger.error("An error occurred while enabling AuthMeVelocity.", e);
return;
}
server.getChannelRegistrar().register(new LegacyChannelIdentifier("authmevelocity:main"), MinecraftChannelIdentifier.create("authmevelocity", "main")); server.getChannelRegistrar().register(new LegacyChannelIdentifier("authmevelocity:main"), MinecraftChannelIdentifier.create("authmevelocity", "main"));
server.getEventManager().register(this, new ProxyListener(this)); server.getEventManager().register(this, new ProxyListener(this));
AuthMeConfig.defaultConfig();
logger.info("AuthMeVelocity enabled."); logger.info("AuthMeVelocity enabled.");
logger.info("AuthServers:" + config.getList("authservers"));
} }
public static Yaml getConfig(){
return config;
}
} }

View File

@ -1,36 +1,11 @@
package com.glyart.authmevelocity.proxy.config; 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; import java.util.List;
@Getter import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin;
public class AuthMeConfig {
private List<String> authServers = Arrays.asList("auth-1", "auth-2"); public interface AuthMeConfig {
public static void defaultConfig(){
public static AuthMeConfig loadConfig(Path folder) throws IOException { AuthMeVelocityPlugin.getConfig().setDefault("authservers", List.of("auth1", "auth2"));
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;
}
return mapper.readValue(file, AuthMeConfig.class);
} }
} }

View File

@ -1,7 +1,6 @@
package com.glyart.authmevelocity.proxy.listener; package com.glyart.authmevelocity.proxy.listener;
import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin; import com.glyart.authmevelocity.proxy.AuthMeVelocityPlugin;
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataInput;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent;
@ -21,66 +20,74 @@ public class ProxyListener {
private final AuthMeVelocityPlugin plugin; private final AuthMeVelocityPlugin plugin;
private final ProxyServer server; private final ProxyServer server;
private final AuthMeConfig config;
public ProxyListener(AuthMeVelocityPlugin plugin) { public ProxyListener(AuthMeVelocityPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
server = plugin.getServer(); server = plugin.server;
config = plugin.getConfig();
} }
@Subscribe @Subscribe
public void onPluginMessage(PluginMessageEvent event) { public void onPluginMessage(final PluginMessageEvent event) {
if (!(event.getSource() instanceof ServerConnection)) if (!(event.getSource() instanceof ServerConnection)) {
return; return;
}
if (!event.getIdentifier().getId().equals("authmevelocity:main")) if (!event.getIdentifier().getId().equals("authmevelocity:main")) {
return; return;
}
ByteArrayDataInput input = event.dataAsDataStream(); ByteArrayDataInput input = event.dataAsDataStream();
String sChannel = input.readUTF(); String sChannel = input.readUTF();
if (!sChannel.equals("LOGIN")) if (!sChannel.equals("LOGIN")) {
return; return;
}
String user = input.readUTF(); String user = input.readUTF();
Optional<Player> player = server.getPlayer(UUID.fromString(user)); Optional<Player> player = server.getPlayer(UUID.fromString(user));
if (!player.isPresent()) if (!player.isPresent()) {
return; return;
}
plugin.getLoggedPlayers().add(player.get().getUniqueId()); plugin.loggedPlayers.add(player.get().getUniqueId());
} }
@Subscribe @Subscribe
public void onDisconnect(DisconnectEvent event) { public void onDisconnect(final DisconnectEvent event) {
plugin.getLoggedPlayers().remove(event.getPlayer().getUniqueId()); plugin.loggedPlayers.remove(event.getPlayer().getUniqueId());
} }
@Subscribe @Subscribe
public void onCommandExecute(CommandExecuteEvent event) { public void onCommandExecute(final CommandExecuteEvent event) {
if (!(event.getCommandSource() instanceof Player)) if (!(event.getCommandSource() instanceof Player))
return; return;
Player player = (Player) event.getCommandSource(); final var player = (Player) event.getCommandSource();
if (plugin.getLoggedPlayers().contains(player.getUniqueId())) if (plugin.loggedPlayers.contains(player.getUniqueId()))
return; return;
Optional<ServerConnection> server = player.getCurrentServer(); Optional<ServerConnection> server = player.getCurrentServer();
boolean isAuthServer = server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName()); boolean isAuthServer =
if (isAuthServer) server.isPresent() &&
AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName());
if (isAuthServer) {
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer()); event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
else }
else {
event.setResult(CommandExecuteEvent.CommandResult.denied()); event.setResult(CommandExecuteEvent.CommandResult.denied());
}
} }
@Subscribe @Subscribe
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(final PlayerChatEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (plugin.getLoggedPlayers().contains(player.getUniqueId())) if (plugin.loggedPlayers.contains(player.getUniqueId()))
return; return;
Optional<ServerConnection> server = player.getCurrentServer(); 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; return;
}
event.setResult(PlayerChatEvent.ChatResult.denied()); event.setResult(PlayerChatEvent.ChatResult.denied());
} }
@ -88,14 +95,14 @@ public class ProxyListener {
@Subscribe @Subscribe
public void onServerPreConnect(ServerPreConnectEvent event) { public void onServerPreConnect(ServerPreConnectEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (plugin.getLoggedPlayers().contains(player.getUniqueId())) if (plugin.loggedPlayers.contains(player.getUniqueId()))
return; return;
Optional<RegisteredServer> server = event.getResult().getServer(); 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; return;
}
event.setResult(ServerPreConnectEvent.ServerResult.denied()); event.setResult(ServerPreConnectEvent.ServerResult.denied());
} }
} }

View File

@ -5,15 +5,15 @@
<parent> <parent>
<artifactId>parent</artifactId> <artifactId>parent</artifactId>
<groupId>com.glyart.authmevelocity</groupId> <groupId>com.glyart.authmevelocity</groupId>
<version>1.0.1</version> <version>1.1.0</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>spigot</artifactId> <artifactId>spigot</artifactId>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target> <maven.compiler.target>16</maven.compiler.target>
</properties> </properties>
<repositories> <repositories>
@ -35,7 +35,6 @@
<version>1.17.1-R0.1-SNAPSHOT</version> <version>1.17.1-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>fr.xephi</groupId> <groupId>fr.xephi</groupId>
<artifactId>authme</artifactId> <artifactId>authme</artifactId>
@ -43,5 +42,4 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -28,5 +28,4 @@ public class AuthMeVelocityPlugin extends JavaPlugin {
player.sendPluginMessage(this, "authmevelocity:main", out.toByteArray()); player.sendPluginMessage(this, "authmevelocity:main", out.toByteArray());
} }
} }