added velocity support, needs testing

This commit is contained in:
lax1dude 2024-05-29 16:39:30 -07:00
parent c072df950f
commit 50c400c806
8 changed files with 592 additions and 0 deletions

View File

@ -0,0 +1,29 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity;
import com.velocitypowered.api.command.CommandManager;
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 CommandRegisterHelper {
public static void register(OriginBlacklistPluginVelocity plugin, EaglerCommand cmd) {
CommandManager cmdManager = OriginBlacklistPluginVelocity.proxy().getCommandManager();
cmdManager.register(cmdManager.metaBuilder(cmd.name).aliases(cmd.alias).plugin(plugin).build(), cmd);
}
}

View File

@ -0,0 +1,128 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.EaglerXVelocityVersion;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.config.bungee.Configuration;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.config.bungee.ConfigurationProvider;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.config.bungee.YamlConfiguration;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklistConfigAdapter;
/**
* 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 OriginBlacklistConfigVelocity implements OriginBlacklistConfigAdapter {
private static final String NO_INLINE_USER_AGENT;
static {
try {
// workaround for compilers inlining the "ID" and "VERSION" fields
// (due to them being defined as static and final)
StringBuilder uaBuilder = new StringBuilder();
uaBuilder.append("Mozilla/5.0 ");
uaBuilder.append(EaglerXVelocityVersion.class.getDeclaredField("ID").get(null));
uaBuilder.append("/");
uaBuilder.append(EaglerXVelocityVersion.class.getDeclaredField("VERSION").get(null));
NO_INLINE_USER_AGENT = uaBuilder.toString();
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
public static OriginBlacklistConfigVelocity loadConfig(File dataDir) throws IOException {
if(!dataDir.isDirectory() && !dataDir.mkdirs()) {
throw new IOException("Could not create directory: " + dataDir.getAbsolutePath());
}
File configFile = new File(dataDir, "config.yml");
if(!configFile.exists()) {
try(InputStream defaultConf = OriginBlacklistConfigVelocity.class.getResourceAsStream("/net/lax1dude/eaglercraft/v1_8/plugin/origin_blacklist/default_config.yml")) {
try(OutputStream os = new FileOutputStream(configFile)) {
byte[] copyBuffer = new byte[1024];
int i;
while((i = defaultConf.read(copyBuffer)) != -1) {
os.write(copyBuffer, 0, i);
}
}
}
}
Configuration conf = ConfigurationProvider.getProvider(YamlConfiguration.class).load(configFile);
return new OriginBlacklistConfigVelocity(dataDir, conf);
}
private final File dataDir;
private final Configuration conf;
private OriginBlacklistConfigVelocity(File dataDir, Configuration conf) {
this.dataDir = dataDir;
this.conf = conf;
}
@Override
public File getLocalBlacklistFile() {
return new File(dataDir, "origin_blacklist.txt");
}
@Override
public String getKickMessage() {
return conf.getString("origin_blacklist_kick_message", "End of stream");
}
@Override
public boolean getBlockClientsWithNoOriginHeader() {
return conf.getBoolean("origin_blacklist_block_missing_origin_header", false);
}
@Override
public String getSubscriptionDownloadUserAgent() {
return NO_INLINE_USER_AGENT;
}
@Override
public Collection<String> getBlacklistURLs() {
boolean enableSubscribe = conf.getBoolean("enable_web_origin_blacklist", false);
if(!enableSubscribe) {
return null;
}
return (Collection<String>)conf.getList("origin_blacklist_subscriptions", new ArrayList<String>());
}
@Override
public boolean shouldBlacklistOfflineDownload() {
return conf.getBoolean("origin_blacklist_block_offline_download", false);
}
@Override
public boolean shouldBlacklistReplits() {
return conf.getBoolean("origin_blacklist_block_replit_clients", false);
}
@Override
public boolean isSimpleWhitelistEnabled() {
return conf.getBoolean("origin_blacklist_use_simple_whitelist", false);
}
@Override
public Collection<String> getBlacklistSimpleWhitelist() {
return (Collection<String>)conf.getList("origin_blacklist_simple_whitelist", new ArrayList<String>());
}
}

View File

@ -0,0 +1,60 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.ResultedEvent.ComponentResult;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.LoginEvent;
import net.kyori.adventure.text.Component;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.EaglerXVelocityAPIHelper;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.server.EaglerPlayerData;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklist;
/**
* 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 OriginBlacklistListenerVelocity {
private final OriginBlacklistPluginVelocity plugin;
public OriginBlacklistListenerVelocity(OriginBlacklistPluginVelocity plugin) {
this.plugin = plugin;
}
@Subscribe(order = PostOrder.FIRST)
public void handleLoginEvent(LoginEvent evt) {
EaglerPlayerData eaglerCon = EaglerXVelocityAPIHelper.getEaglerHandle(evt.getPlayer());
if(eaglerCon != null) {
String origin = eaglerCon.getOrigin();
OriginBlacklist blacklist = plugin.list;
boolean shouldKick = true;
try {
shouldKick = origin == null ? blacklist.getBlockClientsWithNoOriginHeader() : blacklist.test(OriginBlacklist.removeProtocolFromOrigin(origin));
}catch(Throwable t) {
plugin.getLogger().error("Failed to check origin blacklist for: " + origin, t);
}
if(shouldKick) {
plugin.getLogger().info("Disconnecting a player who joined from blacklisted origin: " + origin);
String msg = blacklist.getKickMessage();
if(msg != null) {
evt.setResult(ComponentResult.denied(Component.text(msg)));
}else {
evt.setResult(ComponentResult.denied(Component.translatable("disconnect.endOfStream")));
}
}
}
}
}

View File

@ -0,0 +1,154 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Timer;
import java.util.TimerTask;
import org.slf4j.Logger;
import com.google.inject.Inject;
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.gateway_velocity.EaglerXVelocityVersion;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklist;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklistConfigAdapter;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklistLoggerAdapter;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.command.CommandDomainBlock;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.command.CommandDomainBlockDomain;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.command.CommandDomainUnblock;
/**
* 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 = OriginBlacklistPluginVersion.ID,
name = OriginBlacklistPluginVersion.NAME,
description = OriginBlacklistPluginVersion.DESCRIPTION,
version = OriginBlacklistPluginVersion.VERSION,
authors = {
OriginBlacklistPluginVersion.AUTHOR
},
dependencies = {
@Dependency(
id = EaglerXVelocityVersion.PLUGIN_ID,
optional = false
)
}
)
public class OriginBlacklistPluginVelocity {
private static OriginBlacklistPluginVelocity instance = null;
private final ProxyServer proxy;
private final Logger logger;
private final Path dataDirAsPath;
private final File dataDir;
public final OriginBlacklist list;
private Timer updateOriginBlacklistTimer = null;
@Inject
public OriginBlacklistPluginVelocity(ProxyServer proxyIn, Logger loggerIn, @DataDirectory Path dataDirIn) {
instance = this;
proxy = proxyIn;
logger = loggerIn;
dataDirAsPath = dataDirIn;
dataDir = dataDirIn.toFile();
list = new OriginBlacklist(new OriginBlacklistLoggerAdapter() {
@Override
public void warn(String msg) {
OriginBlacklistPluginVelocity.this.logger.warn(msg);
}
@Override
public void info(String msg) {
OriginBlacklistPluginVelocity.this.logger.info(msg);
}
@Override
public void error(String msg) {
OriginBlacklistPluginVelocity.this.logger.error(msg);
}
});
}
private void reloadConfig() {
OriginBlacklistConfigAdapter cfg;
try {
cfg = OriginBlacklistConfigVelocity.loadConfig(dataDir);
}catch(IOException ex) {
throw new RuntimeException("Could not load origin blacklist config file!", ex);
}
list.init(cfg);
}
@Subscribe
public void onProxyInit(ProxyInitializeEvent e) {
reloadConfig();
if(updateOriginBlacklistTimer == null) {
updateOriginBlacklistTimer = new Timer("EaglerXBungee: Origin Blacklist Updater");
updateOriginBlacklistTimer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
try {
list.update();
}catch(Throwable t) {
OriginBlacklistPluginVelocity.this.logger.error("Could not update origin blacklist!", t);
}
}
}, 0, 6000l);
}
proxy.getEventManager().register(this, new OriginBlacklistListenerVelocity(this));
CommandRegisterHelper.register(this, new CommandDomainBlock());
CommandRegisterHelper.register(this, new CommandDomainBlockDomain());
CommandRegisterHelper.register(this, new CommandDomainUnblock());
}
@Subscribe
public void onProxyShutdown(ProxyShutdownEvent e) {
if(updateOriginBlacklistTimer != null) {
updateOriginBlacklistTimer.cancel();
updateOriginBlacklistTimer = null;
}
}
public ProxyServer getProxy() {
return proxy;
}
public Logger getLogger() {
return logger;
}
public static OriginBlacklistPluginVelocity getPlugin() {
return instance;
}
public static ProxyServer proxy() {
return instance.proxy;
}
public static Logger logger() {
return instance.logger;
}
}

View File

@ -0,0 +1,26 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.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 OriginBlacklistPluginVersion {
public static final String ID = "originblacklist";
public static final String NAME = "OriginBlacklist";
public static final String DESCRIPTION = "Plugin for EaglercraftXVelocity servers to add the \"origin blacklist\" feature from 1.5.2";
public static final String VERSION = "1.0.0";
public static final String AUTHOR = "lax1dude";
}

View File

@ -0,0 +1,85 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.EaglerXVelocityAPIHelper;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.command.EaglerCommand;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.server.EaglerPlayerData;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklist;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.OriginBlacklistPluginVelocity;
/**
* Copyright (c) 2022-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 CommandDomainBlock extends EaglerCommand {
public CommandDomainBlock() {
super("block-domain", "eaglercraft.command.blockdomain");
}
@Override
public void execute(CommandSource p0, String[] p1) {
if (p1.length < 1) {
p0.sendMessage(Component.text("Please follow this command by a username", NamedTextColor.RED));
return;
}
final Player user = OriginBlacklistPluginVelocity.proxy().getPlayer(p1[0]).orElse(null);
if (user == null) {
p0.sendMessage(Component.text("That user is not online", NamedTextColor.RED));
}else {
EaglerPlayerData eagPlayer = EaglerXVelocityAPIHelper.getEaglerHandle(user);
if(eagPlayer != null) {
String o = OriginBlacklist.removeProtocolFromOrigin(eagPlayer.getOrigin());
if(o != null) {
if("null".equals(o)) {
p0.sendMessage(Component.text("That user is on an offline download", NamedTextColor.RED));
}else {
OriginBlacklist bl = OriginBlacklistPluginVelocity.getPlugin().list;
bl.addLocal(o);
for(Player p : OriginBlacklistPluginVelocity.proxy().getAllPlayers()) {
eagPlayer = EaglerXVelocityAPIHelper.getEaglerHandle(p);
if(eagPlayer != null) {
String oo = OriginBlacklist.removeProtocolFromOrigin(eagPlayer.getOrigin());
if(oo != null) {
if(bl.test(oo)) {
String msg = bl.getKickMessage();
if(msg != null) {
p.disconnect(Component.text(msg));
}else {
p.disconnect(Component.translatable("disconnect.endOfStream"));
}
}
}
}
}
p0.sendMessage(Component.text("Domain of ", NamedTextColor.RED)
.append(Component.text(p1[0], NamedTextColor.WHITE))
.append(Component.text(" is ", NamedTextColor.RED))
.append(Component.text(o, NamedTextColor.WHITE)));
p0.sendMessage(Component.text("It was added to the local block list.", NamedTextColor.RED));
}
}else {
p0.sendMessage(Component.text("Domain of " + p1[0] + " is unknown (desktop runtime?)", NamedTextColor.RED));
}
}else {
p0.sendMessage(Component.text("That user is not using an Eaglercraft client", NamedTextColor.RED));
}
}
}
}

View File

@ -0,0 +1,64 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.api.EaglerXVelocityAPIHelper;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.command.EaglerCommand;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.server.EaglerPlayerData;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklist;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.OriginBlacklistPluginVelocity;
/**
* Copyright (c) 2022-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 CommandDomainBlockDomain extends EaglerCommand {
public CommandDomainBlockDomain() {
super("block-domain-name", "eaglercraft.command.blockdomainname");
}
@Override
public void execute(CommandSource p0, String[] p1) {
if (p1.length < 1) {
p0.sendMessage(Component.text("Please follow this command by a domain", NamedTextColor.RED));
return;
}
OriginBlacklist bl = OriginBlacklistPluginVelocity.getPlugin().list;
bl.addLocal(p1[0]);
for(Player p : OriginBlacklistPluginVelocity.proxy().getAllPlayers()) {
EaglerPlayerData eagPlayer = EaglerXVelocityAPIHelper.getEaglerHandle(p);
if(eagPlayer != null) {
String o = OriginBlacklist.removeProtocolFromOrigin(eagPlayer.getOrigin());
if(o != null) {
if(bl.test(o)) {
String msg = bl.getKickMessage();
if(msg != null) {
p.disconnect(Component.text(msg));
}else {
p.disconnect(Component.translatable("disconnect.endOfStream"));
}
}
}
}
}
p0.sendMessage(Component.text("The domain '", NamedTextColor.GREEN)
.append(Component.text(p1[0], NamedTextColor.WHITE))
.append(Component.text("' was added to the block list", NamedTextColor.GREEN)));
}
}

View File

@ -0,0 +1,46 @@
package net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.command;
import com.velocitypowered.api.command.CommandSource;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.lax1dude.eaglercraft.v1_8.plugin.gateway_velocity.command.EaglerCommand;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.OriginBlacklist;
import net.lax1dude.eaglercraft.v1_8.plugin.origin_blacklist.velocity.OriginBlacklistPluginVelocity;
/**
* Copyright (c) 2022-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 CommandDomainUnblock extends EaglerCommand {
public CommandDomainUnblock() {
super("unblock-domain", "eaglercraft.command.unblockdomain", "unblock-domain-name");
}
@Override
public void execute(CommandSource p0, String[] p1) {
if (p1.length < 1) {
p0.sendMessage(Component.text("Please follow this command by a domain", NamedTextColor.RED));
return;
}
OriginBlacklist bl = OriginBlacklistPluginVelocity.getPlugin().list;
if(bl.removeLocal(p1[0])) {
p0.sendMessage(Component.text("The domain '" + p1[0] + "' was removed from the local block list", NamedTextColor.GREEN));
}else {
p0.sendMessage(Component.text("The domain was not removed, is it on the block list? Check '" + bl.getLocalBlacklist().getName() + "' in your plugin directory", NamedTextColor.RED));
}
}
}