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.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.event.world.ChunkEvent;
|
import org.bukkit.event.world.ChunkEvent;
|
||||||
import org.bukkit.event.world.ChunkLoadEvent;
|
import org.bukkit.event.world.ChunkLoadEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
@ -15,6 +16,7 @@ import org.bukkit.util.Vector;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class FoliaFlow extends JavaPlugin implements Listener {
|
public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
private final Vector velocity1 = new Vector(0, 0.5, -1);
|
private final Vector velocity1 = new Vector(0, 0.5, -1);
|
||||||
|
|
@ -29,6 +31,7 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
|
Bukkit.getScheduler().runTaskTimer(this, this::tick, 0, 1);
|
||||||
getServer().getPluginManager().registerEvents(this, this);
|
getServer().getPluginManager().registerEvents(this, this);
|
||||||
getServer().getConsoleSender().sendMessage("");
|
getServer().getConsoleSender().sendMessage("");
|
||||||
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ ");
|
getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ ");
|
||||||
|
|
@ -93,34 +96,27 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
private void tick() {
|
||||||
public void onChunkLoadend(ChunkLoadEvent e) {
|
for (Entity entity : Bukkit.getWorlds().stream().flatMap(world -> world.getEntities().stream())
|
||||||
Chunk chunk = e.getChunk();
|
.filter(entity -> entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END)
|
||||||
World world = chunk.getWorld();
|
.collect(Collectors.toList())) {
|
||||||
if (world.getEnvironment() == World.Environment.THE_END) {
|
Location loc = entity.getLocation();
|
||||||
// Iterate through all the entities in the chunk
|
|
||||||
for (Entity entity : chunk.getEntities()) {
|
|
||||||
if (entity.getType() == EntityType.FALLING_BLOCK) {
|
|
||||||
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
|
// Set the initial velocity of the falling block
|
||||||
int index = counter % 4;
|
int index = counter % 4;
|
||||||
counter ++;
|
counter ++;
|
||||||
Vector velocity = velocities[index];
|
Vector velocity = velocities[index];
|
||||||
entity.setVelocity(velocity);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Block getBlockMovingTo(Location loc, Vector vel) {
|
Block getBlockMovingTo(Location loc, Vector vel) {
|
||||||
double absMax = 0, max = 0;
|
double absMax = 0, max = 0;
|
||||||
char dir = ' ';
|
char dir = ' ';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue