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

A lot of improvements #28

Merged
merged 11 commits into from
Feb 9, 2024
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ labyMod {
author = "RappyTV"
description = "Get yourself a custom Globaltag that's publicly visible to anyone using this addon."
minecraftVersion = "*"
version = System.getenv().getOrDefault("VERSION", "1.1.0")
version = System.getenv().getOrDefault("VERSION", "1.1.5")
}

minecraft {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/rappytv/globaltags/GlobalTagAddon.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import com.rappytv.globaltags.interaction.ReportBulletPoint;
import com.rappytv.globaltags.listener.ServerNavigationListener;
import com.rappytv.globaltags.nametag.CustomTag;
import com.rappytv.globaltags.util.TagCache;
import com.rappytv.globaltags.util.Util;
import net.labymod.api.Laby;
import net.labymod.api.addon.LabyAddon;
Expand Down Expand Up @@ -40,8 +39,9 @@ protected void enable() {

TagRegistry tagRegistry = labyAPI().tagRegistry();
for (PositionType positionType : PositionType.values())
tagRegistry.register(
tagRegistry.registerBefore(
"friendtags_tag",
"globaltag",
positionType,
new CustomTag(this, positionType)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public CompletableFuture<Void> sendAsyncRequest() {
CompletableFuture<Void> future = new CompletableFuture<>();

try {
// TODO: Use Request#ofGson
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("https://gt.rappytv.com" + path))
.header("Content-Type", "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public GlobalTagConfig() {
@SliderSetting(min = 5, max = 10)
private final ConfigProperty<Integer> tagSize = new ConfigProperty<>(10);
@IntroducedIn(namespace = "globaltags", value = "1.1.0")
@SpriteSlot(size = 32, y = 2)
@SpriteSlot(size = 32, y = 2, x = 1)
@SwitchSetting
private final ConfigProperty<Boolean> displayExceptions = new ConfigProperty<>(false);
@SpriteSlot(size = 32, x = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.rappytv.globaltags.api.ApiHandler;
import com.rappytv.globaltags.util.GlobalIcon;
import com.rappytv.globaltags.util.Util;
import net.labymod.api.Laby;
import net.labymod.api.client.entity.player.tag.PositionType;
import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget.ButtonSetting;
import net.labymod.api.client.gui.screen.widget.widgets.input.TextFieldWidget.TextFieldSetting;
Expand All @@ -23,8 +24,14 @@ public class TagSubConfig extends Config {

public TagSubConfig() {
apiHandler = GlobalTagAddon.getAddon().getApiHandler();
position.addChangeListener((property, oldValue, newValue) -> apiHandler.setPosition(newValue));
globalIcon.addChangeListener((property, oldValue, newValue) -> apiHandler.setIcon(newValue));
position.addChangeListener((property, oldValue, newValue) -> {
if(Laby.labyAPI().isFullyInitialized())
apiHandler.setPosition(newValue);
});
globalIcon.addChangeListener((property, oldValue, newValue) -> {
if(Laby.labyAPI().isFullyInitialized())
apiHandler.setIcon(newValue);
});
}

@TextFieldSetting
Expand All @@ -44,19 +51,21 @@ public void setTag(Setting setting) {
@SpriteSlot(size = 32, x = 3)
private final ConfigProperty<PositionType> position = new ConfigProperty<>(PositionType.ABOVE_NAME);


@DropdownSetting
@SpriteSlot(size = 32, y = 1, x = 2)
private final ConfigProperty<GlobalIcon> globalIcon = new ConfigProperty<>(GlobalIcon.NONE);

@MethodOrder(after = "globalIcon")
@ButtonSetting
@SpriteSlot(size = 32, y = 1, x = 2)
@SpriteSlot(size = 32, y = 1, x = 3)
public void resetTag(Setting setting) {
apiHandler.resetTag();
}

@MethodOrder(after = "resetTag")
@ButtonSetting
@SpriteSlot(size = 32, y = 1, x = 3)
@SpriteSlot(size = 32, y = 2)
public void clearCache(Setting setting) {
if(Util.clearCache(true))
Util.notify(
Expand Down
32 changes: 19 additions & 13 deletions core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import com.rappytv.globaltags.GlobalTagAddon;
import com.rappytv.globaltags.api.requests.InfoGetRequest;
import com.rappytv.globaltags.config.GlobalTagConfig;
import com.rappytv.globaltags.util.GlobalIcon;
import com.rappytv.globaltags.util.PlayerInfo;
import com.rappytv.globaltags.util.TagCache;
import com.rappytv.globaltags.util.Util;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.serializer.legacy.LegacyComponentSerializer;
import net.labymod.api.client.entity.Entity;
import net.labymod.api.client.entity.player.Player;
import net.labymod.api.client.entity.player.tag.PositionType;
Expand All @@ -23,29 +25,30 @@
@SuppressWarnings("deprecation")
public class CustomTag extends NameTag {

private final GlobalTagAddon addon;
private final GlobalTagConfig config;
private final PositionType position;
private final Set<UUID> resolving = new HashSet<>();
private PlayerInfo info;

public CustomTag(GlobalTagAddon addon, PositionType position) {
this.addon = addon;
this.config = addon.configuration();
this.position = position;
}

@Override
public float getScale() {
return (float) addon.configuration().tagSize().get() / 10;
return (float) config.tagSize().get() / 10;
}

@Override
protected @Nullable RenderableComponent getRenderableComponent() {
if(!addon.configuration().enabled().get()) return null;
if(!config.enabled().get()) return null;
if(entity == null || !(entity instanceof Player)) return null;
UUID uuid = entity.getUniqueId();
if(!addon.configuration().showOwnTag().get() && Laby.labyAPI().getUniqueId().equals(uuid))
if(!config.showOwnTag().get() && Laby.labyAPI().getUniqueId().equals(uuid))
return null;

PlayerInfo info = null;
info = null;
if(TagCache.has(uuid))
info = TagCache.get(uuid);
else {
Expand All @@ -54,7 +57,7 @@ public float getScale() {
InfoGetRequest request = new InfoGetRequest(uuid, Util.getSessionToken());
request.sendAsyncRequest().thenRun(() -> {
TagCache.add(uuid, new PlayerInfo(
request.getTag(),
translateColorCodes(request.getTag()),
request.getPosition(),
request.getIcon()
));
Expand All @@ -65,28 +68,31 @@ public float getScale() {
if(info == null || info.getTag() == null) return null;
if(!position.equals(info.getPosition())) return null;

return RenderableComponent.of(Component.text(
info.getTag().replace('&', '§')
));
return RenderableComponent.of(info.getTag());
}

@Override
public void render(Stack stack, Entity entity) {
super.render(stack, entity);
if(this.getRenderableComponent() == null) return;
PlayerInfo info = TagCache.get(entity.getUniqueId());
if(info == null || info.getIcon() == GlobalIcon.NONE) return;

addon.labyAPI().renderPipeline().renderSeeThrough(entity, () -> {
Laby.labyAPI().renderPipeline().renderSeeThrough(entity, () -> {
if(!info.getIcon().resourceLocation().exists()) return;
Icon icon = Icon.texture(info.getIcon().resourceLocation());

icon.render(stack, -12, -1, 10, 10);
icon.render(stack, -11, 0, 9, 9);
});
}

@Override
public boolean isVisible() {
return !this.entity.isCrouching() && super.isVisible();
}

private Component translateColorCodes(String string) {
return LegacyComponentSerializer
.legacyAmpersand()
.deserialize(string);
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.rappytv.globaltags.util;

import net.labymod.api.client.component.Component;
import net.labymod.api.client.entity.player.tag.PositionType;

public class PlayerInfo {

private final String tag;
private final Component tag;
private final String position;
private final String icon;

public PlayerInfo(String tag, String position, String icon) {
public PlayerInfo(Component tag, String position, String icon) {
this.tag = tag;
this.position = position;
this.icon = icon;
}

public String getTag() {
public Component getTag() {
return tag;
}

Expand Down
1 change: 0 additions & 1 deletion core/src/main/java/com/rappytv/globaltags/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public static boolean clearCache(boolean notify) {

public static @Nullable String getSessionToken() {
LabyConnectSession session = Laby.labyAPI().labyConnect().getSession();

if(session == null) return null;

Token token = session.tokenStorage().getToken(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified core/src/main/resources/assets/globaltags/textures/icons/x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading