diff --git a/pom.xml b/pom.xml
index bf4e4d0..5280ec0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,9 +6,72 @@
org.lintx.plugin
WebAuth
- 1.3.0-SNAPSHOT
+ 1.4
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.1
+
+
+ 1.8
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.1.0
+
+
+ package
+
+ shade
+
+
+
+
+ org.bstats
+ org.lintx.plugins.webauth.maven.bstats
+
+
+ org.lintx.plugins.modules
+ org.lintx.plugins.webauth.maven.modules
+
+
+ true
+
+
+ org.bstats
+ org.lintx.plugins.modules
+
+
+
+
+
+
+
+
+
+ true
+ src/main/resources
+
+
+
+
+
+ CodeMC
+ https://repo.codemc.io/repository/maven-public/
+
+
+
+ org.projectlombok
+ lombok
+ 1.16.16
+ provided
+
net.md-5.bungee
BungeeCord
@@ -16,17 +79,23 @@
system
${project.basedir}/libs/BungeeCord.jar
-
- org.lintx.plugins.modules
- Configure
- 1.0
- system
- ${project.basedir}/libs/Configure-1.2.3-SNAPSHOT.jar
-
-
+
+
+
+
+ org.bstats
+ bstats-bungeecord
+ 1.5
+ compile
+
+
+ org.lintx.plugins.modules
+ Configure
+ 1.2.3-SNAPSHOT
+
\ No newline at end of file
diff --git a/src/main/java/org/lintx/plugin/webauth/Commands.java b/src/main/java/org/lintx/plugin/webauth/Commands.java
index 01f3e1f..3d2b0a3 100644
--- a/src/main/java/org/lintx/plugin/webauth/Commands.java
+++ b/src/main/java/org/lintx/plugin/webauth/Commands.java
@@ -1,11 +1,13 @@
package org.lintx.plugin.webauth;
-import com.google.common.base.Charsets;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Command;
+import org.lintx.plugin.webauth.httpserver.Caches;
+import org.lintx.plugin.webauth.httpserver.Messages;
import org.lintx.plugin.webauth.models.PlayerModel;
+import org.lintx.plugin.webauth.utils.MojangApi;
import org.lintx.plugin.webauth.utils.Utils;
import java.io.*;
@@ -48,8 +50,22 @@ public void execute(CommandSender sender, String[] args) {
sender.sendMessage(new TextComponent(Message.playerNameLong));
return;
}
+
String password = args[3];
PlayerModel model = new PlayerModel(username,password);
+ if (Config.getInstance().isCheckPlayerNameFromMojang()){
+ MojangApi.MojangAccount account = MojangApi.getMojangAccount(username);
+ if (!account.checkName(username)){
+ if (args.length == 4 || (!args[4].equalsIgnoreCase("confirm") && !args[4].equalsIgnoreCase("ignore"))){
+ sender.sendMessage(new TextComponent(Message.addMojangPlayer.replaceAll("\\{name\\}",username).replaceAll("\\{uuid\\}",account.id)));
+ return;
+ }
+ if (args[4].equalsIgnoreCase("confirm")){
+ model.setUuid(account.getUUID());
+ }
+ }
+ }
+
if (auth.getModel().insertPlayer(model)){
model = auth.getModel().getPlayerWithPlayerName(username);
sender.sendMessage(new TextComponent(Message.addPlayerSuccess));
diff --git a/src/main/java/org/lintx/plugin/webauth/Config.java b/src/main/java/org/lintx/plugin/webauth/Config.java
index fbdd861..6870d9b 100644
--- a/src/main/java/org/lintx/plugin/webauth/Config.java
+++ b/src/main/java/org/lintx/plugin/webauth/Config.java
@@ -1,5 +1,6 @@
package org.lintx.plugin.webauth;
+import lombok.Getter;
import org.lintx.plugin.webauth.config.DatabaseConfig;
import org.lintx.plugins.modules.configure.Configure;
import org.lintx.plugins.modules.configure.YamlConfig;
@@ -24,111 +25,65 @@ public void load(WebAuth plugin){
}
@YamlConfig
+ @Getter
private String notRegister = "你还没有注册,请打开网页\n{url}\n注册后登录游戏";
+
@YamlConfig
+ @Getter
private String tokenIsValid = "登录凭证无效,请检查您的凭证\n如忘记凭证请打开网页\n{url}\n重置凭证";
+
@YamlConfig
+ @Getter
private String tokenIsExpired = "登录凭证已过期,请打开网页\n{url}\n重置凭证";
+
@YamlConfig
+ @Getter
private String nameIsValid = "玩家名中含有不允许的字符,请打开网页\n{url}\n修改玩家名或联系管理员";
+
@YamlConfig
private String tokenManageUrl = "";
+
@YamlConfig
+ @Getter
private DatabaseConfig databaseConfig = new DatabaseConfig();
+
@YamlConfig
+ @Getter
private int webPort = 0;
+
@YamlConfig
+ @Getter
private boolean openRegister = true;
+
@YamlConfig
+ @Getter
private boolean openChangePlayername = false;
+
@YamlConfig
+ @Getter
private String playerNameRegexp = "^[a-zA-Z0-9\\u4e00-\\u9fa5]+$";
- public String getNameIsValid() {
- return nameIsValid;
- }
+ @YamlConfig
+ @Getter
+ private boolean checkPlayerNameFromMojang = false;
- public void setNameIsValid(String nameIsValid) {
- this.nameIsValid = nameIsValid;
- }
+ @YamlConfig
+ @Getter
+ private String httpProxyType = "http/socks";
- public String getPlayerNameRegexp() {
- return playerNameRegexp;
- }
+ @YamlConfig
+ @Getter
+ private String httpProxyAddress = "";
- public void setPlayerNameRegexp(String playerNameRegexp) {
- this.playerNameRegexp = playerNameRegexp;
- }
+ @YamlConfig
+ @Getter
+ private int httpProxyPort = 0;
public String formatMessage(String message){
return message.replaceAll("\\{url\\}",tokenManageUrl);
}
- public String getNotRegister() {
- return notRegister;
- }
-
- public void setNotRegister(String notRegister) {
- this.notRegister = notRegister;
- }
-
- public String getTokenIsValid() {
- return tokenIsValid;
- }
-
- public void setTokenIsValid(String tokenIsValid) {
- this.tokenIsValid = tokenIsValid;
- }
-
- public String getTokenIsExpired() {
- return tokenIsExpired;
- }
-
- public void setTokenIsExpired(String tokenIsExpired) {
- this.tokenIsExpired = tokenIsExpired;
- }
-
public static void setInstance(Config instance) {
Config.instance = instance;
}
-
- public String getTokenManageUrl() {
- return tokenManageUrl;
- }
-
- public void setTokenManageUrl(String tokenManageUrl) {
- this.tokenManageUrl = tokenManageUrl;
- }
-
- public DatabaseConfig getDatabaseConfig() {
- return databaseConfig;
- }
-
- public void setDatabaseConfig(DatabaseConfig databaseConfig) {
- this.databaseConfig = databaseConfig;
- }
-
- public int getWebPort() {
- return webPort;
- }
-
- public void setWebPort(int webPort) {
- this.webPort = webPort;
- }
-
- public boolean isOpenRegister() {
- return openRegister;
- }
-
- public void setOpenRegister(boolean openRegister) {
- this.openRegister = openRegister;
- }
-
- public boolean isOpenChangePlayername() {
- return openChangePlayername;
- }
-
- public void setOpenChangePlayername(boolean openChangePlayername) {
- this.openChangePlayername = openChangePlayername;
- }
}
diff --git a/src/main/java/org/lintx/plugin/webauth/Listeners.java b/src/main/java/org/lintx/plugin/webauth/Listeners.java
index a9478ef..3247c2a 100644
--- a/src/main/java/org/lintx/plugin/webauth/Listeners.java
+++ b/src/main/java/org/lintx/plugin/webauth/Listeners.java
@@ -1,8 +1,5 @@
package org.lintx.plugin.webauth;
-import net.md_5.bungee.api.chat.BaseComponent;
-import net.md_5.bungee.api.chat.ClickEvent;
-import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.event.PreLoginEvent;
@@ -11,9 +8,6 @@
import net.md_5.bungee.event.EventHandler;
import org.lintx.plugin.webauth.models.PlayerModel;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Listeners implements Listener {
diff --git a/src/main/java/org/lintx/plugin/webauth/Message.java b/src/main/java/org/lintx/plugin/webauth/Message.java
index b7627aa..59dff9a 100644
--- a/src/main/java/org/lintx/plugin/webauth/Message.java
+++ b/src/main/java/org/lintx/plugin/webauth/Message.java
@@ -30,6 +30,9 @@ public class Message {
static final String passwordUpdateSuccess = "§a密码更新成功";
static final String addPlayerFail = "§c新增玩家失败";
static final String addPlayerSuccess = "§a新增玩家成功";
+ static final String addMojangPlayer = "§a新增玩家{name}经查询是正版玩家,UUID为{uuid}。\n" +
+ "§a新增并设置UUID为正版UUID请输入命令§b/webauth player add {name} 密码 confirm\n" +
+ "§a新增并不设置UUID为正版UUID请输入命令§b/webauth player add {name} 密码 ignore";
static final String playerNameRepeat = "§c玩家用户名或玩家名重复";
static final String reloadConfig = "§a重新加载配置文件";
static final String playerNameShort = "§c玩家名太短(不能小于4字符)";
diff --git a/src/main/java/org/lintx/plugin/webauth/WebAuth.java b/src/main/java/org/lintx/plugin/webauth/WebAuth.java
index da0e81a..95d151b 100644
--- a/src/main/java/org/lintx/plugin/webauth/WebAuth.java
+++ b/src/main/java/org/lintx/plugin/webauth/WebAuth.java
@@ -2,6 +2,7 @@
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.api.scheduler.ScheduledTask;
+import org.bstats.bungeecord.Metrics;
import org.lintx.plugin.webauth.config.DatabaseConfig;
import org.lintx.plugin.webauth.httpserver.Caches;
import org.lintx.plugin.webauth.httpserver.NettyHttpServer;
@@ -33,6 +34,8 @@ public void onEnable() {
getProxy().getPluginManager().registerListener(this,new Listeners(this));
getProxy().getPluginManager().registerCommand(this,new Commands(this,"webauth",null,"auth","wa"));
+
+ Metrics metrics = new Metrics(this);
}
@Override
@@ -128,7 +131,7 @@ void reload(){
if (mySql!=null){
mySql.close();
}
- mySql = new MySql(config.getDatabaseConfig().getMysqlUri(),config.getDatabaseConfig().getMysqlUser(),config.getDatabaseConfig().getMysqlPassword());
+ mySql = new MySql(config.getDatabaseConfig().getMysqlUri(),config.getDatabaseConfig().getMysqlUser(),config.getDatabaseConfig().getMysqlPassword(),config.getDatabaseConfig().getTimeout());
model = new Model(mySql);
}else {
sqLite = new SQLite(getDataFolder(),"database");
diff --git a/src/main/java/org/lintx/plugin/webauth/config/DatabaseConfig.java b/src/main/java/org/lintx/plugin/webauth/config/DatabaseConfig.java
index 8435538..5c64a63 100644
--- a/src/main/java/org/lintx/plugin/webauth/config/DatabaseConfig.java
+++ b/src/main/java/org/lintx/plugin/webauth/config/DatabaseConfig.java
@@ -16,6 +16,26 @@ public enum DatabaseType{
private String mysqlUser = "root";
@YamlConfig
private String mysqlPassword = "root";
+ @YamlConfig
+ private boolean printError = false;
+ @YamlConfig
+ private long timeout = 60 * 60 * 5;
+
+ public long getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public boolean isPrintError() {
+ return printError;
+ }
+
+ public void setPrintError(boolean printError) {
+ this.printError = printError;
+ }
public DatabaseType getType() {
return type;
diff --git a/src/main/java/org/lintx/plugin/webauth/httpserver/Messages.java b/src/main/java/org/lintx/plugin/webauth/httpserver/Messages.java
index d340dbe..3a7d0c9 100644
--- a/src/main/java/org/lintx/plugin/webauth/httpserver/Messages.java
+++ b/src/main/java/org/lintx/plugin/webauth/httpserver/Messages.java
@@ -5,6 +5,7 @@ public class Messages {
static final String usernameShort = "用户名太短(不能小于4字符)";
static final String usernameLong = "用户名太长(不能大于16字符)";
static final String usernameRepeat = "用户名重复";
+ static final String usernameInMojang = "存在同名正版帐号";
static final String playerNameRepeat = "玩家名重复";
static final String playerNameShort = "玩家名太短(不能小于4字符)";
static final String playerNameLong = "玩家名太长(不能大于16字符)";
diff --git a/src/main/java/org/lintx/plugin/webauth/httpserver/NettyHttpHandler.java b/src/main/java/org/lintx/plugin/webauth/httpserver/NettyHttpHandler.java
index f1febdf..6dfa66f 100644
--- a/src/main/java/org/lintx/plugin/webauth/httpserver/NettyHttpHandler.java
+++ b/src/main/java/org/lintx/plugin/webauth/httpserver/NettyHttpHandler.java
@@ -10,6 +10,7 @@
import org.lintx.plugin.webauth.Config;
import org.lintx.plugin.webauth.WebAuth;
import org.lintx.plugin.webauth.models.PlayerModel;
+import org.lintx.plugin.webauth.utils.MojangApi;
import org.lintx.plugin.webauth.utils.Utils;
import java.io.*;
@@ -126,6 +127,14 @@ protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request)
Caches.loginFail(ip);
return;
}
+ if (Config.getInstance().isCheckPlayerNameFromMojang()){
+ MojangApi.MojangAccount account = MojangApi.getMojangAccount(inputModel.getUsername());
+ if (!account.checkName(inputModel.getUsername())){
+ writeError(ctx,Messages.usernameInMojang);
+ Caches.loginFail(ip);
+ return;
+ }
+ }
model = new PlayerModel(inputModel.getUsername(),inputModel.getPassword());
if (WebAuth.plugin.getModel().insertPlayer(model)){
writeSuccess(ctx,Messages.registerSuccess);
diff --git a/src/main/java/org/lintx/plugin/webauth/sql/Model.java b/src/main/java/org/lintx/plugin/webauth/sql/Model.java
index d0e5e5d..eb22772 100644
--- a/src/main/java/org/lintx/plugin/webauth/sql/Model.java
+++ b/src/main/java/org/lintx/plugin/webauth/sql/Model.java
@@ -1,5 +1,6 @@
package org.lintx.plugin.webauth.sql;
+import org.lintx.plugin.webauth.Config;
import org.lintx.plugin.webauth.models.PlayerModel;
import org.lintx.plugin.webauth.utils.Utils;
@@ -27,8 +28,10 @@ private PlayerModel playerModelWithResultSet(ResultSet rs){
model.setToken(rs.getString("token"));
model.setToken_timeString(rs.getString("token_time"));
return model;
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
}
return null;
}
@@ -46,8 +49,10 @@ public PlayerModel getPlayerWithId(int id){
while(rs.next()){
return playerModelWithResultSet(rs);
}
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
} finally {
release(conn,ps,rs);
}
@@ -67,8 +72,10 @@ public PlayerModel getPlayerWithUUID(UUID uuid){
while(rs.next()){
return playerModelWithResultSet(rs);
}
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
} finally {
release(conn,ps,rs);
}
@@ -88,8 +95,10 @@ public PlayerModel getPlayerWithToken(String token){
while(rs.next()){
return playerModelWithResultSet(rs);
}
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
} finally {
release(conn,ps,rs);
}
@@ -109,8 +118,10 @@ public PlayerModel getPlayerWithUsername(String username){
while(rs.next()){
return playerModelWithResultSet(rs);
}
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
} finally {
release(conn,ps,rs);
}
@@ -130,8 +141,10 @@ public PlayerModel getPlayerWithPlayerName(String name){
while(rs.next()){
return playerModelWithResultSet(rs);
}
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
} finally {
release(conn,ps,rs);
}
@@ -153,8 +166,10 @@ public boolean updatePlayer(PlayerModel model){
int r = ps.executeUpdate();
return r>0;
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
} finally {
release(conn,ps,null);
}
@@ -191,8 +206,10 @@ public boolean insertPlayer(PlayerModel model){
int r = ps.executeUpdate();
return r>0;
- } catch (SQLException ignored) {
-
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
} finally {
release(conn,ps,null);
}
@@ -203,22 +220,28 @@ private void release(Connection conn, PreparedStatement ps, ResultSet rs) {
if (rs != null) {
try {
rs.close();
- } catch (Exception ignored) {
-
+ } catch (Exception e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
}
}
if (ps != null) {
try {
ps.close();
- } catch (Exception ignored) {
-
+ } catch (Exception e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
}
}
if (conn != null) {
try {
conn.close();
- } catch (Exception ignored) {
-
+ } catch (Exception e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
}
}
}
diff --git a/src/main/java/org/lintx/plugin/webauth/sql/MySql.java b/src/main/java/org/lintx/plugin/webauth/sql/MySql.java
index cc4e3e0..a73ad6c 100644
--- a/src/main/java/org/lintx/plugin/webauth/sql/MySql.java
+++ b/src/main/java/org/lintx/plugin/webauth/sql/MySql.java
@@ -1,9 +1,11 @@
package org.lintx.plugin.webauth.sql;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
+import org.lintx.plugin.webauth.Config;
+
import java.lang.reflect.Proxy;
import java.sql.*;
+import java.time.Duration;
+import java.time.LocalDateTime;
import java.util.*;
public class MySql implements SqlInterface {
@@ -11,20 +13,21 @@ public class MySql implements SqlInterface {
private static String username;
private static String password;
- private static LinkedList linkedlist = new LinkedList();
+// private static LinkedList linkedlist = new LinkedList<>();
+ private static LinkedList pools = new LinkedList<>();
//最小连接数量
private static int jdbcConnectionInitSize = 10;
//当前最大连接数量=max*jdbcConnectionInitSize
private static int max = 1;
- //是否真的关闭连接
- private boolean onClose = false;
+ private final long timeout;
- public MySql(String uri,String username,String password){
+ public MySql(String uri,String username,String password,long timeout){
MySql.db_url = uri;
MySql.username = username;
MySql.password = password;
+ this.timeout = timeout;
load();
}
@@ -33,19 +36,22 @@ public void close(){
}
private void linkedListClear(){
- onClose = true;
try {
- final Connection conn = linkedlist.removeFirst();
- if (conn!=null) {
- conn.close();
+ final ConnectionPool pool = pools.removeFirst();
+ if (pool!=null) {
+ pool.close = true;
+ pool.connection.close();
linkedListClear();
}
- } catch (Exception ignored) {
+ } catch (Exception e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
}
}
public Connection getSQLConnection() {
- if (linkedlist.size() == 0 && max <= 5) {
+ if (pools.size() == 0 && max <= 5 * jdbcConnectionInitSize) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
@@ -54,34 +60,52 @@ public Connection getSQLConnection() {
try {
for (int i = 0; i < jdbcConnectionInitSize; i++) {
Connection conn = DriverManager.getConnection(db_url, username, password);
- linkedlist.add(conn);
+ ConnectionPool pool = new ConnectionPool(conn,timeout);
+ pool.connection = (Connection) Proxy.newProxyInstance(
+ pool.connection.getClass().getClassLoader(),
+ pool.connection.getClass().getInterfaces(), (proxy, method, args) -> {
+ if (!method.getName().equalsIgnoreCase("close") || pool.close) {
+ if (method.getName().equalsIgnoreCase("close") && pool.close){
+ max--;
+ }
+ return method.invoke(pool.connection, args);
+ } else {
+ pool.update();
+ pools.add(pool);
+ return null;
+ }
+ }
+ );
+
+ pools.add(pool);
+ max++;
}
- max++;
}
catch (Exception e){
- e.printStackTrace();
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
}
}
- if (linkedlist.size() > 0) {
- final Connection conn1 = linkedlist.removeFirst();
- return (Connection) Proxy.newProxyInstance(
- conn1.getClass().getClassLoader(),
- conn1.getClass().getInterfaces(), new InvocationHandler() {
- @Override
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
- if (!method.getName().equalsIgnoreCase("close") || onClose) {
- return method.invoke(conn1, args);
- } else {
- linkedlist.add(conn1);
- return null;
- }
- }
- }
- );
+ if (pools.size() > 0) {
+ final ConnectionPool pool = pools.removeFirst();
+ if (!pool.check()){
+ pool.close = true;
+ try {
+ pool.connection.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return getSQLConnection();
+ }
+
+ return pool.connection;
}
return null;
}
+
+
private void load() {
Connection connection = getSQLConnection();
if (connection==null){
@@ -107,12 +131,37 @@ private void load() {
// s.executeUpdate(SQLiteCreateTable2);
s.close();
} catch (SQLException e) {
- e.printStackTrace();
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
}
try {
connection.close();
- } catch (SQLException ignored) {
+ } catch (SQLException e) {
+ if (Config.getInstance().getDatabaseConfig().isPrintError()){
+ e.printStackTrace();
+ }
+ }
+ }
+
+ static class ConnectionPool{
+ Connection connection;
+ LocalDateTime lastTime;
+ final long timeout;
+ boolean close = false;
+ ConnectionPool(Connection connection,long timeout){
+ this.connection = connection;
+ this.timeout = timeout;
+ update();
+ }
+
+ void update(){
+ lastTime = LocalDateTime.now();
+ }
+ boolean check(){
+ Duration duration = Duration.between(LocalDateTime.now(),lastTime);
+ return duration.getSeconds() > timeout;
}
}
}
diff --git a/src/main/java/org/lintx/plugin/webauth/utils/MojangApi.java b/src/main/java/org/lintx/plugin/webauth/utils/MojangApi.java
new file mode 100644
index 0000000..8f09a90
--- /dev/null
+++ b/src/main/java/org/lintx/plugin/webauth/utils/MojangApi.java
@@ -0,0 +1,71 @@
+package org.lintx.plugin.webauth.utils;
+
+import com.google.gson.Gson;
+import org.lintx.plugin.webauth.Config;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.HttpURLConnection;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.UUID;
+
+public class MojangApi {
+ public static MojangAccount getMojangAccount(String name){
+ try {
+ String url = "https://api.mojang.com/users/profiles/minecraft/" + name;
+ URL obj = new URL(url);
+ Config config = Config.getInstance();
+ HttpURLConnection conn;
+ if (!config.getHttpProxyAddress().isEmpty() && config.getHttpProxyPort()>0){
+ Proxy.Type proxyType = Proxy.Type.HTTP;
+ if (config.getHttpProxyType().equalsIgnoreCase("socks")){
+ proxyType = Proxy.Type.SOCKS;
+ }
+ Proxy proxy = new Proxy(proxyType,new InetSocketAddress(config.getHttpProxyAddress(),config.getHttpProxyPort()));
+ conn = (HttpURLConnection) obj.openConnection(proxy);
+ }else {
+ conn = (HttpURLConnection) obj.openConnection();
+ }
+ conn.setRequestMethod("GET");
+
+ if (conn.getInputStream()==null){
+ return new MojangAccount();
+ }
+
+ try(Reader reader = new InputStreamReader(conn.getInputStream(),StandardCharsets.UTF_8)) {
+ return new Gson().fromJson(reader,MojangAccount.class);
+ } catch (IOException ignored) {
+
+ }
+ }catch (Exception ignore){
+
+ }
+ return new MojangAccount();
+ }
+
+ public static class MojangAccount{
+ public String id = "";
+ public String name = "";
+
+ public boolean checkName(String name){
+ return !name.equalsIgnoreCase(this.name);
+ }
+
+ public UUID getUUID(){
+ String str = this.name;
+ if (str==null || str.isEmpty()) return null;
+ if (str.length()==32){
+ str = str.substring(0,8) + "-" + str.substring(8,12) + "-" + str.substring(12,16) + "-" + str.substring(16,20) + "-" + str.substring(20,32);
+ }
+ try {
+ return UUID.fromString(str);
+ }catch (Exception ignore){
+ return null;
+ }
+ }
+ }
+}
diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml
index 0735764..e54fb8d 100644
--- a/src/main/resources/bungee.yml
+++ b/src/main/resources/bungee.yml
@@ -1,4 +1,4 @@
main: org.lintx.plugin.webauth.WebAuth
-name: WebAuth
-version: 1.3.0
+name: ${artifactId}
+version: ${version}
author: LinTx
\ No newline at end of file