Advertisement
Gamebuster

WhoIsCommand.java

Apr 28th, 2020
1,976
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.53 KB | None | 0 0
  1. package com.gamebuster19901.excite.bot.command;
  2.  
  3. import com.gamebuster19901.excite.Main;
  4. import com.gamebuster19901.excite.Player;
  5. import com.gamebuster19901.excite.Wiimmfi;
  6. import com.gamebuster19901.excite.bot.WiimmfiCommand;
  7. import com.mojang.brigadier.CommandDispatcher;
  8. import com.mojang.brigadier.arguments.StringArgumentType;
  9.  
  10. @SuppressWarnings("rawtypes")
  11. public class WhoIsCommand extends WiimmfiCommand{
  12.  
  13.     public static void register(CommandDispatcher<MessageContext> dispatcher) {
  14.         dispatcher.register(Commands.literal("!whois")
  15.             .then(Commands.argument("player", StringArgumentType.word())).executes((command) -> {
  16.                 send(getResponse(command.getSource()), command.getSource());
  17.                 return 1;
  18.             })
  19.         );
  20.     }
  21.    
  22.     @SuppressWarnings("static-access")
  23.     public static String getResponse(MessageContext messageContext) {
  24.         Wiimmfi wiimmfi = Main.discordBot.getWiimmfi();
  25.         if(checkNotErrored(messageContext)) {
  26.             Player[] players = wiimmfi.getKnownPlayers();
  27.             int maxLines = 10000;
  28.             if(messageContext.isGuildMessage() || messageContext.isPrivateMessage()) {
  29.                 maxLines = 24;
  30.             }
  31.            
  32.             String response = "";
  33.             for(int i = 0; i < players.length && i < maxLines; i++) {
  34.                 response += players[i].toString() + '\n';
  35.                 if (i == maxLines - 1 && players.length > maxLines) {
  36.                     response += "and (" + (players.length - 24) + ") others";
  37.                 }
  38.             }
  39.             return response;
  40.         }
  41.         return "Bot offline due to an error: " + wiimmfi.getError().getClass().getCanonicalName() + ": " + wiimmfi.getError().getMessage();
  42.     }
  43.    
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement