much simple
This commit is contained in:
parent
4b740415ff
commit
8647f3c2b2
1 changed files with 53 additions and 56 deletions
|
|
@ -11,41 +11,12 @@ 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.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.bukkit.event.block.BlockPhysicsEvent;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
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;
|
||||||
|
|
||||||
public class Bbsdfia extends JavaPlugin implements Listener {
|
public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
private static final Material[] BLOCK_TYPES = {
|
|
||||||
Material.BLACK_CONCRETE_POWDER,
|
|
||||||
Material.BLUE_CONCRETE_POWDER,
|
|
||||||
Material.BROWN_CONCRETE_POWDER,
|
|
||||||
Material.CYAN_CONCRETE_POWDER,
|
|
||||||
Material.GRAY_CONCRETE_POWDER,
|
|
||||||
Material.GREEN_CONCRETE_POWDER,
|
|
||||||
Material.LIGHT_BLUE_CONCRETE_POWDER,
|
|
||||||
Material.LIGHT_GRAY_CONCRETE_POWDER,
|
|
||||||
Material.LIME_CONCRETE_POWDER,
|
|
||||||
Material.MAGENTA_CONCRETE_POWDER,
|
|
||||||
Material.ORANGE_CONCRETE_POWDER,
|
|
||||||
Material.PINK_CONCRETE_POWDER,
|
|
||||||
Material.PURPLE_CONCRETE_POWDER,
|
|
||||||
Material.RED_CONCRETE_POWDER,
|
|
||||||
Material.WHITE_CONCRETE_POWDER,
|
|
||||||
Material.YELLOW_CONCRETE_POWDER,
|
|
||||||
Material.DRAGON_EGG,
|
|
||||||
Material.GRAVEL,
|
|
||||||
Material.RED_SAND,
|
|
||||||
Material.SAND
|
|
||||||
};
|
|
||||||
|
|
||||||
private static final Vector VELOCITY_SOUTH = new Vector(0, 1, -2);
|
|
||||||
private static final Vector VELOCITY_EAST = new Vector(2, 1, 0);
|
|
||||||
private static final Vector VELOCITY_NORTH = new Vector(0, 1, 2);
|
|
||||||
private static final Vector VELOCITY_WEST = new Vector(-2, 1, 0);
|
|
||||||
|
|
||||||
private static final Location START_LOCATION = new Location(Bukkit.getWorld("world_the_end"), 101, 49, 1);
|
|
||||||
private static final Location END_LOCATION = new Location(Bukkit.getWorld("world_the_end"), 99, 51, -1);
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
|
|
@ -85,38 +56,64 @@ public class Bbsdfia extends JavaPlugin implements Listener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBlockBreak(BlockBreakEvent event) {
|
public void onBlockPhysics(BlockPhysicsEvent event) {
|
||||||
Block block = event.getBlock();
|
Block block = event.getBlock();
|
||||||
if (isTargetBlock(block.getType())) {
|
if (isFallingBlock(block.getType())) {
|
||||||
World world = block.getWorld();
|
// Get the location of the block
|
||||||
FallingBlock fallingBlock = world.spawnFallingBlock(block.getLocation(), block.getBlockData());
|
Location loc = block.getLocation();
|
||||||
Vector velocity = getVelocity(block.getLocation());
|
|
||||||
fallingBlock.setVelocity(velocity);
|
|
||||||
block.setType(Material.AIR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isTargetBlock(Material material) {
|
// Check if the block is within the desired area
|
||||||
for (Material blockType : BLOCK_TYPES) {
|
if (isWithinArea(loc)) {
|
||||||
if (blockType == material) {
|
// Create a new falling block entity at the location of the block
|
||||||
return true;
|
FallingBlock fallingBlock = loc.getWorld().spawnFallingBlock(loc, block.getBlockData());
|
||||||
|
|
||||||
|
// Set the velocity of the falling block entity
|
||||||
|
fallingBlock.setVelocity(getRandomVelocity());
|
||||||
|
|
||||||
|
// Remove the original block
|
||||||
|
block.setType(Material.AIR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Vector getVelocity(Location location) {
|
private boolean isFallingBlock(Material material) {
|
||||||
Vector velocity = null;
|
return material == Material.BLACK_CONCRETE_POWDER ||
|
||||||
if (location.getBlockX() == START_LOCATION.getBlockX()) {
|
material == Material.BLUE_CONCRETE_POWDER ||
|
||||||
velocity = VELOCITY_EAST;
|
material == Material.BROWN_CONCRETE_POWDER ||
|
||||||
} else if (location.getBlockZ() == END_LOCATION.getBlockZ()) {
|
material == Material.CYAN_CONCRETE_POWDER ||
|
||||||
velocity = VELOCITY_SOUTH;
|
material == Material.GRAY_CONCRETE_POWDER ||
|
||||||
} else if (location.getBlockX() == END_LOCATION.getBlockX()) {
|
material == Material.GREEN_CONCRETE_POWDER ||
|
||||||
velocity = VELOCITY_NORTH;
|
material == Material.LIGHT_BLUE_CONCRETE_POWDER ||
|
||||||
} else if (location.getBlockX() == END_LOCATION.getBlockX()) {
|
material == Material.LIGHT_GRAY_CONCRETE_POWDER ||
|
||||||
velocity = VELOCITY_WEST;
|
material == Material.LIME_CONCRETE_POWDER ||
|
||||||
}
|
material == Material.MAGENTA_CONCRETE_POWDER ||
|
||||||
return velocity;
|
material == Material.ORANGE_CONCRETE_POWDER ||
|
||||||
|
material == Material.PINK_CONCRETE_POWDER ||
|
||||||
|
material == Material.PURPLE_CONCRETE_POWDER ||
|
||||||
|
material == Material.RED_CONCRETE_POWDER ||
|
||||||
|
material == Material.WHITE_CONCRETE_POWDER ||
|
||||||
|
material == Material.YELLOW_CONCRETE_POWDER ||
|
||||||
|
material == Material.DRAGON_EGG ||
|
||||||
|
material == Material.GRAVEL ||
|
||||||
|
material == Material.RED_SAND ||
|
||||||
|
material == Material.SAND;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isWithinArea(Location loc) {
|
||||||
|
return loc.getWorld().getName().equals("world_the_end") &&
|
||||||
|
loc.getBlockX() >= 101 && loc.getBlockX() <= 99 &&
|
||||||
|
loc.getBlockY() >= 49 && loc.getBlockY() <= 51 &&
|
||||||
|
loc.getBlockZ() >= -1 && loc.getBlockZ() <= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector getRandomVelocity() {
|
||||||
|
int direction = (int) (Math.random() * 4);
|
||||||
|
return switch (direction) {
|
||||||
|
case 0 -> new Vector(0, 1, -2);
|
||||||
|
case 1 -> new Vector(2, 1, 0);
|
||||||
|
case 2 -> new Vector(0, 1, 2);
|
||||||
|
default -> new Vector(-2, 1, 0);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue