1
0
mirror of https://e.coding.net/circlecloud/CTZLoginServer.git synced 2025-01-05 12:18:59 +00:00

Add Socket Class...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092 2015-07-25 18:15:14 +08:00
parent 49f0e65a85
commit 59169ad42d
4 changed files with 129 additions and 25 deletions

View File

@ -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");
}
}

View File

@ -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) {
}
}
}
}

12
src/config.yml Normal file
View File

@ -0,0 +1,12 @@
#本文件为登录插件的主配置文件
version: '1.0'
#服务器名称
servername: ''
#插件名称
pluginname: '&6[&bCTZL&6]&r'
#是否提示
tipplayer: true
#服务器配置
server:
port: 20000
timeout: 120

14
src/plugin.yml Normal file
View File

@ -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