bungee impl almost complete

This commit is contained in:
lax1dude 2024-05-07 15:01:17 -07:00
parent 66a67bd79a
commit 40167877e3
4 changed files with 97 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee;
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDConnectionUpdater;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.api.event.EaglercraftMOTDEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
@ -21,9 +22,31 @@ import net.md_5.bungee.event.EventHandler;
*/
public class EaglerMOTDListenerBungee implements Listener {
private final EaglerMOTDPluginBungee plugin;
public EaglerMOTDListenerBungee(EaglerMOTDPluginBungee plugin) {
this.plugin = plugin;
}
@EventHandler
public void handleMOTDEvent(EaglercraftMOTDEvent evt) {
if(!evt.getAccept().equalsIgnoreCase("motd") && !evt.getAccept().equalsIgnoreCase("motd.noicon")) {
return;
}
EaglerMOTDConnectionUpdater con = new EaglerMOTDConnectionUpdater(plugin.conf,
EaglerMOTDPluginBungee.getListenerName(evt.getListener()), evt.getListener().getMaxPlayer(),
new EaglerMOTDConnectionBungee(evt.getConnection()));
if(con.execute()) {
synchronized(plugin.motdConnections) {
if(plugin.conf.max_total_sockets > 0) {
while(plugin.motdConnections.size() >= plugin.conf.max_total_sockets) {
EaglerMOTDConnectionUpdater c = plugin.motdConnections.remove(plugin.motdConnections.size() - 1);
c.close();
}
}
plugin.motdConnections.add(0, con);
}
}
}
}

View File

@ -1,7 +1,12 @@
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee;
import java.io.File;
import java.io.IOException;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@ -14,7 +19,9 @@ import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDConfiguration;
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDConnectionUpdater;
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDLoggerAdapter;
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee.command.CommandMOTDReloadBungee;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.EaglerXBungee;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.api.query.EaglerQueryHandler;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.config.EaglerListenerConfig;
import net.md_5.bungee.api.plugin.Plugin;
/**
@ -68,7 +75,12 @@ public class EaglerMOTDPluginBungee extends Plugin {
if(!dataFolder.isDirectory() && !dataFolder.mkdirs()) {
throw new RuntimeException("Could not create config folder!");
}
conf.reload(dataFolder, loggerAdapter);
try {
conf.reload(dataFolder, loggerAdapter, getListenerNames());
}catch(IOException ex) {
throw new RuntimeException("Could not reload config!", ex);
}
}
public void installQueryHandlers() {
@ -85,8 +97,34 @@ public class EaglerMOTDPluginBungee extends Plugin {
installedQueries.clear();
}
public Collection<String> getListenerNames() {
Collection<EaglerListenerConfig> figs = EaglerXBungee.getEagler().getConfig().getServerListeners();
Collection<String> ret = new ArrayList(figs.size());
for(EaglerListenerConfig el : figs) {
ret.add(getListenerName(el));
}
return ret;
}
public static String getListenerName(EaglerListenerConfig listenerConf) {
InetSocketAddress sockAddr = listenerConf.getAddress();
if(sockAddr == null) {
sockAddr = listenerConf.getAddressV6();
if(sockAddr == null) {
throw new RuntimeException("Listener doesn't have an address: " + listenerConf);
}
}
InetAddress addr = sockAddr.getAddress();
if(addr instanceof Inet6Address) {
return "[" + addr.getHostAddress() + "]:" + sockAddr.getPort();
}else {
return addr.getHostAddress() + ":" + sockAddr.getPort();
}
}
@Override
public void onEnable() {
getProxy().getPluginManager().registerListener(this, new EaglerMOTDListenerBungee(this));
getProxy().getPluginManager().registerCommand(this, new CommandMOTDReloadBungee(this));
installQueryHandlers();
if(tickTimer == null) {
@ -117,6 +155,8 @@ public class EaglerMOTDPluginBungee extends Plugin {
@Override
public void onDisable() {
getProxy().getPluginManager().unregisterListeners(this);
getProxy().getPluginManager().unregisterCommands(this);
removeQueryHandlers();
if(tickTimer != null) {
tickTimer.cancel();

View File

@ -1,7 +1,12 @@
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee.command;
import java.util.logging.Level;
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDLoggerAdapter;
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee.EaglerMOTDPluginBungee;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
/**
@ -30,7 +35,32 @@ public class CommandMOTDReloadBungee extends Command {
@Override
public void execute(CommandSender arg0, String[] arg1) {
try {
plugin.removeQueryHandlers();
plugin.conf.reload(plugin.getDataFolder(), new EaglerMOTDLoggerAdapter() {
@Override
public void info(String msg) {
CommandMOTDReloadBungee.this.plugin.getLogger().info(msg);
arg0.sendMessage(new TextComponent(ChatColor.GREEN + "[EaglerMOTD] " + msg));
}
@Override
public void warn(String msg) {
CommandMOTDReloadBungee.this.plugin.getLogger().warning(msg);
arg0.sendMessage(new TextComponent(ChatColor.YELLOW + "[EaglerMOTD] " + msg));
}
@Override
public void error(String msg) {
CommandMOTDReloadBungee.this.plugin.getLogger().severe(msg);
arg0.sendMessage(new TextComponent(ChatColor.RED + "[EaglerMOTD] " + msg));
}
}, plugin.getListenerNames());
plugin.installQueryHandlers();
}catch(Throwable ex) {
arg0.sendMessage(new TextComponent(ChatColor.RED + "[EaglerMOTD] Failed to reload! " + ex.toString()));
plugin.getLogger().log(Level.SEVERE, "Exception thrown while reloading config!", ex);
}
}
}