Skip to content
Merged

Dev #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ repositories {
dependencies {
compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
compileOnly 'com.comphenix.protocol:ProtocolLib:5.1.0'
compileOnly 'org.jetbrains:annotations:23.0.0'
implementation ('cc.carm.lib:easysql-hikaricp:0.4.7')
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/top/redstarmc/plugin/redstarlib/RedStarLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void onEnable() {
instance = this;
loadManager();

loggerManager.info("a");
loggerManager.debugDataBase("a");

}

Expand All @@ -44,7 +44,7 @@ public void loadManager() {
configManager = new ImplConfigManager();
configManager.init();

loggerManager = new ImplLoggerManager(INFO_PREFIX);
loggerManager = new ImplLoggerManager(INFO_PREFIX, true);

serverManager = new ImplServerManager(INFO_PREFIX);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package top.redstarmc.plugin.redstarlib.database;

import cc.carm.lib.easysql.api.SQLAction;
import cc.carm.lib.easysql.api.SQLQuery;
import cc.carm.lib.easysql.api.function.SQLDebugHandler;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.redstarmc.plugin.redstarlib.manager.LoggerManager;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* <h1>EasySQL 的 DebugHandler 预设模块</h1>
* 重写了该模块,以便通过插件输出。
* 可直接使用本类,或继承后使用
* {@link cc.carm.lib.easysql.api.SQLManager#setDebugHandler(SQLDebugHandler)}
*
* 将 "SQLDebugHandler" 替换为 "CustomDebugHandler"
*/
public abstract class CustomDebugHandler implements SQLDebugHandler {

public CustomDebugHandler(LoggerManager loggerManager){
this.loggerManager = loggerManager;
}

LoggerManager loggerManager;

@Override
public void beforeExecute(@NotNull SQLAction<?> action, @NotNull List<@Nullable Object[]> params) {
loggerManager.debugDataBase("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
loggerManager.debugDataBase("┣# ActionUUID: {}", action.getActionUUID());
loggerManager.debugDataBase("┣# ActionType: " + action.getClass().getSimpleName());
if (action.getSQLContents().size() == 1) {
loggerManager.debugDataBase("┣# SQLContent: " + action.getSQLContents().get(0));
} else {
loggerManager.debugDataBase("┣# SQLContents: ");
int i = 0;
for (String sqlContent : action.getSQLContents()) {
loggerManager.debugDataBase("┃ - [{}] {}", ++i, sqlContent);
}
}
if (params.size() == 1) {
Object[] param = params.get(0);
if (param != null) {
loggerManager.debugDataBase("┣# SQLParam: " + parseParams(param));
}
} else if (params.size() > 1) {
loggerManager.debugDataBase("┣# SQLParams: ");
int i = 0;
for (Object[] param : params) {
loggerManager.debugDataBase("┃ - [{}] {}", ++i, parseParams(param));
}
}
loggerManager.debugDataBase("┣# CreateTime: " + action.getCreateTime(TimeUnit.MILLISECONDS));
loggerManager.debugDataBase("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
}

@Override
public void afterQuery(@NotNull SQLQuery query, long executeNanoTime, long closeNanoTime) {
loggerManager.debugDataBase("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
loggerManager.debugDataBase("┣# ActionUUID: {}", query.getAction().getActionUUID());
loggerManager.debugDataBase("┣# SQLContent: " + query.getSQLContent());
loggerManager.debugDataBase("┣# CloseTime: {} (cost {} ms)",
TimeUnit.NANOSECONDS.toMillis(closeNanoTime),
((double) (closeNanoTime - executeNanoTime) / 1000000)
);
loggerManager.debugDataBase("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

public class ImplLoggerManager extends LoggerManager {


public ImplLoggerManager(String INFO_PREFIX) {
super(INFO_PREFIX);
public ImplLoggerManager(String INFO_PREFIX, boolean debugMode) {
super(INFO_PREFIX, debugMode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ConfigurationManager(ConfigurationManager manager){
}

/**
* <h2>初始化文件</h2>
* <h2>创建文件</h2>
* 如果没有这个文件就自动创建,并返回 {@link YamlConfiguration} 配置文件,方便操作
* @return 读取到的 {@link YamlConfiguration} 配置文件
*/
Expand Down Expand Up @@ -65,6 +65,11 @@ public void saveMapConfig(Map<String, Object> configMap){
save();
}

public void saveJarConfig(String fileName){


}

/**
* <h2>从内存中保存 {@link YamlConfiguration} 格式文件</h2>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ public abstract class LoggerManager {

public String INFO_PREFIX;

public LoggerManager(String INFO_PREFIX) {
public boolean debugMode;

public LoggerManager(String INFO_PREFIX, boolean debugMode) {
this.INFO_PREFIX = INFO_PREFIX;
this.debugMode = debugMode;
}

public boolean debugMode;

/**
* <h2>发送插件普通信息</h2>
* @param messages 字符串
*/
public final void info(String... messages) {
public void info(String... messages) {
if (messages == null) return;
for (String message : messages) {
if (message == null) continue;
Expand All @@ -30,7 +32,7 @@ public final void info(String... messages) {
* @param messages 字符串
* @param objects 传入的格式化内容
*/
public final void info(String messages,Object... objects) {
public void info(String messages, Object... objects) {
if (messages == null) return;
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§a[INFO] §r" + toStrings.format(messages,objects) + "§r");
}
Expand All @@ -39,7 +41,7 @@ public final void info(String messages,Object... objects) {
* <h2>发送插件警告信息</h2>
* @param messages 字符串
*/
public final void warn(String... messages) {
public void warn(String... messages) {
if (messages == null) return;
for (String message : messages) {
if (message == null) continue;
Expand All @@ -51,7 +53,7 @@ public final void warn(String... messages) {
* <h2>发送插件错误信息</h2>
* @param messages 字符串
*/
public final void error(String... messages) {
public void error(String... messages) {
if (messages == null) return;
for (String message : messages) {
if (message == null) continue;
Expand All @@ -63,7 +65,7 @@ public final void error(String... messages) {
* <h2>发送插件debug信息</h2>
* @param messages 字符串
*/
public final void debug(String... messages) {
public void debug(String... messages) {
if (messages == null) return;
if (isDebugMode()) {
for (String message : messages) {
Expand All @@ -77,7 +79,7 @@ public final void debug(String... messages) {
* <h2>发送插件debug堆栈</h2>
* @param e 堆栈
*/
public final void debug(Throwable e) {
public void debug(Throwable e) {
if (e == null) return;
if (isDebugMode())
e.printStackTrace();
Expand All @@ -88,16 +90,40 @@ public final void debug(Throwable e) {
* @param e 堆栈
* @param msg 字符串
*/
public final void debug(String msg, Throwable e) {
public void debug(String msg, Throwable e) {
if (msg == null || e == null) return;
if (isDebugMode()) {
debug(msg);
debug(e);
}
}

/**
* <h2>发送插件 数据库 debug信息</h2>
* @param messages 字符串
*/
public void debugDataBase(String messages, Object... objects) {
if (messages == null) return;
if (isDebugMode()) {
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§6[DEBUG DB] §r" + toStrings.format(messages,objects) + "§r");
}
}


/**
* 抛出错误堆栈和错误信息
* @param throwable 堆栈
* @param messages 信息
*/
public void crash(Throwable throwable, String... messages){
for (String message : messages) {
if (message == null) continue;
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§c[ERROR] §r" + message + "§r");
}
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§c[ERROR] §r" + "抛出错误信息 ->" + "§r");
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§c[ERROR] §r" + throwable.getMessage() + "§r");
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§c[ERROR] §r" + "抛出错误堆栈 ->" + "§r");
throwable.printStackTrace();
}

public String getINFO_PREFIX() {
return INFO_PREFIX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class toStrings {

/**
* 字符串按照 slf 方式进行格式化返回
* 字符串按照 slf4j 方式进行格式化返回
* @return 格式化后的字符串
*/
public static String format(String format, Object... params) {
Expand Down