Skip to content

Commit b01f074

Browse files
committed
improve injection
1 parent 995bda3 commit b01f074

9 files changed

Lines changed: 121 additions & 147 deletions

File tree

src/core/main/java/org/comroid/mcsd/core/module/console/McsdCommandModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
@Getter
2828
@ToString
2929
@FieldDefaults(level = AccessLevel.PRIVATE)
30-
@Component.Requires(ConsoleModule.class)
3130
public class McsdCommandModule extends ServerModule<McsdCommandModulePrototype> implements Command.Handler {
3231
public static final Pattern McsdPattern = ConsoleModule.commandPattern("mcsd");
3332
final Command.Manager cmdr = new Command.Manager(this);

src/core/main/java/org/comroid/mcsd/core/module/discord/DiscordModule.java

Lines changed: 114 additions & 116 deletions
Large diffs are not rendered by default.

src/core/main/java/org/comroid/mcsd/core/module/local/LocalExecutionModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
@Log
4444
@Getter
4545
@ToString
46-
@Component.Requires(UpdateModule.class)
4746
@FieldDefaults(level = AccessLevel.PRIVATE)
4847
public final class LocalExecutionModule extends ConsoleModule<LocalExecutionModulePrototype> {
4948
public static final Pattern DonePattern = pattern("Done \\((?<time>[\\d.]+)s\\).*\\r?\\n?.*?");

src/core/main/java/org/comroid/mcsd/core/module/player/ConsolePlayerEventModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
@Getter
2424
@ToString
2525
@FieldDefaults(level = AccessLevel.PRIVATE)
26-
@Component.Requires(ConsoleModule.class)
2726
public class ConsolePlayerEventModule extends PlayerEventModule<ConsolePlayerEventModulePrototype> {
27+
private @Inject ConsoleModule<?> console;
28+
2829
public ConsolePlayerEventModule(Server server, ConsolePlayerEventModulePrototype proto) {
2930
super(server, proto);
3031
}
3132

3233
@Override
3334
@SuppressWarnings({"RedundantSuppression", "RedundantTypeArguments", "RedundantCast"}) // intellij is being weird
3435
protected Event.Bus<PlayerEvent> initEventBus() {
35-
ConsoleModule<?> console = server.component(ConsoleModule.class).orElseThrow(() -> new InitFailed("No Console module is loaded"));
3636
//noinspection unchecked
3737
return console.getBus()
3838
.<Matcher>mapData(str -> Stream.of(ChatPattern, BroadcastPattern, JoinLeavePattern, AchievementPattern)

src/core/main/java/org/comroid/mcsd/core/module/player/ForceOpModule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
@Getter
1818
@ToString
1919
@FieldDefaults(level = AccessLevel.PRIVATE)
20-
@Component.Requires({ConsoleModule.class, PlayerEventModule.class})
2120
public class ForceOpModule extends ServerModule<ForceOpModulePrototype> {
2221
private @Inject ConsoleModule<ConsoleModulePrototype> console;
2322
private @Inject PlayerEventModule<PlayerEventModulePrototype> events;

src/core/main/java/org/comroid/mcsd/core/module/player/PlayerListModule.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
1313

1414
import static org.comroid.mcsd.core.util.ApplicationContextProvider.bean;
1515

16-
@Component.Requires(ConsolePlayerEventModule.class)
1716
public class PlayerListModule extends ServerModule<PlayerListModulePrototype> {
1817
private final Set<User> players = new HashSet<>();
19-
private ConsolePlayerEventModule chat;
18+
private @Inject PlayerEventModule<?> chat;
2019
private UserRepo users;
2120

2221
public PlayerListModule(Server server, PlayerListModulePrototype proto) {
@@ -25,7 +24,6 @@ public PlayerListModule(Server server, PlayerListModulePrototype proto) {
2524

2625
@Override
2726
protected void $initialize() {
28-
chat = server.component(ConsolePlayerEventModule.class).assertion();
2927
users = bean(UserRepo.class);
3028

3129
chat.getBus().filterData(e->e.getType().hasFlag(PlayerEvent.Type.JoinLeave))

src/core/main/java/org/comroid/mcsd/core/module/status/BackupModule.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,15 @@
3838
@Getter
3939
@ToString
4040
@FieldDefaults(level = AccessLevel.PRIVATE)
41-
@Component.Requires(LocalShellModule.class)
4241
public class BackupModule extends ServerModule<BackupModulePrototype> {
4342
public static final Pattern SaveCompletePattern = ConsoleModule.pattern("Saved the game");
4443
final AtomicReference<CompletableFuture<File>> currentBackup = new AtomicReference<>(CompletableFuture.completedFuture(null));
45-
@Component.Inject ConsoleModule<?> consoleModule;
44+
private @Inject ConsoleModule<?> consoleModule;
4645

4746
public BackupModule(Server server, BackupModulePrototype proto) {
4847
super(server, proto);
4948
}
5049

51-
@Override
52-
protected void $initialize() {
53-
consoleModule = server.component(ConsoleModule.class).assertion();
54-
}
55-
5650
@Override
5751
protected void $tick() {
5852
var status = server.component(StatusModule.class).assertion().getCurrentStatus().getStatus();

src/core/main/java/org/comroid/mcsd/core/module/status/UpdateModule.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,14 @@
2727
@Getter
2828
@ToString
2929
@FieldDefaults(level = AccessLevel.PRIVATE)
30-
@Component.Requires({FileModule.class, StatusModule.class})
3130
public class UpdateModule extends ServerModule<UpdateModulePrototype> {
3231
final AtomicReference<@Nullable CompletableFuture<Boolean>> updateRunning = new AtomicReference<>();
33-
@Inject FileModule<?> files;
32+
private @Inject FileModule<?> files;
3433

3534
public UpdateModule(Server server, UpdateModulePrototype proto) {
3635
super(server, proto);
3736
}
3837

39-
@Override
40-
protected void $initialize() {
41-
files= server.component(FileModule.class).assertion();
42-
}
43-
4438
@Override
4539
protected void $tick() {
4640
if ((proto.getUpdatePeriod() == null || proto.getLastUpdate().plus(proto.getUpdatePeriod()).isAfter(now()))

src/core/main/java/org/comroid/mcsd/core/module/status/UptimeModule.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,14 @@
2222
@Getter
2323
@ToString
2424
@FieldDefaults(level = AccessLevel.PRIVATE)
25-
@Component.Requires({LocalExecutionModule.class, StatusModule.class})
2625
public class UptimeModule extends ServerModule<UptimeModulePrototype> {
27-
LocalExecutionModule execution;
28-
StatusModule statusModule;
26+
private @Inject LocalExecutionModule execution;
27+
private @Inject StatusModule statusModule;
2928

3029
public UptimeModule(Server server, UptimeModulePrototype proto) {
3130
super(server, proto);
3231
}
3332

34-
@Override
35-
protected void $initialize() {
36-
execution = component(LocalExecutionModule.class).assertion();
37-
statusModule = component(StatusModule.class).assertion();
38-
}
39-
4033
@Override
4134
protected void $tick() {
4235
pushUptime();

0 commit comments

Comments
 (0)