Fix the issue where it didn't run as expected in the update suppressor.

This commit is contained in:
tanyaofei 2024-08-11 14:48:30 +08:00
parent 5142ccd39f
commit 2f006a835d
2 changed files with 21 additions and 5 deletions

View File

@ -52,13 +52,17 @@ public abstract class BaseActionTicker implements ActionTicker {
return true;
}
var valid = this.action.tick();
if (valid) {
try {
if (this.action.tick()) {
if (this.setting.remains > 0) {
this.setting.remains--;
}
}
} finally {
// 声音更新抑制器会抛出异常, 但同样需要进入冷却
this.setting.wait = this.setting.interval;
}
return false;
}

View File

@ -1,5 +1,6 @@
package io.github.hello09x.fakeplayer.core.manager.action;
import com.google.common.base.Throwables;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import io.github.hello09x.fakeplayer.api.spi.ActionSetting;
@ -14,14 +15,18 @@ import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
@Singleton
public class ActionManager {
private final static Logger log = Main.getInstance().getLogger();
private final Map<UUID, Map<ActionType, ActionTicker>> managers = new HashMap<>();
private final NMSBridge bridge;
@Inject
public ActionManager(NMSBridge bridge) {
this.bridge = bridge;
@ -66,7 +71,14 @@ public class ActionManager {
}
// do tick
entry.getValue().values().removeIf(ActionTicker::tick);
entry.getValue().values().removeIf(ticker -> {
try {
return ticker.tick();
} catch (Throwable e) {
log.warning(Throwables.getStackTraceAsString(e));
return false;
}
});
if (entry.getValue().isEmpty()) {
itr.remove();
}