scheduler idk do it work on folia ?

This commit is contained in:
MidnightTale 2023-04-13 10:52:29 +07:00
commit b9202a4656

View file

@ -8,6 +8,7 @@ import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.world.ChunkEvent;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;
@ -15,6 +16,7 @@ import org.bukkit.util.Vector;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
public class FoliaFlow extends JavaPlugin implements Listener {
private final Vector velocity1 = new Vector(0, 0.5, -1);
@ -29,6 +31,7 @@ public class FoliaFlow extends JavaPlugin implements Listener {
@Override
public void onEnable() {
super.onEnable();
Bukkit.getScheduler().runTaskTimer(this, this::tick, 0, 1);
getServer().getPluginManager().registerEvents(this, this);
getServer().getConsoleSender().sendMessage("");
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ ");
@ -93,34 +96,27 @@ public class FoliaFlow extends JavaPlugin implements Listener {
}
@EventHandler
public void onChunkLoadend(ChunkLoadEvent e) {
Chunk chunk = e.getChunk();
World world = chunk.getWorld();
if (world.getEnvironment() == World.Environment.THE_END) {
// Iterate through all the entities in the chunk
for (Entity entity : chunk.getEntities()) {
if (entity.getType() == EntityType.FALLING_BLOCK) {
Location loc = entity.getLocation();
private void tick() {
for (Entity entity : Bukkit.getWorlds().stream().flatMap(world -> world.getEntities().stream())
.filter(entity -> entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END)
.collect(Collectors.toList())) {
Location loc = entity.getLocation();
debug("Falling block spawned at location " + loc);
debug("Falling block spawned at location " + loc);
// Set the initial velocity of the falling block
int index = counter % 4;
counter ++;
Vector velocity = velocities[index];
entity.setVelocity(velocity);
// Remove the block from the movingBlocks set after a delay, to prevent it from being immediately moved again
//getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(loc.getBlock().getLocation()), 20L);
}
}
// Set the initial velocity of the falling block
int index = counter % 4;
counter ++;
Vector velocity = velocities[index];
entity.setVelocity(velocity);
}
}
Block getBlockMovingTo(Location loc, Vector vel) {
double absMax = 0, max = 0;
char dir = ' ';