Search in sources :

Example 1 with Component

use of com.griefdefender.lib.kyori.adventure.text.Component in project GDHooks by bloodmc.

the class CommandVersion method execute.

@CommandAlias("gdhooksversion")
@Description("%version")
@Subcommand("version")
public void execute(CommandSender src) {
    Component gpVersion = Component.text().append(GDHooks.GDHOOKS_TEXT).append(Component.text("Running ")).append(Component.text("GDHooks " + GDHooks.IMPLEMENTATION_VERSION, NamedTextColor.AQUA)).build();
    Component bukkitVersion = Component.text().append(GDHooks.GDHOOKS_TEXT).append(Component.text("Running ")).append(Component.text(Bukkit.getVersion(), NamedTextColor.YELLOW)).build();
    GriefDefender.getAudienceProvider().getSender(src).sendMessage(Component.text().append(gpVersion).append(Component.newline()).append(bukkitVersion).build());
}
Also used : Component(com.griefdefender.lib.kyori.adventure.text.Component) Description(co.aikar.commands.annotation.Description) Subcommand(co.aikar.commands.annotation.Subcommand) CommandAlias(co.aikar.commands.annotation.CommandAlias)

Example 2 with Component

use of com.griefdefender.lib.kyori.adventure.text.Component in project GDHooks by bloodmc.

the class CommandClanClaim method execute.

@CommandCompletion("@gdidentifiers")
@CommandAlias("clanclaim")
@Description("%clan-claim")
@Syntax("[identifier]")
@Subcommand("clan claim")
public void execute(Player player, @Optional String identifier) {
    final ClanPlayer clanPlayer = GDHooks.getInstance().getClanProvider().getClanPlayer(player.getUniqueId());
    if (clanPlayer == null) {
        return;
    }
    final Clan clan = clanPlayer.getClan();
    if (clan == null) {
        return;
    }
    if (!clanPlayer.isLeader()) {
        return;
    }
    final Audience audience = GriefDefender.getAudienceProvider().getSender(player);
    final CommandResult result = GriefDefender.getCore().canUseCommand(player, 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.hasAttribute(GDHooksAttributes.ATTRIBUTE_CLAN)) {
        claim.removeAttribute(GDHooksAttributes.ATTRIBUTE_CLAN);
        audience.sendMessage(Component.text("Removed clan attribute."));
    } else {
        claim.addAttribute(GDHooksAttributes.ATTRIBUTE_CLAN);
        audience.sendMessage(Component.text("Added clan attribute."));
    }
}
Also used : Audience(com.griefdefender.lib.kyori.adventure.audience.Audience) Clan(com.griefdefender.api.Clan) Component(com.griefdefender.lib.kyori.adventure.text.Component) ClanPlayer(com.griefdefender.api.ClanPlayer) 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 Component

use of com.griefdefender.lib.kyori.adventure.text.Component 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 4 with Component

use of com.griefdefender.lib.kyori.adventure.text.Component in project GDHooks by bloodmc.

the class CommandClanTrustRank method execute.

@CommandCompletion("@gdclanranks @gdtrusttypes @gddummy")
@CommandAlias("clantrustrank")
@Description("%clan-trust-rank")
@Syntax("<rank> <accessor|builder|container|manager|resident>")
@Subcommand("clan trust rank")
public void execute(Player player, String rank, String type) {
    final Audience audience = GriefDefender.getAudienceProvider().getSender(player);
    TrustType trustType = HooksUtil.getTrustType(type);
    if (trustType == null) {
        audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_INVALID));
        return;
    }
    final ClanPlayer clanPlayer = GDHooks.getInstance().getClanProvider().getClanPlayer(player.getUniqueId());
    if (clanPlayer == null) {
        return;
    }
    final Clan clan = clanPlayer.getClan();
    if (clan == null) {
        return;
    }
    if (!clanPlayer.isLeader()) {
        return;
    }
    final ClanConfig clanConfig = GDHooks.getInstance().getClanConfigMap().get(clan.getTag());
    if (clanConfig == null) {
        return;
    }
    clanConfig.getData().addRankTrust(rank, trustType);
    clanConfig.save();
    final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.CLAN_TRUST_RANK, ImmutableMap.of("rank", rank, "type", trustType.getName()));
    audience.sendMessage(message);
}
Also used : ClanConfig(com.griefdefender.hooks.config.ClanConfig) 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) ClanPlayer(com.griefdefender.api.ClanPlayer) 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 5 with Component

use of com.griefdefender.lib.kyori.adventure.text.Component in project GDHooks by bloodmc.

the class CommandClanUntrustAll method execute.

@CommandCompletion("@gdclans @gdtrusttypes @gddummy")
@CommandAlias("clanuntrustall")
@Description("%clan-untrust-all")
@Syntax("<clan> [<accessor|builder|container|manager|resident>]")
@Subcommand("clan untrustall")
public void execute(Player player, String clanTag, @Optional String type, @Optional String identifier) {
    TrustType trustType = null;
    final Audience audience = GriefDefender.getAudienceProvider().getSender(player);
    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(player, 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;
    }
    PlayerData playerData = GriefDefender.getCore().getPlayerData(player.getWorld().getUID(), player.getUniqueId());
    Set<Claim> claimList = null;
    if (playerData != null) {
        claimList = playerData.getClaims();
    }
    if (playerData == null || claimList == null || claimList.size() == 0) {
        audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_NO_CLAIMS));
        return;
    }
    GriefDefender.getEventManager().getCauseStackManager().pushCause(player);
    GDClanTrustClaimEvent.Remove event = new GDClanTrustClaimEvent.Remove(new ArrayList<>(claimList), ImmutableSet.of(clan), trustType);
    GriefDefender.getEventManager().post(event);
    GriefDefender.getEventManager().getCauseStackManager().popCause();
    if (event.cancelled()) {
        audience.sendMessage(event.getMessage().orElse(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_PLUGIN_CANCEL, ImmutableMap.of("target", clan.getTag()))));
        return;
    }
    for (Claim claim : claimList) {
        claim.removeClanTrust(clan, trustType);
    }
    final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.UNTRUST_INDIVIDUAL_ALL_CLAIMS, ImmutableMap.of("player", clan.getTag()));
    audience.sendMessage(message);
}
Also used : Audience(com.griefdefender.lib.kyori.adventure.audience.Audience) Clan(com.griefdefender.api.Clan) GDClanTrustClaimEvent(com.griefdefender.hooks.event.GDClanTrustClaimEvent) TrustType(com.griefdefender.api.claim.TrustType) Component(com.griefdefender.lib.kyori.adventure.text.Component) PlayerData(com.griefdefender.api.data.PlayerData) 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)

Aggregations

Component (com.griefdefender.lib.kyori.adventure.text.Component)11 CommandAlias (co.aikar.commands.annotation.CommandAlias)10 Description (co.aikar.commands.annotation.Description)10 Subcommand (co.aikar.commands.annotation.Subcommand)10 CommandCompletion (co.aikar.commands.annotation.CommandCompletion)9 Syntax (co.aikar.commands.annotation.Syntax)9 Clan (com.griefdefender.api.Clan)9 Audience (com.griefdefender.lib.kyori.adventure.audience.Audience)9 TrustType (com.griefdefender.api.claim.TrustType)8 CommandResult (com.griefdefender.api.CommandResult)7 Claim (com.griefdefender.api.claim.Claim)7 GDClanTrustClaimEvent (com.griefdefender.hooks.event.GDClanTrustClaimEvent)4 ClanPlayer (com.griefdefender.api.ClanPlayer)3 ClaimManager (com.griefdefender.api.claim.ClaimManager)2 ClaimResult (com.griefdefender.api.claim.ClaimResult)2 PlayerData (com.griefdefender.api.data.PlayerData)2 ClanConfig (com.griefdefender.hooks.config.ClanConfig)2 HashSet (java.util.HashSet)2 TextComponent (com.griefdefender.lib.kyori.adventure.text.TextComponent)1 Duration (java.time.Duration)1