diff options
author | alemi <me@alemi.dev> | 2023-02-16 02:53:28 +0100 |
---|---|---|
committer | alemi <me@alemi.dev> | 2023-02-16 02:53:28 +0100 |
commit | bad0ff82c93c81f372889b3236f07b255514721c (patch) | |
tree | 2207437b4675272c59df7b1e0a6a45b5f435f6f3 /src | |
parent | f85188f31038d2c58c04628d557ef361ba9982da (diff) |
feat: rudimentary autodisconnect
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/ftbsc/bscv/BoSCoVicino.java | 1 | ||||
-rw-r--r-- | src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java | 43 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/bscv/BoSCoVicino.java b/src/main/java/ftbsc/bscv/BoSCoVicino.java index 8479ed8..60735c3 100644 --- a/src/main/java/ftbsc/bscv/BoSCoVicino.java +++ b/src/main/java/ftbsc/bscv/BoSCoVicino.java @@ -60,6 +60,7 @@ public class BoSCoVicino implements ICommons { ForgeConfigSpec.Builder cfg = new ForgeConfigSpec.Builder(); CommandDispatcher<CommandSource> dp = this.dispatcher; + BoSCoVicino.mods.add(new AutoDisconnect(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new ActiveModules(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new VanillaFlight(cfg, dp).done(cfg)); BoSCoVicino.mods.add(new FastInteract(cfg, dp).done(cfg)); diff --git a/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java new file mode 100644 index 0000000..a192581 --- /dev/null +++ b/src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java @@ -0,0 +1,43 @@ +package ftbsc.bscv.modules.self; + +import com.mojang.brigadier.CommandDispatcher; +import com.mojang.brigadier.arguments.DoubleArgumentType; + +import ftbsc.bscv.ICommons; +import ftbsc.bscv.events.PacketEvent; +import ftbsc.bscv.modules.Module; +import net.minecraft.command.CommandSource; +import net.minecraft.network.play.server.SDisconnectPacket; +import net.minecraft.network.play.server.SUpdateHealthPacket; +import net.minecraft.util.text.StringTextComponent; +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class AutoDisconnect extends Module implements ICommons { + + public final ForgeConfigSpec.ConfigValue<Double> threshold; + + public AutoDisconnect(ForgeConfigSpec.Builder builder, CommandDispatcher<CommandSource> dispatcher) { + super("AutoDisconnect", Group.SELF, builder, dispatcher); + + this.threshold = this.option( + "threshold", "hp below which connection should be closed", 10., + DoubleArgumentType.doubleArg(0., 20.), Double.class, + builder, dispatcher + ); + } + + @SubscribeEvent + public void onPacket(PacketEvent event) { + if (event.outgoing) return; + if (event.packet instanceof SUpdateHealthPacket) { + SUpdateHealthPacket packet = (SUpdateHealthPacket) event.packet; + if (packet.getHealth() < this.threshold.get()) { + MC.player.connection.handleDisconnect( // this basically invokes disconnect() for us + new SDisconnectPacket(new StringTextComponent("HP fell below threshold")) + ); + this.disable(); + } + } + } +} |