LinkTelegramCmd.java 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package de.Linus122.TelegramChat;
  2. import java.io.IOException;
  3. import org.bukkit.command.Command;
  4. import org.bukkit.command.CommandExecutor;
  5. import org.bukkit.command.CommandSender;
  6. import org.bukkit.entity.Player;
  7. public class LinkTelegramCmd implements CommandExecutor {
  8. @Override
  9. public boolean onCommand(CommandSender cs, Command arg1, String arg2, String[] args) {
  10. if(!(cs instanceof Player)){
  11. cs.sendMessage("§cSorry, but you can't link the console currently.");
  12. }
  13. if(!cs.hasPermission("telegram.linktelegram")){
  14. cs.sendMessage("§cYou don't have permissions to use this!");
  15. return true;
  16. }
  17. if(Main.data == null){
  18. Main.data = new Data();
  19. }
  20. if(Telegram.authJson == null){
  21. cs.sendMessage("§cPlease add a bot to your server first! /telegram");
  22. return true;
  23. }
  24. String token = Main.generateLinkToken();
  25. Main.data.linkCodes.put(token, ((Player) cs).getUniqueId());
  26. cs.sendMessage("§aAdd " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + " to Telegram and send this message to " + Telegram.authJson.getAsJsonObject("result").get("username").getAsString() + ":");
  27. cs.sendMessage("§c" + token);
  28. return true;
  29. }
  30. }