Skip to content

Commit

Permalink
Fix bug with everyone beeing displayed as Tag
Browse files Browse the repository at this point in the history
  • Loading branch information
HerXayah committed Sep 8, 2024
1 parent 1018d55 commit 08ae8a4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/com/funkeln/pronouns/PronounAddon.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -56,11 +58,8 @@ public FlagNameTag(RectangleRenderer rectangleRenderer) {
}

return RenderableComponent.of(component, alignment);
} else {
return null;
}

}
@Override
protected void renderText(
Stack stack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/com/funkeln/pronouns/utils/Pridetags.java
Original file line number Diff line number Diff line change
@@ -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<Profile> profiles = ConcurrentHashMap.newKeySet();
public static Set<Profile> profiles = new CopyOnWriteArraySet<>();



public static Set<Profile> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Consumer<Void>> queues = new ConcurrentLinkedQueue<>();
private static final Map<String, ProfileFetchListener> listeners = new HashMap<>();

public static void addProfileFetchListener(String username, ProfileFetchListener listener) {
Expand Down

0 comments on commit 08ae8a4

Please sign in to comment.