i was gonna fix the player getting removed when you do /username
i found the cause but idk how to fix it
This commit is contained in:
Chayapak 2023-06-11 13:03:12 +07:00
parent 29ef3324fc
commit 3810b4e611
4 changed files with 27 additions and 51 deletions

View file

@ -1,6 +1,7 @@
package land.chipmunk.chipmunkmod;
import com.google.gson.GsonBuilder;
import land.chipmunk.chipmunkmod.modules.Players;
import land.chipmunk.chipmunkmod.util.gson.BlockPosTypeAdapter;
import net.fabricmc.api.ModInitializer;
import java.io.InputStream;
@ -42,6 +43,8 @@ public class ChipmunkMod implements ModInitializer {
throw new RuntimeException("Could not load the config", exception);
}
Players.INSTANCE.init();
LOGGER.info("Loaded ChipmunkMod (chayapak's fork)");
}

View file

@ -1,11 +0,0 @@
package land.chipmunk.chipmunkmod.mixin;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(ClientPlayNetworkHandler.class)
public interface ClientPlayNetworkHandlerInvoker {
@Invoker("isSecureChatEnforced")
public boolean isSecureChatEnforced();
}

View file

@ -3,9 +3,12 @@ package land.chipmunk.chipmunkmod.mixin;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.command.CommandManager;
import land.chipmunk.chipmunkmod.modules.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientDynamicRegistryType;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
import net.minecraft.registry.CombinedDynamicRegistries;
import net.minecraft.resource.featuretoggle.FeatureSet;
@ -15,6 +18,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Iterator;
@Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin {
@Shadow private FeatureSet enabledFeatures;
@ -31,11 +36,6 @@ public class ClientPlayNetworkHandlerMixin {
RainbowName.INSTANCE.init();
}
@Inject(method = "onGameJoin", at = @At("HEAD"))
private void onGameJoinHead (GameJoinS2CPacket packet, CallbackInfo ci) {
Players.INSTANCE.init();
}
@Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true)
private void onPlayerRemove (PlayerRemoveS2CPacket packet, CallbackInfo ci) {
ci.cancel();

View file

@ -3,13 +3,12 @@ package land.chipmunk.chipmunkmod.modules;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.suggestion.Suggestion;
import com.mojang.brigadier.suggestion.Suggestions;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.data.MutablePlayerListEntry;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerAccessor;
import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerInvoker;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.CommandSuggestionsS2CPacket;
@ -17,7 +16,9 @@ import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket;
import net.minecraft.text.Text;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand;
@ -27,8 +28,6 @@ public class Players extends Listener {
public static Players INSTANCE = new Players(MinecraftClient.getInstance());
private Timer timer;
private final MinecraftClient client;
public Players (MinecraftClient client) {
@ -38,34 +37,7 @@ public class Players extends Listener {
TabComplete.INSTANCE.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();
}
public void init () {}
@Override
public void packetReceived (Packet<?> packet) {
@ -142,10 +114,13 @@ public class Players extends Listener {
try {
final MutablePlayerListEntry duplicate = getEntry(newEntry);
if (duplicate != null) {
System.out.println("there is a duplicate, removing " + duplicate.profile().getId());
removeFromPlayerList(duplicate.profile().getId());
list.remove(duplicate);
}
System.out.println(newEntry.profile().getName() + " (" + newEntry.profile().getId() + ")");
list.add(new MutablePlayerListEntry(newEntry));
} catch (Exception e) {
e.printStackTrace();
@ -183,6 +158,7 @@ public class Players extends Listener {
if (target == null) return;
if (!serverHasCommand("scoreboard")) {
ChipmunkMod.LOGGER.warn("Server doesn't have /scoreboard, so not showing vanished players.");
removeFromPlayerList(uuid);
return;
}
@ -204,9 +180,11 @@ public class Players extends Listener {
return packet;
}
System.out.println("removing " + uuid);
removeFromPlayerList(uuid);
list.remove(target);
return packet;
});
} catch (Exception e) {
@ -216,9 +194,15 @@ public class Players extends Listener {
private void removeFromPlayerList (UUID uuid) {
client.getSocialInteractionsManager().setPlayerOffline(uuid);
final PlayerListEntry playerListEntry = ((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler()).playerListEntries().remove(uuid);
final ClientPlayNetworkHandlerAccessor accessor = ((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler());
if (accessor == null) return;
final PlayerListEntry playerListEntry = accessor.playerListEntries().remove(uuid);
if (playerListEntry != null) {
((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler()).listedPlayerListEntries().remove(playerListEntry);
accessor.listedPlayerListEntries().remove(playerListEntry);
}
}
}