Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabList: Change api to be similar to Scoreboard #129

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions api/ctjs.api
Original file line number Diff line number Diff line change
Expand Up @@ -2370,6 +2370,12 @@ public final class com/chattriggers/ctjs/api/world/Server {

public final class com/chattriggers/ctjs/api/world/TabList {
public static final field INSTANCE Lcom/chattriggers/ctjs/api/world/TabList;
public static final fun addName (Lcom/chattriggers/ctjs/api/message/TextComponent;)V
public static final fun addName (Lcom/chattriggers/ctjs/api/message/TextComponent;Z)V
public static final fun addName (Ljava/lang/String;)V
public static final fun addName (Ljava/lang/String;Z)V
public static synthetic fun addName$default (Lcom/chattriggers/ctjs/api/message/TextComponent;ZILjava/lang/Object;)V
public static synthetic fun addName$default (Ljava/lang/String;ZILjava/lang/Object;)V
public static final fun clearFooter ()V
public static final fun clearHeader ()V
public static final fun getFooter ()Ljava/lang/String;
Expand All @@ -2378,12 +2384,31 @@ public final class com/chattriggers/ctjs/api/world/TabList {
public static final fun getHeaderComponent ()Lcom/chattriggers/ctjs/api/message/TextComponent;
public static final fun getNames ()Ljava/util/List;
public static final fun getNamesByObjectives ()Ljava/util/List;
public static final fun getObjective ()Lnet/minecraft/scoreboard/ScoreboardObjective;
public static final fun getUnformattedNames ()Ljava/util/List;
public static final fun removeNames (Lcom/chattriggers/ctjs/api/message/TextComponent;)V
public static final fun removeNames (Ljava/lang/String;)V
public static final fun setFooter (Ljava/lang/Object;)V
public static final fun setHeader (Ljava/lang/Object;)V
public static final fun toMC ()Lnet/minecraft/client/gui/hud/PlayerListHud;
}

public final class com/chattriggers/ctjs/api/world/TabList$Name : com/chattriggers/ctjs/api/CTWrapper {
public fun <init> (Lnet/minecraft/client/network/PlayerListEntry;)V
public final fun getLatency ()I
public synthetic fun getMcValue ()Ljava/lang/Object;
public fun getMcValue ()Lnet/minecraft/client/network/PlayerListEntry;
public final fun getName ()Lcom/chattriggers/ctjs/api/message/TextComponent;
public final fun getTeam ()Lcom/chattriggers/ctjs/api/entity/Team;
public final fun remove ()V
public final fun setLatency (I)Lcom/chattriggers/ctjs/api/world/TabList$Name;
public final fun setName (Lcom/chattriggers/ctjs/api/message/TextComponent;)Lcom/chattriggers/ctjs/api/world/TabList$Name;
public final fun setTeam (Lcom/chattriggers/ctjs/api/entity/Team;)Lcom/chattriggers/ctjs/api/world/TabList$Name;
public synthetic fun toMC ()Ljava/lang/Object;
public fun toMC ()Lnet/minecraft/client/network/PlayerListEntry;
public fun toString ()Ljava/lang/String;
}

public final class com/chattriggers/ctjs/api/world/World {
public static final field INSTANCE Lcom/chattriggers/ctjs/api/world/World;
public static final field border Lcom/chattriggers/ctjs/api/world/World$BorderWrapper;
Expand Down
5 changes: 5 additions & 0 deletions docs/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ Here is a list of targeted changes for various different APIs:
- `TabList`
- Renamed `getHeaderMessage()` to `getHeaderComponent()`, and it now returns a `TextComponent` instead of a `Message`
- Renamed `getFooterMessage()` to `getFooterComponent()`, and it now returns a `TextComponent` instead of a `Message`
- Added `addName()`, `getList()`, and `removeNames()`
- `getNames()` now returns a list of `Name`
- Added `Name`
- acts similarly to `Scoreboard.Score`, with the following methods
- `getLatency()`, `setLatency()`, `getName()`, `setName()`, `getTeam()`, `setTeam()`, and `remove()`
- `Team`
- `Team.getNameTagVisibility()` and `Team.getDeathMessageVisibility()` now return a `Team.Visibility` instead of a string
- Added `setColor()`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.chattriggers.ctjs.internal.mixins;

import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.PlayerListEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

import java.util.Collection;
import java.util.Map;
import java.util.UUID;

@Mixin(ClientPlayNetworkHandler.class)
public interface ClientPlayNetworkHandlerAccessor {
@Accessor
Map<UUID, PlayerListEntry> getPlayerListEntries();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.chattriggers.ctjs.internal.mixins;

import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(MinecraftClient.class)
public interface MinecraftClientAccessor {
@Accessor
YggdrasilAuthenticationService getAuthenticationService();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.chattriggers.ctjs.internal.mixins;

import com.chattriggers.ctjs.api.world.Scoreboard;
import com.chattriggers.ctjs.api.world.TabList;
import com.chattriggers.ctjs.internal.engine.CTEvents;
import com.chattriggers.ctjs.api.triggers.TriggerType;
import com.chattriggers.ctjs.internal.engine.module.ModuleManager;
Expand Down Expand Up @@ -34,6 +35,7 @@ private void injectWorldUnload(ClientWorld world, DownloadingTerrainScreen.World
if (this.world != null) {
TriggerType.WORLD_UNLOAD.triggerAll();
Scoreboard.INSTANCE.clearCustom$ctjs();
TabList.INSTANCE.clearCustom$ctjs();
}
}

Expand All @@ -51,6 +53,7 @@ private void injectDisconnect(Screen screen, CallbackInfo ci) {
TriggerType.WORLD_UNLOAD.triggerAll();
TriggerType.SERVER_DISCONNECT.triggerAll();
Scoreboard.INSTANCE.clearCustom$ctjs();
TabList.INSTANCE.clearCustom$ctjs();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.chattriggers.ctjs.internal.mixins;

import net.minecraft.client.network.PlayerListEntry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

@Mixin(PlayerListEntry.class)
public interface PlayerListEntryAccessor {
@Invoker
void invokeSetLatency(int latency);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.chattriggers.ctjs.internal.mixins;

import com.chattriggers.ctjs.api.triggers.TriggerType;
import com.chattriggers.ctjs.api.world.TabList;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.PlayerListHud;
import net.minecraft.scoreboard.Scoreboard;
import net.minecraft.scoreboard.ScoreboardObjective;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
Expand All @@ -16,4 +18,18 @@ public class PlayerListHudMixin {
private void injectRenderPlayerList(DrawContext context, int scaledWindowWidth, Scoreboard scoreboard, ScoreboardObjective objective, CallbackInfo ci) {
TriggerType.RENDER_PLAYER_LIST.triggerAll(ci);
}

@Inject(method = "setHeader", at = @At("HEAD"), cancellable = true)
private void ctjs$keepCustomHeader(Text header, CallbackInfo ci) {
if (TabList.INSTANCE.getCustomHeader$ctjs()) {
ci.cancel();
}
}

@Inject(method = "setFooter", at = @At("HEAD"), cancellable = true)
private void ctjs$keepCustomFooter(Text footer, CallbackInfo ci) {
if (TabList.INSTANCE.getCustomFooter$ctjs()) {
ci.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ object Scoreboard {
}

/**
* Gets the display string of this score
* Gets the display text of this score
*
* @return the display name
*/
Expand Down
Loading