feat: 更新添加VBossAuth支持

Signed-off-by: 502647092 <admin@yumc.pw>
master
502647092 2016-12-24 17:54:36 +08:00
parent dfcea78eb3
commit 516cd09daa
10 changed files with 266 additions and 208 deletions

211
pom.xml
View File

@ -1,101 +1,114 @@
<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>pw.yumc</groupId>
<artifactId>MiaoLobby</artifactId>
<version>1.3</version>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>pw.yumc:YumCore</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>pw.yumc.YumCore</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<ciManagement>
<system>Jenkins</system>
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement>
<properties>
<update.description></update.description>
<update.changes></update.changes>
<env.GIT_COMMIT>DEBUG</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>jtb</id>
<name>YUMC</name>
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<type>jar</type>
<version>1.10.2-R0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>AuthMe</artifactId>
<type>jar</type>
<version>6.1</version>
</dependency>
</dependencies>
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>pw.yumc</groupId>
<artifactId>MiaoLobby</artifactId>
<version>1.4</version>
<build>
<finalName>${project.name}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>pw.yumc:YumCore</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>pw.yumc.YumCore</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
<configuration>
<options>
<option>-keep class ${project.groupId}.${project.artifactId}.${project.artifactId}</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
</libs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<ciManagement>
<system>Jenkins</system>
<url>http://ci.yumc.pw/job/${project.artifactId}/</url>
</ciManagement>
<properties>
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>yumc-repo</id>
<url>http://repo.yumc.pw/content/groups/public/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>jtb</id>
<name>YUMC</name>
<url>http://repo.yumc.pw/content/repositories/yumcenter/</url>
</repository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>pw.yumc</groupId>
<artifactId>YumCore</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>AuthMe</artifactId>
<type>jar</type>
<version>6.1</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>VBossAuth</artifactId>
<version>1.5.2</version>
</dependency>
</dependencies>
</project>

View File

@ -1,21 +0,0 @@
package pw.yumc.MiaoLobby;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import fr.xephi.authme.events.LoginEvent;
import pw.yumc.YumCore.bukkit.P;
public class AuthMeHook implements Listener {
private MiaoLobby plugin = P.getPlugin();
public AuthMeHook() {
Bukkit.getPluginManager().registerEvents(this, P.instance);
}
@EventHandler
public void onLogin(final LoginEvent e) {
plugin.delayTP(e.getPlayer());
}
}

View File

@ -18,7 +18,7 @@ public class Config extends InjectConfig {
public String TPDelay;
public String Unavailable;
public Boolean AutoTP;
public Boolean AuthMeAutoTP;
public Boolean LoginAutoTP;
public Integer AutoTPDelay;
public Boolean ReTry;
}

View File

@ -1,23 +1,14 @@
package pw.yumc.MiaoLobby;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import pw.yumc.MiaoLobby.hook.AuthMeHook;
import pw.yumc.MiaoLobby.hook.LoginHook;
import pw.yumc.MiaoLobby.hook.VBossAuthHook;
import pw.yumc.YumCore.bukkit.Log;
import pw.yumc.YumCore.bukkit.compatible.C;
import pw.yumc.YumCore.commands.CommandArgument;
import pw.yumc.YumCore.commands.CommandExecutor;
import pw.yumc.YumCore.commands.CommandManager;
@ -25,37 +16,18 @@ import pw.yumc.YumCore.commands.annotation.Cmd;
import pw.yumc.YumCore.commands.annotation.Cmd.Executor;
import pw.yumc.YumCore.commands.annotation.Help;
import pw.yumc.YumCore.statistic.Statistics;
import pw.yumc.YumCore.update.SubscribeTask;
public class MiaoLobby extends JavaPlugin implements CommandExecutor, Listener {
public class MiaoLobby extends JavaPlugin implements CommandExecutor {
Config config;
private final SecureRandom random = new SecureRandom();
@Cmd(permission = "MiaoLobby.default", executor = Executor.PLAYER)
@Help("进行随机服务器传送")
public boolean def(final CommandArgument e) {
random((Player) e.getSender());
Util.random((Player) e.getSender());
return true;
}
public void delayTP(final Player player) {
new BukkitRunnable() {
int delay = config.AutoTPDelay;
@Override
public void run() {
if (player.isOnline()) {
if (delay > 0) {
C.ActionBar.send(player, String.format(config.TPDelay, delay));
delay--;
return;
}
random(player);
}
cancel();
}
}.runTaskTimerAsynchronously(this, 0, 20);
}
@Override
public FileConfiguration getConfig() {
return config.getConfig();
@ -66,19 +38,17 @@ public class MiaoLobby extends JavaPlugin implements CommandExecutor, Listener {
new CommandManager("MiaoLobby", this);
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
if (config.AutoTP) {
Bukkit.getPluginManager().registerEvents(this, this);
} else if (config.AuthMeAutoTP && Bukkit.getPluginManager().isPluginEnabled("AuthMe")) {
new AuthMeHook();
new LoginHook();
} else if (config.LoginAutoTP) {
if (Bukkit.getPluginManager().isPluginEnabled("AuthMe")) {
new AuthMeHook();
}
if (Bukkit.getPluginManager().isPluginEnabled("VBossAuth")) {
new VBossAuthHook();
}
}
new Statistics();
// new SubscribeTask(true, true);
}
@EventHandler
public void onJoin(PlayerJoinEvent e) {
if (config.AutoTP) {
delayTP(e.getPlayer());
}
new SubscribeTask(true, true);
}
@Override
@ -92,40 +62,4 @@ public class MiaoLobby extends JavaPlugin implements CommandExecutor, Listener {
config.reload();
Log.toSender(e.getSender(), "§a配置文件已重载!");
}
private void connect(final Player p, final String server) {
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
try {
out.writeUTF("Connect");
out.writeUTF(server);
} catch (final Exception ignored) {
}
p.sendPluginMessage(this, "BungeeCord", out.toByteArray());
}
void random(final Player player) {
new BukkitRunnable() {
List<String> servers = new ArrayList<>(config.Servers);
int i = 0;
@Override
public void run() {
if (servers.isEmpty()) {
if (config.ReTry) {
servers.addAll(config.Servers);
return;
}
C.ActionBar.send(player, config.Unavailable);
player.sendMessage(config.Unavailable);
} else if (player.isOnline()) {
final String sname = servers.remove(random.nextInt(servers.size()));
C.ActionBar.send(player, String.format(i > 0 ? config.TimeOut : config.Message, sname));
connect(player, sname);
i++;
return;
}
cancel();
}
}.runTaskTimerAsynchronously(this, 0, config.WaitTime);
}
}

View File

@ -0,0 +1,79 @@
package pw.yumc.MiaoLobby;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import pw.yumc.YumCore.bukkit.P;
import pw.yumc.YumCore.bukkit.compatible.C;
/**
* @author
* @since 2016/12/25 0025
*/
public class Util {
private final static SecureRandom random = new SecureRandom();
private static MiaoLobby plugin = P.getPlugin();
private static Config config = plugin.config;
public static void delayTp(final Player player) {
new BukkitRunnable() {
int delay = config.AutoTPDelay;
@Override
public void run() {
if (player.isOnline()) {
if (delay > 0) {
C.ActionBar.send(player, String.format(plugin.config.TPDelay, delay));
delay--;
return;
}
random(player);
}
cancel();
}
}.runTaskTimerAsynchronously(plugin, 0, 20);
}
public static void connect(final Player p, final String server) {
final ByteArrayDataOutput out = ByteStreams.newDataOutput();
try {
out.writeUTF("Connect");
out.writeUTF(server);
} catch (final Exception ignored) {
}
p.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
public static void random(final Player player) {
new BukkitRunnable() {
List<String> servers = new ArrayList<>(config.Servers);
int i = 0;
@Override
public void run() {
if (servers.isEmpty()) {
if (config.ReTry) {
servers.addAll(config.Servers);
return;
}
C.ActionBar.send(player, config.Unavailable);
player.sendMessage(config.Unavailable);
} else if (player.isOnline()) {
final String sname = servers.remove(random.nextInt(servers.size()));
C.ActionBar.send(player, String.format(i > 0 ? config.TimeOut : config.Message, sname));
connect(player, sname);
i++;
return;
}
cancel();
}
}.runTaskTimerAsynchronously(plugin, 0, config.WaitTime);
}
}

View File

@ -0,0 +1,13 @@
package pw.yumc.MiaoLobby.hook;
import org.bukkit.event.EventHandler;
import fr.xephi.authme.events.LoginEvent;
import pw.yumc.MiaoLobby.Util;
public class AuthMeHook extends Hook {
@EventHandler
public void onLogin(final LoginEvent e) {
Util.delayTp(e.getPlayer());
}
}

View File

@ -0,0 +1,12 @@
package pw.yumc.MiaoLobby.hook;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import pw.yumc.YumCore.bukkit.P;
public class Hook implements Listener {
public Hook() {
Bukkit.getPluginManager().registerEvents(this, P.instance);
}
}

View File

@ -0,0 +1,15 @@
package pw.yumc.MiaoLobby.hook;
import org.bukkit.event.player.PlayerJoinEvent;
import pw.yumc.MiaoLobby.Util;
/**
* @author
* @since 2016/12/25 0025
*/
public class LoginHook extends Hook {
public void onJoin(PlayerJoinEvent e) {
Util.delayTp(e.getPlayer());
}
}

View File

@ -0,0 +1,13 @@
package pw.yumc.MiaoLobby.hook;
import org.bukkit.event.EventHandler;
import cn.citycraft.VBossAuth.event.LoginEvent;
import pw.yumc.MiaoLobby.Util;
public class VBossAuthHook extends Hook {
@EventHandler
public void onLogin(final LoginEvent e) {
Util.delayTp(e.getPlayer());
}
}

View File

@ -1,17 +1,17 @@
#配置文件版本 请勿修改
Version: 1.3
Version: 1.4
#数据库信息
#服务器列表
Servers:
- lobby1
- lobby2
#传送超时时间(单位: Tick)
WaitTime: 35
#自带传送(如果开启 则AuthMe自动传送失效)
#自带传送(如果开启 则Login自动传送失效)
AutoTP: false
#AuthMe自动传送
AuthMeAutoTP: true
#自动传送延时(单位: 秒)
#登录自动传送(暂时支持AuthMe和VBossAuth)
LoginAutoTP: true
#传送延时(单位: 秒)
AutoTPDelay: 10
#尝试完毕后是否继续重试
ReTry: true