feat: rudimentary autodisconnect
This commit is contained in:
parent
f85188f310
commit
bad0ff82c9
2 changed files with 44 additions and 0 deletions
|
@ -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));
|
||||
|
|
43
src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java
Normal file
43
src/main/java/ftbsc/bscv/modules/self/AutoDisconnect.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue