Initial commit
This commit is contained in:
commit
a63f523357
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea
|
||||
target
|
||||
*.iml
|
58
pom.xml
Normal file
58
pom.xml
Normal file
@ -0,0 +1,58 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<artifactId>parent</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<version>1.0.0</version>
|
||||
|
||||
<modules>
|
||||
<module>spigot</module>
|
||||
<module>proxy</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>AuthMeVelocity-${project.name}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
49
proxy/pom.xml
Normal file
49
proxy/pom.xml
Normal file
@ -0,0 +1,49 @@
|
||||
<?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>parent</artifactId>
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<version>1.0.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>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.1.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.18</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>2.12.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,56 @@
|
||||
package com.glyart.authmevelocity.proxy;
|
||||
|
||||
import com.glyart.authmevelocity.proxy.config.AuthMeConfig;
|
||||
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 java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Plugin(id = "authmevelocity", name = "AuthMeVelocity", version = "1.0.0", url = "https://github.com/Glyart/AuthMeVelocity", description = "This plugin adds the support for AuthMeReloaded to Velocity.", authors = {"xQuickGlare"})
|
||||
@Getter
|
||||
public class AuthMeVelocityPlugin {
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
private final Path dataFolder;
|
||||
|
||||
private final List<UUID> loggedPlayers = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
private AuthMeConfig config;
|
||||
|
||||
@Inject
|
||||
public AuthMeVelocityPlugin(ProxyServer server, Logger logger, @DataDirectory Path dataFolder) {
|
||||
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;
|
||||
}
|
||||
|
||||
server.getChannelRegistrar().register(new LegacyChannelIdentifier("authmevelocity:main"), MinecraftChannelIdentifier.create("authmevelocity", "main"));
|
||||
server.getEventManager().register(this, new ProxyListener(this));
|
||||
logger.info("AuthMeVelocity enabled.");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
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 {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return mapper.readValue(file, AuthMeConfig.class);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,101 @@
|
||||
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;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.connection.PluginMessageEvent;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||
import com.velocitypowered.api.event.player.ServerPreConnectEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.ServerConnection;
|
||||
import com.velocitypowered.api.proxy.server.RegisteredServer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPluginMessage(PluginMessageEvent event) {
|
||||
if (!(event.getSource() instanceof ServerConnection))
|
||||
return;
|
||||
|
||||
if (!event.getIdentifier().getId().equals("authmevelocity:main"))
|
||||
return;
|
||||
|
||||
ByteArrayDataInput input = event.dataAsDataStream();
|
||||
String sChannel = input.readUTF();
|
||||
if (!sChannel.equals("LOGIN"))
|
||||
return;
|
||||
|
||||
String user = input.readUTF();
|
||||
Optional<Player> player = server.getPlayer(UUID.fromString(user));
|
||||
if (!player.isPresent())
|
||||
return;
|
||||
|
||||
plugin.getLoggedPlayers().add(player.get().getUniqueId());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onDisconnect(DisconnectEvent event) {
|
||||
plugin.getLoggedPlayers().remove(event.getPlayer().getUniqueId());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onCommandExecute(CommandExecuteEvent event) {
|
||||
if (!(event.getCommandSource() instanceof Player))
|
||||
return;
|
||||
|
||||
Player player = (Player) event.getCommandSource();
|
||||
if (plugin.getLoggedPlayers().contains(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
Optional<ServerConnection> server = player.getCurrentServer();
|
||||
boolean isAuthServer = server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName());
|
||||
if (isAuthServer)
|
||||
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||
else
|
||||
event.setResult(CommandExecuteEvent.CommandResult.denied());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.getLoggedPlayers().contains(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
Optional<ServerConnection> server = player.getCurrentServer();
|
||||
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName()))
|
||||
return;
|
||||
|
||||
event.setResult(PlayerChatEvent.ChatResult.denied());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onServerPreConnect(ServerPreConnectEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.getLoggedPlayers().contains(player.getUniqueId()))
|
||||
return;
|
||||
|
||||
Optional<RegisteredServer> server = event.getResult().getServer();
|
||||
if (server.isPresent() && config.getAuthServers().contains(server.get().getServerInfo().getName()))
|
||||
return;
|
||||
|
||||
event.setResult(ServerPreConnectEvent.ServerResult.denied());
|
||||
}
|
||||
|
||||
}
|
47
spigot/pom.xml
Normal file
47
spigot/pom.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?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>parent</artifactId>
|
||||
<groupId>com.glyart.authmevelocity</groupId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spigot</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>fr.xephi</groupId>
|
||||
<artifactId>authme</artifactId>
|
||||
<version>5.6.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,32 @@
|
||||
package com.glyart.authmevelocity.spigot;
|
||||
|
||||
import com.glyart.authmevelocity.spigot.listeners.AuthMeListener;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getServer().getMessenger().registerOutgoingPluginChannel(this, "authmevelocity:main");
|
||||
getServer().getPluginManager().registerEvents(new AuthMeListener(this), this);
|
||||
|
||||
getLogger().info("AuthMeVelocity enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
public void sendLoginToProxy(Player player) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("LOGIN");
|
||||
out.writeUTF(player.getUniqueId().toString());
|
||||
|
||||
player.sendPluginMessage(this, "authmevelocity:main", out.toByteArray());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.glyart.authmevelocity.spigot.listeners;
|
||||
|
||||
import com.glyart.authmevelocity.spigot.AuthMeVelocityPlugin;
|
||||
import fr.xephi.authme.events.LoginEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class AuthMeListener implements Listener {
|
||||
|
||||
private final AuthMeVelocityPlugin plugin;
|
||||
|
||||
public AuthMeListener(AuthMeVelocityPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(LoginEvent event) {
|
||||
plugin.sendLoginToProxy(event.getPlayer());
|
||||
}
|
||||
|
||||
}
|
5
spigot/src/main/resources/plugin.yml
Normal file
5
spigot/src/main/resources/plugin.yml
Normal file
@ -0,0 +1,5 @@
|
||||
name: AuthMeVelocity
|
||||
author: xQuickGlare
|
||||
version: ${project.version}
|
||||
main: com.glyart.authmevelocity.spigot.AuthMeVelocityPlugin
|
||||
depend: [AuthMe]
|
Loading…
x
Reference in New Issue
Block a user