diff --git a/build.gradle.kts b/build.gradle.kts index 46e2398f..5e2d2d97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -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 { @@ -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) { diff --git a/core/src/main/java/com/rappytv/globaltags/api/ApiHandler.java b/core/src/main/java/com/rappytv/globaltags/api/ApiHandler.java index 9eccd5ae..d1a513ad 100644 --- a/core/src/main/java/com/rappytv/globaltags/api/ApiHandler.java +++ b/core/src/main/java/com/rappytv/globaltags/api/ApiHandler.java @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/core/src/main/java/com/rappytv/globaltags/api/RequestBody.java b/core/src/main/java/com/rappytv/globaltags/api/RequestBody.java index e39e5846..8f063de7 100644 --- a/core/src/main/java/com/rappytv/globaltags/api/RequestBody.java +++ b/core/src/main/java/com/rappytv/globaltags/api/RequestBody.java @@ -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) { @@ -23,6 +25,10 @@ public RequestBody(PositionType type) { }; } + public RequestBody(GlobalIcon icon) { + this.icon = icon.name(); + } + public enum StringType { TAG, REPORT_REASON diff --git a/core/src/main/java/com/rappytv/globaltags/api/ResponseBody.java b/core/src/main/java/com/rappytv/globaltags/api/ResponseBody.java index 56d3de61..853115f4 100644 --- a/core/src/main/java/com/rappytv/globaltags/api/ResponseBody.java +++ b/core/src/main/java/com/rappytv/globaltags/api/ResponseBody.java @@ -5,6 +5,7 @@ public class ResponseBody { // For success public String tag; public String position; + public String icon; public String message; // For errors diff --git a/core/src/main/java/com/rappytv/globaltags/api/requests/IconSetRequest.java b/core/src/main/java/com/rappytv/globaltags/api/requests/IconSetRequest.java new file mode 100644 index 00000000..1bc179a2 --- /dev/null +++ b/core/src/main/java/com/rappytv/globaltags/api/requests/IconSetRequest.java @@ -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); + } +} diff --git a/core/src/main/java/com/rappytv/globaltags/api/requests/InfoGetRequest.java b/core/src/main/java/com/rappytv/globaltags/api/requests/InfoGetRequest.java index 5cfda9ba..43a3a278 100644 --- a/core/src/main/java/com/rappytv/globaltags/api/requests/InfoGetRequest.java +++ b/core/src/main/java/com/rappytv/globaltags/api/requests/InfoGetRequest.java @@ -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); @@ -20,6 +21,7 @@ public CompletableFuture sendAsyncRequest() { if(isSuccessful()) { this.tag = responseBody.tag; this.position = responseBody.position; + this.icon = responseBody.icon; } }); } @@ -35,4 +37,7 @@ public String getTag() { public String getPosition() { return position; } + public String getIcon() { + return icon; + } } diff --git a/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java b/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java index 57f802c3..9645e0f3 100644 --- a/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java +++ b/core/src/main/java/com/rappytv/globaltags/config/subconfig/TagSubConfig.java @@ -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; @@ -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 @@ -42,12 +44,14 @@ public void setTag(Setting setting) { @SpriteSlot(size = 32, x = 3) private final ConfigProperty position = new ConfigProperty<>(PositionType.ABOVE_NAME); - @MethodOrder(after = "position") + @DropdownSetting + private final ConfigProperty 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") diff --git a/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java b/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java index ee711cf4..46a1e2d0 100644 --- a/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java +++ b/core/src/main/java/com/rappytv/globaltags/nametag/CustomTag.java @@ -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; @@ -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)) @@ -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); }); } @@ -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(); diff --git a/core/src/main/java/com/rappytv/globaltags/util/GlobalIcon.java b/core/src/main/java/com/rappytv/globaltags/util/GlobalIcon.java new file mode 100644 index 00000000..069d1018 --- /dev/null +++ b/core/src/main/java/com/rappytv/globaltags/util/GlobalIcon.java @@ -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; + } +} diff --git a/core/src/main/java/com/rappytv/globaltags/util/PlayerInfo.java b/core/src/main/java/com/rappytv/globaltags/util/PlayerInfo.java index c66d2b70..1561d147 100644 --- a/core/src/main/java/com/rappytv/globaltags/util/PlayerInfo.java +++ b/core/src/main/java/com/rappytv/globaltags/util/PlayerInfo.java @@ -6,10 +6,12 @@ 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() { @@ -17,6 +19,7 @@ public String getTag() { } public PositionType getPosition() { + if(position == null) return PositionType.ABOVE_NAME; return switch(position) { default -> PositionType.ABOVE_NAME; case "BELOW" -> PositionType.BELOW_NAME; @@ -24,4 +27,12 @@ public PositionType getPosition() { case "LEFT" -> PositionType.LEFT_TO_NAME; }; } + + public GlobalIcon getIcon() { + try { + return GlobalIcon.valueOf(icon.toUpperCase()); + } catch (IllegalArgumentException e) { + return GlobalIcon.NONE; + } + } } diff --git a/core/src/main/resources/assets/globaltags/i18n/en_us.json b/core/src/main/resources/assets/globaltags/i18n/en_us.json index f561bf78..f16509b9 100644 --- a/core/src/main/resources/assets/globaltags/i18n/en_us.json +++ b/core/src/main/resources/assets/globaltags/i18n/en_us.json @@ -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\"." @@ -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" diff --git a/core/src/main/resources/assets/globaltags/textures/icons/bereal.png b/core/src/main/resources/assets/globaltags/textures/icons/bereal.png new file mode 100644 index 00000000..e3a766b0 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/bereal.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/discord.png b/core/src/main/resources/assets/globaltags/textures/icons/discord.png new file mode 100644 index 00000000..4c9d6670 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/discord.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/ebio.png b/core/src/main/resources/assets/globaltags/textures/icons/ebio.png new file mode 100644 index 00000000..c8c58995 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/ebio.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/epicgames.png b/core/src/main/resources/assets/globaltags/textures/icons/epicgames.png new file mode 100644 index 00000000..ea3d0a36 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/epicgames.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/github.png b/core/src/main/resources/assets/globaltags/textures/icons/github.png new file mode 100644 index 00000000..a5b690d8 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/github.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/gitlab.png b/core/src/main/resources/assets/globaltags/textures/icons/gitlab.png new file mode 100644 index 00000000..5c73be89 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/gitlab.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/instagram.png b/core/src/main/resources/assets/globaltags/textures/icons/instagram.png new file mode 100644 index 00000000..fedc3ae8 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/instagram.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/kick.png b/core/src/main/resources/assets/globaltags/textures/icons/kick.png new file mode 100644 index 00000000..839a40a8 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/kick.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/pinterest.png b/core/src/main/resources/assets/globaltags/textures/icons/pinterest.png new file mode 100644 index 00000000..9724f31b Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/pinterest.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/playstation.png b/core/src/main/resources/assets/globaltags/textures/icons/playstation.png new file mode 100644 index 00000000..61ffbb93 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/playstation.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/snapchat.png b/core/src/main/resources/assets/globaltags/textures/icons/snapchat.png new file mode 100644 index 00000000..d2662cc1 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/snapchat.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/steam.png b/core/src/main/resources/assets/globaltags/textures/icons/steam.png new file mode 100644 index 00000000..1a8eb743 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/steam.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/threads.png b/core/src/main/resources/assets/globaltags/textures/icons/threads.png new file mode 100644 index 00000000..e37326af Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/threads.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/tiktok.png b/core/src/main/resources/assets/globaltags/textures/icons/tiktok.png new file mode 100644 index 00000000..818996c5 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/tiktok.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/twitch.png b/core/src/main/resources/assets/globaltags/textures/icons/twitch.png new file mode 100644 index 00000000..dcbd6c84 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/twitch.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/x.png b/core/src/main/resources/assets/globaltags/textures/icons/x.png new file mode 100644 index 00000000..38dcb38e Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/x.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/xbox.png b/core/src/main/resources/assets/globaltags/textures/icons/xbox.png new file mode 100644 index 00000000..87168462 Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/xbox.png differ diff --git a/core/src/main/resources/assets/globaltags/textures/icons/youtube.png b/core/src/main/resources/assets/globaltags/textures/icons/youtube.png new file mode 100644 index 00000000..d6012b0f Binary files /dev/null and b/core/src/main/resources/assets/globaltags/textures/icons/youtube.png differ diff --git a/settings.gradle.kts b/settings.gradle.kts index 5e89b634..81d9f540 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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) }