Merge pull request #60 from TheBritishMidget/master

Friend Tab Highlight
This commit is contained in:
noil 2021-04-10 16:40:14 -04:00 committed by GitHub
commit 29cc2f0aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,21 @@
package me.rigamortis.seppuku.api.event.gui;
/**
* Written by TBM
*/
public class EventGetGuiTabName {
private String name;
public EventGetGuiTabName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -170,6 +170,7 @@ public final class ModuleManager {
add(new AutoTorchModule());
add(new AutoClickerModule());
add(new FakePlayerModule());
add(new FriendTabModule());
// p2w experience
if (Seppuku.INSTANCE.getCapeManager().hasCape())

View File

@ -61,6 +61,7 @@ public final class PatchManager {
this.patchList.add(new RenderGlobalPatch());
this.patchList.add(new GuiChatPatch());
this.patchList.add(new ParticleManagerPatch());
this.patchList.add(new GuiPlayerTabOverlayPatch());
//load custom external patches
//TODO this needs more testing

View File

@ -0,0 +1,27 @@
package me.rigamortis.seppuku.impl.module.misc;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.EventStageable;
import me.rigamortis.seppuku.api.event.gui.EventGetGuiTabName;
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
import me.rigamortis.seppuku.api.friend.Friend;
import me.rigamortis.seppuku.api.module.Module;
import net.minecraft.network.play.server.SPacketPlayerListHeaderFooter;
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
/**
* Written by TBM
*/
public final class FriendTabModule extends Module {
public FriendTabModule() {
super("FriendTab", new String[]{"FTab", "FriendT", "FriendTabOverlay", "FriendTabHighlight"}, "Displays friends names in tab as a different colour and as their nickname.", "NONE", -1, ModuleType.MISC);
}
@Listener
public void onGetGuiTabName(EventGetGuiTabName event) {
final Friend friend = Seppuku.INSTANCE.getFriendManager().find(event.getName());
if (friend != null) event.setName("\247d" + friend.getAlias());
}
}

View File

@ -0,0 +1,48 @@
package me.rigamortis.seppuku.impl.patch;
import me.rigamortis.seppuku.Seppuku;
import me.rigamortis.seppuku.api.event.gui.EventGetGuiTabName;
import me.rigamortis.seppuku.api.patch.ClassPatch;
import me.rigamortis.seppuku.api.patch.MethodPatch;
import me.rigamortis.seppuku.impl.management.PatchManager;
import net.minecraft.client.gui.GuiPlayerTabOverlay;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.scoreboard.ScorePlayerTeam;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import static org.objectweb.asm.Opcodes.*;
/**
* Written by TBM
*/
public final class GuiPlayerTabOverlayPatch extends ClassPatch {
public GuiPlayerTabOverlayPatch() {
super("net.minecraft.client.gui.GuiPlayerTabOverlay", "bjq");
}
@MethodPatch(
mcpName = "getPlayerName",
notchName = "a",
mcpDesc = "(Lnet/minecraft/client/network/NetworkPlayerInfo;)Ljava/lang/String;",
notchDesc = "(Lbsc;)Ljava/lang/String;"
)
public void getPlayerName(MethodNode methodNode, PatchManager.Environment env) {
final InsnList insnList = new InsnList();
insnList.add(new VarInsnNode(ALOAD, 1));
insnList.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(this.getClass()), "getPlayerNameHook", env == PatchManager.Environment.IDE ? "(Lnet/minecraft/client/network/NetworkPlayerInfo;)Ljava/lang/String;" : "(Lbsc;)Ljava/lang/String;", false));
insnList.add(new InsnNode(ARETURN));
methodNode.instructions.insert(insnList);
}
public static String getPlayerNameHook(NetworkPlayerInfo networkPlayerInfo) {
final EventGetGuiTabName event = new EventGetGuiTabName(networkPlayerInfo.getDisplayName() != null ? networkPlayerInfo.getDisplayName().getUnformattedComponentText() : networkPlayerInfo.getGameProfile().getName());
Seppuku.INSTANCE.getEventManager().dispatchEvent(event);
return event.getName();
}
}