Skip to content

Commit

Permalink
优化代码结构,提高性能
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdeZhang committed May 12, 2024
1 parent 10fd19b commit 4f752d1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
10 changes: 7 additions & 3 deletions src/main/java/cn/lunadeer/dominion/Dominion.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +18,7 @@ public class DominionDTO {

private static List<DominionDTO> query(String sql) {
List<DominionDTO> 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();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/lunadeer/dominion/dtos/PlayerDTO.java
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -31,7 +31,7 @@ public PlayerDTO onJoin() {

private static List<PlayerDTO> query(String sql) {
List<PlayerDTO> 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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -582,7 +582,7 @@ public PlayerPrivilegeDTO(UUID playerUUID, Integer domID,

private static List<PlayerPrivilegeDTO> query(String sql) {
List<PlayerPrivilegeDTO> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 4f752d1

Please sign in to comment.