Gamebuster icon

WhoIsCommand.java

Gamebuster | PRO | 04/29/20 01:35:19 AM UTC | 0 ⭐ | 2664 👁️ | Never ⏰ | []
Java |

1.53 KB

|

None

|

0 👍

/

0 👎

package com.gamebuster19901.excite.bot.command;
 
import com.gamebuster19901.excite.Main;
import com.gamebuster19901.excite.Player;
import com.gamebuster19901.excite.Wiimmfi;
import com.gamebuster19901.excite.bot.WiimmfiCommand;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
 
@SuppressWarnings("rawtypes")
public class WhoIsCommand extends WiimmfiCommand{
 
    public static void register(CommandDispatcher<MessageContext> dispatcher) {
        dispatcher.register(Commands.literal("!whois")
            .then(Commands.argument("player", StringArgumentType.word())).executes((command) -> {
                send(getResponse(command.getSource()), command.getSource());
                return 1;
            })
        );
    }
    
    @SuppressWarnings("static-access")
    public static String getResponse(MessageContext messageContext) {
        Wiimmfi wiimmfi = Main.discordBot.getWiimmfi();
        if(checkNotErrored(messageContext)) {
            Player[] players = wiimmfi.getKnownPlayers();
            int maxLines = 10000;
            if(messageContext.isGuildMessage() || messageContext.isPrivateMessage()) {
                maxLines = 24;
            }
            
            String response = "";
            for(int i = 0; i < players.length && i < maxLines; i++) {
                response += players[i].toString() + '\n';
                if (i == maxLines - 1 && players.length > maxLines) {
                    response += "and (" + (players.length - 24) + ") others";
                }
            }
            return response;
        }
        return "Bot offline due to an error: " + wiimmfi.getError().getClass().getCanonicalName() + ": " + wiimmfi.getError().getMessage();
    }
    
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎