finally fix vanish lmfaooooooooo

This commit is contained in:
Chipmunk 2023-03-18 23:35:28 -04:00
parent afa6f7ec8a
commit 81637be24f
3 changed files with 60 additions and 4 deletions

View file

@ -15,6 +15,7 @@ import java.util.List;
public class ChipmunkBot extends Client {
@Getter public final ChatPlugin chat = new ChatPlugin(this);
@Getter public final TabCompletePlugin tabComplete = new TabCompletePlugin(this);
@Getter public final QueryPlugin query = new QueryPlugin(this);
@Getter public final PlayerListPlugin playerList = new PlayerListPlugin(this);
@Getter public final CommandManager commandManager = new CommandManager(this);

View file

@ -1,6 +1,6 @@
package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.Client;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoPacket;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session;
@ -16,10 +16,10 @@ import java.util.ArrayList;
import java.util.UUID;
public class PlayerListPlugin extends SessionAdapter {
private Client client;
private ChipmunkBot client;
public List<MutablePlayerListEntry> list = new ArrayList<>();
public PlayerListPlugin (Client client) {
public PlayerListPlugin (ChipmunkBot client) {
this.client = client;
client.addListener((SessionListener) this);
}
@ -106,6 +106,18 @@ public class PlayerListPlugin extends SessionAdapter {
final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return;
list.remove(target);
client.tabComplete().complete("/scoreboard players add ").thenApply(packet -> {
final String[] matches = packet.getMatches();
final Component[] tooltips = packet.getTooltips();
final String username = target.profile().getName();
for (int i = 0; i < matches.length; i++) {
if (tooltips[i] != null || !matches[i].equals(username)) continue;
return packet;
}
list.remove(target);
return packet;
});
}
}

View file

@ -0,0 +1,43 @@
package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.Client;
import com.nukkitx.math.vector.Vector3i;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionListener;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundCommandSuggestionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundCommandSuggestionsPacket;
import java.util.concurrent.CompletableFuture;
import java.util.Map;
import java.util.HashMap;
public class TabCompletePlugin extends SessionAdapter {
private Client client;
private int nextTransactionId = 0;
private Map<Integer, CompletableFuture<ClientboundCommandSuggestionsPacket>> transactions = new HashMap<>();
public TabCompletePlugin (Client client) {
this.client = client;
client.addListener((SessionListener) this);
}
public CompletableFuture<ClientboundCommandSuggestionsPacket> complete (String command) {
final int transactionId = nextTransactionId++;
if (nextTransactionId > Integer.MAX_VALUE) nextTransactionId = 0; // ? Can and should I use negative numbers too?
client.session().send(new ServerboundCommandSuggestionPacket(transactionId, command));
final CompletableFuture<ClientboundCommandSuggestionsPacket> future = new CompletableFuture<ClientboundCommandSuggestionsPacket>();
transactions.put(transactionId, future);
return future;
}
@Override
public void packetReceived (Session session, Packet packet) {
if (packet instanceof ClientboundCommandSuggestionsPacket) packetReceived(session, (ClientboundCommandSuggestionsPacket) packet);
}
public void packetReceived (Session session, ClientboundCommandSuggestionsPacket packet) {
transactions.get(packet.getTransactionId()).complete(packet);
}
}