From 25fb664b8d22c964c89bc22b2c561e20a412cdf9 Mon Sep 17 00:00:00 2001 From: jzitnik-dev Date: Fri, 28 Mar 2025 08:50:53 +0100 Subject: [PATCH] fix: Annotation on annotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Yeah I'm dumb I know. But whatever this code doesn't have any real value anyways other than finding weird things about java. Like really why am I doing this to my self. Why do I even code? What’s the point? Does it even matter? I don’t even enjoy it—I do it because I’m not good at anything else. I've lost all motivation to code. I have about 30 unfinished projects and not a single one completed. I go to school, but honestly, it feels like a waste of time... Yet, what else would I do? Code? For what? What is programming even for? Sometimes I wonder, what value do I even have in this life? What’s the point of school? To get a good job? And what’s the point of a good job? Money? And money—what for? To survive? And surviving—for what? To... To... Why am I even coding in Java? Why do I do this to myself? I could be peacefully writing in Rust, but no—I’m stuck here, suffering with this cursed Java. Hope nobody’s reading this. And if you are, well—I hope you have a great day. Got a little carried away there. Alright, back to focusing on English class... But why should I? I can speak English just fine. Why do we study history? "Because it’s basic knowledge." Yeah, well, you can shove your basic knowledge where the sun doesn’t shine. I feel like I’m wasting my life. The last five years... --- src/main/java/cz/jzitnik/game/Game.java | 27 +++++++++---------- .../cz/jzitnik/game/core/sound/Sound.java | 12 ++++----- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/main/java/cz/jzitnik/game/Game.java b/src/main/java/cz/jzitnik/game/Game.java index c9930f5..3418dd5 100644 --- a/src/main/java/cz/jzitnik/game/Game.java +++ b/src/main/java/cz/jzitnik/game/Game.java @@ -208,8 +208,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(MiningSound.class)) { new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, - block.getClass().getAnnotation(MiningSound.class).value()); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -223,8 +223,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(MiningSound.class)) { new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, - block.getClass().getAnnotation(MiningSound.class).value()); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -238,8 +238,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(MiningSound.class)) { new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, - block.getClass().getAnnotation(MiningSound.class).value()); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -309,10 +309,9 @@ public class Game extends AutoTransientSupport { for (Block block : blocksCopy) { if (block.getClass().isAnnotationPresent(MineSound.class)) { - var key = block.getClass().getAnnotation(MineSound.class).value(); - new Thread(() -> { - gameStates.dependencies.sound.playSound(configuration, key); + var anot = block.getClass().getAnnotation(MiningSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); }).start(); } } @@ -473,9 +472,8 @@ public class Game extends AutoTransientSupport { blocks.removeAll(blocksRemove); for (Block block : blocks) { if (block.getClass().isAnnotationPresent(PlaceSound.class)) { - var key = block.getClass().getAnnotation(PlaceSound.class).value(); - - gameStates.dependencies.sound.playSound(configuration, key); + var anot = block.getClass().getAnnotation(PlaceSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); } } gameStates.dependencies.eventHandlerProvider.handlePlace(screenRenderer, this, x, y); @@ -518,9 +516,8 @@ public class Game extends AutoTransientSupport { for (Block block : blocks) { if (block.getClass().isAnnotationPresent(WalkSound.class)) { - var key = block.getClass().getAnnotation(WalkSound.class).value(); - - gameStates.dependencies.sound.playSound(configuration, key); + var anot = block.getClass().getAnnotation(WalkSound.class); + gameStates.dependencies.sound.playSound(configuration, anot.value(), anot.annotationType()); } } } diff --git a/src/main/java/cz/jzitnik/game/core/sound/Sound.java b/src/main/java/cz/jzitnik/game/core/sound/Sound.java index 5eaa9c2..5db11fe 100644 --- a/src/main/java/cz/jzitnik/game/core/sound/Sound.java +++ b/src/main/java/cz/jzitnik/game/core/sound/Sound.java @@ -1,6 +1,7 @@ package cz.jzitnik.game.core.sound; import java.io.IOException; +import java.lang.annotation.Annotation; import java.util.HashMap; import java.util.Random; import java.util.Set; @@ -37,7 +38,7 @@ public class Sound { } } - public void playSound(Configuration configuration, SoundKey soundKey) { + public void playSound(Configuration configuration, SoundKey soundKey, Class anot) { var volume = configuration.getSoundVolume(); var annotation = map.get(soundKey); @@ -45,17 +46,14 @@ public class Sound { var resources = annotation.resourceLocation(); var resource = resources[random.nextInt(resources.length)]; - var typeVolume = annotation.getClass().isAnnotationPresent(SoundTypeSet.class) - ? annotation.getClass().getAnnotation(SoundTypeSet.class).value().getVolume() + var typeVolume = anot.isAnnotationPresent(SoundTypeSet.class) + ? anot.getAnnotation(SoundTypeSet.class).value().getVolume() : 0; - log.debug("Type volume: {}", typeVolume); - log.debug("Config volume: {}", volume); - new Thread(() -> { try { SoundPlayer.playSound(resource, typeVolume, volume); - } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { + } catch (LineUnavailableException | IOException | UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); }