cleanup
This commit is contained in:
parent
8c9ee11dd8
commit
bb2803dbb4
@ -12,16 +12,15 @@ import org.slf4j.Logger;
|
||||
|
||||
import de.leonhard.storage.Yaml;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AuthMeVelocityPlugin {
|
||||
public final ProxyServer server;
|
||||
private final ProxyServer server;
|
||||
private final Logger logger;
|
||||
static Yaml config = new Yaml("config", "plugins/AuthmeVelocity");
|
||||
private static Yaml config = new Yaml("config", "plugins/AuthmeVelocity");
|
||||
|
||||
public final List<UUID> loggedPlayers = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
@ -32,12 +31,12 @@ public class AuthMeVelocityPlugin {
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialize(ProxyInitializeEvent event) throws IOException {
|
||||
public void onProxyInitialize(ProxyInitializeEvent event) {
|
||||
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, server));
|
||||
AuthMeConfig.defaultConfig();
|
||||
logger.info("AuthMeVelocity enabled.");
|
||||
logger.info("AuthServers:" + config.getList("authservers"));
|
||||
logger.info("AuthMeVelocity enabled");
|
||||
logger.info("AuthServers: " + config.getList("authservers"));
|
||||
}
|
||||
|
||||
public static Yaml getConfig(){
|
||||
|
@ -17,36 +17,27 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ProxyListener {
|
||||
|
||||
private final AuthMeVelocityPlugin plugin;
|
||||
private final ProxyServer server;
|
||||
|
||||
public ProxyListener(AuthMeVelocityPlugin plugin) {
|
||||
public ProxyListener(AuthMeVelocityPlugin plugin, ProxyServer server) {
|
||||
this.plugin = plugin;
|
||||
server = plugin.server;
|
||||
this.server = server;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onPluginMessage(final PluginMessageEvent event) {
|
||||
if (!(event.getSource() instanceof ServerConnection)) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getSource() instanceof ServerConnection)) return;
|
||||
|
||||
if (!event.getIdentifier().getId().equals("authmevelocity:main")) {
|
||||
return;
|
||||
}
|
||||
if (!event.getIdentifier().getId().equals("authmevelocity:main")) return;
|
||||
|
||||
ByteArrayDataInput input = event.dataAsDataStream();
|
||||
String sChannel = input.readUTF();
|
||||
if (!sChannel.equals("LOGIN")) {
|
||||
return;
|
||||
}
|
||||
if (!sChannel.equals("LOGIN")) return;
|
||||
|
||||
String user = input.readUTF();
|
||||
Optional<Player> player = server.getPlayer(UUID.fromString(user));
|
||||
if (!player.isPresent()) {
|
||||
return;
|
||||
}
|
||||
if (!player.isPresent()) return;
|
||||
|
||||
plugin.loggedPlayers.add(player.get().getUniqueId());
|
||||
}
|
||||
@ -58,22 +49,17 @@ public class ProxyListener {
|
||||
|
||||
@Subscribe
|
||||
public void onCommandExecute(final CommandExecuteEvent event) {
|
||||
if (!(event.getCommandSource() instanceof Player))
|
||||
return;
|
||||
if (!(event.getCommandSource() instanceof Player player)) return;
|
||||
|
||||
final var player = (Player) event.getCommandSource();
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId()))
|
||||
return;
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId())) return;
|
||||
|
||||
Optional<ServerConnection> server = player.getCurrentServer();
|
||||
boolean isAuthServer =
|
||||
server.isPresent() &&
|
||||
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());
|
||||
}
|
||||
}
|
||||
@ -81,8 +67,7 @@ public class ProxyListener {
|
||||
@Subscribe
|
||||
public void onPlayerChat(final PlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId()))
|
||||
return;
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId())) return;
|
||||
|
||||
Optional<ServerConnection> server = player.getCurrentServer();
|
||||
if (server.isPresent() && AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName())) {
|
||||
@ -95,8 +80,7 @@ public class ProxyListener {
|
||||
@Subscribe
|
||||
public void onServerPreConnect(ServerPreConnectEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId()))
|
||||
return;
|
||||
if (plugin.loggedPlayers.contains(player.getUniqueId())) return;
|
||||
|
||||
Optional<RegisteredServer> server = event.getResult().getServer();
|
||||
if (server.isPresent() && AuthMeVelocityPlugin.getConfig().getList("authservers").contains(server.get().getServerInfo().getName())) {
|
||||
|
@ -7,7 +7,6 @@ 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");
|
||||
@ -16,11 +15,6 @@ public class AuthMeVelocityPlugin extends JavaPlugin {
|
||||
getLogger().info("AuthMeVelocity enabled.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
|
||||
}
|
||||
|
||||
public void sendLoginToProxy(Player player) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("LOGIN");
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class AuthMeListener implements Listener {
|
||||
|
||||
private final AuthMeVelocityPlugin plugin;
|
||||
|
||||
public AuthMeListener(AuthMeVelocityPlugin plugin) {
|
||||
@ -17,5 +16,4 @@ public class AuthMeListener implements Listener {
|
||||
public void onLogin(LoginEvent event) {
|
||||
plugin.sendLoginToProxy(event.getPlayer());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user