java.lang.Object
net.sacredlabyrinth.phaed.simpleclans.hooks.discord.DiscordHook
All Implemented Interfaces:
org.bukkit.event.Listener

public class DiscordHook extends Object implements org.bukkit.event.Listener
Hooks SimpleClans and Discord, using DiscordSRV.

On server' startup:

  • Creates categories and channels, respecting discord's limits.
  • Removes invalid channels, resets permissions and roles.

Manages events:

  • Clan creation/deletion
  • ClanPlayer joining/resigning
  • Player linking/unlinking
  • ClanPlayer promoting/demoting

Currently, works with clan chat only.

  • Constructor Details

  • Method Details

    • onMessageReceived

      public void onMessageReceived(github.scarsz.discordsrv.api.events.DiscordGuildMessageReceivedEvent event)
    • onClanDisband

      public void onClanDisband(DisbandClanEvent event)
    • onClanCreate

      public void onClanCreate(CreateClanEvent event)
    • onPlayerClanLeave

      public void onPlayerClanLeave(PlayerKickedClanEvent event)
    • onPlayerClanJoin

      public void onPlayerClanJoin(PlayerJoinedClanEvent event)
    • onPlayerPromote

      public void onPlayerPromote(PlayerPromoteEvent event)
    • onPlayerDemote

      public void onPlayerDemote(PlayerDemoteEvent event)
    • onPlayerLinking

      public void onPlayerLinking(github.scarsz.discordsrv.api.events.AccountLinkedEvent event)
    • onPlayerUnlinking

      public void onPlayerUnlinking(github.scarsz.discordsrv.api.events.AccountUnlinkedEvent event)
    • setupDiscord

      protected void setupDiscord()
    • getGuild

      @NotNull public @NotNull github.scarsz.discordsrv.dependencies.jda.api.entities.Guild getGuild()
    • getLeaderRole

      @NotNull public @NotNull github.scarsz.discordsrv.dependencies.jda.api.entities.Role getLeaderRole()
      Returns:
      A leader role from guild, otherwise creates one.
    • getLeaderColor

      public Color getLeaderColor()
      Returns:
      A leader color from configuration
    • createCategory

      @Nullable public @Nullable github.scarsz.discordsrv.dependencies.jda.api.entities.Category createCategory()
      Creates a new SimpleClans Category
      Returns:
      Category or null, if reached the limit
    • createChannel

      public void createChannel(@NotNull @NotNull String clanTag) throws InvalidChannelException, CategoriesLimitException, ChannelsLimitException, ChannelExistsException
      Creates a new TextChannel in available SimpleClans' categories, otherwise creates one.

      Sets positive Permission.VIEW_CHANNEL permission to all linked clan members.

      Parameters:
      clanTag - the clan tag
      Throws:
      InvalidChannelException - clan is not verified or permanent, no one member is linked or clan is not in the whitelist.
      ChannelExistsException - if channel is already exist
      CategoriesLimitException - if categories reached the limit.
      ChannelsLimitException - if discord reached the channels limit.
    • getCachedChannel

      public Optional<github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel> getCachedChannel(@NotNull @NotNull String channelName)
      Retrieves channel in SimpleClans categories.
      Parameters:
      channelName - the channel name
      Returns:
      the channel
      See Also:
    • categoryExists

      public boolean categoryExists(String categoryId)
      Checks if a category can be obtained by id.
      Parameters:
      categoryId - the category id
      Returns:
      true if the category exists
      See Also:
    • channelExists

      public boolean channelExists(String clanTag)
      Checks if a channel with the specified clan tag exists
      See Also:
    • getChannel

      public Optional<github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel> getChannel(@NotNull @NotNull String channelName)
      Retrieves the channel in SimpleClans categories.
      Parameters:
      channelName - the channel name
      Returns:
      the channel
      See Also:
    • deleteChannel

      public boolean deleteChannel(@NotNull @NotNull String channelName)
      Deletes channel from SimpleClans categories. If there are no channels, removes category as well.
      Parameters:
      channelName - the channel name
      Returns:
      true, if channel was deleted and false if not.
    • getCachedCategories

      public List<github.scarsz.discordsrv.dependencies.jda.api.entities.Category> getCachedCategories()
      Returns:
      categories from config
    • getCategories

      public List<github.scarsz.discordsrv.dependencies.jda.api.entities.Category> getCategories()
      In most cases, you will use getCachedCategories().
      Returns:
      categories from guild
    • getChannels

      public List<github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel> getChannels()
      In most cases, you will use getCachedChannels().
      Returns:
      all channels from guild
    • getCachedChannels

      public List<github.scarsz.discordsrv.dependencies.jda.api.entities.TextChannel> getCachedChannels()
      Returns:
      All channels in categories
    • getMember

      @Nullable public @Nullable github.scarsz.discordsrv.dependencies.jda.api.entities.Member getMember(@NotNull @NotNull ClanPlayer clanPlayer)