From 08ae8a418d35c6e104086b60b581eb8d4427382c Mon Sep 17 00:00:00 2001 From: Sarah Engel Date: Sun, 8 Sep 2024 16:53:35 +0200 Subject: [PATCH] Fix bug with everyone beeing displayed as Tag --- .../java/com/funkeln/pronouns/PronounAddon.java | 4 ++-- .../funkeln/pronouns/nametag/FlagNameTag.java | 7 +++---- .../funkeln/pronouns/nametag/PronounNameTag.java | 6 +----- .../com/funkeln/pronouns/utils/Pridetags.java | 16 ++++++++++++++-- .../com/funkeln/pronouns/utils/PronounsAPI.java | 1 - 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/com/funkeln/pronouns/PronounAddon.java b/core/src/main/java/com/funkeln/pronouns/PronounAddon.java index bdb0611..ad926df 100644 --- a/core/src/main/java/com/funkeln/pronouns/PronounAddon.java +++ b/core/src/main/java/com/funkeln/pronouns/PronounAddon.java @@ -1,6 +1,7 @@ package com.funkeln.pronouns; import com.funkeln.pronouns.nametag.FlagNameTag; +import com.funkeln.pronouns.utils.Pridetags; import net.labymod.api.Laby; import net.labymod.api.addon.LabyAddon; import net.labymod.api.client.component.Component; @@ -38,7 +39,7 @@ protected void enable() { this.registerSettingCategory(); if(this.configuration().enabled().get()) { if(configuration().name().get().isEmpty()) { - meow = labyAPI().minecraft().getClientPlayer().getName().trim(); + displayMessage("Please set the name in the config"); } else { meow = configuration().name().get().trim(); } @@ -57,7 +58,6 @@ public void onProfileFetchFailed(String username, Exception e) { }); // Request the profile - // if name is empty, set it to the ingame user PronounsAPI.getProfile(meow); // Wait to ensure the async task completes (for demonstration purposes) diff --git a/core/src/main/java/com/funkeln/pronouns/nametag/FlagNameTag.java b/core/src/main/java/com/funkeln/pronouns/nametag/FlagNameTag.java index 6bb6072..5e8eb73 100644 --- a/core/src/main/java/com/funkeln/pronouns/nametag/FlagNameTag.java +++ b/core/src/main/java/com/funkeln/pronouns/nametag/FlagNameTag.java @@ -36,7 +36,9 @@ public FlagNameTag(RectangleRenderer rectangleRenderer) { @Override protected @Nullable RenderableComponent getRenderableComponent() { - if (this.entity instanceof Player && !this.entity.isCrouching()) { + if (!(this.entity instanceof Player) || this.entity.isCrouching() || !Laby.labyAPI().minecraft().getClientPlayer().getName().equals(((Player) this.entity).getName())) { + return null; + } HorizontalAlignment alignment; alignment = HorizontalAlignment.CENTER; @@ -56,11 +58,8 @@ public FlagNameTag(RectangleRenderer rectangleRenderer) { } return RenderableComponent.of(component, alignment); - } else { - return null; } - } @Override protected void renderText( Stack stack, diff --git a/core/src/main/java/com/funkeln/pronouns/nametag/PronounNameTag.java b/core/src/main/java/com/funkeln/pronouns/nametag/PronounNameTag.java index 57b5594..5c724f0 100644 --- a/core/src/main/java/com/funkeln/pronouns/nametag/PronounNameTag.java +++ b/core/src/main/java/com/funkeln/pronouns/nametag/PronounNameTag.java @@ -6,17 +6,13 @@ import net.labymod.api.client.entity.player.Player; import net.labymod.api.client.entity.player.tag.tags.NameTag; import net.labymod.api.client.gui.HorizontalAlignment; -import net.labymod.api.client.gui.icon.Icon; import net.labymod.api.client.render.RenderPipeline; import net.labymod.api.client.render.draw.RectangleRenderer; import net.labymod.api.client.render.font.RenderableComponent; import net.labymod.api.client.render.matrix.Stack; import com.funkeln.pronouns.utils.Profile; -import com.funkeln.pronouns.utils.PronounsAPI; import org.jetbrains.annotations.Nullable; -import static com.funkeln.pronouns.utils.Profile.flags; - /** * @author https://github.com/PrincessAkira (Sarah) Today is the 8/16/2024 @7:26 PM This project is * named labymod4-addon-template @@ -33,7 +29,7 @@ public PronounNameTag(RenderPipeline renderPipeline, RectangleRenderer rectangle @Override protected @Nullable RenderableComponent getRenderableComponent() { - if (!(this.entity instanceof Player) || this.entity.isCrouching()) { + if (!(this.entity instanceof Player) || this.entity.isCrouching() || !Laby.labyAPI().minecraft().getClientPlayer().getName().equals(((Player) this.entity).getName())) { return null; } diff --git a/core/src/main/java/com/funkeln/pronouns/utils/Pridetags.java b/core/src/main/java/com/funkeln/pronouns/utils/Pridetags.java index abafcb0..4981ca1 100644 --- a/core/src/main/java/com/funkeln/pronouns/utils/Pridetags.java +++ b/core/src/main/java/com/funkeln/pronouns/utils/Pridetags.java @@ -1,10 +1,22 @@ package com.funkeln.pronouns.utils; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArraySet; public final class Pridetags { - public static Set profiles = ConcurrentHashMap.newKeySet(); + public static Set profiles = new CopyOnWriteArraySet<>(); + + + + public static Set getProfiles() { + // return all profiles from the HashMap + StringBuilder sb = new StringBuilder(); + for (Profile profile : profiles) { + // put them into a big string + sb.append(profile.getUsername() + " : " + profile.getPronoun() + "\n"); + } + return profiles; + } } \ No newline at end of file diff --git a/core/src/main/java/com/funkeln/pronouns/utils/PronounsAPI.java b/core/src/main/java/com/funkeln/pronouns/utils/PronounsAPI.java index a6522ea..297bedb 100644 --- a/core/src/main/java/com/funkeln/pronouns/utils/PronounsAPI.java +++ b/core/src/main/java/com/funkeln/pronouns/utils/PronounsAPI.java @@ -20,7 +20,6 @@ public class PronounsAPI { public static final String FLAGS_URL = "https://en.pronouns.page/flags/"; private static PronounsAPI instance; - private static final Queue> queues = new ConcurrentLinkedQueue<>(); private static final Map listeners = new HashMap<>(); public static void addProfileFetchListener(String username, ProfileFetchListener listener) {