Skip to content

Commit

Permalink
Merge pull request #20 from RappyLabyAddons/feat/icons
Browse files Browse the repository at this point in the history
Add icons next to tag
  • Loading branch information
RappyTV authored Jan 26, 2024
2 parents 81c6fd1 + c524ef6 commit 55ce28c
Show file tree
Hide file tree
Showing 30 changed files with 165 additions and 21 deletions.
8 changes: 2 additions & 6 deletions 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.0.10")
version = System.getenv().getOrDefault("VERSION", "1.1.0")
}

minecraft {
Expand Down Expand Up @@ -72,11 +72,7 @@ fun configureRun(provider: net.labymod.gradle.core.minecraft.provider.VersionPro
args("--addon-dev-environment", "true")
}

provider.javaVersion = when (gameVersion) {
else -> {
JavaVersion.VERSION_17
}
}
provider.javaVersion = JavaVersion.VERSION_17

provider.mixin {
val mixinMinVersion = when (gameVersion) {
Expand Down
23 changes: 23 additions & 0 deletions core/src/main/java/com/rappytv/globaltags/api/ApiHandler.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.rappytv.globaltags.api;

import com.rappytv.globaltags.api.RequestBody.StringType;
import com.rappytv.globaltags.api.requests.IconSetRequest;
import com.rappytv.globaltags.api.requests.PositionSetRequest;
import com.rappytv.globaltags.api.requests.TagSetRequest;
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;
Expand All @@ -24,6 +26,7 @@ public void setTag(String tag) {
return;
}
Util.notify(I18n.translate("globaltags.notifications.success"), request.getMessage(), false);
Util.clearCache(false);
}).exceptionally((e) -> {
Util.notify(I18n.translate("globaltags.notifications.error"), e.getMessage(), true);
return null;
Expand All @@ -41,6 +44,25 @@ public void setPosition(PositionType position) {
return;
}
Util.notify(I18n.translate("globaltags.notifications.success"), request.getMessage(), false);
Util.clearCache(false);
}).exceptionally((e) -> {
Util.notify(I18n.translate("globaltags.notifications.error"), e.getMessage(), true);
return null;
});
}

public void setIcon(GlobalIcon icon) {
IconSetRequest request = new IconSetRequest(
Util.getSessionToken(),
icon
);
request.sendAsyncRequest().thenRun(() -> {
if(!request.isSuccessful()) {
Util.notify(I18n.translate("globaltags.notifications.error"), request.getError(), true);
return;
}
Util.notify(I18n.translate("globaltags.notifications.success"), request.getMessage(), false);
Util.clearCache(false);
}).exceptionally((e) -> {
Util.notify(I18n.translate("globaltags.notifications.error"), e.getMessage(), true);
return null;
Expand All @@ -64,6 +86,7 @@ public RequestBody getBody() {
return;
}
Util.notify(I18n.translate("globaltags.notifications.success"), request.getMessage(), false);
Util.clearCache(false);
}).exceptionally((e) -> {
Util.notify(I18n.translate("globaltags.notifications.error"), e.getMessage(), true);
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.rappytv.globaltags.api;

import com.rappytv.globaltags.util.GlobalIcon;
import net.labymod.api.client.entity.player.tag.PositionType;

public class RequestBody {

public String tag;
public String position;
public String icon;
public String reason;

public RequestBody(String argument, StringType type) {
Expand All @@ -23,6 +25,10 @@ public RequestBody(PositionType type) {
};
}

public RequestBody(GlobalIcon icon) {
this.icon = icon.name();
}

public enum StringType {
TAG,
REPORT_REASON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class ResponseBody {
// For success
public String tag;
public String position;
public String icon;
public String message;

// For errors
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.rappytv.globaltags.api.requests;

import com.rappytv.globaltags.api.ApiRequest;
import com.rappytv.globaltags.api.RequestBody;
import com.rappytv.globaltags.util.GlobalIcon;
import net.labymod.api.Laby;

public class IconSetRequest extends ApiRequest {

private final GlobalIcon icon;

public IconSetRequest(String key, GlobalIcon icon) {
super("POST", "/players/" + Laby.labyAPI().getUniqueId() + "/icon", key);
this.icon = icon;
}

@Override
public RequestBody getBody() {
return new RequestBody(icon);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class InfoGetRequest extends ApiRequest {

private String tag;
private String position;
private String icon;

public InfoGetRequest(UUID uuid, String key) {
super("GET", "/players/" + uuid, key);
Expand All @@ -20,6 +21,7 @@ public CompletableFuture<Void> sendAsyncRequest() {
if(isSuccessful()) {
this.tag = responseBody.tag;
this.position = responseBody.position;
this.icon = responseBody.icon;
}
});
}
Expand All @@ -35,4 +37,7 @@ public String getTag() {
public String getPosition() {
return position;
}
public String getIcon() {
return icon;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.rappytv.globaltags.GlobalTagAddon;
import com.rappytv.globaltags.api.ApiHandler;
import com.rappytv.globaltags.util.GlobalIcon;
import com.rappytv.globaltags.util.Util;
import net.labymod.api.client.entity.player.tag.PositionType;
import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget.ButtonSetting;
Expand All @@ -23,6 +24,7 @@ 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));
}

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

@MethodOrder(after = "position")
@DropdownSetting
private final ConfigProperty<GlobalIcon> globalIcon = new ConfigProperty<>(GlobalIcon.NONE);

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

@MethodOrder(after = "resetTag")
Expand Down
29 changes: 27 additions & 2 deletions core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@

import com.rappytv.globaltags.GlobalTagAddon;
import com.rappytv.globaltags.api.requests.InfoGetRequest;
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.entity.Entity;
import net.labymod.api.client.entity.player.Player;
import net.labymod.api.client.entity.player.tag.PositionType;
import net.labymod.api.client.entity.player.tag.tags.NameTag;
import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.render.font.RenderableComponent;
import net.labymod.api.client.render.matrix.Stack;
import org.jetbrains.annotations.Nullable;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

@SuppressWarnings("deprecation")
public class CustomTag extends NameTag {

private final GlobalTagAddon addon;
Expand All @@ -37,7 +42,8 @@ public float getScale() {
if(!addon.configuration().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)) return null;
if(!addon.configuration().showOwnTag().get() && Laby.labyAPI().getUniqueId().equals(uuid))
return null;

PlayerInfo info = null;
if(TagCache.has(uuid))
Expand All @@ -47,7 +53,11 @@ public float getScale() {
resolving.add(uuid);
InfoGetRequest request = new InfoGetRequest(uuid, Util.getSessionToken());
request.sendAsyncRequest().thenRun(() -> {
TagCache.add(uuid, new PlayerInfo(request.getTag(), request.getPosition()));
TagCache.add(uuid, new PlayerInfo(
request.getTag(),
request.getPosition(),
request.getIcon()
));
resolving.remove(uuid);
});
}
Expand All @@ -60,6 +70,21 @@ public float getScale() {
));
}

@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, () -> {
if(!info.getIcon().resourceLocation().exists()) return;
Icon icon = Icon.texture(info.getIcon().resourceLocation());

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

@Override
public boolean isVisible() {
return !this.entity.isCrouching() && super.isVisible();
Expand Down
37 changes: 37 additions & 0 deletions core/src/main/java/com/rappytv/globaltags/util/GlobalIcon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.rappytv.globaltags.util;

import net.labymod.api.client.resources.ResourceLocation;

public enum GlobalIcon {
NONE,
BEREAL,
DISCORD,
EBIO,
EPICGAMES,
GITHUB,
GITLAB,
INSTAGRAM,
KICK,
PLAYSTATION,
SNAPCHAT,
STEAM,
THREADS,
TIKTOK,
TWITCH,
X,
XBOX,
YOUTUBE;

private final ResourceLocation resourceLocation;

GlobalIcon() {
this.resourceLocation = ResourceLocation.create(
"globaltags",
"textures/icons/" + this.name().toLowerCase() + ".png"
);
}

public ResourceLocation resourceLocation() {
return resourceLocation;
}
}
13 changes: 12 additions & 1 deletion core/src/main/java/com/rappytv/globaltags/util/PlayerInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,33 @@ public class PlayerInfo {

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

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

public String getTag() {
return tag;
}

public PositionType getPosition() {
if(position == null) return PositionType.ABOVE_NAME;
return switch(position) {
default -> PositionType.ABOVE_NAME;
case "BELOW" -> PositionType.BELOW_NAME;
case "RIGHT" -> PositionType.RIGHT_TO_NAME;
case "LEFT" -> PositionType.LEFT_TO_NAME;
};
}

public GlobalIcon getIcon() {
try {
return GlobalIcon.valueOf(icon.toUpperCase());
} catch (IllegalArgumentException e) {
return GlobalIcon.NONE;
}
}
}
33 changes: 24 additions & 9 deletions core/src/main/resources/assets/globaltags/i18n/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
"tagSize": {
"name": "Tag size"
},
"position": {
"name": "Position",
"entries": {
"aboveName": "Above name",
"belowName": "Below name",
"rightToName": "Right to name",
"leftToName": "Left to name"
}
},
"displayExceptions": {
"name": "Java Exceptions",
"description": "Shows Java Exceptions instead of \"An unknown error ocurred\"."
Expand All @@ -44,6 +35,30 @@
"leftToName": "Left to name"
}
},
"globalIcon": {
"name": "Global Icon",
"entries": {
"none": "None",
"discord": "Discord",
"bereal": "BeReal.",
"ebio": "e.bio",
"epicgames": "Epic Games",
"github": "GitHub",
"gitlab": "GitLab",
"instagram": "Instagram",
"kick": "Kick",
"pinterest": "Pinterest",
"playstation": "Playstation",
"snapchat": "Snapchat",
"steam": "Steam",
"threads": "Threads",
"tiktok": "TikTok",
"twitch": "Twitch",
"x": "x",
"xbox": "Xbox",
"youtube": "YouTube"
}
},
"resetTag": {
"name": "Delete global tag",
"text": "Delete"
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.
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.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rootProject.name = "GlobalTags"

pluginManagement {
val labyGradlePluginVersion = "0.3.31"
val labyGradlePluginVersion = "0.3.44"
plugins {
id("net.labymod.gradle") version (labyGradlePluginVersion)
}
Expand Down

0 comments on commit 55ce28c

Please sign in to comment.