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 @@ -11,18 +11,32 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v3
uses: actions/setup-java@v4
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
run: ./gradlew build --full-stacktrace
- name: Upload Artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Artifacts
path: build/libs/*-release.jar
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import net.labymod.api.client.resources.ResourceLocation;
import net.labymod.api.reference.annotation.Referenceable;
import org.jetbrains.annotations.Nullable;

@Nullable
@Referenceable
public interface ITimerSound {
public interface TimerSound {

ResourceLocation getNotificationSound();
}
40 changes: 20 additions & 20 deletions api/src/main/java/com/rappytv/speedruntimer/util/Timer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public Timer(Runnable onCountdownComplete) {
}

public void startCountUp() {
if(state != TimerState.OFF) return;
if(this.state != TimerState.OFF) return;
this.direction = TimerDirection.COUNT_UP;
this.seconds = 0;
start();
this.start();
}

public void startCountDown(long seconds) {
if(state != TimerState.OFF) return;
if(this.state != TimerState.OFF) return;
this.direction = TimerDirection.COUNT_DOWN;
this.seconds = seconds;
start();
this.start();
}

public void reset() {
if(state == TimerState.OFF) return;
if(this.state == TimerState.OFF) return;
this.direction = TimerDirection.COUNT_UP;
this.seconds = 0;
this.state = TimerState.OFF;
Expand All @@ -51,7 +51,7 @@ public Component getDisplay() {
(String.valueOf(seconds).length() > 1 ? "" : "0") + seconds
));

if(state == TimerState.PAUSED) component.decorate(TextDecoration.ITALIC).color(NamedTextColor.RED);
if(this.state == TimerState.PAUSED) component.decorate(TextDecoration.ITALIC).color(NamedTextColor.RED);
else component.color(NamedTextColor.GREEN);
return component.decorate(TextDecoration.BOLD);
}
Expand All @@ -61,16 +61,16 @@ private void start() {
timer.schedule(new TimerTask() {
@Override
public void run() {
if(state == TimerState.OFF) cancel();
if(state == TimerState.PAUSED) return;

if(direction == TimerDirection.COUNT_UP) seconds++;
else if(direction == TimerDirection.COUNT_DOWN) {
seconds--;
if(seconds < 0) {
seconds = 0;
state = TimerState.PAUSED;
onCountdownComplete.run();
if(Timer.this.state == TimerState.OFF) this.cancel();
if(Timer.this.state == TimerState.PAUSED) return;

if(Timer.this.direction == TimerDirection.COUNT_UP) Timer.this.seconds++;
else if(Timer.this.direction == TimerDirection.COUNT_DOWN) {
Timer.this.seconds--;
if(Timer.this.seconds < 0) {
Timer.this.seconds = 0;
Timer.this.state = TimerState.PAUSED;
Timer.this.onCountdownComplete.run();
}
}
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public long resolveSeconds(String timeValue) {
case "y" -> duration * 60 * 60 * 24 * 7 * 52;
default -> {
try {
yield resolveSeconds(Integer.parseInt(timeValue) + "s");
yield this.resolveSeconds(Integer.parseInt(timeValue) + "s");
} catch (NumberFormatException e) {
yield -1;
}
Expand All @@ -108,23 +108,23 @@ public long resolveSeconds(String timeValue) {
}

public TimerDirection getDirection() {
return direction;
return this.direction;
}

public void setDirection(TimerDirection direction) {
this.direction = direction;
}

public TimerState getState() {
return state;
return this.state;
}

public void setState(TimerState state) {
this.state = state;
}

public long getSeconds() {
return seconds;
return this.seconds;
}

public void setSeconds(long seconds) {
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ plugins {
val versions = providers.gradleProperty("net.labymod.minecraft-versions").get().split(";")

group = "com.rappytv.speedruntimer"
version = providers.environmentVariable("VERSION").getOrElse("1.0.0")
version = providers.environmentVariable("VERSION").getOrElse("1.0.1")

labyMod {
defaultPackageName = "com.rappytv.speedruntimer"

addonInfo {
namespace = "speedruntimer"
displayName = "SpeedrunTimer"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.rappytv.speedruntimer;

import com.rappytv.speedruntimer.api.generated.ReferenceStorage;
import com.rappytv.speedruntimer.command.TimerCommand;
import com.rappytv.speedruntimer.core.generated.DefaultReferenceStorage;
import com.rappytv.speedruntimer.hudWidget.TimerHudWidget;
import com.rappytv.speedruntimer.hudwidget.TimerHudWidget;
import com.rappytv.speedruntimer.sound.DefaultTimerSound;
import com.rappytv.speedruntimer.sound.ITimerSound;
import com.rappytv.speedruntimer.sound.TimerSound;
import com.rappytv.speedruntimer.util.Timer;
import net.labymod.api.Laby;
import net.labymod.api.addon.LabyAddon;
Expand All @@ -29,17 +29,17 @@ public class SpeedrunTimerAddon extends LabyAddon<SpeedrunTimerConfig> {
@SuppressWarnings("ConstantConditions")
@Override
protected void enable() {
ITimerSound timerSound = ((DefaultReferenceStorage) this.referenceStorageAccessor()).iTimerSound();
TimerSound timerSound = ((ReferenceStorage) this.referenceStorageAccessor()).getTimerSound();
if(timerSound == null)
timerSound = new DefaultTimerSound();
ResourceLocation sound = timerSound.getNotificationSound();
timer = new Timer(() -> {
if(configuration().countdownSound().get()) {
this.timer = new Timer(() -> {
if(this.configuration().countdownSound().get()) {
Laby.references().minecraftSounds().playSound(sound, 1f, 1f);
}
});
registerSettingCategory();
registerCommand(new TimerCommand(this));
this.registerSettingCategory();
this.registerCommand(new TimerCommand(this));
Laby.labyAPI().hudWidgetRegistry().register(new TimerHudWidget(this));
}

Expand All @@ -50,7 +50,7 @@ protected Class<? extends SpeedrunTimerConfig> configurationClass() {

@NotNull
public Timer getTimer() {
return timer;
return this.timer;
}

public static Component prefix() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public class SpeedrunTimerConfig extends AddonConfig {

@Override
public ConfigProperty<Boolean> enabled() {
return enabled;
return this.enabled;
}

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