Initial Commit

This commit is contained in:
ryans1230 2017-09-09 10:40:09 -04:00
commit 4863f9a29f
6 changed files with 184 additions and 0 deletions

70
pom.xml Normal file
View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.ryans1230</groupId>
<artifactId>BungeeKickListener</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>BungeeKickListener</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<defaultGoal>clean package</defaultGoal>
<plugins>
<plugin>
<version>3.6.1</version>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>true</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>sonatype-oss-repo</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.md-5</groupId>
<artifactId>bungeecord-api</artifactId>
<version>1.12-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,26 @@
package me.ryans1230.bungeekicklistener;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.plugin.Plugin;
import java.util.List;
public final class BungeeKickListener extends Plugin {
List<String> reasonList;
boolean banCheck;
ServerInfo fallback;
@Override
public void onEnable() {
ConfigUtil util = new ConfigUtil(this);
util.createConfig();
getProxy().getPluginManager().registerListener(this, new KickListener(this));
reasonList = ConfigUtil.c.getStringList("list");
banCheck = ConfigUtil.c.getBoolean("ban-check");
fallback = getProxy().getServerInfo(ConfigUtil.c.getString("fallback-server"));
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}

View File

@ -0,0 +1,42 @@
package me.ryans1230.bungeekicklistener;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
@SuppressWarnings("ResultOfMethodCallIgnored")
class ConfigUtil {
private volatile BungeeKickListener plugin;
ConfigUtil(BungeeKickListener plugin) {this.plugin = plugin;}
static Configuration c;
private static ConfigurationProvider provider = ConfigurationProvider.getProvider(YamlConfiguration.class);
synchronized void createConfig() {
plugin.getLogger().info("Generating default configuration file. Edit it and restart your network.");
File f = plugin.getDataFolder();
File conf = new File(f, "config.yml");
try {
plugin.getDataFolder().mkdir();
conf.createNewFile();
Configuration config = provider.load(conf);
c = config;
if(config.getString("fallback-server").isEmpty()) {
config.set("fallback-server", "lobby");
}
if(!config.getBoolean("ban-check")) {
config.set("ban-check", false);
}
if (config.getStringList("list").isEmpty()) {
config.set("list", Arrays.asList("kicked", "restarting"));
}
provider.save(config, conf);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,37 @@
package me.ryans1230.bungeekicklistener;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.event.ServerKickEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
public class KickListener implements Listener {
private BungeeKickListener plugin;
KickListener(BungeeKickListener plugin) {this.plugin = plugin;}
@EventHandler(priority = EventPriority.HIGHEST)
public void onServerKickEvent(ServerKickEvent e) {
ServerInfo fallback = plugin.fallback;
String reason = BaseComponent.toLegacyText(e.getKickReasonComponent());
String from = e.getKickedFrom().getName();
e.setCancelServer(fallback);
e.setCancelled(true);
if(plugin.banCheck) {
e.getPlayer().disconnect(e.getKickReasonComponent());
return;
}
if(plugin.reasonList.contains(reason)) {
if(!from.equals(fallback.getName())) {
e.getPlayer().sendMessage(new ComponentBuilder(ChatColor.RED + from + " is most likely restarting, you have been connected to \"" + fallback.getName() + "\"").create());
return;
}
}
e.getPlayer().sendMessage(new ComponentBuilder(ChatColor.RED + "Your connection to " + e.getKickedFrom().getName() + " was interrupted. You have been connected to: " + e.getCancelServer().getName()).color(ChatColor.RED).create());
}
}

View File

@ -0,0 +1,5 @@
fallback-server: lobby
ban-check: true
list:
- restarting
- kicked

View File

@ -0,0 +1,4 @@
name: BungeeKickListener
version: ${project.version}
main: me.ryans1230.bungeekicklistener.BungeeKickListener
author: ryans1230