forked from CryLegend/AuthMeBridge
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multi-module project, initial velocity implementation [WIP]
- Loading branch information
Showing
42 changed files
with
1,510 additions
and
728 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?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> | ||
|
||
<parent> | ||
<groupId>fr.xephi</groupId> | ||
<artifactId>authmeproxy-parent</artifactId> | ||
<version>2.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>authmeproxy-bungee</artifactId> | ||
<name>AuthMeProxy-Bungee</name> | ||
|
||
<build> | ||
<finalName>${project.name}-${project.version}-noshade</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<repositories> | ||
<!-- Bungeecord repository --> | ||
<repository> | ||
<id>oss-repo</id> | ||
<url>https://oss.sonatype.org/content/groups/public</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>fr.xephi</groupId> | ||
<artifactId>authmeproxy-common</artifactId> | ||
<version>2.3.0-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<!-- Bungeecord API --> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.20-R0.1-SNAPSHOT</version> | ||
<type>jar</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.md-5</groupId> | ||
<artifactId>bungeecord-api</artifactId> | ||
<version>1.20-R0.1-SNAPSHOT</version> | ||
<type>javadoc</type> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Metrics --> | ||
<dependency> | ||
<groupId>org.bstats</groupId> | ||
<artifactId>bstats-bungeecord</artifactId> | ||
<version>3.0.2</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
34 changes: 34 additions & 0 deletions
34
bungee/src/main/java/fr/xephi/authmeproxy/bungee/AuthMeBungeeLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package fr.xephi.authmeproxy.bungee; | ||
|
||
import fr.xephi.authmeproxy.common.AbstractAuthMeLogger; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
|
||
public class AuthMeBungeeLogger extends AbstractAuthMeLogger { | ||
|
||
public java.util.logging.Logger logger; | ||
|
||
public AuthMeBungeeLogger(java.util.logging.Logger logger) { | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public void send(String message) { | ||
ProxyServer.getInstance().getConsole().sendMessage(TextComponent.fromLegacyText(message)); | ||
} | ||
|
||
@Override | ||
public void info(String... messages) { | ||
this.logger.info(String.join(" ", messages)); | ||
} | ||
|
||
@Override | ||
public void warn(String... messages) { | ||
this.logger.warning(String.join(" ", messages)); | ||
} | ||
|
||
@Override | ||
public void error(String... messages) { | ||
this.logger.severe(String.join(" ", messages)); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
bungee/src/main/java/fr/xephi/authmeproxy/bungee/AuthMeProxyBungee.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package fr.xephi.authmeproxy.bungee; | ||
|
||
import fr.xephi.authmeproxy.bungee.listeners.MessageListener; | ||
import fr.xephi.authmeproxy.bungee.listeners.PlayerListener; | ||
import fr.xephi.authmeproxy.bungee.platform.BungeePlatform; | ||
import fr.xephi.authmeproxy.bungee.platform.BungeePlayer; | ||
import fr.xephi.authmeproxy.common.AbstractAuthMeProxy; | ||
import fr.xephi.authmeproxy.common.commands.AbstractCommand; | ||
import fr.xephi.authmeproxy.common.commands.ReloadCommand; | ||
import fr.xephi.authmeproxy.common.platform.AbstractPlayer; | ||
import net.md_5.bungee.api.CommandSender; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.plugin.Command; | ||
import net.md_5.bungee.api.plugin.Plugin; | ||
import org.bstats.bungeecord.Metrics; | ||
|
||
public class AuthMeProxyBungee extends Plugin { | ||
|
||
private final AuthMeProxyBungeeImpl implementation; | ||
|
||
public AuthMeProxyBungee() { | ||
implementation = new AuthMeProxyBungeeImpl(this); | ||
} | ||
|
||
// Dirty hack as we can't extend multiple classes | ||
public static class AuthMeProxyBungeeImpl extends AbstractAuthMeProxy<BungeePlatform> { | ||
|
||
private final AuthMeProxyBungee plugin; | ||
|
||
public AuthMeProxyBungeeImpl(AuthMeProxyBungee plugin) { | ||
super( | ||
new BungeePlatform(), | ||
new AuthMeBungeeLogger(plugin.getLogger()), | ||
plugin.getDataFolder() | ||
); | ||
this.plugin = plugin; | ||
} | ||
|
||
@Override | ||
protected void registerCommands() { | ||
plugin.registerCommand(injector.getSingleton(ReloadCommand.class)); | ||
} | ||
|
||
@Override | ||
protected void registerListeners() { | ||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, injector.getSingleton(MessageListener.class)); | ||
ProxyServer.getInstance().getPluginManager().registerListener(plugin, injector.getSingleton(PlayerListener.class)); | ||
} | ||
|
||
@Override | ||
protected void registerMetrics() { | ||
// Send metrics data | ||
new Metrics(plugin, 1880); | ||
} | ||
} | ||
|
||
@Override | ||
public void onEnable() { | ||
implementation.initialize(); | ||
} | ||
|
||
private void registerCommand(AbstractCommand command) { | ||
ProxyServer.getInstance().getPluginManager().registerCommand(this, new Command( | ||
command.getCommand(), | ||
command.getPermission() | ||
) { | ||
@Override | ||
public void execute(CommandSender sender, String[] args) { | ||
ProxiedPlayer player = null; | ||
if (sender instanceof ProxiedPlayer) { | ||
player = (ProxiedPlayer) sender; | ||
} | ||
AbstractPlayer abstractPlayer = player == null ? null : BungeePlayer.fromPlayer(player); | ||
command.execute(abstractPlayer, args); | ||
} | ||
}); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
bungee/src/main/java/fr/xephi/authmeproxy/bungee/listeners/MessageListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fr.xephi.authmeproxy.bungee.listeners; | ||
|
||
import fr.xephi.authmeproxy.common.services.MessageHandleService; | ||
import net.md_5.bungee.api.connection.Server; | ||
import net.md_5.bungee.api.event.PluginMessageEvent; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.event.EventHandler; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class MessageListener implements Listener { | ||
|
||
@Inject | ||
private MessageHandleService messageHandleService; | ||
|
||
@EventHandler | ||
public void onPluginMessage(final PluginMessageEvent event) { | ||
if (event.isCancelled()) { | ||
return; | ||
} | ||
|
||
boolean fromPlayer = !(event.getSender() instanceof Server); | ||
messageHandleService.handleMessage(fromPlayer, event.getTag(), event.getData()); | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
bungee/src/main/java/fr/xephi/authmeproxy/bungee/listeners/PlayerListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package fr.xephi.authmeproxy.bungee.listeners; | ||
|
||
import fr.xephi.authmeproxy.bungee.platform.BungeePlayer; | ||
import fr.xephi.authmeproxy.common.services.AuthStateService; | ||
import net.md_5.bungee.api.chat.BaseComponent; | ||
import net.md_5.bungee.api.chat.TextComponent; | ||
import net.md_5.bungee.api.connection.ProxiedPlayer; | ||
import net.md_5.bungee.api.connection.Server; | ||
import net.md_5.bungee.api.event.*; | ||
import net.md_5.bungee.api.plugin.Listener; | ||
import net.md_5.bungee.event.EventHandler; | ||
import net.md_5.bungee.event.EventPriority; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class PlayerListener implements Listener { | ||
|
||
@Inject | ||
private AuthStateService authStateService; | ||
|
||
@EventHandler | ||
public void onPlayerJoin(final PostLoginEvent event) { | ||
// Register player in our list | ||
authStateService.trackUser(event.getPlayer().getName()); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerDisconnect(final PlayerDisconnectEvent event) { | ||
// Remove player from out list | ||
authStateService.untrackUser(event.getPlayer().getName()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOWEST) | ||
public void onCommand(final ChatEvent event) { | ||
if (event.isCancelled()) { | ||
return; | ||
} | ||
if (!event.isCommand() && event.isProxyCommand()) { | ||
return; | ||
} | ||
if (!(event.getSender() instanceof ProxiedPlayer)) { | ||
return; | ||
} | ||
ProxiedPlayer player = (ProxiedPlayer) event.getSender(); | ||
String command = event.getMessage().split(" ")[0].toLowerCase(); | ||
if (!authStateService.shouldAllowCommand(BungeePlayer.fromPlayer(player), command)) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
// Priority is set to lowest to keep compatibility with some chat plugins | ||
@EventHandler(priority = EventPriority.LOWEST) | ||
public void onPlayerChat(final ChatEvent event) { | ||
if (event.isCancelled()) { | ||
return; | ||
} | ||
if (event.isCommand() || event.isProxyCommand()) { | ||
return; | ||
} | ||
if (!(event.getSender() instanceof ProxiedPlayer)) { | ||
return; | ||
} | ||
ProxiedPlayer player = (ProxiedPlayer) event.getSender(); | ||
|
||
if (!authStateService.shouldAllowChat(BungeePlayer.fromPlayer(player))) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
|
||
@EventHandler(priority = EventPriority.LOWEST) | ||
public void onPlayerConnectedToServer(final ServerConnectedEvent event) { | ||
ProxiedPlayer player = event.getPlayer(); | ||
Server server = event.getServer(); | ||
authStateService.handleServerConnected(BungeePlayer.fromPlayer(player), server.getInfo().getName()); | ||
} | ||
|
||
@EventHandler(priority = EventPriority.HIGHEST) | ||
public void onPlayerConnectingToServer(final ServerConnectEvent event) { | ||
if (event.isCancelled()) { | ||
return; | ||
} | ||
|
||
ProxiedPlayer player = event.getPlayer(); | ||
String cancelReason = authStateService.shouldAllowServerSwitch( | ||
BungeePlayer.fromPlayer(player), | ||
event.getTarget().getName() | ||
).orElse(null); | ||
if (cancelReason == null) { | ||
return; | ||
} | ||
event.setCancelled(true); | ||
BaseComponent[] parsedCancelReason = TextComponent.fromLegacyText(cancelReason); | ||
if (event.getPlayer().getServer() == null || !event.getPlayer().getServer().isConnected()) { | ||
player.disconnect(parsedCancelReason); | ||
} else { | ||
player.sendMessage(parsedCancelReason); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
bungee/src/main/java/fr/xephi/authmeproxy/bungee/platform/BungeePlatform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package fr.xephi.authmeproxy.bungee.platform; | ||
|
||
import fr.xephi.authmeproxy.common.platform.AbstractPlatform; | ||
import net.md_5.bungee.api.ProxyServer; | ||
import net.md_5.bungee.api.config.ServerInfo; | ||
|
||
import java.util.Collection; | ||
import java.util.stream.Collectors; | ||
|
||
public class BungeePlatform extends AbstractPlatform<BungeePlayer> { | ||
|
||
public BungeePlatform() { | ||
} | ||
|
||
@Override | ||
public Collection<BungeePlayer> getAllPlayers() { | ||
return ProxyServer.getInstance().getPlayers().stream() | ||
.map(BungeePlayer::fromPlayer) | ||
.collect(Collectors.toUnmodifiableList()); | ||
} | ||
|
||
@Override | ||
public boolean connect(BungeePlayer player, String serverName) { | ||
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(serverName); | ||
if (serverInfo == null) { | ||
return false; | ||
} | ||
player.getHandle().connect(serverInfo); | ||
return true; | ||
} | ||
} |
Oops, something went wrong.