From b21e85a9983f78f98e1f92b7941ba0c8ad3b4fea Mon Sep 17 00:00:00 2001 From: TudbuT Date: Tue, 25 Jun 2024 22:31:15 +0200 Subject: [PATCH] stabilize PlayerSelector, improve its rendering a bit, rewrite Notifier's player notifications --- .../java/de/com/baseband/client/Setup.java | 2 +- .../event/events/PlayerJoinedEvent.java | 12 +++++ .../client/event/events/PlayerLeftEvent.java | 14 ++++++ .../com/baseband/client/feature/Category.java | 2 +- .../feature/background/PlayerListHandler.java | 24 +++++++-- .../category/{Chat.java => ChatCategory.java} | 2 +- .../feature/modules/chat/ChatAppend.java | 3 +- .../feature/modules/chat/ChatCrypt.java | 3 +- .../feature/modules/chat/ChatExtras.java | 3 +- .../feature/modules/chat/ChatFilter.java | 3 +- .../client/feature/modules/chat/TPAccept.java | 3 +- .../client/feature/modules/client/Client.java | 2 +- .../feature/modules/client/Notifier.java | 50 +++++++++++-------- .../PlayerSelector.java | 10 ++-- 14 files changed, 95 insertions(+), 38 deletions(-) create mode 100644 Client/src/main/java/de/com/baseband/client/event/events/PlayerJoinedEvent.java create mode 100644 Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftEvent.java rename Client/src/main/java/de/com/baseband/client/feature/category/{Chat.java => ChatCategory.java} (89%) rename Client/src/main/java/de/com/baseband/client/feature/modules/{experimental => render}/PlayerSelector.java (93%) diff --git a/Client/src/main/java/de/com/baseband/client/Setup.java b/Client/src/main/java/de/com/baseband/client/Setup.java index 4c478f1..9180814 100644 --- a/Client/src/main/java/de/com/baseband/client/Setup.java +++ b/Client/src/main/java/de/com/baseband/client/Setup.java @@ -10,7 +10,7 @@ import de.com.baseband.client.feature.modules.combat.AutoKill; import de.com.baseband.client.feature.modules.combat.AutoTotem; import de.com.baseband.client.feature.modules.experimental.Inventory; import de.com.baseband.client.feature.modules.experimental.NoParticles; -import de.com.baseband.client.feature.modules.experimental.PlayerSelector; +import de.com.baseband.client.feature.modules.render.PlayerSelector; import de.com.baseband.client.feature.modules.movement.*; import de.com.baseband.client.feature.modules.ingame.AutoRespawn; import de.com.baseband.client.feature.modules.ingame.InteractionTweaks; diff --git a/Client/src/main/java/de/com/baseband/client/event/events/PlayerJoinedEvent.java b/Client/src/main/java/de/com/baseband/client/event/events/PlayerJoinedEvent.java new file mode 100644 index 0000000..a4f582f --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/event/events/PlayerJoinedEvent.java @@ -0,0 +1,12 @@ +package de.com.baseband.client.event.events; + +import de.com.baseband.client.event.Event; +import net.minecraft.client.network.NetworkPlayerInfo; + +public class PlayerJoinedEvent extends Event { + public final NetworkPlayerInfo playerInfo; + + public PlayerJoinedEvent(NetworkPlayerInfo playerInfo) { + this.playerInfo = playerInfo; + } +} diff --git a/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftEvent.java b/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftEvent.java new file mode 100644 index 0000000..58a98e1 --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/event/events/PlayerLeftEvent.java @@ -0,0 +1,14 @@ +package de.com.baseband.client.event.events; + +import de.com.baseband.client.event.Event; +import net.minecraft.client.network.NetworkPlayerInfo; + +public class PlayerLeftEvent extends Event { + public final NetworkPlayerInfo playerInfo; + public final int index; + + public PlayerLeftEvent(NetworkPlayerInfo playerInfo, int index) { + this.playerInfo = playerInfo; + this.index = index; + } +} diff --git a/Client/src/main/java/de/com/baseband/client/feature/Category.java b/Client/src/main/java/de/com/baseband/client/feature/Category.java index ad549e6..1f75a46 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/Category.java +++ b/Client/src/main/java/de/com/baseband/client/feature/Category.java @@ -11,7 +11,7 @@ import java.lang.reflect.AnnotatedElement; public enum Category { - CHAT("Chat", Chat.class), + CHAT("Chat", ChatCategory.class), COMBAT("Combat", Combat.class), MOVEMENT("Movement", Movement.class), RENDER("Render", Render.class), diff --git a/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java b/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java index d482d91..ada6e97 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java +++ b/Client/src/main/java/de/com/baseband/client/feature/background/PlayerListHandler.java @@ -2,6 +2,8 @@ package de.com.baseband.client.feature.background; import de.com.baseband.client.BaseBand; import de.com.baseband.client.event.events.PlayerEnteredViewEvent; +import de.com.baseband.client.event.events.PlayerJoinedEvent; +import de.com.baseband.client.event.events.PlayerLeftEvent; import de.com.baseband.client.event.events.PlayerLeftViewEvent; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.category.Background; @@ -15,27 +17,43 @@ import java.util.Optional; public class PlayerListHandler extends Feature { public static ArrayList playersInRenderDistance = new ArrayList<>(); + public static ArrayList entityPlayersInRenderDistance = new ArrayList<>(); + public static ArrayList playersInTab = new ArrayList<>(); @Override public void onTick() { - ArrayList players = new ArrayList<>(); + ArrayList playersRD = new ArrayList<>(), playersTab = new ArrayList<>(); for (NetworkPlayerInfo playerInfo : mc.player.connection.getPlayerInfoMap()) { Optional player = mc.world.playerEntities.stream().filter(x -> x.getGameProfile().getId().equals(playerInfo.getGameProfile().getId())).findAny(); + playersTab.add(playerInfo); + if(!playersInTab.contains(playerInfo)) { + playersInTab.add(playerInfo); + BaseBand.publish(new PlayerJoinedEvent(playerInfo)); + } if(player.isPresent()) { - players.add(playerInfo); + playersRD.add(playerInfo); if(!playersInRenderDistance.contains(playerInfo)) { playersInRenderDistance.add(playerInfo); + entityPlayersInRenderDistance.add(player.get()); BaseBand.publish(new PlayerEnteredViewEvent(playerInfo, player.get())); } } } for (int i = 0; i < playersInRenderDistance.size(); i++) { NetworkPlayerInfo playerInfo = playersInRenderDistance.get(i); - if (!players.contains(playerInfo)) { + if (!playersRD.contains(playerInfo)) { BaseBand.publish(new PlayerLeftViewEvent(playerInfo, i)); + entityPlayersInRenderDistance.remove(i); playersInRenderDistance.remove(i--); } } + for (int i = 0; i < playersInTab.size(); i++) { + NetworkPlayerInfo playerInfo = playersInTab.get(i); + if (!playersTab.contains(playerInfo)) { + BaseBand.publish(new PlayerLeftEvent(playerInfo, i)); + playersInTab.remove(i--); + } + } } @Override diff --git a/Client/src/main/java/de/com/baseband/client/feature/category/Chat.java b/Client/src/main/java/de/com/baseband/client/feature/category/ChatCategory.java similarity index 89% rename from Client/src/main/java/de/com/baseband/client/feature/category/Chat.java rename to Client/src/main/java/de/com/baseband/client/feature/category/ChatCategory.java index d300312..2b16628 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/category/Chat.java +++ b/Client/src/main/java/de/com/baseband/client/feature/category/ChatCategory.java @@ -7,5 +7,5 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) -public @interface Chat { +public @interface ChatCategory { } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatAppend.java b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatAppend.java index b1dc49e..a5be560 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatAppend.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatAppend.java @@ -1,13 +1,14 @@ package de.com.baseband.client.feature.modules.chat; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.category.ChatCategory; import de.com.baseband.client.registry.annotation.Config; import de.com.baseband.client.registry.annotation.Gate; import de.com.baseband.client.util.adapt.Marker; import net.minecraftforge.client.event.ClientChatEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -@de.com.baseband.client.feature.category.Chat +@ChatCategory public class ChatAppend extends Feature { @Override diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatCrypt.java b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatCrypt.java index c30a5cf..f9c9ff8 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatCrypt.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatCrypt.java @@ -3,6 +3,7 @@ package de.com.baseband.client.feature.modules.chat; import de.com.baseband.client.BaseBand; import de.com.baseband.client.event.events.PacketEvent; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.category.ChatCategory; import de.com.baseband.client.feature.modules.render.HUD; import de.com.baseband.client.mixin.mixins.ICPacketChat; import de.com.baseband.client.registry.annotation.*; @@ -23,7 +24,7 @@ import java.util.Arrays; import java.util.regex.Matcher; import java.util.regex.Pattern; -@de.com.baseband.client.feature.category.Chat +@ChatCategory public class ChatCrypt extends Feature { @Override public String toString() { diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatExtras.java b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatExtras.java index 63a1652..1dd55fb 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatExtras.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatExtras.java @@ -4,6 +4,7 @@ import com.mojang.realmsclient.gui.ChatFormatting; import de.com.baseband.client.BaseBand; import de.com.baseband.client.event.events.PacketEvent; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.category.ChatCategory; import de.com.baseband.client.registry.annotation.Config; import de.com.baseband.client.registry.annotation.Description; import de.com.baseband.client.registry.annotation.Gate; @@ -23,7 +24,7 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -@de.com.baseband.client.feature.category.Chat +@ChatCategory public class ChatExtras extends Feature { diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatFilter.java b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatFilter.java index 0199dc6..cc375a8 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatFilter.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/ChatFilter.java @@ -3,6 +3,7 @@ package de.com.baseband.client.feature.modules.chat; import de.com.baseband.client.BaseBand; import de.com.baseband.client.event.events.PacketEvent; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.category.ChatCategory; import de.com.baseband.client.registry.annotation.Config; import de.com.baseband.client.util.adapt.FieldFinder; import net.minecraft.network.play.server.SPacketChat; @@ -12,7 +13,7 @@ import net.minecraft.util.text.TextComponentString; import java.util.regex.Matcher; import java.util.regex.Pattern; -@de.com.baseband.client.feature.category.Chat +@ChatCategory public class ChatFilter extends Feature { public enum Mode { diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/TPAccept.java b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/TPAccept.java index 4d75ca6..80aaee5 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/chat/TPAccept.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/chat/TPAccept.java @@ -2,6 +2,7 @@ package de.com.baseband.client.feature.modules.chat; import de.com.baseband.client.event.events.PlayerDestroyEvent; import de.com.baseband.client.feature.Feature; +import de.com.baseband.client.feature.category.ChatCategory; import de.com.baseband.client.registry.PlayerDB; import de.com.baseband.client.registry.annotation.Config; import de.com.baseband.client.registry.annotation.Description; @@ -9,7 +10,7 @@ import de.com.baseband.client.util.interact.Chat; import net.minecraftforge.client.event.ClientChatReceivedEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; -@de.com.baseband.client.feature.category.Chat +@ChatCategory @Description("Accepts TPA-Requests automatically") public class TPAccept extends Feature { diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java index ef7db3d..9f0ff98 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java @@ -5,7 +5,7 @@ import de.com.baseband.client.event.events.PacketEvent; import de.com.baseband.client.event.events.PlayerDestroyEvent; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.category.ClientCategory; -import de.com.baseband.client.feature.modules.experimental.PlayerSelector; +import de.com.baseband.client.feature.modules.render.PlayerSelector; import de.com.baseband.client.gui.GuiTheme; import de.com.baseband.client.registry.Configuration; import de.com.baseband.client.registry.annotation.*; diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Notifier.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Notifier.java index 4b1dde0..971646c 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Notifier.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Notifier.java @@ -1,8 +1,7 @@ package de.com.baseband.client.feature.modules.client; import de.com.baseband.client.BaseBand; -import de.com.baseband.client.event.events.PacketEvent; -import de.com.baseband.client.event.events.TotemPopEvent; +import de.com.baseband.client.event.events.*; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.category.ClientCategory; import de.com.baseband.client.registry.annotation.Config; @@ -10,14 +9,10 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.play.server.SPacketEntityTeleport; -import java.util.ArrayList; import java.util.HashMap; @ClientCategory public class Notifier extends Feature { - - private final ArrayList names = new ArrayList<>(); - private final ArrayList newnames = new ArrayList<>(); private final HashMap popList = new HashMap<>(); @Config("Totem Pops") @@ -26,6 +21,9 @@ public class Notifier extends Feature { @Config("Visual Range") public boolean visualRange; + @Config("Join messages") + public boolean joins; + @Config("Trace Teleport") public boolean traceTeleport; @@ -34,21 +32,32 @@ public class Notifier extends Feature { return "Notifier"; } + public void onPlayerEnterView(PlayerEnteredViewEvent event) { + if(visualRange && !event.playerInfo.getGameProfile().getId().equals(mc.getSession().getProfile().getId())) { + BaseBand.notify("[" + this + "] Player §aentered§r render distance: " + event.playerInfo.getGameProfile().getName()); + } + } + + public void onPlayerLeaveView(PlayerLeftViewEvent event) { + if(visualRange && !event.playerInfo.getGameProfile().getId().equals(mc.getSession().getProfile().getId())) { + BaseBand.notify("[" + this + "] Player §cleft§r render distance: " + event.playerInfo.getGameProfile().getName()); + } + } + + public void onPlayerJoin(PlayerJoinedEvent event) { + if(joins && !event.playerInfo.getGameProfile().getId().equals(mc.getSession().getProfile().getId())) { + BaseBand.notify("[" + this + "] Player §ajoined§r: " + event.playerInfo.getGameProfile().getName()); + } + } + + public void onPlayerLeave(PlayerLeftEvent event) { + if(joins && !event.playerInfo.getGameProfile().getId().equals(mc.getSession().getProfile().getId())) { + BaseBand.notify("[" + this + "] Player §cleft§r: " + event.playerInfo.getGameProfile().getName()); + } + } + @Override public void onTick() { - if(visualRange) { - newnames.clear(); - try { - for (final Entity entity : mc.world.loadedEntityList) if (entity instanceof EntityPlayer && !entity.getName().equalsIgnoreCase(mc.player.getName())) newnames.add(entity.getName()); - if (!names.equals(newnames)) { - for (final String name : newnames) if (!names.contains(name)) BaseBand.notify("[" + this + "] "+name+" has entered Visual Range."); - for (final String name : names) if (!newnames.contains(name)) BaseBand.notify("[" + this + "] "+name+" has left Visual Range."); - names.clear(); - names.addAll(newnames); - } - } catch (Exception ignored) {} - } - if(totemPops) { for (EntityPlayer player : mc.world.playerEntities) { if (player.getHealth() <= 0) { @@ -80,7 +89,6 @@ public class Notifier extends Feature { } } - public void totemPop(TotemPopEvent event) { if(popList.get(event.getEntity().getName()) == null) { popList.put(event.getEntity().getName(), 1); @@ -96,8 +104,6 @@ public class Notifier extends Feature { @Override public void onDisable() { - names.clear(); - newnames.clear(); popList.clear(); } } diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/experimental/PlayerSelector.java b/Client/src/main/java/de/com/baseband/client/feature/modules/render/PlayerSelector.java similarity index 93% rename from Client/src/main/java/de/com/baseband/client/feature/modules/experimental/PlayerSelector.java rename to Client/src/main/java/de/com/baseband/client/feature/modules/render/PlayerSelector.java index 581c986..aaee1a5 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/experimental/PlayerSelector.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/render/PlayerSelector.java @@ -1,10 +1,10 @@ -package de.com.baseband.client.feature.modules.experimental; +package de.com.baseband.client.feature.modules.render; import de.com.baseband.client.event.KeyManager; import de.com.baseband.client.event.events.PlayerLeftViewEvent; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.background.PlayerListHandler; -import de.com.baseband.client.feature.category.Experimental; +import de.com.baseband.client.feature.category.Render; import de.com.baseband.client.registry.AnyGate; import de.com.baseband.client.registry.annotation.Gate; import de.com.baseband.client.registry.annotation.Requires; @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; import java.util.function.BiConsumer; -@Experimental +@Render @Requires(PlayerListHandler.class) public class PlayerSelector extends Feature { @@ -36,6 +36,7 @@ public class PlayerSelector extends Feature { private Mode mode = Mode.LIST; List display = new ArrayList<>(); + List displayPlayers = new ArrayList<>(); int cursor = 0; int optionCursor = 0; @@ -95,7 +96,7 @@ public class PlayerSelector extends Feature { mode = Mode.OPTIONS; optionCursor = 0; } - mc.fontRenderer.drawStringWithShadow((selected ? "§c§m| §r§a " : "§c| §r ") + playerInfo.getGameProfile().getName() + (selected ? " §c>" : ""), x, y, 0xffffffff); + mc.fontRenderer.drawStringWithShadow((selected ? "§c§m| §r§a " : "§c| §r ") + displayPlayers.get(i).getDisplayName().getFormattedText() + (selected ? " §c>" : ""), x, y, 0xffffffff); y += mc.fontRenderer.FONT_HEIGHT; } } @@ -128,6 +129,7 @@ public class PlayerSelector extends Feature { @Override public void onTick() { display = PlayerListHandler.playersInRenderDistance; + displayPlayers = PlayerListHandler.entityPlayersInRenderDistance; } @Override