From 7a98072a8dc97bd265c0d4d076e112665d085225 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 15 Sep 2015 20:55:40 +0800 Subject: [PATCH] init project... --- .classpath | 31 +++++++ .gitignore | 38 +++++++++ .project | 23 ++++++ pom.xml | 80 +++++++++++++++++++ .../CTZServerBridge/CTZServerBridge.java | 70 ++++++++++++++++ .../CTZServerBridge/listen/PlayerListen.java | 73 +++++++++++++++++ src/main/resources/plugin.yml | 14 ++++ 7 files changed, 329 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 pom.xml create mode 100644 src/main/java/cn/citycraft/CTZServerBridge/CTZServerBridge.java create mode 100644 src/main/java/cn/citycraft/CTZServerBridge/listen/PlayerListen.java create mode 100644 src/main/resources/plugin.yml diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..d19be42 --- /dev/null +++ b/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..043fc2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +# Eclipse stuff +/.settings + +# netbeans +/nbproject + +# we use maven! +/build.xml + +# maven +/target +/repo + +# vim +.*.sw[a-p] + +# various other potential build files +/build +/bin +/dist +/manifest.mf + +/world + +# Mac filesystem dust +*.DS_Store + +# intellij +*.iml +*.ipr +*.iws +.idea/ + +# Project Stuff +/src/main/resources/Soulbound + +# Atlassian Stuff +/atlassian-ide-plugin.xml \ No newline at end of file diff --git a/.project b/.project new file mode 100644 index 0000000..389e85b --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + CTZServerBridge + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..d168e72 --- /dev/null +++ b/pom.xml @@ -0,0 +1,80 @@ + + 4.0.0 + cn.citycraft + CTZServerBridge + 1.0 + CTZServerBridge + 服务器桥接插件... + + ${project.name} + + + src/main/resources + true + + + + + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + true + + + cn.citycraft:PluginHelper + + + + cn.citycraft.PluginHelper + ${project.groupId}.${project.artifactId} + + + + + package + + shade + + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/groups/public/ + + + citycraft-repo + http://ci.citycraft.cn:8800/jenkins/plugin/repository/everything/ + + + + + org.spigotmc + spigot-api + jar + 1.8.3-R0.1-SNAPSHOT + + + cn.citycraft + PluginHelper + jar + 1.0 + + + + UTF-8 + + \ No newline at end of file diff --git a/src/main/java/cn/citycraft/CTZServerBridge/CTZServerBridge.java b/src/main/java/cn/citycraft/CTZServerBridge/CTZServerBridge.java new file mode 100644 index 0000000..26ff179 --- /dev/null +++ b/src/main/java/cn/citycraft/CTZServerBridge/CTZServerBridge.java @@ -0,0 +1,70 @@ +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.PluginHelper.sql.SQLHelper; + +public class CTZServerBridge extends JavaPlugin { + + ConsoleCommandSender ccs; + SQLHelper sql; + + public SQLHelper getSql() { + return sql; + } + + @Override + public void onDisable() { + super.onDisable(); + } + + @Override + public void onEnable() { + this.initDatabase(); + this.initListener(); + } + + private void initListener() { + PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents(new PlayerListen(this), this); + } + + /** + * 初始化数据库 + */ + 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"); + String Conditions = "UNIQUE (`player`)"; + if (!sql.createTables(dbtable, kv, Conditions)) + ccs.sendMessage(ChatColor.RED + "数据表 " + dbtable + " 创建失败,请尝试手动创建并重启服务器..."); + else + ccs.sendMessage(ChatColor.GREEN + "数据表 " + dbtable + " 创建成功..."); + } + } +} diff --git a/src/main/java/cn/citycraft/CTZServerBridge/listen/PlayerListen.java b/src/main/java/cn/citycraft/CTZServerBridge/listen/PlayerListen.java new file mode 100644 index 0000000..c6aa549 --- /dev/null +++ b/src/main/java/cn/citycraft/CTZServerBridge/listen/PlayerListen.java @@ -0,0 +1,73 @@ +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.PlayerLoginEvent; +import org.bukkit.event.player.PlayerLoginEvent.Result; + +import cn.citycraft.CTZServerBridge.CTZServerBridge; +import cn.citycraft.PluginHelper.sql.KeyValue; + +public class PlayerListen implements Listener { + static final String TableName = "ctzserver"; + static final String UserField = "player"; + static final String PWDField = "password"; + CTZServerBridge plugin; + + public PlayerListen(CTZServerBridge ctzServerBridge) { + plugin = ctzServerBridge; + } + + @EventHandler + public void Join(PlayerLoginEvent e) { + Player p = e.getPlayer(); + String result = plugin.getSql().dbSelectFirst(TableName, "islogged", new KeyValue(UserField, p.getName())); + if (result == null && !result.equalsIgnoreCase("1")) { + e.setKickMessage("§6[§bCTZLS§6] §c禁止入服 请使用服务器专用启动器进入游戏!"); + e.setResult(Result.KICK_WHITELIST); + } + } +} +// 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()); +// } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..0ffe0bc --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,14 @@ +name: ${project.artifactId} +description: ${project.description} +main: ${project.groupId}.${project.artifactId}.${project.artifactId} +version: ${project.version} +auther: 喵♂呜 +website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/ +commands: + ctzs: + description: CTZ服务器桥接插件 + usage: §b使用/ctzs help 查看帮助! +permissions: + ctzs.reload: + description: 重新载入插件! + default: op \ No newline at end of file