- 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.
51 lines
1.9 KiB
Java
51 lines
1.9 KiB
Java
package com.mrkayjaydee.playhours.events;
|
|
|
|
import com.mrkayjaydee.playhours.PlayHoursMod;
|
|
import net.minecraft.network.chat.Component;
|
|
|
|
/**
|
|
* Validates and truncates MOTD to comply with Minecraft protocol limits.
|
|
* Enforces: 2 lines maximum, ~59 characters per line.
|
|
*/
|
|
public final class MOTDValidator {
|
|
private MOTDValidator() {}
|
|
|
|
private static final int MINECRAFT_LINE_LIMIT = 59;
|
|
private static final int MINECRAFT_MAX_LINES = 2;
|
|
|
|
/**
|
|
* Validates and truncates MOTD to comply with Minecraft protocol limits.
|
|
* Minecraft MOTD: 2 lines max, ~59 characters per line
|
|
*
|
|
* @param motd the MOTD component to validate
|
|
* @return the validated/truncated MOTD component
|
|
*/
|
|
public static Component validateAndTruncate(Component motd) {
|
|
String text = motd.getString();
|
|
String[] lines = text.split("\n", -1);
|
|
|
|
// Limit to 2 lines maximum (Minecraft displays 2 lines in server list)
|
|
if (lines.length > MINECRAFT_MAX_LINES) {
|
|
PlayHoursMod.LOGGER.warn("MOTD has {} lines but Minecraft only displays {}. Truncating.", lines.length, MINECRAFT_MAX_LINES);
|
|
lines = new String[]{lines[0], lines[1]};
|
|
}
|
|
|
|
// Truncate each line to ~59 characters (Minecraft MOTD line width limit)
|
|
StringBuilder validatedMotd = new StringBuilder();
|
|
|
|
for (int i = 0; i < lines.length; i++) {
|
|
String line = lines[i];
|
|
if (line.length() > MINECRAFT_LINE_LIMIT) {
|
|
PlayHoursMod.LOGGER.warn("MOTD line {} is {} chars but Minecraft limit is ~{}. Truncating.", i + 1, line.length(), MINECRAFT_LINE_LIMIT);
|
|
line = line.substring(0, Math.min(line.length(), MINECRAFT_LINE_LIMIT));
|
|
}
|
|
validatedMotd.append(line);
|
|
if (i < lines.length - 1) {
|
|
validatedMotd.append("\n");
|
|
}
|
|
}
|
|
|
|
return Component.literal(validatedMotd.toString());
|
|
}
|
|
}
|