impl server watcher for minecraft servers
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m27s

This commit is contained in:
Lee
2024-07-06 06:21:05 +01:00
parent ee7e8b64c5
commit 514f4757a9
11 changed files with 482 additions and 12 deletions

View File

@ -2,11 +2,17 @@ package cc.fascinated.bat.features.minecraft;
import cc.fascinated.bat.features.Feature;
import cc.fascinated.bat.features.FeatureProfile;
import cc.fascinated.bat.features.minecraft.command.MinecraftCommand;
import cc.fascinated.bat.features.minecraft.command.minecraft.MinecraftCommand;
import cc.fascinated.bat.features.minecraft.command.serverwatcher.ServerWatcherCommand;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.service.CommandService;
import cc.fascinated.bat.service.DiscordService;
import cc.fascinated.bat.service.GuildService;
import lombok.NonNull;
import net.dv8tion.jda.api.entities.Guild;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
@ -14,10 +20,25 @@ import org.springframework.stereotype.Component;
*/
@Component
public class MinecraftFeature extends Feature {
private final GuildService guildService;
@Autowired
public MinecraftFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService) {
public MinecraftFeature(@NonNull ApplicationContext context, @NonNull CommandService commandService, @NonNull GuildService guildService) {
super("Minecraft", FeatureProfile.FeatureState.DISABLED, true);
this.guildService = guildService;
super.registerCommand(commandService, context.getBean(MinecraftCommand.class));
super.registerCommand(commandService, context.getBean(ServerWatcherCommand.class));
}
/**
* Check servers every minute
*/
@Scheduled(cron = "0 * * * * *")
public void checkServers() {
for (Guild guild : DiscordService.JDA.getGuilds()) {
BatGuild batGuild = guildService.getGuild(guild.getId());
batGuild.getMinecraftProfile().checkServers();
}
}
}