feat: 收到频道消息后先移除前缀再触发时间

This commit is contained in:
2023-11-20 17:03:00 +08:00
parent 04cea1896e
commit da710e5af8
5 changed files with 9 additions and 6 deletions

View File

@@ -59,7 +59,7 @@ public class BallBukkitAPI extends BallAPI {
BallConfig ballConfig = new BallConfig( BallConfig ballConfig = new BallConfig(
config.getBoolean("debug", false), config.getBoolean("debug", false),
RedisClient.create(config.getString("redis-url")), RedisClient.create(config.getString("redis-url")),
config.getString("channel-prefix", ""), config.getString("channel-prefix", "") + ":",
config.getBoolean("game-server-update-player-info", false), config.getBoolean("game-server-update-player-info", false),
serverInfo, serverInfo,
datasource datasource

View File

@@ -56,7 +56,7 @@ public class BallBungeeCordAPI extends BallAPI {
BallConfig ballConfig = new BallConfig( BallConfig ballConfig = new BallConfig(
config.getBoolean("debug", false), config.getBoolean("debug", false),
RedisClient.create(config.getString("redis-url")), RedisClient.create(config.getString("redis-url")),
config.getString("channel-prefix", ""), config.getString("channel-prefix", "") + ":",
config.getBoolean("game-server-update-player-info", false), config.getBoolean("game-server-update-player-info", false),
serverInfo, serverInfo,
datasource datasource

View File

@@ -448,7 +448,7 @@ public abstract class BallAPI {
*/ */
public void sendBallMessage(@NotNull String channel, @NotNull BallMessage message, boolean prefix, boolean block) { public void sendBallMessage(@NotNull String channel, @NotNull BallMessage message, boolean prefix, boolean block) {
if (prefix) { if (prefix) {
channel = ballConfig.getChannelPrefix() + ":" + channel; channel = ballConfig.getChannelPrefix() + channel;
} }
if (block) { if (block) {
pubConnection.sync().publish(channel, message); pubConnection.sync().publish(channel, message);
@@ -466,7 +466,7 @@ public abstract class BallAPI {
public void subscribe(@NotNull String... channel) { public void subscribe(@NotNull String... channel) {
for (int i = 0; i < channel.length; i++) { for (int i = 0; i < channel.length; i++) {
channel[i] = ballConfig.getChannelPrefix() + ":" + channel[i]; channel[i] = ballConfig.getChannelPrefix() + channel[i];
} }
subConnection.sync().subscribe(channel); subConnection.sync().subscribe(channel);
} }
@@ -477,7 +477,7 @@ public abstract class BallAPI {
public void unsubscribe(@NotNull String... channel) { public void unsubscribe(@NotNull String... channel) {
for (int i = 0; i < channel.length; i++) { for (int i = 0; i < channel.length; i++) {
channel[i] = ballConfig.getChannelPrefix() + ":" + channel[i]; channel[i] = ballConfig.getChannelPrefix() + channel[i];
} }
subConnection.sync().unsubscribe(channel); subConnection.sync().unsubscribe(channel);
} }

View File

@@ -19,6 +19,9 @@ public class BallRedisListener implements RedisPubSubListener<String, BallMessag
@Override @Override
public void message(String channel, BallMessage ballMessage) { public void message(String channel, BallMessage ballMessage) {
if (channel.startsWith(BallAPI.getInstance().getBallConfig().getChannelPrefix())) {
channel = channel.substring(BallAPI.getInstance().getBallConfig().getChannelPrefix().length());
}
BallAPI api = BallAPI.getInstance(); BallAPI api = BallAPI.getInstance();
if (ballMessage.getReceiverType() != null && ballMessage.getReceiverType() != api.getLocalServerInfo().getType()) { if (ballMessage.getReceiverType() != null && ballMessage.getReceiverType() != api.getLocalServerInfo().getType()) {
return; return;

View File

@@ -5,7 +5,7 @@ plugins {
} }
group = "cn.hamster3.mc.plugin" group = "cn.hamster3.mc.plugin"
version = "1.4.1" version = "1.4.2"
subprojects { subprojects {
apply { apply {