Skip to content

Commit 7a1f706

Browse files
committed
feat: 新增指令userlist, userdel,更改指令useradd, reconnect(权限)
1 parent f0754df commit 7a1f706

File tree

5 files changed

+81
-11
lines changed

5 files changed

+81
-11
lines changed

src/main/java/center/xzy/qb/messagesync/commands/impl/reconnect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public boolean onCommand(CommandSender sender, String[] args) {
2525
}
2626

2727
public String permission(){
28-
return "messagesync.ms.disable";
28+
return "messagesync.ms.reconnect";
2929
}
3030
}
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
package center.xzy.qb.messagesync.commands.impl;
22

33
import center.xzy.qb.messagesync.Main;
4+
import center.xzy.qb.messagesync.commands.ICommand;
45
import org.bukkit.ChatColor;
56
import org.bukkit.command.CommandSender;
6-
import center.xzy.qb.messagesync.commands.ICommand;
7-
import org.sqlite.util.StringUtils;
87

98
import java.sql.ResultSet;
109
import java.sql.SQLException;
1110
import java.sql.Statement;
1211
import java.text.SimpleDateFormat;
1312
import java.util.Date;
1413

15-
public class user extends ICommand {
16-
public user(){
17-
super("user", "<玩家ID> <密码>", "添加/修改玩家密码 - 登陆系统");
14+
public class useradd extends ICommand {
15+
public useradd(){
16+
super("useradd", "<玩家ID> <密码>", "添加/修改玩家密码 - 登陆系统");
1817
}
1918

2019
public boolean onCommand(CommandSender sender, String[] args) {
2120
try {
2221
String userID = args[0],
2322
password = args[1];
2423
Statement statement = Main.dbConn.createStatement();
25-
ResultSet rs = statement.executeQuery("select * from `password` where `id`='" + userID + "'");
24+
ResultSet rs = statement.executeQuery("select * from `ms_users` where `id`='" + userID + "'");
2625
boolean flag = false;
2726
while(rs.next()) {
2827
flag = true;
@@ -34,20 +33,21 @@ public boolean onCommand(CommandSender sender, String[] args) {
3433
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
3534
String dateString = sdf.format(date);
3635

37-
statement.executeUpdate("INSERT `password` (`password`, `id`, `time`) VALUES ('" + Main.MD5(password) + "', '" + userID + "', '" + dateString + "')");
36+
statement.executeUpdate("INSERT INTO `ms_users` (`password`, `id`, `time`) VALUES ('" + Main.MD5(password) + "', '" + userID + "', '" + dateString + "')");
3837
sender.sendMessage(ChatColor.GREEN + "已新建用户!");
3938
} else {
4039
// 已存在
41-
statement.executeUpdate("UPDATE `password` SET `password`='" + Main.MD5(password) + "' WHERE `id`='" + userID + "'");
40+
statement.executeUpdate("UPDATE `ms_users` SET `password`='" + Main.MD5(password) + "' WHERE `id`='" + userID + "'");
4241
sender.sendMessage(ChatColor.GREEN + "已修改密码!");
4342
}
4443
} catch (SQLException e) {
44+
Main.instance.getLogger().warning(e.getMessage());
4545
return false;
4646
}
4747
return true;
4848
}
4949

5050
public String permission(){
51-
return "messagesync.ms.user";
51+
return "messagesync.ms.useradd";
5252
}
5353
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package center.xzy.qb.messagesync.commands.impl;
2+
3+
import center.xzy.qb.messagesync.Main;
4+
import center.xzy.qb.messagesync.commands.ICommand;
5+
import org.bukkit.ChatColor;
6+
import org.bukkit.command.CommandSender;
7+
8+
import java.sql.SQLException;
9+
import java.sql.Statement;
10+
11+
public class userdel extends ICommand {
12+
public userdel(){
13+
super("userdel", "<玩家ID>", "删除玩家信息 - 登陆系统");
14+
}
15+
16+
public boolean onCommand(CommandSender sender, String[] args) {
17+
try {
18+
String userID = args[0];
19+
Statement statement = Main.dbConn.createStatement();
20+
statement.executeUpdate("DELETE FROM `ms_users` WHERE `id`='" + userID + "'");
21+
sender.sendMessage(ChatColor.GREEN + "已删除用户!");
22+
} catch (SQLException e) {
23+
Main.instance.getLogger().warning(e.getMessage());
24+
return false;
25+
}
26+
return true;
27+
}
28+
29+
public String permission(){
30+
return "messagesync.ms.userdel";
31+
}
32+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package center.xzy.qb.messagesync.commands.impl;
2+
3+
import center.xzy.qb.messagesync.Main;
4+
import center.xzy.qb.messagesync.commands.ICommand;
5+
import org.bukkit.ChatColor;
6+
import org.bukkit.command.CommandSender;
7+
8+
import java.sql.ResultSet;
9+
import java.sql.SQLException;
10+
import java.sql.Statement;
11+
12+
public class userlist extends ICommand {
13+
public userlist(){
14+
super("userlist", "", "列出玩家 - 登陆系统");
15+
}
16+
17+
public boolean onCommand(CommandSender sender, String[] args) {
18+
try {
19+
Statement statement = Main.dbConn.createStatement();
20+
ResultSet rs = statement.executeQuery("select * from `ms_users`");
21+
while(rs.next()) {
22+
sender.sendMessage(ChatColor.BLUE + "> 玩家ID: " + rs.getString("id"));
23+
sender.sendMessage(ChatColor.BLUE + " 注册时间: " + rs.getString("time"));
24+
sender.sendMessage(ChatColor.BLUE + " 注册IP: " + rs.getString("ip"));
25+
}
26+
27+
} catch (SQLException e) {
28+
return false;
29+
}
30+
return true;
31+
}
32+
33+
public String permission(){
34+
return "messagesync.ms.userlist";
35+
}
36+
}

src/main/java/center/xzy/qb/messagesync/executor/CommandHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ private void initHandler() {
5555

5656
registerCommand(new enable());
5757
registerCommand(new disable());
58-
registerCommand(new user());
58+
registerCommand(new useradd());
59+
registerCommand(new userdel());
60+
registerCommand(new userlist());
5961
registerCommand(new login());
6062
registerCommand(new reload());
6163
registerCommand(new reconnect());

0 commit comments

Comments
 (0)