From 59169ad42d6c18d8d6ed36c04e013b40f70c64c1 Mon Sep 17 00:00:00 2001 From: j502647092 Date: Sat, 25 Jul 2015 18:15:14 +0800 Subject: [PATCH] Add Socket Class... Signed-off-by: j502647092 --- .../CTZLoginServer/CTZLoginServer.java | 68 ++++++++++++------- .../Socket/CTZLoginServerSocket.java | 60 ++++++++++++++++ src/config.yml | 12 ++++ src/plugin.yml | 14 ++++ 4 files changed, 129 insertions(+), 25 deletions(-) create mode 100644 src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java create mode 100644 src/config.yml create mode 100644 src/plugin.yml diff --git a/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java b/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java index 8113403..44db25b 100644 --- a/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java +++ b/src/cn/citycraft/CTZLoginServer/CTZLoginServer.java @@ -1,25 +1,43 @@ -package cn.citycraft.CTZLoginServer; - -import org.bukkit.plugin.java.JavaPlugin; - -import cn.citycraft.CTZLoginServer.config.Config; - - -public class CTZLoginServer extends JavaPlugin{ - @Override - public void onDisable() { - getLogger().info("Gui登陆界面已卸载!"); - } - - @Override - public void onEnable() { - //PluginManager pm = Bukkit.getPluginManager(); - - getLogger().info("Gui登陆界面已加载!"); - } - - @Override - public void onLoad() { - Config.load(this, "1.1"); - } -} +package cn.citycraft.CTZLoginServer; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.java.JavaPlugin; + +import cn.citycraft.CTZLoginServer.config.Config; + + +public class CTZLoginServer extends JavaPlugin{ + public String version; + + @Override + public void onDisable() { + getLogger().info("已卸载!"); + } + + @Override + public void onEnable() { + PluginManager pm = Bukkit.getPluginManager(); + version = this.getServer().getBukkitVersion().substring(0, 5); + this.getLogger().info("Bukkit 版本: " + version); + if (pm.isPluginEnabled("AuthMe")) { + this.getLogger().info("发现前置插件 AuthMe 载入API..."); + } else { + this.getLogger().info("未发现 前置插件 AuthMe 关闭插件..."); + pm.disablePlugin(this); + return; + } + + getLogger().info("已加载!"); + } + + @Override + public void onLoad() { + Config.load(this, "1.0"); + } +} + + + + + diff --git a/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java b/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java new file mode 100644 index 0000000..1c03adf --- /dev/null +++ b/src/cn/citycraft/CTZLoginServer/Socket/CTZLoginServerSocket.java @@ -0,0 +1,60 @@ +package cn.citycraft.CTZLoginServer.Socket; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.ServerSocket; +import java.net.Socket; + +public class CTZLoginServerSocket { + + public static int PORT = 8080; + public static void main(String[] agrs) { + ServerSocket s = null; + Socket socket = null; + BufferedReader br = null; + PrintWriter pw = null; + try { + //设定服务端的端口号 + s = new ServerSocket(PORT); + System.out.println("ServerSocket Start:"+s); + //等待请求,此方法会一直阻塞,直到获得请求才往下走 + socket = s.accept(); + System.out.println("Connection accept socket:"+socket); + //用于接收客户端发来的请求 + br = new BufferedReader(new InputStreamReader(socket.getInputStream())); + //用于发送返回信息,可以不需要装饰这么多io流使用缓冲流时发送数据要注意调用.flush()方法 + pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true); + while(true){ + String str = br.readLine(); + if(str.equals("END")){ + break; + } + System.out.println("Client Socket Message:"+str); + Thread.sleep(1000); + pw.println("Message Received"); + pw.flush(); + } + + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }finally{ + System.out.println("Close....."); + try { + br.close(); + pw.close(); + socket.close(); + s.close(); + } catch (Exception e2) { + + } + } + } + +} + + + diff --git a/src/config.yml b/src/config.yml new file mode 100644 index 0000000..5bd142f --- /dev/null +++ b/src/config.yml @@ -0,0 +1,12 @@ +#本文件为登录插件的主配置文件 +version: '1.0' +#服务器名称 +servername: '' +#插件名称 +pluginname: '&6[&bCTZL&6]&r' +#是否提示 +tipplayer: true +#服务器配置 +server: + port: 20000 + timeout: 120 \ No newline at end of file diff --git a/src/plugin.yml b/src/plugin.yml new file mode 100644 index 0000000..907ec5c --- /dev/null +++ b/src/plugin.yml @@ -0,0 +1,14 @@ +name: CTZLoginServer +main: cn.citycraft.CTZLoginServer.CTZLoginServer +version: 0.0.1 +depended: [Authme] +commands: + ctzl: + description: CTZLoginServer Reload. + usage: /ctzl reload 重载插件 + permission: ctzl.reload + permission-message: §c你没有此命令的权限! +permissions: + ctzl.reload: + description: 允许重载插件! + default: op \ No newline at end of file