- Add complete PlayHours mod source code with all features: * Schedule enforcement with per-day schedules and midnight-spanning support * Login control with configurable thresholds and exemptions * Warnings and auto-kick system with countdown functionality * Force modes (NORMAL/FORCE_OPEN/FORCE_CLOSED) for maintenance * Whitelist/blacklist system for player access control * Date exceptions for holidays and special events * Multi-language support (English/French) with smart time formatting * LuckPerms integration with vanilla ops fallback * Dynamic MOTD system with real-time schedule display * Comprehensive command system with permission integration * TOML configuration with hot-reload support - Add comprehensive documentation suite: * Installation guide with step-by-step setup instructions * Complete configuration reference with all options * Commands reference with usage examples * Features overview with detailed explanations * MOTD system configuration and customization guide * Permissions system documentation with LuckPerms integration * Technical details covering architecture and limitations * Usage examples with real-world scenarios * Changelog with version history - Add resource files: * Language files (en_us.json, fr_fr.json) with localized messages * Mod metadata (mods.toml) with proper Forge configuration * Resource pack metadata (pack.mcmeta) - Update build configuration: * Gradle build system with proper dependencies * Project properties and version management * Development environment setup - Restructure documentation: * Replace old README.txt with new comprehensive README.md * Create modular documentation structure in docs/ directory * Add cross-references and navigation between documents * Include quick start guide and common use cases This commit represents the complete v1.0.0 release of PlayHours, a production-ready server operation hours enforcement mod for Minecraft Forge 1.20.1.
71 lines
2.4 KiB
Java
71 lines
2.4 KiB
Java
package com.mrkayjaydee.playhours.events;
|
|
|
|
import com.mrkayjaydee.playhours.PlayHoursMod;
|
|
import com.mrkayjaydee.playhours.config.GeneralConfig;
|
|
import com.mrkayjaydee.playhours.config.MOTDConfig;
|
|
import com.mrkayjaydee.playhours.core.ScheduleService;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import net.minecraftforge.event.TickEvent;
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import java.time.ZonedDateTime;
|
|
|
|
/**
|
|
* Handles server MOTD (Message of the Day) customization.
|
|
* Orchestrates periodic MOTD updates based on current schedule state.
|
|
*/
|
|
@Mod.EventBusSubscriber(modid = PlayHoursMod.MODID)
|
|
public final class MOTDHandler {
|
|
|
|
private static long lastMOTDUpdate = 0;
|
|
|
|
private MOTDHandler() {}
|
|
|
|
/**
|
|
* Handles server tick to periodically update MOTD with schedule information.
|
|
*
|
|
* @param event the server tick event
|
|
*/
|
|
@SubscribeEvent
|
|
public static void onServerTick(TickEvent.ServerTickEvent event) {
|
|
if (event.phase != TickEvent.Phase.END) return;
|
|
if (event.getServer() == null) return;
|
|
|
|
try {
|
|
// Check if MOTD feature is enabled
|
|
if (!GeneralConfig.MOTD_ENABLED.get()) {
|
|
return;
|
|
}
|
|
|
|
// Only update periodically based on configured delay
|
|
long currentTime = System.currentTimeMillis();
|
|
long updateIntervalMillis = MOTDConfig.UPDATE_DELAY_SECONDS.get() * 1000L;
|
|
if (currentTime - lastMOTDUpdate < updateIntervalMillis) {
|
|
return;
|
|
}
|
|
lastMOTDUpdate = currentTime;
|
|
|
|
MinecraftServer server = event.getServer();
|
|
|
|
// Get current schedule information
|
|
ScheduleService scheduleService = ScheduleService.get();
|
|
ZonedDateTime now = ZonedDateTime.now(scheduleService.getZoneId());
|
|
|
|
// Build MOTD component
|
|
Component motd = MOTDBuilder.build(scheduleService, now);
|
|
|
|
// Validate and truncate to Minecraft limits (2 lines, 59 chars per line)
|
|
Component validatedMotd = MOTDValidator.validateAndTruncate(motd);
|
|
|
|
// Apply MOTD to server
|
|
server.setMotd(validatedMotd.getString());
|
|
|
|
} catch (Exception e) {
|
|
PlayHoursMod.LOGGER.error("Error updating MOTD", e);
|
|
}
|
|
}
|
|
}
|
|
|