Optimize fake player movement

This commit is contained in:
tanyaofei 2024-08-09 13:45:29 +08:00
parent f0b6375659
commit 4d22061c6c

View File

@ -3,8 +3,7 @@ package io.github.hello09x.fakeplayer.core.command.impl;
import com.google.inject.Singleton; import com.google.inject.Singleton;
import dev.jorel.commandapi.executors.CommandExecutor; import dev.jorel.commandapi.executors.CommandExecutor;
import io.github.hello09x.fakeplayer.core.Main; import io.github.hello09x.fakeplayer.core.Main;
import net.kyori.adventure.util.Ticks; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.Bukkit;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap; import java.util.HashMap;
@ -36,12 +35,20 @@ public class MoveCommand extends AbstractCommand {
task.cancel(); task.cancel();
} }
// 只移动 1 var fakeId = fake.getUniqueId();
this.stopTasks.put(fake.getUniqueId(), Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> { var stopping = new BukkitRunnable() {
handle.setXxa(0); @Override
handle.setZza(0); public void run() {
this.stopTasks.remove(fake.getUniqueId()); handle.setXxa(0);
}, Ticks.TICKS_PER_SECOND)); handle.setZza(0);
var self = stopTasks.get(fakeId);
if (self != null && self.getTaskId() == this.getTaskId()) {
stopTasks.remove(fakeId);
}
}
};
this.stopTasks.put(fakeId, stopping.runTaskLater(Main.getInstance(), 20));
}; };
} }