diff options
author | IlmarsXd <ilmars500@gmail.com> | 2023-06-29 18:05:08 +0300 |
---|---|---|
committer | IlmarsXd <ilmars500@gmail.com> | 2023-06-29 18:05:08 +0300 |
commit | 5f0fd39650659010a23055c11eae66fb3ffb2ad0 (patch) | |
tree | cd3eb0615037b8650f469f194a28fcac88cf6adb /src | |
parent | 1fc9c0f7fe8a998e4cf04c8b498abc643533d6e7 (diff) | |
download | DulkirMod-Fabric-5f0fd39650659010a23055c11eae66fb3ffb2ad0.tar.gz DulkirMod-Fabric-5f0fd39650659010a23055c11eae66fb3ffb2ad0.tar.bz2 DulkirMod-Fabric-5f0fd39650659010a23055c11eae66fb3ffb2ad0.zip |
Fix NPE with PlaySoundEvent
Diffstat (limited to 'src')
3 files changed, 13 insertions, 16 deletions
diff --git a/src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java b/src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java index ce84582..3f4c0af 100644 --- a/src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java +++ b/src/main/java/com/dulkirfabric/mixin/SoundSystemMixin.java @@ -1,19 +1,18 @@ package com.dulkirfabric.mixin; import com.dulkirfabric.events.PlaySoundEvent; -import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.client.sound.SoundInstance; import net.minecraft.client.sound.SoundSystem; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(SoundSystem.class) public class SoundSystemMixin { - @ModifyExpressionValue(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", - at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundInstance;canPlay()Z")) - public boolean onSound(boolean original, SoundInstance sound) { - return !(new PlaySoundEvent(sound).post()); + @Inject(method = "play(Lnet/minecraft/client/sound/SoundInstance;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/sound/SoundInstance;getSound()Lnet/minecraft/client/sound/Sound;"), cancellable = true) + public void onSound(SoundInstance sound, CallbackInfo ci) { + if (new PlaySoundEvent(sound).post()) ci.cancel(); } } diff --git a/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt b/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt index 09027ed..c7c8ea6 100644 --- a/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt +++ b/src/main/kotlin/com/dulkirfabric/events/base/CancellableEvent.kt @@ -4,8 +4,7 @@ import com.dulkirfabric.DulkirModFabric import meteordevelopment.orbit.ICancellable abstract class CancellableEvent: ICancellable { - @JvmField - var cancelled: Boolean = false + private var cancelled = false override fun isCancelled(): Boolean { return cancelled @@ -19,7 +18,6 @@ abstract class CancellableEvent: ICancellable { * Posts a given event to the bus and returns whether the user wishes to cancel it */ fun post(): Boolean { - DulkirModFabric.EVENT_BUS.post(this) - return cancelled + return DulkirModFabric.EVENT_BUS.post(this).isCancelled } }
\ No newline at end of file diff --git a/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt b/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt index 2172c4b..52224ff 100644 --- a/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt +++ b/src/main/kotlin/com/dulkirfabric/features/chat/AbiPhoneDND.kt @@ -18,7 +18,7 @@ object AbiPhoneDND { if (!DulkirConfig.configOptions.abiPhoneDND) return if (System.currentTimeMillis() - lastRing < 5000) { if (event.sound.id.path == "block.note_block.pling" && event.sound.volume == 0.69f && event.sound.pitch == 1.6666666f) { - event.isCancelled = true + event.cancel() } } } @@ -26,11 +26,10 @@ object AbiPhoneDND { @EventHandler fun handle(event: ChatReceivedEvent) { if (!DulkirConfig.configOptions.abiPhoneDND) return - val unformatted: String = event.message.unformattedString - println(unformatted) + val unformatted = event.message.unformattedString if (unformatted matches abiPhoneFormat && !unformatted.contains("Elle") && !unformatted.contains("Dean")) { val matchResult = abiPhoneFormat.find(unformatted) - event.isCancelled = true + event.cancel() lastRing = System.currentTimeMillis() if (DulkirConfig.configOptions.abiPhoneCallerID) { val blocked = if (Math.random() < .001) "Breefing" @@ -39,8 +38,9 @@ object AbiPhoneDND { } } if (unformatted.startsWith("✆ Ring...") && unformatted.endsWith("[PICK UP]") - && System.currentTimeMillis() - lastRing < 5000) { - event.isCancelled = true + && System.currentTimeMillis() - lastRing < 5000 + ) { + event.cancel() } } }
\ No newline at end of file |