Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. package de.staticfx.godBot.commands;
  2.  
  3. import com.jagrosh.jdautilities.commandclient.Command;
  4. import com.jagrosh.jdautilities.commandclient.CommandEvent;
  5. import de.staticfx.godBot.DiscordBot;
  6. import net.dv8tion.jda.core.entities.Role;
  7. import net.dv8tion.jda.core.entities.TextChannel;
  8. import xyz.dodo.fortnite.Fortnite;
  9. import xyz.dodo.fortnite.entity.FortniteData;
  10. import xyz.dodo.fortnite.entity.League;
  11. import xyz.dodo.fortnite.entity.Stat;
  12.  
  13. import java.util.List;
  14. import java.util.stream.Collectors;
  15.  
  16. public class RankCommandExecuter extends Command {
  17. Fortnite fortnite = new Fortnite("8fdc1618-608d-4733-b581-d3141c189c57");
  18.  
  19. public RankCommandExecuter() {
  20. this.name = "rank";
  21. this.aliases = new String[]{"rank1"};
  22. }
  23.  
  24. List<Stat> stats = data.getLeague(League.Mode.life_time).getStats();
  25. String kdRatio = findStat(stats, "K/d");
  26.  
  27. protected void execute(CommandEvent event) {
  28. Role role1 = DiscordBot.getInstance().getJda().getGuildById("556210184100249623").getRoleById("557260408575229978");
  29. Role role2 = DiscordBot.getInstance().getJda().getGuildById("556210184100249623").getRoleById("557260459858853891");
  30. Role role3 = DiscordBot.getInstance().getJda().getGuildById("556210184100249623").getRoleById("557260508462317588");
  31. // use camelCase
  32. String username = event.getMember().getNickname();
  33. String[] args = event.getArgs().split(" ");
  34. // what's this? : TextChannel textchanal = event.getGuild().getTextChannelsByName("skillgruppe-erhalten",true).get(0);
  35.  
  36. // code is repeated?
  37. /*
  38. if(event.getMember().getRoles().stream().filter(r -> r.getName().equalsIgnoreCase("xbox")).collect(Collectors.toList()).isEmpty()) {
  39. if(event.getMember().getRoles().stream().filter(r -> r.getName().equalsIgnoreCase("ps4")).collect(Collectors.toList()).isEmpty()) {
  40. if(event.getMember().getRoles().stream().filter(r -> r.getName().equalsIgnoreCase("pc")).collect(Collectors.toList()).isEmpty()) {
  41. event.reply(":warning:Whoop, sieht so aus als ob du deine Plattform noch nicht registriert hast " + event.getAuthor().getAsMention() + ".");
  42. return;
  43. }
  44. }
  45. }
  46. */
  47.  
  48. // pull out event.getMember().getroles().stream() to a variable, you could do this whole thing ina better way
  49. String platform = "ps4";
  50. if(!(event.getMember().getRoles().stream().filter(r -> r.getName().equalsIgnoreCase("ps4")).collect(Collectors.toList()).isEmpty())) {
  51. platform = "ps4";
  52. }
  53. else if(!(event.getMember().getRoles().stream().filter(r -> r.getName().equalsIgnoreCase("xbox")).collect(Collectors.toList()).isEmpty())) {
  54. platform = "xbox";
  55. }
  56. else if(!(event.getMember().getRoles().stream().filter(r -> r.getName().equalsIgnoreCase("pc")).collect(Collectors.toList()).isEmpty())) {
  57. platform = "pc";
  58. }
  59.  
  60. // now both platform and username are set
  61. FortniteData data = fortnite.getPlayerInfo(platform, username);
  62. if(!data.getResult().isOk()){
  63. System.out.println("do something - fetch failed")
  64. return;
  65. }
  66.  
  67.  
  68. List<Stat> stats = data.getLeague(League.Mode.life_time).getStats()
  69. String kdRatio = this.findStat(stats, "K/d");
  70. System.out.println("k/d ratio: " + kdRatio);
  71. }
  72. public String findStat(List<Stat> stats, String label){
  73. for(Stat stat : stats){
  74. if(stat.label.equals(label))
  75. return stat.value;
  76. }
  77.  
  78. return "0";
  79. }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement