Skip to content
Merged
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
6 changes: 5 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
name: "CodeQL Advanced"

on:
# 支持手动触发
workflow_dispatch:
push:
branches: [ "main" , "dev" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '34 1 * * 3'
- cron: '00 1 * * 3'

jobs:
analyze:
Expand All @@ -43,6 +45,8 @@ jobs:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
- language: java-kotlin
build-mode: none # This mode only analyzes Java. Set this to 'autobuild' or 'manual' to analyze Kotlin too.
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
Expand Down
36 changes: 36 additions & 0 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 此工作流使用未经 GitHub 认证的操作。
# 它们由第三方提供,并受
# 单独的服务条款、隐私政策和支持
# 文档。

# GitHub 建议将操作固定到提交 SHA。
# 若要获取较新版本,需要更新 SHA。
# 还可以引用标记或分支,但该操作可能会更改而不发出警告。

name: Publish package to GitHub Packages

on:
# 支持手动触发
workflow_dispatch:
release:
types: [created]

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

- name: Publish package
run: ./gradlew publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.gradle
.idea
gradle
build


debug.bat
27 changes: 26 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'maven-publish'
}

group = 'top.redstarmc.plugin'
Expand All @@ -25,7 +26,7 @@ dependencies {
implementation ('cc.carm.lib:easysql-hikaricp:0.4.7')
}

def targetJavaVersion = 17
def targetJavaVersion = 19
java {
def javaVersion = JavaVersion.toVersion(targetJavaVersion)
sourceCompatibility = javaVersion
Expand All @@ -51,3 +52,27 @@ processResources {
expand props
}
}

publishing {

publications {
mavenJava(MavenPublication) {
groupId = group
artifactId = "RedStarLib"
version = version

from components.java
}
}

repositories {
maven {
name = "GitHubPackages"
url = "https://maven.pkg.github.com/RedStarMC/RedStarLib"
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}
21 changes: 20 additions & 1 deletion src/main/java/top/redstarmc/plugin/redstarlib/RedStarLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,36 @@

import org.bukkit.plugin.java.JavaPlugin;
import top.redstarmc.plugin.redstarlib.impl.ImplConfigManager;
import top.redstarmc.plugin.redstarlib.impl.ImplLoggerManager;
import top.redstarmc.plugin.redstarlib.impl.ImplServerManager;
import top.redstarmc.plugin.redstarlib.manager.ConfigurationManager;
import top.redstarmc.plugin.redstarlib.manager.LoggerManager;
import top.redstarmc.plugin.redstarlib.manager.ServerManager;

/**
* <h1>RedStarLib 插件主类</h1>
* 实现 {@link RedStarLibInterface} 接口,同时也可作为其他使用本插件开发的插件代码规范。 <br>
* 内部维护了多个字段,不可被继承( final 类)。
*/
public final class RedStarLib extends JavaPlugin implements RedStarLibInterface{

private static RedStarLib instance;

public String INFO_PREFIX = "[RedStarLib]";

private ConfigurationManager configManager;

private LoggerManager loggerManager;

private ServerManager serverManager;

@Override
public void onEnable() {
instance = this;
loadManager();

loggerManager.info("a");

}

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

serverManager = new ImplServerManager();
loggerManager = new ImplLoggerManager(INFO_PREFIX);

serverManager = new ImplServerManager(INFO_PREFIX);
}

public static RedStarLib getInstance() {
Expand All @@ -42,6 +57,10 @@ public ConfigurationManager getConfigManager() {
return configManager;
}

public LoggerManager getLoggerManager() {
return loggerManager;
}

public ServerManager getServerManager() {
return serverManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ImplConfigManager extends ConfigurationManager {

private static YamlConfiguration config;

private static final String versioning = "${version}";
private static final String versioning = "0.0.0";

@Override
public void init() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package top.redstarmc.plugin.redstarlib.impl;

import top.redstarmc.plugin.redstarlib.manager.LoggerManager;

public class ImplLoggerManager extends LoggerManager {


public ImplLoggerManager(String INFO_PREFIX) {
super(INFO_PREFIX);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package top.redstarmc.plugin.redstarlib.impl;

import org.bukkit.Bukkit;
import top.redstarmc.plugin.redstarlib.manager.ServerManager;

public class ImplServerManager extends ServerManager {

@Override
public void broadcast(String... messages) {
for (String message : messages) {
Bukkit.broadcastMessage(message);
}
public ImplServerManager(String INFO_PREFIX) {
super(INFO_PREFIX);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
*/
public abstract class ConfigurationManager {


/**
* <h2>初始化方法</h2>
*/
public abstract void init();

/**
Expand Down Expand Up @@ -48,6 +50,11 @@ public void saveMapConfig(Map<String, Object> configMap, YamlConfiguration confi
save(config, configFile);
}

/**
* <h2>从内存中保存 {@link YamlConfiguration} 格式文件</h2>
* @param config {@link YamlConfiguration} 内存中配置文件
* @param configFile {@link File} IO配置文件
*/
public void save(YamlConfiguration config, File configFile){
try {
config.save(configFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package top.redstarmc.plugin.redstarlib.manager;

import org.bukkit.Bukkit;
import top.redstarmc.plugin.redstarlib.utils.toStrings;

public abstract class LoggerManager {

public String INFO_PREFIX;

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

public boolean debugMode;

/**
* <h2>发送插件普通信息</h2>
* @param messages 字符串
*/
public final void info(String... messages) {
if (messages == null) return;
for (String message : messages) {
if (message == null) continue;
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§a[INFO] §r" + message + "§r");
}
}

/**
* <h2>发送插件格式化信息</h2>
* @param messages 字符串
* @param objects 传入的格式化内容
*/
public final void info(String messages,Object... objects) {
if (messages == null) return;
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§a[INFO] §r" + toStrings.format(messages,objects) + "§r");
}

/**
* <h2>发送插件警告信息</h2>
* @param messages 字符串
*/
public final void warn(String... messages) {
if (messages == null) return;
for (String message : messages) {
if (message == null) continue;
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§e[WARN] §r" + message + "§r");
}
}

/**
* <h2>发送插件错误信息</h2>
* @param messages 字符串
*/
public final void error(String... messages) {
if (messages == null) return;
for (String message : messages) {
if (message == null) continue;
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§c[ERROR] §r" + message + "§r");
}
}

/**
* <h2>发送插件debug信息</h2>
* @param messages 字符串
*/
public final void debug(String... messages) {
if (messages == null) return;
if (isDebugMode()) {
for (String message : messages) {
if (message == null) continue;
Bukkit.getConsoleSender().sendMessage(INFO_PREFIX + "§6[DEBUG] §r" + message + "§r");
}
}
}

/**
* <h2>发送插件debug堆栈</h2>
* @param e 堆栈
*/
public final void debug(Throwable e) {
if (e == null) return;
if (isDebugMode())
e.printStackTrace();
}

/**
* <h2>同时发送插件debug信息和堆栈</h2>
* @param e 堆栈
* @param msg 字符串
*/
public final void debug(String msg, Throwable e) {
if (msg == null || e == null) return;
if (isDebugMode()) {
debug(msg);
debug(e);
}
}




public String getINFO_PREFIX() {
return INFO_PREFIX;
}

public boolean isDebugMode() {
return debugMode;
}

}
Loading