fix concurrent fard exception i guess

finally !!!!
This commit is contained in:
Chayapak 2023-05-05 16:02:17 +07:00
parent 3b34eaf9cb
commit cb2fd9401e
2 changed files with 42 additions and 6 deletions

View file

@ -6,27 +6,61 @@ import com.mojang.brigadier.suggestion.Suggestions;
import land.chipmunk.chipmunkmod.data.MutablePlayerListEntry;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.CommandSuggestionsS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
import net.minecraft.text.Text;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
public class Players extends Listener {
public List<MutablePlayerListEntry> list = new ArrayList<>();
public static Players INSTANCE = new Players();
public static Players INSTANCE = new Players(MinecraftClient.getInstance());
public Players () {
private Timer timer;
private final MinecraftClient client;
public Players (MinecraftClient client) {
this.client = client;
ListenerManager.addListener(this);
TabComplete.INSTANCE.init();
}
public void init () {}
public void init () {
final TimerTask task = new TimerTask() {
public void run () {
tick();
}
};
if (timer != null) cleanup();
timer = new Timer();
timer.schedule(task, 0, 50);
}
public void cleanup () {
list.clear();
if (timer == null) return;
timer.cancel();
timer.purge();
timer = null;
}
private void tick () {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();
if (networkHandler == null) cleanup();
}
@Override
public void packetReceived (Packet packet) {

View file

@ -29,6 +29,8 @@ public class TabComplete extends Listener {
ListenerManager.addListener(this);
}
public void init () {}
public CompletableFuture<CommandSuggestionsS2CPacket> complete (String command) {
final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler();