Files
Bat/src/main/java/cc/fascinated/bat/features/minecraft/MinecraftFeature.java
Liam 6fef1d0092
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m8s
check feature states
2024-07-06 06:26:33 +01:00

49 lines
1.8 KiB
Java

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.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;
/**
* @author Fascinated (fascinated7)
*/
@Component
public class MinecraftFeature extends Feature {
private final GuildService guildService;
@Autowired
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());
if (batGuild.getFeatureProfile().isFeatureDisabled(this)) { // Check if the feature is disabled
continue;
}
batGuild.getMinecraftProfile().checkServers();
}
}
}