Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Jan 9, 2025
2 parents 3c8cf09 + 6a281bb commit 0295ff5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
log4j = "2.24.3"
grpc = "1.69.0"
protobuf = "4.29.2"
protobuf = "4.29.3"
via-version = "5.2.1"
via-backwards = "5.2.1"
via-rewind = "4.0.5"
Expand All @@ -28,7 +28,7 @@ gradle-plugin-licenser = "gradle.plugin.org.cadixdev.gradle:licenser:0.6.1"
gradle-plugin-lombok = "io.freefair.gradle:lombok-plugin:8.11"
gradle-plugin-indra-git = "net.kyori:indra-git:3.1.3"
gradle-plugin-unimined = "xyz.wagyourtail.unimined:xyz.wagyourtail.unimined.gradle.plugin:1.3.12"
gradle-plugin-spotless = "com.diffplug.spotless:spotless-plugin-gradle:7.0.0"
gradle-plugin-spotless = "com.diffplug.spotless:spotless-plugin-gradle:7.0.1"
gradle-plugin-freefair = "io.freefair.gradle:maven-plugin:8.11"
log4j-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" }
log4j-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" }
Expand Down Expand Up @@ -90,7 +90,7 @@ armeria-prometheus1 = { module = "com.linecorp.armeria:armeria-prometheus1" }
reactor-netty-core = { module = "io.projectreactor.netty:reactor-netty-core", version.ref = "reactor" }
reactor-netty-http = { module = "io.projectreactor.netty:reactor-netty-http", version.ref = "reactor" }
spark = "me.lucko:spark-common:1.10.119-SNAPSHOT"
openai = "com.openai:openai-java:0.9.1"
openai = "com.openai:openai-java:0.11.0"
immutables = "org.immutables:value:2.10.1 "
hibernate-core = "org.hibernate.orm:hibernate-core:7.0.0.Beta3"
hibernate-community-dialects = "org.hibernate.orm:hibernate-community-dialects:7.0.0.Beta3"
Expand Down
22 changes: 12 additions & 10 deletions server/src/main/java/com/soulfiremc/server/plugins/KillAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.soulfiremc.server.api.event.bot.BotPostEntityTickEvent;
import com.soulfiremc.server.api.event.bot.BotPreEntityTickEvent;
import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent;
import com.soulfiremc.server.api.metadata.MetadataKey;
import com.soulfiremc.server.protocol.bot.ControllingTask;
import com.soulfiremc.server.protocol.bot.state.entity.Entity;
import com.soulfiremc.server.settings.lib.SettingsObject;
import com.soulfiremc.server.settings.property.*;
Expand All @@ -37,8 +37,6 @@
@Slf4j
@Extension
public class KillAura extends InternalPlugin {
private static final MetadataKey<AttackEntity> ATTACK_ENTITY = MetadataKey.of("kill_aura", "attack_entity", AttackEntity.class);

public KillAura() {
super(new PluginInfo(
"kill-aura",
Expand All @@ -58,6 +56,9 @@ public static void onPreEntityTick(BotPreEntityTickEvent event) {
}

var control = bot.botControl();
if (control.activelyControlled()) {
return;
}

var whitelistedUser = bot.settingsSource().get(KillAuraSettings.WHITELISTED_USER);

Expand Down Expand Up @@ -90,8 +91,8 @@ public static void onPreEntityTick(BotPreEntityTickEvent event) {
return;
}

control.registerControllingTask(ControllingTask.manual(new KillAuraMarker(target, distance)));
bot.dataManager().localPlayer().lookAt(RotationOrigin.EYES, bestVisiblePoint);
bot.metadata().set(ATTACK_ENTITY, new AttackEntity(target, distance));
}

@EventHandler
Expand All @@ -102,16 +103,16 @@ public static void onPostEntityTick(BotPostEntityTickEvent event) {
return;
}

var attackEntity = bot.metadata().getAndRemove(ATTACK_ENTITY);
if (attackEntity == null) {
var marker = control.getMarkerAndUnregister(KillAuraMarker.class);
if (marker == null) {
return;
}

var hitRange = bot.settingsSource().get(KillAuraSettings.HIT_RANGE);
var swingRange = bot.settingsSource().get(KillAuraSettings.SWING_RANGE);
var swing = attackEntity.distance() <= swingRange;
if (attackEntity.distance() <= hitRange) {
control.attack(attackEntity.attackEntity(), swing);
var swing = marker.distance() <= swingRange;
if (marker.distance() <= hitRange) {
control.attack(marker.attackEntity(), swing);
} else if (swing) {
control.swingArm();
}
Expand Down Expand Up @@ -211,5 +212,6 @@ private static class KillAuraSettings implements SettingsObject {
.build();
}

private record AttackEntity(Entity attackEntity, double distance) {}
private record KillAuraMarker(Entity attackEntity, double distance) implements ControllingTask.ManualTaskMarker {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ public void maybeRegister(ControllingTask task) {
this.controllingTask.compareAndSet(null, task);
}

public <M extends ControllingTask.ManualTaskMarker> M getMarkerAndUnregister(Class<M> clazz) {
var task = this.controllingTask.get();
if (task instanceof ControllingTask.ManualControllingTask manual
&& clazz.isInstance(manual.marker())) {
unregisterControllingTask(task);
return clazz.cast(manual.marker());
}

return null;
}

public boolean toggleFlight() {
var dataManager = connection.dataManager();
var abilitiesData = dataManager.localPlayer().abilitiesState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.soulfiremc.server.protocol.bot;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.List;
Expand All @@ -31,6 +32,10 @@ static ControllingTask staged(List<Stage> stages) {
return new StagedTask(stages);
}

static ManualControllingTask manual(ManualTaskMarker taskMarker) {
return new ManualControllingTask(taskMarker);
}

void tick();

void stop();
Expand Down Expand Up @@ -70,6 +75,9 @@ record RunnableStage(Runnable runnable) implements Stage {}

record WaitDelayStage(LongSupplier delaySupplier) implements Stage {}

interface ManualTaskMarker {
}

@RequiredArgsConstructor
class StagedTask implements ControllingTask {
private final List<Stage> stages;
Expand Down Expand Up @@ -116,4 +124,25 @@ public boolean isDone() {
return done;
}
}

@RequiredArgsConstructor
class ManualControllingTask implements ControllingTask {
@Getter
private final ManualTaskMarker marker;
private boolean done = false;

@Override
public void tick() {
}

@Override
public void stop() {
done = true;
}

@Override
public boolean isDone() {
return done;
}
}
}

0 comments on commit 0295ff5

Please sign in to comment.