Search in sources :

Example 6 with Component

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

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

the class CommandClanUntrustAllAdmin method execute.

@CommandCompletion("@gdclans @gdtrusttypes @gddummy")
@CommandAlias("clanuntrustalladmin")
@Description("%clan-untrust-all-admin")
@Syntax("<clan> [<accessor|builder|container|manager|resident>]")
@Subcommand("clan untrustalladmin")
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.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(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;
    }
    Set<Claim> claimList = new HashSet<>();
    final ClaimManager claimManager = GriefDefender.getCore().getClaimManager(player.getWorld().getUID());
    for (Claim claim : claimManager.getWorldClaims()) {
        if (claim.isAdminClaim()) {
            claimList.add(claim);
        }
    }
    if (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) GDClanTrustClaimEvent(com.griefdefender.hooks.event.GDClanTrustClaimEvent) TrustType(com.griefdefender.api.claim.TrustType) CommandResult(com.griefdefender.api.CommandResult) ClaimManager(com.griefdefender.api.claim.ClaimManager) Clan(com.griefdefender.api.Clan) Component(com.griefdefender.lib.kyori.adventure.text.Component) Claim(com.griefdefender.api.claim.Claim) HashSet(java.util.HashSet) 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 8 with Component

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

the class CommandClanUntrustRank method execute.

@CommandCompletion("@gdclanranks @gdtrusttypes @gddummy")
@CommandAlias("clanuntrustrank")
@Description("%clan-untrust-rank")
@Syntax("<rank>")
@Subcommand("clan untrust rank")
public void execute(Player player, String rank) {
    final Audience audience = GriefDefender.getAudienceProvider().getSender(player);
    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;
    }
    final TrustType trustType = clanConfig.getData().getRankTrust(rank);
    clanConfig.getData().deleteRankTrust(rank);
    clanConfig.save();
    final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.CLAN_UNTRUST_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 9 with Component

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

the class LegacyHexSerializer method deserializeTitle.

public static Title deserializeTitle(String title) {
    String[] parts = title.split(";");
    Component titleMain = HEX_SERIALIZER.deserialize(parts[0]);
    Component titleSub = HEX_SERIALIZER.deserialize(parts[1]);
    Duration fadeIn = Duration.ofSeconds(Long.valueOf(parts[2]));
    Duration timeStay = Duration.ofSeconds(Long.valueOf(parts[3]));
    Duration fadeOut = Duration.ofSeconds(Long.valueOf(parts[4]));
    return Title.title(titleMain, titleSub, Times.of(fadeIn, timeStay, fadeOut));
}
Also used : Duration(java.time.Duration) TextComponent(com.griefdefender.lib.kyori.adventure.text.TextComponent) Component(com.griefdefender.lib.kyori.adventure.text.Component)

Example 10 with Component

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

the class CommandClanTrustAllAdmin method execute.

@CommandCompletion("@gdclans @gdtrusttypes @gddummy")
@CommandAlias("clantrustalladmin")
@Description("%clan-trust-all-admin")
@Syntax("<clan> [<accessor|builder|container|manager|resident>]")
@Subcommand("clan trustalladmin")
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.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(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;
    }
    Set<Claim> claimList = new HashSet<>();
    final ClaimManager claimManager = GriefDefender.getCore().getClaimManager(player.getWorld().getUID());
    for (Claim claim : claimManager.getWorldClaims()) {
        if (claim.isAdminClaim()) {
            claimList.add(claim);
        }
    }
    if (claimList == null || claimList.size() == 0) {
        audience.sendMessage(MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_NO_CLAIMS));
        return;
    }
    GriefDefender.getEventManager().getCauseStackManager().pushCause(player);
    GDClanTrustClaimEvent.Add event = new GDClanTrustClaimEvent.Add(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) {
        if (trustType == TrustTypes.RESIDENT && !claim.isAdminClaim() && !claim.isTown()) {
            continue;
        }
        claim.addClanTrust(clan, trustType);
    }
    final Component message = MessageConfig.MESSAGE_DATA.getMessage(MessageConfig.TRUST_INDIVIDUAL_ALL_CLAIMS, ImmutableMap.of("player", clan.getTag()));
    audience.sendMessage(message);
}
Also used : Audience(com.griefdefender.lib.kyori.adventure.audience.Audience) GDClanTrustClaimEvent(com.griefdefender.hooks.event.GDClanTrustClaimEvent) TrustType(com.griefdefender.api.claim.TrustType) CommandResult(com.griefdefender.api.CommandResult) ClaimManager(com.griefdefender.api.claim.ClaimManager) Clan(com.griefdefender.api.Clan) Component(com.griefdefender.lib.kyori.adventure.text.Component) Claim(com.griefdefender.api.claim.Claim) HashSet(java.util.HashSet) 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