map
This commit is contained in:
parent
93495012fc
commit
d7fd645123
1 changed files with 14 additions and 13 deletions
|
|
@ -13,7 +13,9 @@ import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
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 final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4};
|
||||||
private int counter = 0;
|
private int counter = 0;
|
||||||
private final Set<Location> movingBlocks = new HashSet<>();
|
private final Set<Location> movingBlocks = new HashSet<>();
|
||||||
|
private final Map<Entity, Vector> velocitiesMap = new HashMap<>(); // Create a map to store velocities
|
||||||
private ScheduledTask task;
|
private ScheduledTask task;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
|
|
@ -37,19 +38,18 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds()) {
|
||||||
for (Entity entity : world.getEntities()) {
|
for (Entity entity : world.getEntities()) {
|
||||||
if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
|
if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
|
||||||
FallingBlock fallingBlock = (FallingBlock) entity;
|
Location loc = entity.getLocation();
|
||||||
Location loc = fallingBlock.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 only if it doesn't have a velocity stored
|
||||||
int index = counter % 4;
|
if (!velocitiesMap.containsKey(entity)) {
|
||||||
counter++;
|
int index = counter % 4;
|
||||||
Vector velocity = velocities[index];
|
counter++;
|
||||||
fallingBlock.setVelocity(velocity);
|
Vector velocity = velocities[index];
|
||||||
|
entity.setVelocity(velocity);
|
||||||
// Add the location to the set of moving blocks
|
velocitiesMap.put(entity, velocity); // Store the velocity in the map
|
||||||
movingBlocks.add(loc);
|
movingBlocks.add(entity.getLocation()); // Add the location to the set
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -73,6 +73,7 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
task.cancel();
|
task.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChunkLoad(ChunkLoadEvent event) {
|
public void onChunkLoad(ChunkLoadEvent event) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue