This commit is contained in:
MidnightTale 2023-04-13 11:44:59 +07:00
commit d7fd645123

View file

@ -13,7 +13,9 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
@ -25,10 +27,9 @@ public class FoliaFlow extends JavaPlugin implements Listener {
private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4};
private int counter = 0;
private final Set<Location> movingBlocks = new HashSet<>();
private final Map<Entity, Vector> velocitiesMap = new HashMap<>(); // Create a map to store velocities
private ScheduledTask task;
@Override
public void onEnable() {
super.onEnable();
@ -37,19 +38,18 @@ public class FoliaFlow extends JavaPlugin implements Listener {
for (World world : Bukkit.getWorlds()) {
for (Entity entity : world.getEntities()) {
if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
FallingBlock fallingBlock = (FallingBlock) entity;
Location loc = fallingBlock.getLocation();
Location loc = entity.getLocation();
debug("Falling block spawned at location " + loc);
// Set the initial velocity of the falling block
// Set the initial velocity of the falling block only if it doesn't have a velocity stored
if (!velocitiesMap.containsKey(entity)) {
int index = counter % 4;
counter++;
Vector velocity = velocities[index];
fallingBlock.setVelocity(velocity);
// Add the location to the set of moving blocks
movingBlocks.add(loc);
entity.setVelocity(velocity);
velocitiesMap.put(entity, velocity); // Store the velocity in the map
movingBlocks.add(entity.getLocation()); // Add the location to the set
}
}
}
}
@ -73,6 +73,7 @@ public class FoliaFlow extends JavaPlugin implements Listener {
task.cancel();
}
/*
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {