Search in sources :

Example 1 with AccountLinkedEvent

use of github.scarsz.discordsrv.api.events.AccountLinkedEvent in project DiscordSRV by Scarsz.

the class AccountLinkManager method link.

public void link(String discordId, UUID uuid) {
    linkedAccounts.put(discordId, uuid);
    // call link event
    DiscordSRV.api.callEvent(new AccountLinkedEvent(DiscordUtil.getUserById(discordId), uuid));
    // trigger server commands
    OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
    for (String command : DiscordSRV.config().getStringList("MinecraftDiscordAccountLinkedConsoleCommands")) {
        if (offlinePlayer == null)
            continue;
        command = command.replace("%minecraftplayername%", offlinePlayer.getName()).replace("%minecraftdisplayname%", offlinePlayer.getPlayer() == null ? offlinePlayer.getName() : offlinePlayer.getPlayer().getDisplayName()).replace("%minecraftuuid%", uuid.toString()).replace("%discordid%", discordId).replace("%discordname%", DiscordUtil.getUserById(discordId).getName()).replace("%discorddisplayname%", DiscordSRV.getPlugin().getMainGuild().getMember(DiscordUtil.getUserById(discordId)).getEffectiveName());
        if (StringUtils.isBlank(command))
            continue;
        String finalCommand = command;
        Bukkit.getScheduler().scheduleSyncDelayedTask(DiscordSRV.getPlugin(), () -> Bukkit.dispatchCommand(Bukkit.getConsoleSender(), finalCommand));
    }
    // add user to role
    Role roleToAdd = DiscordUtil.getRole(DiscordSRV.getPlugin().getMainGuild(), DiscordSRV.config().getString("MinecraftDiscordAccountLinkedRoleNameToAddUserTo"));
    if (roleToAdd != null)
        DiscordUtil.addRolesToMember(DiscordUtil.getMemberById(discordId), roleToAdd);
    else
        DiscordSRV.debug("Couldn't add user to null role");
    // set user's discord nickname as their in-game name
    if (DiscordSRV.config().getBoolean("MinecraftDiscordAccountLinkedSetDiscordNicknameAsInGameName"))
        DiscordUtil.setNickname(DiscordUtil.getMemberById(discordId), Bukkit.getOfflinePlayer(uuid).getName());
}
Also used : Role(net.dv8tion.jda.core.entities.Role) AccountLinkedEvent(github.scarsz.discordsrv.api.events.AccountLinkedEvent) OfflinePlayer(org.bukkit.OfflinePlayer)

Aggregations

AccountLinkedEvent (github.scarsz.discordsrv.api.events.AccountLinkedEvent)1 Role (net.dv8tion.jda.core.entities.Role)1 OfflinePlayer (org.bukkit.OfflinePlayer)1