scheduler idk do it work on folia ?
This commit is contained in:
parent
fbeb321d79
commit
b9202a4656
1 changed files with 18 additions and 22 deletions
|
|
@ -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,14 +96,10 @@ 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) {
|
||||
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);
|
||||
|
|
@ -110,13 +109,10 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue