Class DiscordLinker

java.lang.Object
com.github.mafelp.accounts.DiscordLinker

public class DiscordLinker extends Object
The class that handles linking on the Discord side of things.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static Map<org.javacord.api.entity.user.User,​Integer>
    The Map that contains as key the Player that created the link token and as the Value an Integer between 100,000 and 999,999.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    getLinkToken​(org.javacord.api.entity.user.User user)
    Checks the linkableAccounts list, if the User already has a linking token and if so, it returns the token from this map.
    linkToMinecraft​(org.bukkit.entity.Player player, int linkID)
    The method used to create a linked Account with a discord user and the linking ID of a minecraft Player.
    private static int
    The method used to create a new Linking token, aka a Random, 6-Digit number, that is not already in the linkableAccounts list.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • linkableAccounts

      private static final Map<org.javacord.api.entity.user.User,​Integer> linkableAccounts
      The Map that contains as key the Player that created the link token and as the Value an Integer between 100,000 and 999,999.
  • Constructor Details

    • DiscordLinker

      public DiscordLinker()
  • Method Details

    • getLinkToken

      public static int getLinkToken(org.javacord.api.entity.user.User user)
      Checks the linkableAccounts list, if the User already has a linking token and if so, it returns the token from this map. If the user does not have a token yet, it creates one and adds it to the linkableAccounts map, associated with the user.
      Parameters:
      user - The user to get the Linking Token from.
      Returns:
      The Token used to link the account in minecraft.
    • linkToMinecraft

      public static Optional<Account> linkToMinecraft(org.bukkit.entity.Player player, int linkID)
      The method used to create a linked Account with a discord user and the linking ID of a minecraft Player. The linkID has to be generated by getLinkToken(User).
      Parameters:
      player - The minecraft Player to link the discord User to.
      linkID - The ID used for finding the correct discord User.
      Returns:
      If the ID is a valid token, it returns the newly Account, which was added to the list of accounts. If the ID is invalid, it returns an empty account.
    • randomLinkToken

      private static int randomLinkToken()
      The method used to create a new Linking token, aka a Random, 6-Digit number, that is not already in the linkableAccounts list. This prevents two users from having the same linking token.
      Returns:
      a random linking token.