From 5f1597d5d1f0fee4a3b03d34ccb40bc3e7ef790b Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 16:21:12 +0700 Subject: [PATCH] delay --- src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java | 102 ++++++++++++++++++- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java index ebda5f1..88170aa 100644 --- a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java +++ b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java @@ -38,7 +38,7 @@ public class Bbsdfia extends JavaPlugin implements Listener { } - @EventHandler + /*@EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ Entity entity = e.getEntity(); @@ -62,22 +62,65 @@ public class Bbsdfia extends JavaPlugin implements Listener { dummy.setVelocity(dummyVel); } } + }*/ + + @EventHandler + public void onFallingBlockToBlock(EntityChangeBlockEvent e){ + if(e.getEntityType() == EntityType.FALLING_BLOCK){ + Entity entity = e.getEntity(); + Location loc = entity.getLocation(); + Vector vel = entity.getVelocity(); + Block movingTo = getBlockMovingTo(loc, vel); + + if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ + Location spawnLoc = movingTo.getLocation(); + spawnLoc.setX(spawnLoc.getX()+0.5); + spawnLoc.setY(spawnLoc.getY()+0.5); + spawnLoc.setZ(spawnLoc.getZ()+0.5); + + // Spawn the first falling block immediately + FallingBlock firstBlock = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); + Vector dummyVel = vel.clone(); + dummyVel.setY(-dummyVel.getY()); + dummyVel.multiply(new Vector(2, 2, 2)); + dummyVel.add(new Vector(0, -0.2, 0)); + firstBlock.setVelocity(dummyVel); + + // Schedule the spawning of the other two falling blocks with a delay + Bukkit.getScheduler().runTaskLater(this, () -> { + for(int i = 0; i < 2; i++){ + Location spawnLoc1 = movingTo.getLocation(); + spawnLoc1.setX(spawnLoc1.getX()+0.5); + spawnLoc1.setY(spawnLoc1.getY()+0.5); + spawnLoc1.setZ(spawnLoc1.getZ()+0.5); + + FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc1, ((FallingBlock) entity).getBlockData()); + Vector dummyVel1 = vel.clone(); + dummyVel1.setY(-dummyVel1.getY()); + dummyVel1.multiply(new Vector(2, 2, 2)); + dummyVel1.add(new Vector(0, -0.2, 0)); + dummy.setVelocity(dummyVel1); + } + }, 10); + } + } } + @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof FallingBlock)) { - entity.remove(); return; } if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { - entity.remove(); return; } // Spawn a new falling block entity with velocity - + entity.remove(); + Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0); + fuck.getBlock().setType(Material.AIR); World world = entity.getWorld(); Location location = entity.getLocation(); byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; @@ -89,7 +132,58 @@ public class Bbsdfia extends JavaPlugin implements Listener { FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); newFallingBlock.setVelocity(velocity); + } + @EventHandler + public void onEntityChangeBlock2(EntityChangeBlockEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof FallingBlock)) { + return; + } + if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { + return; + } + + // Spawn a new falling block entity with velocity entity.remove(); + Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0); + fuck.getBlock().setType(Material.AIR); + World world = entity.getWorld(); + Location location = entity.getLocation(); + byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; + Material material = ((FallingBlock) entity).getBlockData().getMaterial(); + + int index = counter % 4; + Vector velocity = velocities[index]; + counter++; + + FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); + newFallingBlock.setVelocity(velocity); + } + @EventHandler + public void onEntityChangeBlock1(EntityChangeBlockEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof FallingBlock)) { + return; + } + if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { + return; + } + + // Spawn a new falling block entity with velocity + entity.remove(); + Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0); + fuck.getBlock().setType(Material.AIR); + World world = entity.getWorld(); + Location location = entity.getLocation(); + byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; + Material material = ((FallingBlock) entity).getBlockData().getMaterial(); + + int index = counter % 4; + Vector velocity = velocities[index]; + counter++; + + FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); + newFallingBlock.setVelocity(velocity); }