mirror of
https://github.com/lax1dude/eaglercraft-motd-1.8.git
synced 2024-11-09 07:46:04 -08:00
bungee impl almost complete
This commit is contained in:
parent
66a67bd79a
commit
40167877e3
|
@ -29,7 +29,7 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class EaglerMOTDConnectionBungee implements EaglerMOTDConnectionAdapter {
|
public class EaglerMOTDConnectionBungee implements EaglerMOTDConnectionAdapter {
|
||||||
|
|
||||||
private final MOTDConnection con;
|
private final MOTDConnection con;
|
||||||
private String listenerString = null;
|
private String listenerString = null;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee;
|
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.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.api.event.EaglercraftMOTDEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
@ -21,9 +22,31 @@ import net.md_5.bungee.event.EventHandler;
|
||||||
*/
|
*/
|
||||||
public class EaglerMOTDListenerBungee implements Listener {
|
public class EaglerMOTDListenerBungee implements Listener {
|
||||||
|
|
||||||
|
private final EaglerMOTDPluginBungee plugin;
|
||||||
|
|
||||||
|
public EaglerMOTDListenerBungee(EaglerMOTDPluginBungee plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void handleMOTDEvent(EaglercraftMOTDEvent evt) {
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee;
|
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee;
|
||||||
|
|
||||||
import java.io.File;
|
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.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
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.EaglerMOTDConnectionUpdater;
|
||||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDLoggerAdapter;
|
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.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.api.query.EaglerQueryHandler;
|
||||||
|
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_bungeecord.config.EaglerListenerConfig;
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,7 +75,12 @@ public class EaglerMOTDPluginBungee extends Plugin {
|
||||||
if(!dataFolder.isDirectory() && !dataFolder.mkdirs()) {
|
if(!dataFolder.isDirectory() && !dataFolder.mkdirs()) {
|
||||||
throw new RuntimeException("Could not create config folder!");
|
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() {
|
public void installQueryHandlers() {
|
||||||
|
@ -85,8 +97,34 @@ public class EaglerMOTDPluginBungee extends Plugin {
|
||||||
installedQueries.clear();
|
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
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
getProxy().getPluginManager().registerListener(this, new EaglerMOTDListenerBungee(this));
|
||||||
getProxy().getPluginManager().registerCommand(this, new CommandMOTDReloadBungee(this));
|
getProxy().getPluginManager().registerCommand(this, new CommandMOTDReloadBungee(this));
|
||||||
installQueryHandlers();
|
installQueryHandlers();
|
||||||
if(tickTimer == null) {
|
if(tickTimer == null) {
|
||||||
|
@ -117,6 +155,8 @@ public class EaglerMOTDPluginBungee extends Plugin {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
|
getProxy().getPluginManager().unregisterListeners(this);
|
||||||
|
getProxy().getPluginManager().unregisterCommands(this);
|
||||||
removeQueryHandlers();
|
removeQueryHandlers();
|
||||||
if(tickTimer != null) {
|
if(tickTimer != null) {
|
||||||
tickTimer.cancel();
|
tickTimer.cancel();
|
||||||
|
|
|
@ -1,7 +1,12 @@
|
||||||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.bungee.command;
|
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.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.CommandSender;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +35,32 @@ public class CommandMOTDReloadBungee extends Command {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandSender arg0, String[] arg1) {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user