Skip to content

Commit

Permalink
[RedisSupport] Register messages for features in constructors instead…
Browse files Browse the repository at this point in the history
… of load to make sure they run immediately and sync in the main thread
  • Loading branch information
NEZNAMY committed Oct 29, 2024
1 parent 9b5e63a commit 818701c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ public BelowName(@NotNull BelownameConfiguration configuration) {
disableChecker = new DisableChecker(this, Condition.getCondition(configuration.disableCondition), this::onDisableConditionChange, p -> p.belowNameData.disabled);
TAB.getInstance().getFeatureManager().registerFeature(TabConstants.Feature.BELOW_NAME + "-Condition", disableChecker);
TAB.getInstance().getFeatureManager().registerFeature(TabConstants.Feature.BELOW_NAME_TEXT, textRefresher);
if (redis != null) {
redis.registerMessage("belowname", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
}

@Override
public void load() {
if (redis != null) {
redis.registerMessage("belowname", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
onlinePlayers = new OnlinePlayers(TAB.getInstance().getOnlinePlayers());
Map<TabPlayer, Integer> values = new HashMap<>();
for (TabPlayer loaded : onlinePlayers.getPlayers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public PlayerList(@NotNull TablistFormattingConfiguration configuration) {
}, getFeatureName(), CpuUsageCategory.ANTI_OVERRIDE_TABLIST_PERIODIC), 500
);
}
if (redis != null) {
redis.registerMessage("tabformat", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
}

/**
Expand Down Expand Up @@ -154,9 +157,6 @@ public TabComponent getTabFormat(@NotNull TabPlayer p, @NotNull TabPlayer viewer

@Override
public void load() {
if (redis != null) {
redis.registerMessage("tabformat", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
for (TabPlayer all : TAB.getInstance().getOnlinePlayers()) {
((TrackedTabList<?, ?>)all.getTabList()).setAntiOverride(configuration.antiOverride);
loadProperties(all);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ public YellowNumber(@NotNull PlayerListObjectiveConfiguration configuration) {
this.configuration = configuration;
disableChecker = new DisableChecker(this, Condition.getCondition(configuration.disableCondition), this::onDisableConditionChange, p -> p.playerlistObjectiveData.disabled);
TAB.getInstance().getFeatureManager().registerFeature(TabConstants.Feature.YELLOW_NUMBER + "-Condition", disableChecker);
if (redis != null) {
redis.registerMessage("yellow-number", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
}

/**
Expand Down Expand Up @@ -99,9 +102,6 @@ public int getValueNumber(@NotNull TabPlayer p) {

@Override
public void load() {
if (redis != null) {
redis.registerMessage("yellow-number", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
onlinePlayers = new OnlinePlayers(TAB.getInstance().getOnlinePlayers());
Map<TabPlayer, Integer> values = new HashMap<>();
for (TabPlayer loaded : onlinePlayers.getPlayers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public NameTag(@NotNull TeamConfiguration configuration) {
collisionManager = new CollisionManager(this);
TAB.getInstance().getFeatureManager().registerFeature(TabConstants.Feature.NAME_TAGS + "-Condition", disableChecker);
TAB.getInstance().getFeatureManager().registerFeature(TabConstants.Feature.NAME_TAGS_VISIBILITY, new VisibilityRefresher(this));
if (redis != null) {
redis.registerMessage("teams", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
}

@Override
public void load() {
if (redis != null) {
redis.registerMessage("teams", UpdateRedisPlayer.class, UpdateRedisPlayer::new);
}
onlinePlayers = new OnlinePlayers(TAB.getInstance().getOnlinePlayers());
TAB.getInstance().getFeatureManager().registerFeature(TabConstants.Feature.NAME_TAGS_COLLISION, collisionManager);
collisionManager.load();
Expand Down

0 comments on commit 818701c

Please sign in to comment.