1- package com .rappytv .speedruntimer ;
2-
3- import com .rappytv .speedruntimer .api .generated .ReferenceStorage ;
4- import com .rappytv .speedruntimer .command .TimerCommand ;
5- import com .rappytv .speedruntimer .hudwidget .TimerHudWidget ;
6- import com .rappytv .speedruntimer .sound .DefaultTimerSound ;
7- import com .rappytv .speedruntimer .sound .TimerSound ;
8- import com .rappytv .speedruntimer .util .Timer ;
1+ package com .rappytv .speedruntimer .core ;
2+
3+ import com .rappytv .speedruntimer .core .command .TimerCommand ;
4+ import com .rappytv .speedruntimer .api .event .CountdownCompleteEvent ;
5+ import com .rappytv .speedruntimer .core .hudwidget .TimerHudWidget ;
6+ import com .rappytv .speedruntimer .api .Timer ;
97import net .labymod .api .Laby ;
108import net .labymod .api .addon .LabyAddon ;
119import net .labymod .api .client .component .Component ;
1210import net .labymod .api .client .component .format .NamedTextColor ;
1311import net .labymod .api .client .component .format .TextDecoration ;
1412import net .labymod .api .client .resources .ResourceLocation ;
13+ import net .labymod .api .event .Subscribe ;
14+ import net .labymod .api .loader .MinecraftVersions ;
1515import net .labymod .api .models .addon .annotation .AddonMain ;
1616import org .jetbrains .annotations .NotNull ;
1717
@@ -25,24 +25,29 @@ public class SpeedrunTimerAddon extends LabyAddon<SpeedrunTimerConfig> {
2525 .append (Component .space ());
2626
2727 private Timer timer ;
28+ private ResourceLocation timerSound ;
2829
29- @ SuppressWarnings ("ConstantConditions" )
3030 @ Override
31- protected void enable () {
32- TimerSound timerSound = ((ReferenceStorage ) this .referenceStorageAccessor ()).getTimerSound ();
33- if (timerSound == null )
34- timerSound = new DefaultTimerSound ();
35- ResourceLocation sound = timerSound .getNotificationSound ();
36- this .timer = new Timer (() -> {
37- if (this .configuration ().countdownSound ().get ()) {
38- Laby .references ().minecraftSounds ().playSound (sound , 1f , 1f );
39- }
40- });
31+ public void enable () {
32+ this .timer = new Timer ();
33+ this .initializeTimerSound ();
4134 this .registerSettingCategory ();
4235 this .registerCommand (new TimerCommand (this ));
4336 Laby .labyAPI ().hudWidgetRegistry ().register (new TimerHudWidget (this ));
4437 }
4538
39+ @ Subscribe
40+ public void onCountDownComplete (CountdownCompleteEvent event ) {
41+ if (!this .configuration ().countdownSound ().get () || this .timerSound == null ) {
42+ return ;
43+ }
44+ Laby .references ().minecraftSounds ().playSound (
45+ this .timerSound ,
46+ 1f ,
47+ 1f
48+ );
49+ }
50+
4651 @ Override
4752 protected Class <? extends SpeedrunTimerConfig > configurationClass () {
4853 return SpeedrunTimerConfig .class ;
@@ -56,4 +61,16 @@ public Timer getTimer() {
5661 public static Component prefix () {
5762 return prefix ;
5863 }
64+
65+ private void initializeTimerSound () {
66+ String path ;
67+ if (MinecraftVersions .current ().equals (MinecraftVersions .V1_8_9 )) {
68+ path = "note.pling" ;
69+ } else if (MinecraftVersions .current ().equals (MinecraftVersions .V1_12_2 )) {
70+ path = "block.note.pling" ;
71+ } else {
72+ path = "block.note_block.pling" ;
73+ }
74+ this .timerSound = ResourceLocation .create ("minecraft" , path );
75+ }
5976}
0 commit comments