Search in sources :

Example 1 with ClaimResult

use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.

the class CommandClanTrust method execute.

@CommandCompletion("@gdclans @gdtrusttypes @gddummy")
@CommandAlias("clantrust")
@Description("%clan-trust")
@Syntax("<clan> [<accessor|builder|container|manager|resident>]")
@Subcommand("clan trust")
public void execute(CommandSender sender, String clanTag, @Optional String type, @Optional String identifier) {
    TrustType trustType = null;
    final Audience audience = GriefDefender.getAudienceProvider().getSender(sender);
    if (type == null) {
        trustType = TrustTypes.BUILDER;
    } else {
        trustType = HooksUtil.getTrustType(type);
        if (trustType == null) {
            audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_INVALID));
            return;
        }
    }
    final Clan clan = GDHooks.getInstance().getClanProvider().getClan(clanTag);
    if (clan == null) {
        audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.COMMAND_INVALID_CLAN, ImmutableMap.of("clan", clanTag)));
        return;
    }
    final CommandResult result = GriefDefender.getCore().canUseCommand(sender, TrustTypes.MANAGER, identifier);
    if (!result.successful()) {
        if (result.getClaim() != null) {
            final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_TRUST, ImmutableMap.of("owner", result.getClaim().getOwnerDisplayName()));
            audience.sendMessage(message);
        } else {
            audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_COMMAND_TRUST));
        }
        return;
    }
    final Claim claim = result.getClaim();
    if (!claim.isAdminClaim() && !claim.isTown() && trustType == TrustTypes.RESIDENT) {
        audience.sendMessage(Component.text("Resident trust not allowed in this claim type."));
        return;
    }
    if (claim.isClanTrusted(clan, trustType)) {
        final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_ALREADY_HAS, ImmutableMap.of("target", clan.getTag(), "type", trustType.getName()));
        audience.sendMessage(message);
        return;
    }
    GriefDefender.getEventManager().getCauseStackManager().pushCause(sender);
    final ClaimResult claimResult = claim.addClanTrust(clanTag, trustType);
    GriefDefender.getEventManager().getCauseStackManager().popCause();
    if (!claimResult.successful()) {
        audience.sendMessage(claimResult.getMessage().orElse(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_PLUGIN_CANCEL, ImmutableMap.of("target", clan.getTag()))));
        return;
    }
    final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_GRANT, ImmutableMap.of("target", clan.getTag(), "type", trustType.getName()));
    audience.sendMessage(message);
}
Also used : ClaimResult(com.griefdefender.api.claim.ClaimResult) Audience(com.griefdefender.lib.kyori.adventure.audience.Audience) Clan(com.griefdefender.api.Clan) TrustType(com.griefdefender.api.claim.TrustType) Component(com.griefdefender.lib.kyori.adventure.text.Component) Claim(com.griefdefender.api.claim.Claim) CommandResult(com.griefdefender.api.CommandResult) Description(co.aikar.commands.annotation.Description) Subcommand(co.aikar.commands.annotation.Subcommand) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 2 with ClaimResult

use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.

the class CommandClanUntrust method execute.

@CommandCompletion("@gdclans @gdtrusttypes @gddummy")
@CommandAlias("clanuntrust")
@Description("%clan-untrust")
@Syntax("<clan> [<accessor|builder|container|manager|resident>]")
@Subcommand("clan untrust")
public void execute(CommandSender sender, String clanTag, @Optional String type, @Optional String identifier) {
    TrustType trustType = null;
    final Audience audience = GriefDefender.getAudienceProvider().getSender(sender);
    if (type == null) {
        trustType = TrustTypes.NONE;
    } else {
        trustType = HooksUtil.getTrustType(type);
        if (trustType == null) {
            audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_INVALID));
            return;
        }
    }
    final Clan clan = GDHooks.getInstance().getClanProvider().getClan(clanTag);
    if (clan == null) {
        audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.COMMAND_INVALID_CLAN, ImmutableMap.of("clan", clanTag)));
        return;
    }
    final CommandResult result = GriefDefender.getCore().canUseCommand(sender, TrustTypes.MANAGER, identifier);
    if (!result.successful()) {
        if (result.getClaim() != null) {
            final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_TRUST, ImmutableMap.of("owner", result.getClaim().getOwnerDisplayName()));
            audience.sendMessage(message);
        } else {
            audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.PERMISSION_COMMAND_TRUST));
        }
        return;
    }
    final Claim claim = result.getClaim();
    GriefDefender.getEventManager().getCauseStackManager().pushCause(sender);
    final ClaimResult claimResult = claim.removeClanTrust(clanTag, trustType);
    GriefDefender.getEventManager().getCauseStackManager().popCause();
    if (!claimResult.successful()) {
        audience.sendMessage(claimResult.getMessage().orElse(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_PLUGIN_CANCEL, ImmutableMap.of("target", clan.getTag()))));
        return;
    }
    final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.UNTRUST_INDIVIDUAL_SINGLE_CLAIM, ImmutableMap.of("target", clan.getTag()));
    audience.sendMessage(message);
}
Also used : ClaimResult(com.griefdefender.api.claim.ClaimResult) Audience(com.griefdefender.lib.kyori.adventure.audience.Audience) Clan(com.griefdefender.api.Clan) TrustType(com.griefdefender.api.claim.TrustType) Component(com.griefdefender.lib.kyori.adventure.text.Component) Claim(com.griefdefender.api.claim.Claim) CommandResult(com.griefdefender.api.CommandResult) Description(co.aikar.commands.annotation.Description) Subcommand(co.aikar.commands.annotation.Subcommand) CommandCompletion(co.aikar.commands.annotation.CommandCompletion) Syntax(co.aikar.commands.annotation.Syntax) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 3 with ClaimResult

use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.

the class OreRegeneratorProvider method onCreateRegion.

@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCreateRegion(RegionCreateEvent event) {
    final Player player = event.getCreator();
    final World world = event.getCreator().getWorld();
    final int x1 = event.getLocationOne().getBlockX();
    final int x2 = event.getLocationTwo().getBlockX();
    final int y1 = event.getLocationOne().getBlockY();
    final int y2 = event.getLocationTwo().getBlockY();
    final int z1 = event.getLocationOne().getBlockZ();
    final int z2 = event.getLocationTwo().getBlockZ();
    final Claim currentClaim = GriefDefender.getCore().getClaimAt(event.getLocationOne());
    if (currentClaim.isWilderness()) {
        final ClaimResult result = Claim.builder().world(world.getUID()).bounds(x1, x2, y1, y2, z1, z2).owner(TEMP_USER_UUID).type(ClaimTypes.BASIC).cuboid(true).build();
        if (!result.successful()) {
            event.setCancelled(true);
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cUnable to create ore region. Reason: " + result.getResultType().name()));
        }
        return;
    } else {
        if (!currentClaim.isUserTrusted(player.getUniqueId(), TrustTypes.BUILDER)) {
            event.setCancelled(true);
            event.setReason(ChatColor.translateAlternateColorCodes('&', "&cYou do not have " + currentClaim.getOwnerName() + "'s permission to build here."));
            return;
        }
        final ClaimResult result = Claim.builder().world(world.getUID()).bounds(x1, x2, y1, y2, z1, z2).owner(TEMP_USER_UUID).type(ClaimTypes.SUBDIVISION).cuboid(true).parent(currentClaim).build();
        if (!result.successful()) {
            event.setCancelled(true);
            player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cUnable to create ore region. Reason: " + result.getResultType().name()));
        }
    }
}
Also used : ClaimResult(com.griefdefender.api.claim.ClaimResult) Player(org.bukkit.entity.Player) World(org.bukkit.World) Claim(com.griefdefender.api.claim.Claim) EventHandler(org.bukkit.event.EventHandler)

Example 4 with ClaimResult

use of com.griefdefender.api.claim.ClaimResult in project GDHooks by bloodmc.

the class TownyProvider method canCreateTown.

private boolean canCreateTown(World world, int townBlockX, int townBlockZ) {
    final int sx = townBlockX << 4;
    final int sz = townBlockZ << 4;
    final int bx = sx + 15;
    final int bz = sz + 15;
    final Vector3i lesserBoundary = new Vector3i(sx, -64, sz);
    final Vector3i greaterBoundary = new Vector3i(bx, 319, bz);
    final ClaimResult result = GriefDefender.getRegistry().createBuilder(Claim.Builder.class).bounds(lesserBoundary, greaterBoundary).cuboid(false).owner(TEMP_USER_UUID).type(ClaimTypes.BASIC).world(world.getUID()).build();
    if (!result.successful()) {
        return false;
    }
    return true;
}
Also used : ClaimResult(com.griefdefender.api.claim.ClaimResult) Vector3i(com.griefdefender.lib.flowpowered.math.vector.Vector3i) Claim(com.griefdefender.api.claim.Claim)

Aggregations

Claim (com.griefdefender.api.claim.Claim)4 ClaimResult (com.griefdefender.api.claim.ClaimResult)4 CommandAlias (co.aikar.commands.annotation.CommandAlias)2 CommandCompletion (co.aikar.commands.annotation.CommandCompletion)2 Description (co.aikar.commands.annotation.Description)2 Subcommand (co.aikar.commands.annotation.Subcommand)2 Syntax (co.aikar.commands.annotation.Syntax)2 Clan (com.griefdefender.api.Clan)2 CommandResult (com.griefdefender.api.CommandResult)2 TrustType (com.griefdefender.api.claim.TrustType)2 Audience (com.griefdefender.lib.kyori.adventure.audience.Audience)2 Component (com.griefdefender.lib.kyori.adventure.text.Component)2 Vector3i (com.griefdefender.lib.flowpowered.math.vector.Vector3i)1 World (org.bukkit.World)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1