1
0
mirror of https://e.coding.net/circlecloud/CTZServerBridge.git synced 2024-11-15 12:28:46 +00:00

use CTZServerCommon...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-09-16 14:15:32 +08:00
parent 4b11a9ddfe
commit 7231ef6cd3
3 changed files with 36 additions and 77 deletions

View File

@ -28,6 +28,7 @@
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
@ -73,6 +74,12 @@
<type>jar</type>
<version>1.0</version>
</dependency>
<dependency>
<groupId>cn.citycraft</groupId>
<artifactId>CTZServerCommon</artifactId>
<type>jar</type>
<version>1.0</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -1,20 +1,20 @@
package cn.citycraft.CTZServerBridge;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.CTZServerBridge.listen.PlayerListen;
import cn.citycraft.PluginHelper.sql.KeyValue;
import cn.citycraft.PluginHelper.sql.MySQLHelper;
import cn.citycraft.CTZServerCommon.CTZAuth;
import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.sql.SQLHelper;
public class CTZServerBridge extends JavaPlugin {
ConsoleCommandSender ccs;
SQLHelper sql;
public FileConfig config;
public SQLHelper getSql() {
return sql;
@ -23,7 +23,7 @@ public class CTZServerBridge extends JavaPlugin {
@Override
public void onDisable() {
super.onDisable();
}
};
@Override
public void onEnable() {
@ -31,6 +31,11 @@ public class CTZServerBridge extends JavaPlugin {
this.initListener();
}
@Override
public void onLoad() {
config = new FileConfig(this);
}
private void initListener() {
PluginManager pm = Bukkit.getPluginManager();
pm.registerEvents(new PlayerListen(this), this);
@ -40,32 +45,6 @@ public class CTZServerBridge extends JavaPlugin {
* 初始化数据库
*/
void initDatabase() {
String dbtable = "ctzserver";
ccs.sendMessage(ChatColor.GREEN + "初始化数据库连接...");
sql = new MySQLHelper("127.0.0.1", 3306, "minecraft", "root", "325325");
if (!sql.dbConnection()) {
ccs.sendMessage(ChatColor.RED + "数据库连接失败...");
return;
}
ccs.sendMessage(ChatColor.GREEN + "数据库连接成功,检查数据表是否存在...");
if (!sql.isTableExists(dbtable)) {
ccs.sendMessage(ChatColor.RED + "数据表不存在,新建表" + dbtable + "...");
KeyValue kv = new KeyValue("player", "VARCHAR(16) NOT NULL")
.add("password", "VARCHAR(50) NOT NULL")
.add("ip", "VARCHAR(40) NOT NULL DEFAULT '127.0.0.1'")
.add("lastloginout", "BIGINT(20) NOT NULL DEFAULT 0")
.add("x", "DOUBLE NOT NULL DEFAULT 0")
.add("y", "DOUBLE NOT NULL DEFAULT 0")
.add("z", "DOUBLE NOT NULL DEFAULT 0")
.add("email", "VARCHAR(50) NOT NULL DEFAULT 'mc@mc.com'")
.add("world", "VARCHAR(20) DEFAULT 'world'")
.add("islogged", "SMALLINT(6) NOT NULL DEFAULT 0")
.add("allowlogin", "SMALLINT(6) NOT NULL DEFAULT 0");
String Conditions = "UNIQUE (`player`)";
if (!sql.createTables(dbtable, kv, Conditions))
ccs.sendMessage(ChatColor.RED + "数据表 " + dbtable + " 创建失败,请尝试手动创建并重启服务器...");
else
ccs.sendMessage(ChatColor.GREEN + "数据表 " + dbtable + " 创建成功...");
}
CTZAuth.init(sql, "127.0.0.1", 3306, "ctzserver", "root", "325325");
}
}

View File

@ -3,11 +3,13 @@ package cn.citycraft.CTZServerBridge.listen;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerQuitEvent;
import cn.citycraft.CTZServerBridge.CTZServerBridge;
import cn.citycraft.PluginHelper.sql.KeyValue;
import cn.citycraft.CTZServerCommon.CTZAuth;
public class PlayerListen implements Listener {
static final String TableName = "ctzserver";
@ -20,54 +22,25 @@ public class PlayerListen implements Listener {
}
@EventHandler
public void Join(PlayerLoginEvent e) {
public void PlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
String result = plugin.getSql().dbSelectFirst(TableName, "islogged", new KeyValue(UserField, p.getName()));
if (result == null && !result.equalsIgnoreCase("1")) {
p.sendMessage("§b欢迎回来,已帮您已经自动登录到服务器!");
}
@EventHandler
public void PlayerLogin(PlayerLoginEvent e) {
Player p = e.getPlayer();
if (CTZAuth.checkLastLogout(p.getName(), 10))
return;
if (!CTZAuth.allowLogin(p.getName(), plugin.config.getBoolean("checkip") ? p.getAddress().getAddress().getHostAddress() : null)) {
e.setKickMessage("§6[§bCTZLS§6] §c禁止入服 请使用服务器专用启动器进入游戏!");
e.setResult(Result.KICK_WHITELIST);
}
}
@EventHandler
public void PlayerQuit(PlayerQuitEvent e) {
Player p = e.getPlayer();
CTZAuth.setLastLogout(p.getName(), System.currentTimeMillis());
}
}
// private long getNowTime() {
// return System.currentTimeMillis() / 1000;
// }
//
// @EventHandler
// public void PlayerLogin(PlayerLoginEvent e) {
// String name = e.getPlayer().getName().toLowerCase();
// long lasttime = lastquittime.get(name) == null ? 0 : lastquittime.get(name);
// e.setKickMessage("§6[§bCTZLS§6] §c禁止入服 请使用服务器专用启动器进入游戏!");
// if (getNowTime() - lasttime < Config.getInstance().getInt("server.timeout")) {
// return;
// }
// if (CTZLoginQueue.canLogin(name, e.getAddress().getHostAddress())) {
// return;
// } else {
// if (CTZLoginQueue.canLogin(name))
// if (CTZLoginQueue.isCheckIP())
// e.setKickMessage("§6[§bCTZLS§6] §c禁止入服 申请登录的IP与客户端IP不同!");
// else
// return;
// }
// if (!Config.getInstance().getBoolean("config.forceclient"))
// return;
// e.setResult(Result.KICK_WHITELIST);
// }
//
// @EventHandler(priority = EventPriority.LOWEST)
// public void PlayerJoin(PlayerJoinEvent e) {
// String name = e.getPlayer().getName().toLowerCase();
// if (lastquittime.containsKey(name)) {
// API.forceLogin(e.getPlayer());
// return;
// }
// if (CTZLoginQueue.Login(name)) {
// API.forceLogin(e.getPlayer());
// }
// }
//
// @EventHandler
// public void PlayerQuit(PlayerQuitEvent e) {
// lastquittime.put(e.getPlayer().getName().toLowerCase(), getNowTime());
// }