feat: 使用 guava 的 EventBus
This commit is contained in:
@@ -77,7 +77,7 @@ public abstract class BallAPI {
|
||||
protected void enable() throws SQLException, InterruptedException {
|
||||
BallServerInfo localInfo = getLocalServerInfo();
|
||||
|
||||
try (Connection connection = BallAPI.getInstance().getDatasource().getConnection()) {
|
||||
try (Connection connection = getDatasource().getConnection()) {
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS `hamster_ball_player_info`(" +
|
||||
"`uuid` CHAR(36) PRIMARY KEY," +
|
||||
@@ -142,13 +142,13 @@ public abstract class BallAPI {
|
||||
}
|
||||
RedisClient client = getRedisClient();
|
||||
subConnection.addListener(BallRedisListener.INSTANCE);
|
||||
subConnection.async().subscribe(BALL_CHANNEL);
|
||||
subscribe(BALL_CHANNEL);
|
||||
}
|
||||
|
||||
protected void disable() throws SQLException, InterruptedException {
|
||||
sendBallMessage(new BallMessage(BALL_CHANNEL, BallActions.ServerOffline.name(), new ServerOfflineEvent(getLocalServerId())), true);
|
||||
|
||||
try (Connection connection = BallAPI.getInstance().getDatasource().getConnection()) {
|
||||
try (Connection connection = getDatasource().getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(
|
||||
"DELETE FROM `hamster_ball_server_info` WHERE `id`=?;"
|
||||
)) {
|
||||
@@ -309,7 +309,7 @@ public abstract class BallAPI {
|
||||
if (info != null && info.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
try (Connection connection = BallAPI.getInstance().getDatasource().getConnection()) {
|
||||
try (Connection connection = getDatasource().getConnection()) {
|
||||
try (PreparedStatement statement = connection.prepareStatement(
|
||||
"INSERT INTO `hamster_ball_cached_message` VALUES(?, ?);"
|
||||
)) {
|
||||
@@ -447,6 +447,22 @@ public abstract class BallAPI {
|
||||
}
|
||||
}
|
||||
|
||||
public void subscribe(@NotNull String... channel) {
|
||||
subConnection.sync().subscribe(channel);
|
||||
}
|
||||
|
||||
public void subscribePatterns(@NotNull String patterns) {
|
||||
subConnection.sync().psubscribe(patterns);
|
||||
}
|
||||
|
||||
public void unsubscribe(@NotNull String... channel) {
|
||||
subConnection.sync().unsubscribe(channel);
|
||||
}
|
||||
|
||||
public void unsubscribePatterns(@NotNull String patterns) {
|
||||
subConnection.sync().punsubscribe(patterns);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地服务器ID
|
||||
*
|
||||
|
Reference in New Issue
Block a user