mirror of https://github.com/kami-blue/client
[new] Added SingletonEvent and ShutdownEvent
This commit is contained in:
parent
ae45d5f75f
commit
e5befa4227
|
@ -9,7 +9,7 @@ import net.minecraft.client.network.NetHandlerPlayClient
|
||||||
import org.kamiblue.command.ExecuteEvent
|
import org.kamiblue.command.ExecuteEvent
|
||||||
import org.kamiblue.command.IExecuteEvent
|
import org.kamiblue.command.IExecuteEvent
|
||||||
|
|
||||||
abstract class AbstractClientEvent {
|
abstract class AbstractClientEvent : Event {
|
||||||
val mc = Wrapper.minecraft
|
val mc = Wrapper.minecraft
|
||||||
abstract val world: WorldClient?
|
abstract val world: WorldClient?
|
||||||
abstract val player: EntityPlayerSP?
|
abstract val player: EntityPlayerSP?
|
||||||
|
|
|
@ -1,7 +1,15 @@
|
||||||
package me.zeroeightsix.kami.event
|
package me.zeroeightsix.kami.event
|
||||||
|
|
||||||
|
import org.kamiblue.event.eventbus.IEventBus
|
||||||
|
|
||||||
interface Event
|
interface Event
|
||||||
|
|
||||||
|
open class SingletonEvent(val eventBus: IEventBus) {
|
||||||
|
fun post() {
|
||||||
|
eventBus.post(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface IMultiPhase<T : Event> {
|
interface IMultiPhase<T : Event> {
|
||||||
val phase: Phase
|
val phase: Phase
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package me.zeroeightsix.kami.event.events
|
package me.zeroeightsix.kami.event.events
|
||||||
|
|
||||||
import me.zeroeightsix.kami.event.Event
|
import me.zeroeightsix.kami.event.Event
|
||||||
|
import me.zeroeightsix.kami.event.KamiEventBus
|
||||||
|
import me.zeroeightsix.kami.event.SingletonEvent
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Posted at the return of when Baritone's Settings are initialized.
|
* Posted at the return of when Baritone's Settings are initialized.
|
||||||
*/
|
*/
|
||||||
class BaritoneSettingsInitEvent : Event
|
object BaritoneSettingsInitEvent : Event, SingletonEvent(KamiEventBus)
|
|
@ -0,0 +1,7 @@
|
||||||
|
package me.zeroeightsix.kami.event.events
|
||||||
|
|
||||||
|
import me.zeroeightsix.kami.event.Event
|
||||||
|
import me.zeroeightsix.kami.event.KamiEventBus
|
||||||
|
import me.zeroeightsix.kami.event.SingletonEvent
|
||||||
|
|
||||||
|
object ShutdownEvent : Event, SingletonEvent(KamiEventBus)
|
|
@ -3,8 +3,8 @@ package me.zeroeightsix.kami.mixin.client;
|
||||||
import me.zeroeightsix.kami.KamiMod;
|
import me.zeroeightsix.kami.KamiMod;
|
||||||
import me.zeroeightsix.kami.event.KamiEventBus;
|
import me.zeroeightsix.kami.event.KamiEventBus;
|
||||||
import me.zeroeightsix.kami.event.events.GuiEvent;
|
import me.zeroeightsix.kami.event.events.GuiEvent;
|
||||||
|
import me.zeroeightsix.kami.event.events.ShutdownEvent;
|
||||||
import me.zeroeightsix.kami.module.modules.combat.CrystalAura;
|
import me.zeroeightsix.kami.module.modules.combat.CrystalAura;
|
||||||
import me.zeroeightsix.kami.module.modules.misc.DiscordRPC;
|
|
||||||
import me.zeroeightsix.kami.util.ConfigUtils;
|
import me.zeroeightsix.kami.util.ConfigUtils;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.entity.EntityPlayerSP;
|
import net.minecraft.client.entity.EntityPlayerSP;
|
||||||
|
@ -74,10 +74,11 @@ public class MixinMinecraft {
|
||||||
|
|
||||||
private void save() {
|
private void save() {
|
||||||
if (!KamiMod.isReady()) return;
|
if (!KamiMod.isReady()) return;
|
||||||
|
|
||||||
|
ShutdownEvent.INSTANCE.post();
|
||||||
System.out.println("Shutting down: saving KAMI configuration");
|
System.out.println("Shutting down: saving KAMI configuration");
|
||||||
ConfigUtils.INSTANCE.saveAll();
|
ConfigUtils.INSTANCE.saveAll();
|
||||||
System.out.println("Configuration saved.");
|
System.out.println("Configuration saved.");
|
||||||
DiscordRPC.INSTANCE.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package me.zeroeightsix.kami.mixin.client.baritone;
|
package me.zeroeightsix.kami.mixin.client.baritone;
|
||||||
|
|
||||||
import baritone.api.Settings;
|
import baritone.api.Settings;
|
||||||
import me.zeroeightsix.kami.event.KamiEventBus;
|
|
||||||
import me.zeroeightsix.kami.event.events.BaritoneSettingsInitEvent;
|
import me.zeroeightsix.kami.event.events.BaritoneSettingsInitEvent;
|
||||||
import me.zeroeightsix.kami.util.BaritoneUtils;
|
import me.zeroeightsix.kami.util.BaritoneUtils;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
@ -13,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
public class MixinBaritoneSettings {
|
public class MixinBaritoneSettings {
|
||||||
@Inject(method = "<init>", at = @At("RETURN"))
|
@Inject(method = "<init>", at = @At("RETURN"))
|
||||||
private void baritoneSettingsInit(CallbackInfo ci) {
|
private void baritoneSettingsInit(CallbackInfo ci) {
|
||||||
KamiEventBus.INSTANCE.post(new BaritoneSettingsInitEvent());
|
|
||||||
BaritoneUtils.INSTANCE.setInitialized(true);
|
BaritoneUtils.INSTANCE.setInitialized(true);
|
||||||
|
BaritoneSettingsInitEvent.INSTANCE.post();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import club.minnced.discord.rpc.DiscordEventHandlers
|
||||||
import club.minnced.discord.rpc.DiscordRichPresence
|
import club.minnced.discord.rpc.DiscordRichPresence
|
||||||
import me.zeroeightsix.kami.KamiMod
|
import me.zeroeightsix.kami.KamiMod
|
||||||
import me.zeroeightsix.kami.event.events.SafeTickEvent
|
import me.zeroeightsix.kami.event.events.SafeTickEvent
|
||||||
|
import me.zeroeightsix.kami.event.events.ShutdownEvent
|
||||||
import me.zeroeightsix.kami.module.Module
|
import me.zeroeightsix.kami.module.Module
|
||||||
import me.zeroeightsix.kami.module.modules.client.InfoOverlay
|
import me.zeroeightsix.kami.module.modules.client.InfoOverlay
|
||||||
import me.zeroeightsix.kami.setting.Settings
|
import me.zeroeightsix.kami.setting.Settings
|
||||||
|
@ -58,6 +59,10 @@ object DiscordRPC : Module() {
|
||||||
"Do NOT use this if you do not want your coords displayed")
|
"Do NOT use this if you do not want your coords displayed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listener<ShutdownEvent> {
|
||||||
|
end()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun start() {
|
private fun start() {
|
||||||
|
@ -73,7 +78,7 @@ object DiscordRPC : Module() {
|
||||||
KamiMod.LOG.info("Discord RPC initialised successfully")
|
KamiMod.LOG.info("Discord RPC initialised successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun end() {
|
private fun end() {
|
||||||
if (!connected) return
|
if (!connected) return
|
||||||
|
|
||||||
KamiMod.LOG.info("Shutting down Discord RPC...")
|
KamiMod.LOG.info("Shutting down Discord RPC...")
|
||||||
|
|
Loading…
Reference in New Issue