Files
Coalgov/CoalGov/src/main/java/com/librewiki/coalgov/service/BuildProtectionService.java
2026-05-04 17:00:18 +00:00

44 lines
1.4 KiB
Java

package com.librewiki.coalgov.service;
import com.librewiki.coalgov.CoalGovPlugin;
import com.librewiki.coalgov.model.Claim;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.sql.SQLException;
import java.util.Optional;
public final class BuildProtectionService {
private final CoalGovPlugin plugin;
private final ClaimService claimService;
public BuildProtectionService(CoalGovPlugin plugin, ClaimService claimService) {
this.plugin = plugin;
this.claimService = claimService;
}
public BuildDecision canModify(Player player, Location location) throws SQLException {
if (plugin.hasAdminBypass(player)) {
return BuildDecision.allow();
}
Optional<Claim> claim = claimService.claimAt(location);
if (claim.isEmpty()) {
return BuildDecision.deny("This land is unclaimed and protected by the Ministry.");
}
if (!claim.get().ownerUuid().equals(player.getUniqueId())) {
return BuildDecision.deny("This claim belongs to another citizen.");
}
return BuildDecision.allow();
}
public record BuildDecision(boolean allowed, String message) {
public static BuildDecision allow() {
return new BuildDecision(true, "");
}
public static BuildDecision deny(String message) {
return new BuildDecision(false, message);
}
}
}