Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: LabyAddon Build

on:
push:
branches: [ "master", "main" ]
branches: [ "master" ]
pull_request:
branches: [ "master", "main" ]
branches: [ "master" ]
workflow_dispatch:

jobs:
Expand All @@ -17,6 +17,20 @@ jobs:
with:
distribution: 'corretto'
java-version: '21'
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
gradle-${{ runner.os }}-
- name: Cache Gradle wrapper
uses: actions/cache@v4
with:
path: ~/.gradle/wrapper
key: gradle-wrapper-${{ runner.os }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: |
gradle-wrapper-${{ runner.os }}-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
Expand All @@ -25,4 +39,4 @@ jobs:
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/*-release.jar
path: build/libs/*-release.jar
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ hs_err_pid*
# User-specific stuff
/.idea/
run/**
.DS_Store

# CMake
cmake-build-*/
Expand Down
9 changes: 9 additions & 0 deletions api/src/main/java/com/rappytv/streakdisplay/api/Textures.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.rappytv.streakdisplay.api;

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

public class Textures {

public static final ResourceLocation STREAK = ResourceLocation.create("streakdisplay", "textures/streak.png");

}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";")

group = "org.example"
version = providers.environmentVariable("VERSION").getOrElse("1.0.0")
version = providers.environmentVariable("VERSION").getOrElse("1.0.1")

labyMod {
defaultPackageName = "com.rappytv.streakdisplay"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@Implements(StreakApiController.class)
public class DefaultStreakApiController implements StreakApiController {

private static final String STREAK_ENDPOINT = "https://streaks.rappytv.com/streaks/%s";
private final Map<UUID, Integer> cache = new HashMap<>();
private final Set<UUID> resolving = new HashSet<>();

Expand All @@ -26,26 +27,32 @@ public void resolve(UUID uuid) {
}
this.resolving.add(uuid);
Request.ofGson(JsonElement.class)
.url("https://streaks.rappytv.com/streaks/" + uuid.toString())
.url(String.format(STREAK_ENDPOINT, uuid))
.handleErrorStream()
.async()
.execute(response -> {
if (response.hasException() || response.getStatusCode() != 200) {
this.cache.put(uuid, null);
this.resolving.remove(uuid);
this.cacheFailure(uuid);
return;
}
JsonObject body = response.get().getAsJsonObject();
if (!body.has("streak") || !body.get("streak").isJsonPrimitive()) {
this.cache.put(uuid, null);
this.resolving.remove(uuid);
this.cacheFailure(uuid);
return;
}
this.cache.put(uuid, body.get("streak").getAsInt());
this.resolving.remove(uuid);
this.cacheStreak(uuid, body.get("streak").getAsInt());
});
}

private void cacheFailure(UUID uuid) {
this.cacheStreak(uuid, null);
}

private void cacheStreak(UUID uuid, Integer value) {
this.cache.put(uuid, value);
this.resolving.remove(uuid);
}

@Override
public boolean has(UUID uuid) {
return this.cache.containsKey(uuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.rappytv.streakdisplay.StreakDisplayConfig;
import com.rappytv.streakdisplay.api.StreakApiController;
import java.util.UUID;
import com.rappytv.streakdisplay.api.Textures;
import net.labymod.api.Laby;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
Expand All @@ -13,15 +14,11 @@
import net.labymod.api.client.render.RenderPipeline;
import net.labymod.api.client.render.font.RenderableComponent;
import net.labymod.api.client.render.matrix.Stack;
import net.labymod.api.client.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;

public class StreakNameTag extends NameTag {

private static final Icon STREAK = Icon.texture(ResourceLocation.create(
"streakdisplay",
"textures/streak.png"
));
private static final Icon STREAK = Icon.texture(Textures.STREAK);
private final StreakDisplayConfig config;
private final StreakApiController controller;

Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# StreakDisplay

With this addon you can see the streaks of other players below their name in a separate nametag. [This API](https://github.com/RappyTV/StreakAPI) is used to retrieve the streak data.

### 📦 Installation

1. Press `Win` + `R`
Expand Down