-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d311eae
commit 7bdfc48
Showing
3 changed files
with
55 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/com/tristansmp/elytra/commands/CommandLink.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.tristansmp.elytra.commands | ||
|
||
import com.tristansmp.elytra.Elytra | ||
import khttp.post | ||
import org.bukkit.command.Command | ||
import org.bukkit.command.CommandExecutor | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.entity.Player | ||
|
||
class CommandLink : CommandExecutor { | ||
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>?): Boolean { | ||
if (sender !is Player || Elytra.instance.config.config.token == null || Elytra.instance.config.config.linkAccountEndpoint == null) { | ||
return false | ||
} | ||
|
||
// make sure we have a code | ||
if (args == null || args.isEmpty()) { | ||
return false | ||
} | ||
|
||
val player = sender | ||
val uuid = player.uniqueId.toString() | ||
val code = args[0] | ||
val token = Elytra.instance.config.config.token ?: return false | ||
val endpoint = Elytra.instance.config.config.linkAccountEndpoint ?: return false | ||
|
||
player.sendMessage("§a§l[§b§lElytra§a§l] §a§lLinking account...") | ||
|
||
try { | ||
val response = post( | ||
url = endpoint, | ||
data = mapOf( | ||
"uuid" to uuid, | ||
"code" to code | ||
), | ||
headers = mapOf( | ||
"Authorization" to token | ||
) | ||
) | ||
|
||
// check the response code | ||
if (response.statusCode == 200) { | ||
player.sendMessage("§a§l[§b§lElytra§a§l] §a§lSuccessfully linked account!") | ||
} else { | ||
player.sendMessage("§a§l[§b§lElytra§a§l] §c§lFailed to link account!") | ||
} | ||
} catch (e: Exception) { | ||
player.sendMessage("§a§l[§b§lElytra§a§l] §c§lFailed to link account!") | ||
} | ||
|
||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters