Files
PlayHours/src/main/java/com/mrkayjaydee/playhours/permissions/LuckPermsIntegration.java
Mr¤KayJayDee c0fd2a2787 feat(docs): complete PlayHours mod implementation with comprehensive documentation
- 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.
2025-10-23 23:28:20 +02:00

87 lines
3.0 KiB
Java

package com.mrkayjaydee.playhours.permissions;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.server.ServerLifecycleHooks;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
* Handles LuckPerms integration for permission checking.
* Separates LuckPerms-specific logic from general permission checking.
*/
public final class LuckPermsIntegration {
private LuckPermsIntegration() {}
// LuckPerms soft integration - detected at startup
private static net.luckperms.api.LuckPerms luckPerms;
static {
try {
luckPerms = net.luckperms.api.LuckPermsProvider.get();
} catch (Throwable ignored) {
// LuckPerms not present, will use vanilla fallback
luckPerms = null;
}
}
/**
* Checks if LuckPerms is available.
*
* @return true if LuckPerms is loaded and available
*/
public static boolean isAvailable() {
return luckPerms != null;
}
/**
* Checks a permission for an online player using LuckPerms.
*
* @param player the player to check
* @param permission the permission node
* @return true if the player has the permission
*/
public static boolean hasPermission(ServerPlayer player, String permission) {
if (!isAvailable()) return false;
var user = luckPerms.getUserManager().getUser(player.getUUID());
if (user == null) return false;
var data = user.getCachedData().getPermissionData();
var result = data.checkPermission(permission);
return result.asBoolean();
}
/**
* Checks a permission for an offline player by UUID using LuckPerms.
* Uses a timeout to prevent blocking indefinitely.
*
* @param uuid the player UUID
* @param permission the permission node
* @return true if the player has the permission, false otherwise or on timeout
*/
public static boolean hasPermissionOffline(UUID uuid, String permission) {
if (!isAvailable()) return false;
// Check if player is online first
var server = ServerLifecycleHooks.getCurrentServer();
ServerPlayer online = server.getPlayerList().getPlayer(uuid);
if (online != null) {
return hasPermission(online, permission);
}
// Offline LP check (best-effort with timeout to avoid blocking)
try {
var future = luckPerms.getUserManager().loadUser(uuid);
var user = future.get(PermissionConstants.LUCKPERMS_TIMEOUT_SECONDS, TimeUnit.SECONDS);
if (user != null) {
var result = user.getCachedData().getPermissionData().checkPermission(permission);
return result.asBoolean();
}
} catch (Throwable t) {
// Timeout, interrupted, or other error - log and continue
// This is acceptable as it's best-effort for offline checks
}
return false;
}
}