From 4f752d19084e0428b5d06b5c592f076765f8dea1 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Mon, 13 May 2024 00:51:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93?= =?UTF-8?q?=E6=9E=84=EF=BC=8C=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/cn/lunadeer/dominion/Dominion.java | 10 +++++++--- .../java/cn/lunadeer/dominion/dtos/DominionDTO.java | 4 ++-- src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java | 4 ++-- .../cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java | 4 ++-- .../dominion/{utils => managers}/ConfigManager.java | 3 ++- .../Database.java => managers/DatabaseManager.java} | 5 +++-- 6 files changed, 18 insertions(+), 12 deletions(-) rename src/main/java/cn/lunadeer/dominion/{utils => managers}/ConfigManager.java (99%) rename src/main/java/cn/lunadeer/dominion/{utils/Database.java => managers/DatabaseManager.java} (99%) diff --git a/src/main/java/cn/lunadeer/dominion/Dominion.java b/src/main/java/cn/lunadeer/dominion/Dominion.java index ebc1fe1e..07412741 100644 --- a/src/main/java/cn/lunadeer/dominion/Dominion.java +++ b/src/main/java/cn/lunadeer/dominion/Dominion.java @@ -3,7 +3,11 @@ import cn.lunadeer.dominion.events.EnvironmentEvents; import cn.lunadeer.dominion.events.PlayerEvents; import cn.lunadeer.dominion.events.SelectPointEvents; -import cn.lunadeer.dominion.utils.*; +import cn.lunadeer.dominion.managers.ConfigManager; +import cn.lunadeer.dominion.managers.DatabaseManager; +import cn.lunadeer.dominion.utils.GiteaReleaseCheck; +import cn.lunadeer.dominion.utils.Scheduler; +import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.java.JavaPlugin; @@ -22,8 +26,8 @@ public void onEnable() { // Plugin startup logic instance = this; config = new ConfigManager(this); - dbConnection = Database.createConnection(); - Database.migrate(); + dbConnection = DatabaseManager.createConnection(); + DatabaseManager.migrate(); scheduler = new Scheduler(this); AutoClean.run(); Cache.instance = new Cache(); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java index 8991aff7..407351f8 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java @@ -2,7 +2,7 @@ import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; -import cn.lunadeer.dominion.utils.Database; +import cn.lunadeer.dominion.managers.DatabaseManager; import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Location; import org.bukkit.World; @@ -18,7 +18,7 @@ public class DominionDTO { private static List query(String sql) { List dominions = new ArrayList<>(); - try (ResultSet rs = Database.query(sql)) { + try (ResultSet rs = DatabaseManager.query(sql)) { if (sql.contains("UPDATE") || sql.contains("DELETE") || sql.contains("INSERT")) { // 如果是更新操作,重新加载缓存 Cache.instance.loadDominions(); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java index 39d1205e..b84dbac2 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java @@ -1,6 +1,6 @@ package cn.lunadeer.dominion.dtos; -import cn.lunadeer.dominion.utils.Database; +import cn.lunadeer.dominion.managers.DatabaseManager; import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.entity.Player; @@ -31,7 +31,7 @@ public PlayerDTO onJoin() { private static List query(String sql) { List players = new ArrayList<>(); - try (ResultSet rs = Database.query(sql)) { + try (ResultSet rs = DatabaseManager.query(sql)) { if (rs == null) return players; while (rs.next()) { Integer id = rs.getInt("id"); diff --git a/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java index a09dd216..8a3a21a8 100644 --- a/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java +++ b/src/main/java/cn/lunadeer/dominion/dtos/PlayerPrivilegeDTO.java @@ -1,7 +1,7 @@ package cn.lunadeer.dominion.dtos; import cn.lunadeer.dominion.Cache; -import cn.lunadeer.dominion.utils.Database; +import cn.lunadeer.dominion.managers.DatabaseManager; import cn.lunadeer.dominion.utils.XLogger; import java.sql.ResultSet; @@ -582,7 +582,7 @@ public PlayerPrivilegeDTO(UUID playerUUID, Integer domID, private static List query(String sql) { List players = new ArrayList<>(); - try (ResultSet rs = Database.query(sql)) { + try (ResultSet rs = DatabaseManager.query(sql)) { if (sql.contains("UPDATE") || sql.contains("DELETE") || sql.contains("INSERT")) { // 如果是更新操作,重新加载缓存 Cache.instance.loadPlayerPrivileges(); diff --git a/src/main/java/cn/lunadeer/dominion/utils/ConfigManager.java b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java similarity index 99% rename from src/main/java/cn/lunadeer/dominion/utils/ConfigManager.java rename to src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java index 25517da8..12106ee7 100644 --- a/src/main/java/cn/lunadeer/dominion/utils/ConfigManager.java +++ b/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -1,6 +1,7 @@ -package cn.lunadeer.dominion.utils; +package cn.lunadeer.dominion.managers; import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.utils.XLogger; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; diff --git a/src/main/java/cn/lunadeer/dominion/utils/Database.java b/src/main/java/cn/lunadeer/dominion/managers/DatabaseManager.java similarity index 99% rename from src/main/java/cn/lunadeer/dominion/utils/Database.java rename to src/main/java/cn/lunadeer/dominion/managers/DatabaseManager.java index 2d06c576..2791865a 100644 --- a/src/main/java/cn/lunadeer/dominion/utils/Database.java +++ b/src/main/java/cn/lunadeer/dominion/managers/DatabaseManager.java @@ -1,10 +1,11 @@ -package cn.lunadeer.dominion.utils; +package cn.lunadeer.dominion.managers; import cn.lunadeer.dominion.Dominion; +import cn.lunadeer.dominion.utils.XLogger; import java.sql.*; -public class Database { +public class DatabaseManager { public static Connection createConnection() { try {