I'm having a crash issue with Tab Completion on Online Players with a command. This is what was implemented, followed by a separate file named OnlinePlayers.java
@Override
public List<String> addTabCompletionOptions(final ICommandSender sender, final String[] args, final BlockPos pos) {
return (args.length >= 1) ? getListOfStringsMatchingLastWord(args, OnlinePlayers.getListOfPlayerUsernames()) : null;
}
OnlinePlayers.java:
package me.syns.slashping;
import net.minecraft.client.network.*;
import java.util.*;
public class OnlinePlayers
{
public static String[] getListOfPlayerUsernames() {
final String[] users = null;
final Collection<NetworkPlayerInfo> players = Ping.mc.getNetHandler().getPlayerInfoMap();
final List<String> list = new ArrayList<>();
for (final NetworkPlayerInfo info : players) {
list.add(info.getGameProfile().getName());
}
return list.toArray(new String[0]);
}
}
If you need anymore information, let me know. I've attempted various other methods and keep looking around as to why it's crashing. This is a mod being developed for 1.8.9, and soon to be ported to 1.12.2 (after I get some help regarding the Tab Completion)