Skip to content

Commit

Permalink
Fix shutting down pov server and kill aura config change
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 11, 2024
1 parent c28c255 commit b45ec48
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ public static void onPreEntityTick(BotPreEntityTickEvent event) {
@EventHandler
public static void onPostEntityTick(BotPostEntityTickEvent event) {
var bot = event.connection();
if (!bot.settingsSource().get(KillAuraSettings.ENABLE)) {
return;
}

var control = bot.botControl();
if (control.attackCooldownTicks() > 0) {
return;
Expand Down
27 changes: 15 additions & 12 deletions server/src/main/java/com/soulfiremc/server/plugins/POVServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import com.soulfiremc.server.SoulFireServer;
import com.soulfiremc.server.api.InternalPlugin;
import com.soulfiremc.server.api.PluginInfo;
import com.soulfiremc.server.api.SoulFireAPI;
import com.soulfiremc.server.api.event.attack.AttackEndedEvent;
import com.soulfiremc.server.api.event.attack.AttackStartEvent;
import com.soulfiremc.server.api.event.lifecycle.InstanceSettingsRegistryInitEvent;
import com.soulfiremc.server.api.metadata.MetadataKey;
import com.soulfiremc.server.protocol.BotConnection;
import com.soulfiremc.server.protocol.BuiltInKnownPackRegistry;
import com.soulfiremc.server.protocol.SFProtocolConstants;
Expand Down Expand Up @@ -139,10 +139,10 @@
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

@Slf4j
public class POVServer extends InternalPlugin {
private static final MetadataKey<TcpServer> TCP_SERVER = MetadataKey.of("pov_server", "tcp_server", TcpServer.class);
private static final List<Class<?>> NOT_SYNCED =
List.of(
ClientboundKeepAlivePacket.class,
Expand Down Expand Up @@ -1001,19 +1001,22 @@ public void onAttackStart(AttackStartEvent event) {

var freePort =
PortHelper.getAvailablePort(settingsSource.get(POVServerSettings.PORT_START));
var serverInstance = new AtomicReference<>(startPOVServer(settingsSource, freePort, attackManager));
var serverInstance = startPOVServer(settingsSource, freePort, attackManager);
log.info("Started POV server on 0.0.0.0:{} for attack {}", freePort, attackManager.id());

SoulFireAPI.registerListener(AttackEndedEvent.class, e -> {
var currentInstance = serverInstance.get();
if (currentInstance == null) {
return;
}
attackManager.metadata().set(TCP_SERVER, serverInstance);
}

@EventHandler
public void onAttackEnded(AttackEndedEvent event) {
var attackManager = event.instanceManager();
var currentInstance = attackManager.metadata().getAndRemove(TCP_SERVER);
if (currentInstance == null) {
return;
}

log.info("Stopping POV server for attack {}", attackManager.id());
currentInstance.close();
serverInstance.set(null);
});
log.info("Stopping POV server for attack {}", attackManager.id());
currentInstance.close();
}

@NoArgsConstructor(access = AccessLevel.NONE)
Expand Down

0 comments on commit b45ec48

Please sign in to comment.