ProtocolLib

3M Downloads

Players get kicked - IndexOutOfBoundsException

xtomyserrax opened this issue ยท 3 comments

commented

Describe the bug
Some server owners using my plugin are reporting me an issue with my ProtocolLib hook. This doesnt happen to all servers and I couldnt even recreate it.
Basicly I hook my plugin with ProtocolLib to remove some vanished player names from the TAB_COMPLETE packet.

This is only happening on servers using paper and bungeecord (at least from what people reported). But when they download ProtocolSupport the issue gets fixed (dont know why). I tried checking my code but found nothing, maybe you can find something wrong with it that helps me fix it!

Again: this doesnt happen to all servers which is weird, I even setted up a bungee network with paper servers and nothing happened to me. They are reporting me this issue with latest ProtocolLib version.

And there is no console error which makes it harder to me to detect what is going on wrong. As far as I understand the lenght of the suggestions is really big, but Im getting what was going to be suggested and just removing some lines, right? Im not adding any new stuff.

Screenshots
They get kicked everytime they try to use a command and get suggestions.
image

Version Info
Latest paper version.
Latest ProtocolLib version.

My Code

public class TabCompletePacket extends PacketAdapter {

	public TabCompletePacket(Main plugin) throws IllegalArgumentException {
		super(plugin, ListenerPriority.HIGH, new PacketType[] { PacketType.Play.Server.TAB_COMPLETE });
		this.plugin = plugin;
	}

	public void onPacketSending(PacketEvent event) {
		try {
			Suggestions suggestions = (Suggestions) event.getPacket().getSpecificModifier(Suggestions.class).read(0);
			Iterator<Suggestion> iterator = suggestions.getList().iterator();
			boolean writeChanges = false;
			while (iterator.hasNext()) {
				Suggestion suggestion = iterator.next();
				String string = suggestion.getText();
				Player hidden = Bukkit.getPlayer(string);
				if (hidden != null && VanishUtilities.checkSeeStatus(hidden, event.getPlayer())) {
					iterator.remove();
					writeChanges = true;
				}
			}
			if (writeChanges)
				event.getPacket().getSpecificModifier(Suggestions.class).write(0, suggestions);
		} catch (Exception | Error ex) {
			ex.printStackTrace();
		}
	}
}

Thank you for all the work you do, this API is the best thing ever created! Let me please know if there is a problem with my code or if you need any more information. Thanks!

commented

May be worth setting ListenerOptions.ASYNC in your packet adapter -- IIRC chat packets and tab complete are sent async. With that said, make sure your VanishUtilities.checkSeeStatus is thread safe.

commented

Thank you, I will send a version with those changes to see if it fixes the issue! Ill let you know as soon as I get an answer

Do you know why installing ProtocolSupport stops this issue?
And also what makes me crazy is that it happens in a minority of servers!

commented

ListenerOptions.ASYNC fixed the issue! Thank you so much!!!