Merge branch 'dev'

This commit is contained in:
2024-03-26 22:23:34 +08:00
9 changed files with 60 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
# [HamsterBall](https://git.airgame.net/MiniDay/hamster-ball)
仓鼠球:一个基于 Redis 的 Minecraft 服务端通用消息中间件原HamsterService
基于 Redis 的 Minecraft 服务端通用消息中间件
该插件依赖于 [仓鼠核心](https://git.airgame.net/MiniDay/hamster-core)
@@ -49,9 +49,9 @@ repositories {
dependencies {
// 对于 Bukkit 插件
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.6.2")
compileOnly("cn.hamster3.mc.plugin:ball-bukkit:1.6.3-SNAPSHOT")
// 对于 BungeeCord 插件
compileOnly("cn.hamster3.mc.plugin:ball-bungee:1.6.2")
compileOnly("cn.hamster3.mc.plugin:ball-bungee:1.6.3-SNAPSHOT")
}
```
@@ -77,13 +77,13 @@ dependencies {
<dependency>
<groupId>cn.hamster3.mc.plugin</groupId>
<artifactId>ball-bukkit</artifactId>
<version>1.6.2</version>
<version>1.6.3-SNAPSHOT</version>
</dependency>
<!--对于 BungeeCord 插件-->
<dependency>
<groupId>cn.hamster3.mc.plugin</groupId>
<artifactId>ball-bungee</artifactId>
<version>1.6.2</version>
<version>1.6.3-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -4,8 +4,15 @@ version: ${version}
api-version: 1.13
author: MiniDay
description: ${description}
website: https://git.airgame.net/MiniDay/hamster-ball
description: 仓鼠球:一个基于 Redis 的 Minecraft 服务端通用消息中间件原HamsterService
UPDATE_CHECKER:
VERSION: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-ball
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-ball/
load: STARTUP

View File

@@ -1,6 +0,0 @@
version: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-ball
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-ball/

View File

@@ -3,7 +3,15 @@ main: cn.hamster3.mc.plugin.ball.bungee.HamsterBallPlugin
version: ${version}
author: MiniDay
description: 仓鼠球:一个基于 Redis 的 Minecraft 服务端通用消息中间件原HamsterService
description: ${description}
website: https://git.airgame.net/MiniDay/hamster-ball
UPDATE_CHECKER:
VERSION: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-ball
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-ball/
depend:
- HamsterCore

View File

@@ -1,6 +0,0 @@
version: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-ball
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-ball/

View File

@@ -506,26 +506,28 @@ public abstract class BallAPI {
* <p>
* 会自动加上 config 中设置的频道前缀
*
* @param channel 频道名称
* @param channels 频道名称
*/
public void subscribe(@NotNull String... channel) {
for (int i = 0; i < channel.length; i++) {
channel[i] = ballConfig.getChannelPrefix() + channel[i];
public void subscribe(@NotNull String... channels) {
for (int i = 0; i < channels.length; i++) {
channels[i] = ballConfig.getChannelPrefix() + channels[i];
}
CoreAPI.getInstance().getExecutorService().submit(
() -> redisSub.subscribe(BallRedisListener.INSTANCE, channel)
);
subscribeRaw(channels);
}
/**
* 忽略频道前缀配置,订阅 redis 消息频道
*
* @param channel 频道名称
* @param channels 频道名称
*/
public void subscribeRaw(@NotNull String... channel) {
CoreAPI.getInstance().getExecutorService().submit(
() -> redisSub.subscribe(BallRedisListener.INSTANCE, channel)
);
public void subscribeRaw(@NotNull String... channels) {
CoreAPI.getInstance().getExecutorService().submit(() -> {
try {
redisSub.subscribe(BallRedisListener.INSTANCE, channels);
} catch (Exception | Error e) {
e.printStackTrace();
}
});
}
/**

View File

@@ -15,19 +15,26 @@ public class BallRedisListener extends JedisPubSub {
@Override
public void onMessage(String channel, String message) {
if (channel.startsWith(BallAPI.getInstance().getBallConfig().getChannelPrefix())) {
channel = channel.substring(BallAPI.getInstance().getBallConfig().getChannelPrefix().length());
}
BallMessage ballMessage = CoreAPI.getInstance().getGson().fromJson(message, BallMessage.class);
BallAPI ballAPI = BallAPI.getInstance();
EventBus eventBus = ballAPI.getEventBus();
if (ballMessage.getReceiverType() != null && ballMessage.getReceiverType() != ballAPI.getLocalServerInfo().getType()) {
return;
}
if (ballMessage.getReceiverID() != null && !ballAPI.isLocalServer(ballMessage.getReceiverID())) {
return;
}
eventBus.post(new MessageReceivedEvent(channel, ballMessage));
CoreAPI.getInstance().getExecutorService().submit(() -> {
try {
String finalChannel = channel;
if (finalChannel.startsWith(BallAPI.getInstance().getBallConfig().getChannelPrefix())) {
finalChannel = finalChannel.substring(BallAPI.getInstance().getBallConfig().getChannelPrefix().length());
}
BallMessage ballMessage = CoreAPI.getInstance().getGson().fromJson(message, BallMessage.class);
BallAPI ballAPI = BallAPI.getInstance();
EventBus eventBus = ballAPI.getEventBus();
if (ballMessage.getReceiverType() != null && ballMessage.getReceiverType() != ballAPI.getLocalServerInfo().getType()) {
return;
}
if (ballMessage.getReceiverID() != null && !ballAPI.isLocalServer(ballMessage.getReceiverID())) {
return;
}
eventBus.post(new MessageReceivedEvent(finalChannel, ballMessage));
} catch (Exception | Error e) {
e.printStackTrace();
}
});
}
@Override

View File

@@ -1,6 +1,5 @@
version: ${version}
VERSION: ${version}
CHECK_TYPE: GITEA_RELEASES
GIT_BASE_URL: https://git.airgame.net
GIT_REPO: MiniDay/hamster-ball
GIT_TOKEN: a44a69a4d1b8601bf6091403247759cd28764d5e
DOWNLOAD_URL: https://jenkins.airgame.net/job/opensource/job/hamster-ball/

View File

@@ -5,7 +5,8 @@ plugins {
}
group = "cn.hamster3.mc.plugin"
version = "1.6.2"
version = "1.6.3-SNAPSHOT"
description = "基于 Redis 的 Minecraft 服务端通用消息中间件"
subprojects {
apply {
@@ -16,6 +17,7 @@ subprojects {
group = rootProject.group
version = rootProject.version
description = rootProject.description
repositories {
maven("https://maven.airgame.net/maven-public/")
@@ -43,11 +45,6 @@ subprojects {
from(rootProject.file("LICENSE"))
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
processResources {
filesMatching("update.yml") {
expand(rootProject.properties)
}
}
build {
dependsOn(shadowJar)
}