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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
- name: Set up JDK 25
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '21'
java-version: '25'
- name: Cache Gradle dependencies
uses: actions/cache@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ run/
# LabyGradle | Addon Plugin
build-data.txt
.assetsroot
resources_index.json
access_widener_index.json

# Don't ignore libraries
!libs/*.jar
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
import net.labymod.api.reference.annotation.Referenceable;

@Referenceable
public interface StreakApiController {
public interface StreakCacheController {

void resolve(UUID uuid);

boolean has(UUID uuid);

Integer get(UUID uuid);

void remove(UUID uuid);

void clear();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

public class Textures {
public class StreakDisplayTextures {

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

Expand Down
7 changes: 6 additions & 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.1")
version = providers.environmentVariable("VERSION").getOrElse("1.0.2")

labyMod {
defaultPackageName = "com.rappytv.streakdisplay"
Expand Down Expand Up @@ -37,4 +37,9 @@ subprojects {

group = rootProject.group
version = rootProject.version

extensions.findByType(JavaPluginExtension::class.java)?.apply {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.rappytv.streakdisplay;
package com.rappytv.streakdisplay.core;

import com.rappytv.streakdisplay.api.StreakCacheController;
import com.rappytv.streakdisplay.api.generated.ReferenceStorage;
import com.rappytv.streakdisplay.nametag.StreakNameTag;
import com.rappytv.streakdisplay.core.listener.PlayerInfoListener;
import com.rappytv.streakdisplay.core.ui.nametag.StreakNameTag;
import net.labymod.api.addon.LabyAddon;
import net.labymod.api.client.entity.player.tag.PositionType;
import net.labymod.api.models.addon.annotation.AddonMain;

@AddonMain
public class StreakDisplayAddon extends LabyAddon<StreakDisplayConfig> {

private static StreakDisplayAddon INSTANCE;
private static StreakDisplayAddon instance;

@Override
protected void enable() {
INSTANCE = this;
instance = this;

this.registerSettingCategory();

this.registerListener(new PlayerInfoListener());
this.labyAPI().tagRegistry().register(
"streakdisplay",
PositionType.BELOW_NAME,
Expand All @@ -29,7 +31,7 @@ protected Class<? extends StreakDisplayConfig> configurationClass() {
return StreakDisplayConfig.class;
}

public static ReferenceStorage references() {
return INSTANCE.referenceStorageAccessor();
public static StreakCacheController cacheController() {
return ((ReferenceStorage) instance.referenceStorageAccessor()).streakCacheController();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.rappytv.streakdisplay;
package com.rappytv.streakdisplay.core;

import net.labymod.api.addon.AddonConfig;
import net.labymod.api.client.gui.screen.widget.widgets.input.ButtonWidget.ButtonSetting;
Expand All @@ -22,10 +22,6 @@ public class StreakDisplayConfig extends AddonConfig {
@SliderSetting(min = 5, max = 10)
private final ConfigProperty<Integer> size = new ConfigProperty<>(7);

@SpriteSlot(x = 2)
@SwitchSetting
private final ConfigProperty<Boolean> showBackground = new ConfigProperty<>(true);

@SettingSection("streaks")
@SpriteSlot(x = 3)
@SwitchSetting
Expand All @@ -40,7 +36,7 @@ public class StreakDisplayConfig extends AddonConfig {
@MethodOrder(after = "hideHiddenStreaks")
@ButtonSetting
public void clearCache() {
StreakDisplayAddon.references().streakApiController().clear();
StreakDisplayAddon.cacheController().clear();
}

@Override
Expand All @@ -52,10 +48,6 @@ public ConfigProperty<Integer> size() {
return this.size;
}

public ConfigProperty<Boolean> showBackground() {
return this.showBackground;
}

public ConfigProperty<Boolean> hideZeroStreaks() {
return this.hideZeroStreaks;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.rappytv.streakdisplay.controller;
package com.rappytv.streakdisplay.core.controller;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.rappytv.streakdisplay.api.StreakApiController;
import com.rappytv.streakdisplay.api.StreakCacheController;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand All @@ -13,8 +13,8 @@
import net.labymod.api.util.io.web.request.Request;

@Singleton
@Implements(StreakApiController.class)
public class DefaultStreakApiController implements StreakApiController {
@Implements(StreakCacheController.class)
public class DefaultStreakCacheController implements StreakCacheController {

private static final String STREAK_ENDPOINT = "https://streaks.rappytv.com/streaks/%s";
private final Map<UUID, Integer> cache = new HashMap<>();
Expand Down Expand Up @@ -63,6 +63,11 @@ public Integer get(UUID uuid) {
return this.cache.get(uuid);
}

@Override
public void remove(UUID uuid) {
this.cache.remove(uuid);
}

@Override
public void clear() {
this.cache.clear();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.rappytv.streakdisplay.core.listener;

import com.rappytv.streakdisplay.api.StreakCacheController;
import com.rappytv.streakdisplay.core.StreakDisplayAddon;
import java.util.UUID;
import net.labymod.api.event.Subscribe;
import net.labymod.api.event.client.network.playerinfo.PlayerInfoRemoveEvent;
import net.labymod.api.event.client.network.server.ServerDisconnectEvent;
import net.labymod.api.event.client.render.model.entity.player.PlayerModelRenderEvent;

public class PlayerInfoListener {

private final StreakCacheController controller;

public PlayerInfoListener() {
this.controller = StreakDisplayAddon.cacheController();
}

@Subscribe
public void onPlayerRender(PlayerModelRenderEvent event) {
UUID uuid = event.player().getUniqueId();

if (!this.controller.has(uuid)) {
this.controller.resolve(uuid);
}
}

@Subscribe
public void onPlayerInfoRemove(PlayerInfoRemoveEvent event) {
this.controller.remove(event.playerInfo().profile().getUniqueId());
}

@Subscribe
public void onClientDisconnect(ServerDisconnectEvent event) {
this.controller.clear();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.rappytv.streakdisplay.core.ui.nametag;

import com.rappytv.streakdisplay.api.StreakDisplayTextures;
import com.rappytv.streakdisplay.core.StreakDisplayAddon;
import com.rappytv.streakdisplay.core.StreakDisplayConfig;
import com.rappytv.streakdisplay.core.ui.snapshot.StreakDisplayExtraKeys;
import com.rappytv.streakdisplay.core.ui.snapshot.StreakUserSnapshot;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.entity.player.tag.tags.ComponentNameTag;
import net.labymod.api.client.gui.icon.Icon;
import net.labymod.api.client.render.matrix.Stack;
import net.labymod.api.client.render.state.entity.EntitySnapshot;
import net.labymod.api.laby3d.render.queue.SubmissionCollector;
import net.labymod.api.laby3d.render.queue.submissions.IconSubmission.DisplayMode;
import org.jetbrains.annotations.NotNull;

public class StreakNameTag extends ComponentNameTag {

private static final Icon STREAK_ICON = Icon.texture(StreakDisplayTextures.STREAK);

private final StreakDisplayConfig config;
private float iconSize;

public StreakNameTag(StreakDisplayAddon addon) {
this.config = addon.configuration();
}

@Override
public void begin(EntitySnapshot snapshot) {
super.begin(snapshot);
this.iconSize = this.fontRenderer.getLineHeight();
}

@Override
protected @NotNull List<Component> buildComponents(EntitySnapshot snapshot) {
if (snapshot.isDiscrete()
|| snapshot.isInvisible()
|| !snapshot.has(StreakDisplayExtraKeys.STREAK_USER)) {
return super.buildComponents(snapshot);
}
StreakUserSnapshot streakUser = snapshot.get(StreakDisplayExtraKeys.STREAK_USER);
if (!streakUser.isEnabled()) {
return super.buildComponents(snapshot);
}
Component streakComponent = streakUser.streakComponent();

return streakComponent != null
? Collections.singletonList(streakComponent)
: super.buildComponents(snapshot);
}

@Override
public void render(Stack stack, SubmissionCollector submissionCollector,
EntitySnapshot snapshot) {
super.render(stack, submissionCollector, snapshot);

submissionCollector.submitIcon(
stack,
STREAK_ICON,
DisplayMode.NORMAL,
-11,
-1f,
this.iconSize,
this.iconSize,
-1
);
}

@Override
protected float calculateWidth(Collection<Component> components) {
return super.calculateWidth(components) - this.iconSize;
}

@Override
protected int getBackgroundColor(EntitySnapshot snapshot) {
return 0;
}

@Override
public float getScale() {
return this.config.size().get() / 10f;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.rappytv.streakdisplay.core.ui.snapshot;

import net.labymod.api.client.entity.Entity;
import net.labymod.api.client.entity.player.Player;
import net.labymod.api.client.render.state.entity.EntitySnapshotProcessor;
import net.labymod.api.client.render.state.entity.EntitySnapshotRegistry;
import net.labymod.api.laby3d.renderer.snapshot.ExtrasWriter;
import net.labymod.api.service.annotation.AutoService;

@AutoService(EntitySnapshotProcessor.class)
public class PlayerSnapshotProcessor extends EntitySnapshotProcessor<Player> {

public PlayerSnapshotProcessor(EntitySnapshotRegistry registry) {
super(registry);
}

@Override
public boolean supports(Entity entity) {
return entity instanceof Player;
}

@Override
public void process(Player player, float partialTicks, ExtrasWriter entityWriter) {
this.registry().captureSnapshot(entityWriter, StreakDisplayExtraKeys.STREAK_USER, player);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.rappytv.streakdisplay.core.ui.snapshot;

import net.labymod.api.laby3d.renderer.snapshot.ExtraKey;

public class StreakDisplayExtraKeys {

public static final ExtraKey<StreakUserSnapshot> STREAK_USER = ExtraKey.of(
"streak_user",
StreakUserSnapshot.class
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.rappytv.streakdisplay.core.ui.snapshot;

import com.rappytv.streakdisplay.api.StreakCacheController;
import com.rappytv.streakdisplay.core.StreakDisplayAddon;
import com.rappytv.streakdisplay.core.StreakDisplayConfig;
import net.labymod.api.client.component.Component;
import net.labymod.api.client.component.format.NamedTextColor;
import net.labymod.api.client.entity.player.Player;
import net.labymod.api.laby3d.renderer.snapshot.AbstractLabySnapshot;
import net.labymod.api.laby3d.renderer.snapshot.Extras;
import org.jetbrains.annotations.Nullable;

public class StreakUserSnapshot extends AbstractLabySnapshot {

private static final Component ZERO_COMPONENT = Component.text("0", NamedTextColor.DARK_GRAY);
private static final Component HIDDEN_COMPONENT = Component.translatable(
"streakdisplay.nametag.hiddenStreak",
NamedTextColor.RED
);

private final boolean enabled;
private final Component streakComponent;

public StreakUserSnapshot(Player player, Extras extras, StreakDisplayAddon addon) {
super(extras);
StreakDisplayConfig config = addon.configuration();
StreakCacheController controller = StreakDisplayAddon.cacheController();
Integer streak = controller.get(player.getUniqueId());

this.enabled = config.enabled().get();
this.streakComponent = switch (streak) {
case null -> null;
case -1 -> config.hideHiddenStreaks().get() ? null : HIDDEN_COMPONENT;
case 0 -> config.hideZeroStreaks().get() ? null : ZERO_COMPONENT;
default -> Component.text(streak.toString());
};
}

public boolean isEnabled() {
return this.enabled;
}

@Nullable
public Component streakComponent() {
return this.streakComponent;
}
}
Loading