Skip to content

Commit

Permalink
清理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
ApliNi committed Aug 13, 2023
1 parent 999e4e7 commit 8c68a5f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 85 deletions.
4 changes: 2 additions & 2 deletions src/main/java/aplini/ipacwhitelist/IpacWhitelist.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
return true;
}

boolean b;
wlType b;

// uuid
if(args[1].length() == 36){
Expand All @@ -243,7 +243,7 @@ else if(args[1].length() <= 16){
return true;
}

if(b){
if(b != wlType.ERROR){
sender.sendMessage(plugin.getConfig().getString("message.command.del", "").replace("%player%", args[1]));
}else{
sender.sendMessage(plugin.getConfig().getString("message.command.err", ""));
Expand Down
86 changes: 8 additions & 78 deletions src/main/java/aplini/ipacwhitelist/util/SQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ PRIMARY KEY("ID" AUTOINCREMENT)
}

/**
*
* 修改或创建玩家数据
* @param name 玩家名称, 可使用 null
* @param UUID 玩家 UUID, 可使用 null
* @param Time 时间戳. -1=始终有效, -2=使用默认值
* @param White 白名单状态
* @param Type 白名单类型, 可使用 null
* @return 账户类型 VISIT, VISIT_DEL_DATA, DEFAULT, NOT
*/
// 修改或创建玩家数据
public static wlType setPlayerData(String name, String UUID, int Time, wlType White, wlType Type){
wlType out;
try {
Expand Down Expand Up @@ -167,65 +166,23 @@ public static wlType setPlayerData(String name, String UUID, int Time, wlType Wh
}
return out;
}
// public static wlType addPlayer(String name, String UUID, wlType Type){
// wlType out;
// try {
// PreparedStatement sql;
// ResultSet results;
// // 检查是否有相同的记录
// if(!UUID.isEmpty()){
// sql = connection.prepareStatement("SELECT * FROM `player` WHERE `NAME` = ? AND `UUID` = ? ORDER BY ROWID DESC LIMIT 1;");
// sql.setString(1, name);
// sql.setString(2, UUID);
// }else{
// sql = connection.prepareStatement("SELECT * FROM `player` WHERE `NAME` = ? ORDER BY ROWID DESC LIMIT 1;");
// sql.setString(1, name);
// }
// results = sql.executeQuery();
// if(results.next()){
// // 检查是否为参观账户
// if(results.getLong("Type") == 1){
// out = VISIT;
// }else{
// out = DEFAULT;
// }
// // 已添加, 重置这个ID的 TIME WHITE Type
// sql = connection.prepareStatement("UPDATE `player` SET `TIME` = ?, `WHITE` = ?, `Type` = ? WHERE `ID` = ?;");
// sql.setInt(1, -1);
// sql.setBoolean(2, true);
// sql.setInt(3, Type.getID());
// sql.setLong(4, results.getLong("ID"));
// }else{
// out = NOT;
// // 未添加, 创建记录
// sql = connection.prepareStatement("REPLACE INTO `player` (`UUID`, `NAME`, `TIME`, `WHITE`, `Type`) VALUES (?, ?, ?, ?, ?);");
// sql.setString(1, UUID);
// sql.setString(2, name);
// sql.setInt(3, -1);
// sql.setBoolean(4, true);
// sql.setInt(5, Type.getID());
// }
// sql.execute();
// sql.close();
//
// } catch (Exception e) {
// throw new RuntimeException(e);
// }
// return out;
// }
// 添加玩家
public static wlType addPlayer(String name){
// return addPlayer(name, "", wlType.DEFAULT);
return setPlayerData(name, null, -1, WHITE, DEFAULT);
}
public static wlType addPlayer(String name, String UUID){
// return addPlayer(name, UUID, wlType.DEFAULT);
return setPlayerData(name, UUID, -1, WHITE, DEFAULT);
}
public static void addPlayer(Player player, wlType type){
// return addPlayer(player.getName(), String.valueOf(player.getUniqueId()), type);
setPlayerData(player.getName(), String.valueOf(player.getUniqueId()), -1, WHITE, type);
}
// 移除玩家
public static wlType delPlayerName(String name){
return setPlayerData(name, null, -2, NOT_WHITE, null);
}
public static wlType delPlayerUUID(String UUID){
return setPlayerData(null, UUID, -2, NOT_WHITE, null);
}
// 封禁玩家
public static wlType banPlayerName(String name){
return setPlayerData(name, null, -2, BLACK, null);
Expand All @@ -234,33 +191,6 @@ public static wlType banPlayerUUID(String UUID){
return setPlayerData(null, UUID, -2, BLACK, null);
}

// 删除玩家, 通过名称
public static boolean delPlayerName(String name){
try {
PreparedStatement sql = connection.prepareStatement("UPDATE `player` SET `WHITE` = ? WHERE `NAME` = ? ORDER BY ROWID DESC LIMIT 1;");
sql.setBoolean(1, false);
sql.setString(2, name);
sql.executeUpdate();
sql.close();
} catch (Exception e) {
return false;
}
return true;
}

// 删除玩家, 通过UUID
public static boolean delPlayerUUID(String UUID){
try {
PreparedStatement sql = connection.prepareStatement("UPDATE `player` SET `WHITE` = ? WHERE `UUID` = ? ORDER BY ROWID DESC LIMIT 1;");
sql.setBoolean(1, false);
sql.setString(2, UUID);
sql.executeUpdate();
sql.close();
} catch (Exception e) {
return false;
}
return true;
}

// 是否在白名单中
// NOT = 不在, WHITE = 存在, ERROR = 出错, VISIT = 存在但是参观账号, VISIT_DEL_DATA = 已删除数据的参观账户
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/aplini/ipacwhitelist/util/wlType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ public enum wlType {
// 混合使用, 最初为了填充数据表中的 Type

// 数据表 Type -> ID
DEFAULT(0), // Type 默认, 正常的账户
VISIT(1), // Type 参观账户
VISIT_DEL_DATA(2), // Type 已删除数据的参观账户
DEFAULT(0), // 默认, 正常的账户
VISIT(1), // 参观账户
VISIT_DEL_DATA(2), // 已删除数据的参观账户

// 数据表 White
NOT_WHITE(0), // 不在白名单中
WHITE(1), // 白名单
BLACK(2), // 黑名单

// 表示
NOT(0), // 不存在的/ 移出白名单
ERROR(-1), // 出错
NOT(0), // 不存在的
ERROR(-5), // 出错
;

private final int key;
Expand Down

0 comments on commit 8c68a5f

Please sign in to comment.