mirror of
https://github.com/lax1dude/eaglercraft-motd-1.8.git
synced 2024-11-08 07:16:05 -08:00
added velocity support, needs testing
This commit is contained in:
parent
40e3a2a969
commit
45854f1693
|
@ -0,0 +1,188 @@
|
|||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.velocity;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDConnectionAdapter;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDUtils;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.query.MOTDConnection;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.config.EaglerListenerConfig;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class EaglerMOTDConnectionVelocity implements EaglerMOTDConnectionAdapter {
|
||||
|
||||
private final MOTDConnection con;
|
||||
private String listenerString = null;
|
||||
|
||||
public EaglerMOTDConnectionVelocity(MOTDConnection con) {
|
||||
this.con = con;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isClosed() {
|
||||
return con.isClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
con.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccept() {
|
||||
return con.getAccept();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InetAddress getAddress() {
|
||||
return con.getAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getListener() {
|
||||
if(listenerString == null) {
|
||||
EaglerListenerConfig config = con.getListener();
|
||||
if(config.getAddress() != null) {
|
||||
this.listenerString = EaglerMOTDUtils.makeListenerString(config.getAddress());
|
||||
}else if(config.getAddressV6() != null) {
|
||||
this.listenerString = EaglerMOTDUtils.makeListenerString(config.getAddressV6());
|
||||
}else {
|
||||
throw new RuntimeException("Listener does not have an address!?");
|
||||
}
|
||||
}
|
||||
return listenerString;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionTimestamp() {
|
||||
return con.getConnectionTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getConnectionAge() {
|
||||
return con.getConnectionAge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToUser() {
|
||||
con.sendToUser();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLine1() {
|
||||
return con.getLine1();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLine2() {
|
||||
return con.getLine2();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPlayerList() {
|
||||
return con.getPlayerList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getBitmap() {
|
||||
return con.getBitmap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOnlinePlayers() {
|
||||
return con.getOnlinePlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxPlayers() {
|
||||
return con.getMaxPlayers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSubType() {
|
||||
return con.getSubType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLine1(String p) {
|
||||
con.setLine1(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLine2(String p) {
|
||||
con.setLine2(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerList(List<String> p) {
|
||||
con.setPlayerList(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerList(String... p) {
|
||||
con.setPlayerList(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBitmap(int[] p) {
|
||||
con.setBitmap(p);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnlinePlayers(int i) {
|
||||
con.setOnlinePlayers(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxPlayers(int i) {
|
||||
con.setMaxPlayers(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKeepAlive(boolean b) {
|
||||
con.setKeepAlive(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultMaxPlayers() {
|
||||
return con.getListener().getMaxPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefaultOnlinePlayers() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getDefaultOnlinePlayersList(int maxLen) {
|
||||
Collection<Player> ppl = EaglerMOTDPluginVelocity.proxy().getAllPlayers();
|
||||
List<String> players = new ArrayList(Math.min(ppl.size(), maxLen + 1));
|
||||
for(Player pp : ppl) {
|
||||
players.add(pp.getUsername());
|
||||
if(players.size() >= maxLen) {
|
||||
players.add("\u00A77\u00A7o(" + (ppl.size() - players.size()) + " more)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
return players;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.velocity;
|
||||
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDConnectionUpdater;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.event.EaglercraftMOTDEvent;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class EaglerMOTDListenerVelocity {
|
||||
|
||||
private final EaglerMOTDPluginVelocity plugin;
|
||||
|
||||
public EaglerMOTDListenerVelocity(EaglerMOTDPluginVelocity plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void handleMOTDEvent(EaglercraftMOTDEvent evt) {
|
||||
if(!evt.getAccept().equalsIgnoreCase("motd") && !evt.getAccept().equalsIgnoreCase("motd.noicon")) {
|
||||
return;
|
||||
}
|
||||
EaglerMOTDConnectionUpdater con = new EaglerMOTDConnectionUpdater(plugin.conf,
|
||||
EaglerMOTDPluginVelocity.getListenerName(evt.getListener()), evt.getListener().getMaxPlayer(),
|
||||
new EaglerMOTDConnectionVelocity(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,228 @@
|
|||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.velocity;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
import com.velocitypowered.api.event.proxy.ProxyShutdownEvent;
|
||||
import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
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.velocity.command.CommandMOTDReloadVelocity;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.EaglerXVelocity;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.EaglerXVelocityVersion;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.query.EaglerQueryHandler;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.command.EaglerCommand;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.config.EaglerListenerConfig;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
@Plugin(
|
||||
id = EaglerMOTDPluginVersion.ID,
|
||||
name = EaglerMOTDPluginVersion.NAME,
|
||||
description = EaglerMOTDPluginVersion.DESCRIPTION,
|
||||
version = EaglerMOTDPluginVersion.VERSION,
|
||||
authors = {
|
||||
EaglerMOTDPluginVersion.AUTHOR
|
||||
},
|
||||
dependencies = {
|
||||
@Dependency(
|
||||
id = EaglerXVelocityVersion.PLUGIN_ID,
|
||||
optional = false
|
||||
)
|
||||
}
|
||||
)
|
||||
public class EaglerMOTDPluginVelocity {
|
||||
|
||||
private static EaglerMOTDPluginVelocity instance = null;
|
||||
private final ProxyServer proxy;
|
||||
private final Logger logger;
|
||||
private final Path dataDirAsPath;
|
||||
private final File dataDir;
|
||||
|
||||
public final EaglerMOTDConfiguration conf = new EaglerMOTDConfiguration();
|
||||
public final List<EaglerMOTDConnectionUpdater> motdConnections = new LinkedList();
|
||||
public final EaglerMOTDLoggerAdapter loggerAdapter;
|
||||
private Timer tickTimer = null;
|
||||
private final List<String> installedQueries = new ArrayList();
|
||||
|
||||
@Inject
|
||||
public EaglerMOTDPluginVelocity(ProxyServer proxyIn, Logger loggerIn, @DataDirectory Path dataDirIn) {
|
||||
instance = this;
|
||||
proxy = proxyIn;
|
||||
logger = loggerIn;
|
||||
dataDirAsPath = dataDirIn;
|
||||
dataDir = dataDirIn.toFile();
|
||||
loggerAdapter = new EaglerMOTDLoggerAdapter() {
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
EaglerMOTDPluginVelocity.this.logger.info(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
EaglerMOTDPluginVelocity.this.logger.warn(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
EaglerMOTDPluginVelocity.this.logger.error(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void reloadConfig() {
|
||||
if(!dataDir.isDirectory() && !dataDir.mkdirs()) {
|
||||
throw new RuntimeException("Could not create config folder!");
|
||||
}
|
||||
|
||||
try {
|
||||
conf.reload(dataDir, loggerAdapter, getListenerNames());
|
||||
}catch(IOException ex) {
|
||||
throw new RuntimeException("Could not reload config!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void installQueryHandlers() {
|
||||
for(String str : conf.queryTypes.keySet()) {
|
||||
EaglerQueryHandler.registerQueryType(str, EaglerMOTDQueryHandlerVelocity.class);
|
||||
installedQueries.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeQueryHandlers() {
|
||||
for(String str : installedQueries) {
|
||||
EaglerQueryHandler.unregisterQueryType(str);
|
||||
}
|
||||
installedQueries.clear();
|
||||
}
|
||||
|
||||
public Collection<String> getListenerNames() {
|
||||
Collection<EaglerListenerConfig> figs = EaglerXVelocity.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();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInit(ProxyInitializeEvent e) {
|
||||
reloadConfig();
|
||||
proxy.getEventManager().register(this, new EaglerMOTDListenerVelocity(this));
|
||||
registerCommand(new CommandMOTDReloadVelocity(this));
|
||||
installQueryHandlers();
|
||||
if(tickTimer == null) {
|
||||
tickTimer = new Timer("MOTD Tick Timer");
|
||||
tickTimer.scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized(motdConnections) {
|
||||
Iterator<EaglerMOTDConnectionUpdater> itr = motdConnections.iterator();
|
||||
while(itr.hasNext()) {
|
||||
EaglerMOTDConnectionUpdater c = itr.next();
|
||||
try {
|
||||
if(!c.tick()) {
|
||||
itr.remove();
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
EaglerMOTDPluginVelocity.this.getLogger().error("Error ticking MOTD '" + (c.currentMessage == null ? "null" : c.currentMessage.name) + "' on listener " + c.listenerName, t);
|
||||
c.close();
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, 0, 50l);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyShutdown(ProxyShutdownEvent e) {
|
||||
removeQueryHandlers();
|
||||
if(tickTimer != null) {
|
||||
tickTimer.cancel();
|
||||
tickTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommand(EaglerCommand cmd) {
|
||||
CommandManager cmdManager = proxy.getCommandManager();
|
||||
cmdManager.register(cmdManager.metaBuilder(cmd.name).aliases(cmd.alias).plugin(this).build(), cmd);
|
||||
}
|
||||
|
||||
public ProxyServer getProxy() {
|
||||
return proxy;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
}
|
||||
|
||||
public File getDataFolder() {
|
||||
return dataDir;
|
||||
}
|
||||
|
||||
public static EaglerMOTDPluginVelocity getPlugin() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static ProxyServer proxy() {
|
||||
return instance.proxy;
|
||||
}
|
||||
|
||||
public static Logger logger() {
|
||||
return instance.logger;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.velocity;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class EaglerMOTDPluginVersion {
|
||||
|
||||
public static final String ID = "eaglermotd";
|
||||
public static final String NAME = "EaglerMOTD";
|
||||
public static final String DESCRIPTION = "Plugin to add an animated MOTDs to your EaglercraftXVelocity server";
|
||||
public static final String VERSION = "1.1.0";
|
||||
public static final String AUTHOR = "lax1dude";
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.velocity;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDQueryResponseAdapter;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.QueryType;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.query.EaglerQuerySimpleHandler;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class EaglerMOTDQueryHandlerVelocity extends EaglerQuerySimpleHandler implements EaglerMOTDQueryResponseAdapter {
|
||||
|
||||
@Override
|
||||
protected void begin(String queryType) {
|
||||
if(this.isClosed()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
QueryType queryHandler = EaglerMOTDPluginVelocity.getPlugin().conf.queryTypes.get(queryType.toLowerCase());
|
||||
if(queryHandler != null) {
|
||||
queryHandler.doQuery(this);
|
||||
}
|
||||
}catch(Throwable t) {
|
||||
EaglerMOTDPluginVelocity.logger().error("Failed to handle query type \"" + queryType + "\"!", t);
|
||||
}finally {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stringResponse(String type, String str) {
|
||||
this.sendStringResponse(type, str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void jsonResponse(String type, JsonObject json) {
|
||||
this.sendJsonResponse(type, json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendBinary(byte[] bin) {
|
||||
this.sendBinaryResponse(bin);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.velocity.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ConsoleCommandSource;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.EaglerMOTDLoggerAdapter;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.eaglermotd.velocity.EaglerMOTDPluginVelocity;
|
||||
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.command.EaglerCommand;
|
||||
|
||||
/**
|
||||
* Copyright (c) 2024 lax1dude. All Rights Reserved.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
public class CommandMOTDReloadVelocity extends EaglerCommand {
|
||||
|
||||
private final EaglerMOTDPluginVelocity plugin;
|
||||
|
||||
public CommandMOTDReloadVelocity(EaglerMOTDPluginVelocity plugin) {
|
||||
super("motd-reload", "eaglermotd.command.reload");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandSource arg0, String[] arg1) {
|
||||
try {
|
||||
plugin.removeQueryHandlers();
|
||||
plugin.conf.reload(plugin.getDataFolder(), new EaglerMOTDLoggerAdapter() {
|
||||
@Override
|
||||
public void info(String msg) {
|
||||
CommandMOTDReloadVelocity.this.plugin.getLogger().info(msg);
|
||||
if(!(arg0 instanceof ConsoleCommandSource)) {
|
||||
arg0.sendMessage(Component.text("[EaglerMOTD] " + msg, NamedTextColor.GREEN));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void warn(String msg) {
|
||||
CommandMOTDReloadVelocity.this.plugin.getLogger().warn(msg);
|
||||
if(!(arg0 instanceof ConsoleCommandSource)) {
|
||||
arg0.sendMessage(Component.text("[EaglerMOTD] " + msg, NamedTextColor.YELLOW));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String msg) {
|
||||
CommandMOTDReloadVelocity.this.plugin.getLogger().error(msg);
|
||||
if(!(arg0 instanceof ConsoleCommandSource)) {
|
||||
arg0.sendMessage(Component.text("[EaglerMOTD] " + msg, NamedTextColor.RED));
|
||||
}
|
||||
}
|
||||
}, plugin.getListenerNames());
|
||||
plugin.installQueryHandlers();
|
||||
}catch(Throwable ex) {
|
||||
if(!(arg0 instanceof ConsoleCommandSource)) {
|
||||
arg0.sendMessage(Component.text("[EaglerMOTD] Failed to reload! " + ex.toString(), NamedTextColor.RED));
|
||||
}
|
||||
plugin.getLogger().error("Exception thrown while reloading config!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user