Skip to content

Commit

Permalink
Fix injection
Browse files Browse the repository at this point in the history
  • Loading branch information
voruti committed Jul 22, 2023
1 parent 298c750 commit d7f5ece
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import voruti.velocityplayerlistquery.model.exception.InvalidServerPingException;
import voruti.velocityplayerlistquery.service.ConfigService;
import voruti.velocityplayerlistquery.service.serverpingprocessor.ServerPingProcessor;
import voruti.velocityplayerlistquery.service.serverpingprocessor.ServerPingProcessorRegistry;

import javax.inject.Inject;
import java.util.Optional;
import java.util.Set;

@Plugin(
id = "velocityplayerlistquery",
Expand All @@ -37,7 +37,7 @@ public class VelocityPlayerListQuery {
ConfigService configService;

@Inject
Set<ServerPingProcessor> serverPingProcessors;
ServerPingProcessorRegistry serverPingProcessorRegistry;


@Subscribe
Expand Down Expand Up @@ -84,7 +84,7 @@ private Optional<ServerPing> processPing(@NonNull final ServerPing serverPing) {

// apply all server ping processors:
boolean isModified = false;
for (ServerPingProcessor processor : this.serverPingProcessors) {
for (ServerPingProcessor processor : this.serverPingProcessorRegistry.serverPingProcessorList()) {
if (processor.isEnabled()) {
processor.applyToServerPing(builder);
isModified = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package voruti.velocityplayerlistquery.service.serverpingprocessor;

import lombok.Value;
import lombok.experimental.Accessors;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.List;

@Singleton
@Value
@Accessors(fluent = true)
public class ServerPingProcessorRegistry {

List<ServerPingProcessor> serverPingProcessorList;


@Inject
public ServerPingProcessorRegistry(
FillMissingVersionInfoServerPingProcessor fillMissingVersionInfoServerPingProcessor,
MaxPlayerCountServerPingProcessor maxPlayerCountServerPingProcessor,
OnlinePlayerCountServerPingProcessor onlinePlayerCountServerPingProcessor,
PlayerListServerPingProcessor playerListServerPingProcessor,
ReplaceVersionInfoServerPingProcessor replaceVersionInfoServerPingProcessor) {
this.serverPingProcessorList = List.of(
fillMissingVersionInfoServerPingProcessor,
maxPlayerCountServerPingProcessor,
onlinePlayerCountServerPingProcessor,
playerListServerPingProcessor,
replaceVersionInfoServerPingProcessor
);
}
}

0 comments on commit d7f5ece

Please sign in to comment.