From 4030fe04d1d350652199e9ced697d3dee2a0414e Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 18:55:46 +0700 Subject: [PATCH 01/30] again optimize --- src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java | 179 ++++++++++--------- 1 file changed, 92 insertions(+), 87 deletions(-) diff --git a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java index 3e4ac69..8af925a 100644 --- a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java +++ b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java @@ -1,7 +1,6 @@ package xyz.hynse.bbsdfia; import com.tcoded.folialib.FoliaLib; -import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -15,24 +14,22 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + public class Bbsdfia extends JavaPlugin implements Listener { private final Vector velocity1 = new Vector(0, 0.5, -1); private final Vector velocity2 = new Vector(-1, 0.5, 0); private final Vector velocity3 = new Vector(0, 0.5, 1); private final Vector velocity4 = new Vector(1, 0.5, 0); - private final Vector[] velocities = { velocity1, velocity2, velocity3, velocity4 }; + private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; private int counter = 0; + private ExecutorService executorService = Executors.newFixedThreadPool(4); FoliaLib foliaLib = new FoliaLib(this); - -/* - @Override - public void onEnable() { - super.onEnable(); - getServer().getPluginManager().registerEvents(this, this); - getServer().getLogger().info("Bbsdfia plugin started"); - }*/ @Override public void onEnable() { super.onEnable(); @@ -44,111 +41,87 @@ public class Bbsdfia extends JavaPlugin implements Listener { public void onDisable() { super.onDisable(); getServer().getLogger().info("Bbsdfia plugin stopped"); + executorService.shutdown(); } - - /*@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); - - FallingBlock dummy = 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)); - - dummy.setVelocity(dummyVel); - } - } - }*/ - @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e) { - if (e.getEntityType() == EntityType.FALLING_BLOCK) { - Entity entity = e.getEntity(); + Entity entity = e.getEntity(); + if (entity.getType() != EntityType.FALLING_BLOCK || entity.getVelocity().length() == 0) { + return; + } + + executorService.execute(() -> { Location loc = entity.getLocation(); Vector vel = entity.getVelocity(); Block movingTo = getBlockMovingTo(loc, vel); - if (movingTo != null && movingTo.getType() == Material.END_PORTAL) { + if ( movingTo != null && movingTo.getType() == Material.END_PORTAL) { foliaLib.getImpl().runAtLocation(loc, () -> { - Location spawnLoc = movingTo.getLocation(); - spawnLoc.setX(spawnLoc.getX()+0.5); - spawnLoc.setY(spawnLoc.getY()+0.5); - spawnLoc.setZ(spawnLoc.getZ()+0.5); + Location spawnLoc = movingTo.getLocation().add(0.5, 0.5, 0.5); + 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); + }); + } + }); + } - // 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); + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof FallingBlock) || entity.getWorld().getEnvironment() != World.Environment.THE_END) { + return; + } + + byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; + Material material = ((FallingBlock) entity).getBlockData().getMaterial(); + + synchronized (this) { + counter++; + int index = counter % 4; + Vector velocity = velocities[index]; + entity.remove(); + + fallingBlocks.add(new FallingBlockData(entity.getLocation(), material, data, velocity)); + if (fallingBlocks.size() == 3) { + executorService.execute(() -> { + List blocks = new ArrayList<>(fallingBlocks); + fallingBlocks.clear(); + + for (FallingBlockData blockData : blocks) { + Location location = blockData.getLocation(); + Vector blockVelocity = blockData.getVelocity(); + spawnFallingBlockWithVelocity(location, blockData.getMaterial(), blockData.getData(), blockVelocity); + } }); } } } - - - - - @EventHandler - public void onEntityChangeBlock(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++; - foliaLib.getImpl().runAtLocation(location, () -> { - FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); + private void spawnFallingBlockWithVelocity(Location location, Material material, byte data, Vector velocity) { + FallingBlock newFallingBlock = location.getWorld().spawnFallingBlock(location, material, data); newFallingBlock.setVelocity(velocity); - }); } - - Block getBlockMovingTo(Location loc, Vector vel){ + Block getBlockMovingTo(Location loc, Vector vel) { double absMax = 0, max = 0; char dir = ' '; Block relative = null; - if(Math.abs(vel.getX()) > absMax){ + if (Math.abs(vel.getX()) > absMax) { max = vel.getX(); absMax = Math.abs(vel.getX()); dir = 'x'; } - if(Math.abs(vel.getY()) > absMax){ + if (Math.abs(vel.getY()) > absMax) { max = vel.getY(); absMax = Math.abs(vel.getY()); dir = 'y'; } - if(Math.abs(vel.getZ()) > absMax){ + if (Math.abs(vel.getZ()) > absMax) { max = vel.getZ(); dir = 'z'; } @@ -159,4 +132,36 @@ public class Bbsdfia extends JavaPlugin implements Listener { } return relative; } -} \ No newline at end of file + + private static class FallingBlockData { + private final Location location; + private final Material material; + private final byte data; + private final Vector velocity; + + public FallingBlockData(Location location, Material material, byte data, Vector velocity) { + this.location = location; + this.material = material; + this.data = data; + this.velocity = velocity; + } + + public Location getLocation() { + return location; + } + + public Material getMaterial() { + return material; + } + + public byte getData() { + return data; + } + + public Vector getVelocity() { + return velocity; + } + } + + private final List fallingBlocks = new ArrayList<>(); +} From 8e6c4a2371ef3eff0add0cc033de7239ecb85f0c Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 20:01:55 +0700 Subject: [PATCH 02/30] cap code --- src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java | 120 ++++++------------- 1 file changed, 37 insertions(+), 83 deletions(-) diff --git a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java index 8af925a..79ed32b 100644 --- a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java +++ b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java @@ -1,6 +1,7 @@ package xyz.hynse.bbsdfia; import com.tcoded.folialib.FoliaLib; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; @@ -14,10 +15,7 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; public class Bbsdfia extends JavaPlugin implements Listener { private final Vector velocity1 = new Vector(0, 0.5, -1); @@ -26,84 +24,72 @@ public class Bbsdfia extends JavaPlugin implements Listener { private final Vector velocity4 = new Vector(1, 0.5, 0); private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; private int counter = 0; - private ExecutorService executorService = Executors.newFixedThreadPool(4); - FoliaLib foliaLib = new FoliaLib(this); @Override public void onEnable() { super.onEnable(); - getServer().getPluginManager().registerEvents(this, this); - getServer().getLogger().info("Bbsdfia plugin started"); + Bukkit.getPluginManager().registerEvents(this, this); + Bukkit.getLogger().info("Bbsdfia plugin started"); } @Override public void onDisable() { super.onDisable(); - getServer().getLogger().info("Bbsdfia plugin stopped"); - executorService.shutdown(); + Bukkit.getLogger().info("Bbsdfia plugin stopped"); } @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e) { - Entity entity = e.getEntity(); - if (entity.getType() != EntityType.FALLING_BLOCK || entity.getVelocity().length() == 0) { - return; - } - - executorService.execute(() -> { + 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) { - foliaLib.getImpl().runAtLocation(loc, () -> { - Location spawnLoc = movingTo.getLocation().add(0.5, 0.5, 0.5); - 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); - }); + 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 overworldfallingblock = 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)); + overworldfallingblock.setVelocity(dummyVel); + Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49, 0); + fuck.getBlock().setType(Material.AIR); } - }); + } } @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); - if (!(entity instanceof FallingBlock) || entity.getWorld().getEnvironment() != World.Environment.THE_END) { + 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(); - synchronized (this) { - counter++; - int index = counter % 4; - Vector velocity = velocities[index]; - entity.remove(); + int index = counter % 4; + Vector velocity = velocities[index]; + counter++; - fallingBlocks.add(new FallingBlockData(entity.getLocation(), material, data, velocity)); - if (fallingBlocks.size() == 3) { - executorService.execute(() -> { - List blocks = new ArrayList<>(fallingBlocks); - fallingBlocks.clear(); - - for (FallingBlockData blockData : blocks) { - Location location = blockData.getLocation(); - Vector blockVelocity = blockData.getVelocity(); - spawnFallingBlockWithVelocity(location, blockData.getMaterial(), blockData.getData(), blockVelocity); - } - }); - } - } - } - - private void spawnFallingBlockWithVelocity(Location location, Material material, byte data, Vector velocity) { - FallingBlock newFallingBlock = location.getWorld().spawnFallingBlock(location, material, data); + FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); newFallingBlock.setVelocity(velocity); } @@ -132,36 +118,4 @@ public class Bbsdfia extends JavaPlugin implements Listener { } return relative; } - - private static class FallingBlockData { - private final Location location; - private final Material material; - private final byte data; - private final Vector velocity; - - public FallingBlockData(Location location, Material material, byte data, Vector velocity) { - this.location = location; - this.material = material; - this.data = data; - this.velocity = velocity; - } - - public Location getLocation() { - return location; - } - - public Material getMaterial() { - return material; - } - - public byte getData() { - return data; - } - - public Vector getVelocity() { - return velocity; - } - } - - private final List fallingBlocks = new ArrayList<>(); } From 206367157e372dc3dce9c76b3496fa5a28c6a86d Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 20:03:46 +0700 Subject: [PATCH 03/30] cap code --- src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java index 79ed32b..b2fcf07 100644 --- a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java +++ b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java @@ -60,8 +60,6 @@ public class Bbsdfia extends JavaPlugin implements Listener { dummyVel.multiply(new Vector(2, 2, 2)); dummyVel.add(new Vector(0, -0.2, 0)); overworldfallingblock.setVelocity(dummyVel); - Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49, 0); - fuck.getBlock().setType(Material.AIR); } } } From 47638e9e489e704bb8dd9a870ac544c5f02af852 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 20:58:57 +0700 Subject: [PATCH 04/30] lastest --- build.gradle | 5 ----- src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java | 9 +++------ 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index f47caeb..adfeb39 100644 --- a/build.gradle +++ b/build.gradle @@ -16,15 +16,10 @@ repositories { name = "sonatype" url = "https://oss.sonatype.org/content/groups/public/" } - maven { - name = "devmart-other" - url = "https://nexuslite.gcnt.net/repos/other/" - } } dependencies { compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT" - implementation "com.tcoded:FoliaLib:0.2.0" } def targetJavaVersion = 17 diff --git a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java index b2fcf07..a08b5d1 100644 --- a/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java +++ b/src/main/java/xyz/hynse/bbsdfia/Bbsdfia.java @@ -1,6 +1,5 @@ package xyz.hynse.bbsdfia; -import com.tcoded.folialib.FoliaLib; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -15,8 +14,6 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import java.util.concurrent.TimeUnit; - public class Bbsdfia extends JavaPlugin implements Listener { private final Vector velocity1 = new Vector(0, 0.5, -1); private final Vector velocity2 = new Vector(-1, 0.5, 0); @@ -53,7 +50,7 @@ public class Bbsdfia extends JavaPlugin implements Listener { spawnLoc.setY(spawnLoc.getY() + 0.5); spawnLoc.setZ(spawnLoc.getZ() + 0.5); - // Spawn the first falling block immediately + // Spawn the falling block immediately FallingBlock overworldfallingblock = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); Vector dummyVel = vel.clone(); dummyVel.setY(-dummyVel.getY()); @@ -76,8 +73,8 @@ public class Bbsdfia extends JavaPlugin implements Listener { // 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); + Location block = new Location(Bukkit.getWorld("world_the_end"), 100, 49, 0); + block.getBlock().setType(Material.AIR); World world = entity.getWorld(); Location location = entity.getLocation(); byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; From fa5cf7166a31e902543bad6a02f6db5c7faf2748 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:07:55 +0700 Subject: [PATCH 05/30] cool msg --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 40f3004..dfa07c7 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,9 +1,6 @@ package xyz.hynse.foliaflow; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -27,13 +24,26 @@ public class FoliaFlow extends JavaPlugin implements Listener { public void onEnable() { super.onEnable(); getServer().getPluginManager().registerEvents(this, this); - getServer().getLogger().info("Bbsdfia plugin started"); + getLogger().info(ChatColor.GREEN + " ______________ \n"); + getLogger().info(ChatColor.GREEN + " / ____/ ____/ /___ _ __\n"); + getLogger().info(ChatColor.GREEN + " / /_ / /_ / / __ \\ | /| / /\n"); + getLogger().info(ChatColor.GREEN + " / __/ / __/ / / /_/ / |/ |/ / \n"); + getLogger().info(ChatColor.GREEN + "/_/ /_/ /_/\\____/|__/|__/ \n"); + getLogger().info(""); + getLogger().info(ChatColor.YELLOW + "Plugin started successfully!"); } @Override public void onDisable() { super.onDisable(); - getServer().getLogger().info("Bbsdfia plugin stopped"); + getServer().getPluginManager().registerEvents(this, this); + getLogger().info(ChatColor.RED + " ______________ \n"); + getLogger().info(ChatColor.RED + " / ____/ ____/ /___ _ __\n"); + getLogger().info(ChatColor.RED + " / /_ / /_ / / __ \\ | /| / /\n"); + getLogger().info(ChatColor.RED + " / __/ / __/ / / /_/ / |/ |/ / \n"); + getLogger().info(ChatColor.RED + "/_/ /_/ /_/\\____/|__/|__/ \n"); + getLogger().info(""); + getLogger().info(ChatColor.YELLOW + "Plugin stopped successfully!"); } From c210b86d06d197ffdc763edce6cc46f20f5c2e71 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:10:58 +0700 Subject: [PATCH 06/30] fix msg --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index dfa07c7..00b2b94 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -24,29 +24,30 @@ public class FoliaFlow extends JavaPlugin implements Listener { public void onEnable() { super.onEnable(); getServer().getPluginManager().registerEvents(this, this); - getLogger().info(ChatColor.GREEN + " ______________ \n"); - getLogger().info(ChatColor.GREEN + " / ____/ ____/ /___ _ __\n"); - getLogger().info(ChatColor.GREEN + " / /_ / /_ / / __ \\ | /| / /\n"); - getLogger().info(ChatColor.GREEN + " / __/ / __/ / / /_/ / |/ |/ / \n"); - getLogger().info(ChatColor.GREEN + "/_/ /_/ /_/\\____/|__/|__/ \n"); - getLogger().info(""); - getLogger().info(ChatColor.YELLOW + "Plugin started successfully!"); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ "); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / ____/ ____/ /___ _ __"); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / /_ / /_ / / __ \\ | /| / /"); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / __/ / __/ / / /_/ / |/ |/ / "); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "/_/ /_/ /_/\\____/|__/|__/ "); + getServer().getConsoleSender().sendMessage(""); + getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin started successfully!"); } @Override public void onDisable() { super.onDisable(); getServer().getPluginManager().registerEvents(this, this); - getLogger().info(ChatColor.RED + " ______________ \n"); - getLogger().info(ChatColor.RED + " / ____/ ____/ /___ _ __\n"); - getLogger().info(ChatColor.RED + " / /_ / /_ / / __ \\ | /| / /\n"); - getLogger().info(ChatColor.RED + " / __/ / __/ / / /_/ / |/ |/ / \n"); - getLogger().info(ChatColor.RED + "/_/ /_/ /_/\\____/|__/|__/ \n"); - getLogger().info(""); - getLogger().info(ChatColor.YELLOW + "Plugin stopped successfully!"); + getServer().getConsoleSender().sendMessage(ChatColor.RED + " ______________ "); + getServer().getConsoleSender().sendMessage(ChatColor.RED + " / ____/ ____/ /___ _ __"); + getServer().getConsoleSender().sendMessage(ChatColor.RED + " / /_ / /_ / / __ \\ | /| / /"); + getServer().getConsoleSender().sendMessage(ChatColor.RED + " / __/ / __/ / / /_/ / |/ |/ / "); + getServer().getConsoleSender().sendMessage(ChatColor.RED + "/_/ /_/ /_/\\____/|__/|__/ "); + getServer().getConsoleSender().sendMessage(""); + getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin stopped successfully!"); } + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From 3e3e16a961ed05993b9cc82a15fb892bd1ac61dc Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:12:59 +0700 Subject: [PATCH 07/30] wrong positon msg order --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 00b2b94..51e27fc 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -24,6 +24,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { public void onEnable() { super.onEnable(); getServer().getPluginManager().registerEvents(this, this); + getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ "); getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / ____/ ____/ /___ _ __"); getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / /_ / /_ / / __ \\ | /| / /"); @@ -31,12 +32,13 @@ public class FoliaFlow extends JavaPlugin implements Listener { getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "/_/ /_/ /_/\\____/|__/|__/ "); getServer().getConsoleSender().sendMessage(""); getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin started successfully!"); + getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); } @Override public void onDisable() { - super.onDisable(); getServer().getPluginManager().registerEvents(this, this); + getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); getServer().getConsoleSender().sendMessage(ChatColor.RED + " ______________ "); getServer().getConsoleSender().sendMessage(ChatColor.RED + " / ____/ ____/ /___ _ __"); getServer().getConsoleSender().sendMessage(ChatColor.RED + " / /_ / /_ / / __ \\ | /| / /"); @@ -44,6 +46,8 @@ public class FoliaFlow extends JavaPlugin implements Listener { getServer().getConsoleSender().sendMessage(ChatColor.RED + "/_/ /_/ /_/\\____/|__/|__/ "); getServer().getConsoleSender().sendMessage(""); getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin stopped successfully!"); + getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); + super.onDisable(); } From 3a50beb18da1b58b6bcb9fddc896c7561a9d5437 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:18:46 +0700 Subject: [PATCH 08/30] remove on disable msg --- settings.gradle | 2 +- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/settings.gradle b/settings.gradle index 505fac3..2214d7f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -rootProject.name = 'bbsdfia' +rootProject.name = 'FoliaFlow' diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 51e27fc..69d1ea1 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -37,16 +37,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { @Override public void onDisable() { - getServer().getPluginManager().registerEvents(this, this); - getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); - getServer().getConsoleSender().sendMessage(ChatColor.RED + " ______________ "); - getServer().getConsoleSender().sendMessage(ChatColor.RED + " / ____/ ____/ /___ _ __"); - getServer().getConsoleSender().sendMessage(ChatColor.RED + " / /_ / /_ / / __ \\ | /| / /"); - getServer().getConsoleSender().sendMessage(ChatColor.RED + " / __/ / __/ / / /_/ / |/ |/ / "); - getServer().getConsoleSender().sendMessage(ChatColor.RED + "/_/ /_/ /_/\\____/|__/|__/ "); - getServer().getConsoleSender().sendMessage(""); - getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin stopped successfully!"); - getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); super.onDisable(); } From c2913381bd0db5514f6e89f6f3f1407c2462beb9 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:24:08 +0700 Subject: [PATCH 09/30] not gud --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 69d1ea1..9052c2b 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -81,8 +81,8 @@ public class FoliaFlow extends JavaPlugin implements Listener { return; } entity.remove(); - Location fuck = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0); - fuck.getBlock().setType(Material.AIR); + Location block = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0); + block.getBlock().setType(Material.AIR); World world = entity.getWorld(); Location location = entity.getLocation(); byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; From d2421c7fc0ab1ab7cdf3fbd85ab40e565302eb11 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:27:56 +0700 Subject: [PATCH 10/30] debug added --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 49 +++++++++---------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 9052c2b..bd58666 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -11,12 +11,14 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import java.util.Objects; + public class FoliaFlow extends JavaPlugin implements Listener { private final Vector velocity1 = new Vector(0, 0.5, -1); private final Vector velocity2 = new Vector(-1, 0.5, 0); private final Vector velocity3 = new Vector(0, 0.5, 1); private final Vector velocity4 = new Vector(1, 0.5, 0); - private final Vector[] velocities = { velocity1, velocity2, velocity3, velocity4 }; + private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; private int counter = 0; @@ -24,38 +26,31 @@ public class FoliaFlow extends JavaPlugin implements Listener { public void onEnable() { super.onEnable(); getServer().getPluginManager().registerEvents(this, this); - getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); - getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ "); - getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / ____/ ____/ /___ _ __"); - getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / /_ / /_ / / __ \\ | /| / /"); - getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / __/ / __/ / / /_/ / |/ |/ / "); - getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "/_/ /_/ /_/\\____/|__/|__/ "); - getServer().getConsoleSender().sendMessage(""); - getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin started successfully!"); - getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "-------------------------------"); + debug("Plugin started successfully!"); } @Override public void onDisable() { super.onDisable(); + debug("Plugin stopped successfully!"); } - @EventHandler - public void onFallingBlockToBlock(EntityChangeBlockEvent e){ - if(e.getEntityType() == EntityType.FALLING_BLOCK){ + 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){ + 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); + spawnLoc.setX(spawnLoc.getX() + 0.5); + spawnLoc.setY(spawnLoc.getY() + 0.5); + spawnLoc.setZ(spawnLoc.getZ() + 0.5); + debug("Creating dummy falling block at location " + spawnLoc + " with velocity " + vel); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); Vector dummyVel = vel.clone(); dummyVel.setY(-dummyVel.getY()); @@ -69,8 +64,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { } - - @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); @@ -80,8 +73,9 @@ public class FoliaFlow extends JavaPlugin implements Listener { if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { return; } + debug("EntityChangeBlock event received for falling block at location " + entity.getLocation()); entity.remove(); - Location block = new Location(Bukkit.getWorld("world_the_end"), 100, 49 ,0); + Location block = new Location(Bukkit.getWorld("world_the_end"), 100, 49, 0); block.getBlock().setType(Material.AIR); World world = entity.getWorld(); Location location = entity.getLocation(); @@ -91,26 +85,26 @@ public class FoliaFlow extends JavaPlugin implements Listener { int index = counter % 4; Vector velocity = velocities[index]; counter++; + debug("Spawning new falling block of material " + material + " at location " + location + " with velocity " + velocity.toString()); FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); newFallingBlock.setVelocity(velocity); } - - Block getBlockMovingTo(Location loc, Vector vel){ + Block getBlockMovingTo(Location loc, Vector vel) { double absMax = 0, max = 0; char dir = ' '; Block relative = null; - if(Math.abs(vel.getX()) > absMax){ + if (Math.abs(vel.getX()) > absMax) { max = vel.getX(); absMax = Math.abs(vel.getX()); dir = 'x'; } - if(Math.abs(vel.getY()) > absMax){ + if (Math.abs(vel.getY()) > absMax) { max = vel.getY(); absMax = Math.abs(vel.getY()); dir = 'y'; } - if(Math.abs(vel.getZ()) > absMax){ + if (Math.abs(vel.getZ()) > absMax) { max = vel.getZ(); dir = 'z'; } @@ -119,6 +113,11 @@ public class FoliaFlow extends JavaPlugin implements Listener { case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 0); case 'z' -> relative = loc.getBlock().getRelative(0, 0, (int) Math.signum(max)); } + debug("Moving falling block from location " + loc.toString() + " to location " + Objects.requireNonNull(relative).getLocation()); return relative; } + + private void debug(String message) { + getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "[DEBUG] " + message); + } } \ No newline at end of file From 5ca043ae8b219463330222be4927c92c95f41603 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:29:42 +0700 Subject: [PATCH 11/30] null --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index bd58666..77ee009 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -11,8 +11,6 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import java.util.Objects; - public class FoliaFlow extends JavaPlugin implements Listener { private final Vector velocity1 = new Vector(0, 0.5, -1); private final Vector velocity2 = new Vector(-1, 0.5, 0); @@ -113,7 +111,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 0); case 'z' -> relative = loc.getBlock().getRelative(0, 0, (int) Math.signum(max)); } - debug("Moving falling block from location " + loc.toString() + " to location " + Objects.requireNonNull(relative).getLocation()); + debug("Moving falling block from location " + loc.toString() + " to location " + relative.getLocation()); return relative; } From 65fb16ad4dafa2f25545d870cea6c252de694d8c Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:32:51 +0700 Subject: [PATCH 12/30] dir msg color change --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 77ee009..0c3c893 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -111,11 +111,11 @@ public class FoliaFlow extends JavaPlugin implements Listener { case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 0); case 'z' -> relative = loc.getBlock().getRelative(0, 0, (int) Math.signum(max)); } - debug("Moving falling block from location " + loc.toString() + " to location " + relative.getLocation()); + debug("Moving falling block from location " + loc.toString() + " to location " + dir); return relative; } private void debug(String message) { - getServer().getConsoleSender().sendMessage(ChatColor.GRAY + "[DEBUG] " + message); + getServer().getConsoleSender().sendMessage(ChatColor.AQUA + "[FoliaFlow] " + message); } } \ No newline at end of file From d8fdd77879253bdc99bb13cf65eaa9e449f196d4 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:43:21 +0700 Subject: [PATCH 13/30] track --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 0c3c893..e974631 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -11,6 +11,9 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import java.util.HashSet; +import java.util.Set; + public class FoliaFlow extends JavaPlugin implements Listener { private final Vector velocity1 = new Vector(0, 0.5, -1); private final Vector velocity2 = new Vector(-1, 0.5, 0); @@ -18,6 +21,8 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Vector velocity4 = new Vector(1, 0.5, 0); private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; private int counter = 0; + private final Set movingBlocks = new HashSet<>(); + @Override @@ -61,7 +66,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { } } - @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); @@ -71,8 +75,13 @@ public class FoliaFlow extends JavaPlugin implements Listener { if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { return; } + Location blockLoc = event.getBlock().getLocation(); + if (movingBlocks.contains(blockLoc)) { + return; + } debug("EntityChangeBlock event received for falling block at location " + entity.getLocation()); entity.remove(); + movingBlocks.add(blockLoc); Location block = new Location(Bukkit.getWorld("world_the_end"), 100, 49, 0); block.getBlock().setType(Material.AIR); World world = entity.getWorld(); @@ -86,8 +95,12 @@ public class FoliaFlow extends JavaPlugin implements Listener { debug("Spawning new falling block of material " + material + " at location " + location + " with velocity " + velocity.toString()); FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); newFallingBlock.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(blockLoc), 20L); } + Block getBlockMovingTo(Location loc, Vector vel) { double absMax = 0, max = 0; char dir = ' '; From 0e49b853587eee0d8932b9dd0988da7bad667b4c Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:47:49 +0700 Subject: [PATCH 14/30] check on spawn for fastest detection --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index e974631..179b048 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -3,11 +3,11 @@ package xyz.hynse.foliaflow; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -40,32 +40,39 @@ public class FoliaFlow extends JavaPlugin implements Listener { @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); + public void onEntitySpawn(EntitySpawnEvent event) { + Entity entity = event.getEntity(); + if (!(entity instanceof FallingBlock)) { + return; + } + if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { + return; + } + debug("Falling block spawned in the end at location " + entity.getLocation()); + 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); + 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); - debug("Creating dummy falling block at location " + spawnLoc + " with velocity " + vel); - FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); - Vector dummyVel = vel.clone(); - dummyVel.setY(-dummyVel.getY()); - dummyVel.multiply(new Vector(2, 2, 2)); + debug("Creating dummy falling block at location " + spawnLoc + " with velocity " + vel); + FallingBlock dummy = 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)); + dummyVel.add(new Vector(0, -0.2, 0)); - dummy.setVelocity(dummyVel); - } + dummy.setVelocity(dummyVel); + entity.remove(); } } + @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent event) { Entity entity = event.getEntity(); From f98be2cfa9b5b6867a0e7faf8057c36a9d0ffe68 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 22:48:50 +0700 Subject: [PATCH 15/30] start msg --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 179b048..6c8fa76 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -29,7 +29,15 @@ public class FoliaFlow extends JavaPlugin implements Listener { public void onEnable() { super.onEnable(); getServer().getPluginManager().registerEvents(this, this); - debug("Plugin started successfully!"); + getServer().getConsoleSender().sendMessage(""); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ "); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / ____/ ____/ /___ _ __"); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / /_ / /_ / / __ \\ | /| / /"); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " / __/ / __/ / / /_/ / |/ |/ / "); + getServer().getConsoleSender().sendMessage(ChatColor.GREEN + "/_/ /_/ /_/\\____/|__/|__/ "); + getServer().getConsoleSender().sendMessage(""); + getServer().getConsoleSender().sendMessage(ChatColor.YELLOW + "Plugin started successfully!"); + getServer().getConsoleSender().sendMessage(""); } @Override From ae48f26ba8ef27f4ef4695ca828a5c631b0f3dd0 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:02:22 +0700 Subject: [PATCH 16/30] ok --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 44 +++++++------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 6c8fa76..f260174 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -82,40 +82,26 @@ public class FoliaFlow extends JavaPlugin implements Listener { @EventHandler - public void onEntityChangeBlock(EntityChangeBlockEvent event) { - Entity entity = event.getEntity(); - if (!(entity instanceof FallingBlock)) { - return; - } - if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { - return; - } - Location blockLoc = event.getBlock().getLocation(); - if (movingBlocks.contains(blockLoc)) { - return; - } - debug("EntityChangeBlock event received for falling block at location " + entity.getLocation()); - entity.remove(); - movingBlocks.add(blockLoc); - Location block = new Location(Bukkit.getWorld("world_the_end"), 100, 49, 0); - block.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(); + public void onFallingBlockSpawn(EntitySpawnEvent e) { + if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) { + Entity entity = e.getEntity(); + Location loc = entity.getLocation(); - int index = counter % 4; - Vector velocity = velocities[index]; - counter++; - debug("Spawning new falling block of material " + material + " at location " + location + " with velocity " + velocity.toString()); - FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); - newFallingBlock.setVelocity(velocity); + debug("Falling block spawned at location " + loc); - // Remove the block from the movingBlocks set after a delay, to prevent it from being immediately moved again - getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(blockLoc), 20L); + // Set the initial velocity of the falling block + int index = counter % 4; + counter ++; + Vector velocity = velocities[index]; + 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) { double absMax = 0, max = 0; char dir = ' '; From f6b3b53b145519cd35727c25e655384b3c5b264b Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:14:04 +0700 Subject: [PATCH 17/30] immortal --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 48 +++++++++---------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index f260174..a84d39e 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -3,6 +3,7 @@ package xyz.hynse.foliaflow; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -48,35 +49,32 @@ public class FoliaFlow extends JavaPlugin implements Listener { @EventHandler - public void onEntitySpawn(EntitySpawnEvent event) { - Entity entity = event.getEntity(); - if (!(entity instanceof FallingBlock)) { - return; - } - if (entity.getWorld().getEnvironment() != World.Environment.THE_END) { - return; - } - debug("Falling block spawned in the end at location " + entity.getLocation()); - Location loc = entity.getLocation(); - Vector vel = entity.getVelocity(); - Block movingTo = getBlockMovingTo(loc, vel); + 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); + 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); - debug("Creating dummy falling block at location " + spawnLoc + " with velocity " + vel); - FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); - Vector dummyVel = vel.clone(); - dummyVel.setY(-dummyVel.getY()); - dummyVel.multiply(new Vector(2, 2, 2)); + FallingBlock dummy = 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)); + dummyVel.add(new Vector(0, -0.2, 0)); - dummy.setVelocity(dummyVel); - entity.remove(); + dummy.setVelocity(dummyVel); + dummy.setDropItem(false); + dummy.setHurtEntities(false); + dummy.setInvulnerable(true); + dummy.setVisualFire(true); + } } } From 1ccffcd7160670a1900cc4c113f9d8090f1f3792 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:19:46 +0700 Subject: [PATCH 18/30] wahy --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index a84d39e..00caa22 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -63,6 +63,9 @@ public class FoliaFlow extends JavaPlugin implements Listener { spawnLoc.setZ(spawnLoc.getZ()+0.5); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); + dummy.setDropItem(false); + dummy.setHurtEntities(false); + dummy.setGravity(true); Vector dummyVel = vel.clone(); dummyVel.setY(-dummyVel.getY()); dummyVel.multiply(new Vector(2, 2, 2)); @@ -70,10 +73,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummyVel.add(new Vector(0, -0.2, 0)); dummy.setVelocity(dummyVel); - dummy.setDropItem(false); - dummy.setHurtEntities(false); - dummy.setInvulnerable(true); - dummy.setVisualFire(true); } } } From ce4176e929419da80d8a65251b1e31fc5cb61ed2 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:22:38 +0700 Subject: [PATCH 19/30] change spawn postion and velocity on overworld --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 00caa22..0abb486 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -59,7 +59,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { 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.setY(spawnLoc.getY()-1.5); spawnLoc.setZ(spawnLoc.getZ()+0.5); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); @@ -70,7 +70,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummyVel.setY(-dummyVel.getY()); dummyVel.multiply(new Vector(2, 2, 2)); - dummyVel.add(new Vector(0, -0.2, 0)); + dummyVel.add(new Vector(0, 3, 0)); dummy.setVelocity(dummyVel); } From 9a4e61e20139fb62506ace504c1d5da1c637b727 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:27:02 +0700 Subject: [PATCH 20/30] lower postion --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 0abb486..276e4d0 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -59,7 +59,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ Location spawnLoc = movingTo.getLocation(); spawnLoc.setX(spawnLoc.getX()+0.5); - spawnLoc.setY(spawnLoc.getY()-1.5); + spawnLoc.setY(spawnLoc.getY()-3.5); spawnLoc.setZ(spawnLoc.getZ()+0.5); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); From 787751bd3d53a14f774b0b38b78ef3ebdcea34c0 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:35:44 +0700 Subject: [PATCH 21/30] tweak velocity on overworld --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 276e4d0..427919f 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -59,7 +59,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ Location spawnLoc = movingTo.getLocation(); spawnLoc.setX(spawnLoc.getX()+0.5); - spawnLoc.setY(spawnLoc.getY()-3.5); + spawnLoc.setY(spawnLoc.getY()-0.1); spawnLoc.setZ(spawnLoc.getZ()+0.5); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); @@ -68,9 +68,9 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummy.setGravity(true); Vector dummyVel = vel.clone(); dummyVel.setY(-dummyVel.getY()); - dummyVel.multiply(new Vector(2, 2, 2)); + dummyVel.multiply(new Vector(2, 1, 2)); - dummyVel.add(new Vector(0, 3, 0)); + dummyVel.add(new Vector(0, 0.2, 0)); dummy.setVelocity(dummyVel); } From b1ba1fdeded32f740b61ce4469c9fa7e64cc0441 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:38:24 +0700 Subject: [PATCH 22/30] tw+ --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 427919f..21b65c9 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -70,7 +70,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummyVel.setY(-dummyVel.getY()); dummyVel.multiply(new Vector(2, 1, 2)); - dummyVel.add(new Vector(0, 0.2, 0)); + dummyVel.add(new Vector(0, 2, 0)); dummy.setVelocity(dummyVel); } From 0561f864a8a2c80a3eaf78ab9a706c4c0c2678c8 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:39:56 +0700 Subject: [PATCH 23/30] tw+ --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 21b65c9..dedf36f 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -59,7 +59,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ Location spawnLoc = movingTo.getLocation(); spawnLoc.setX(spawnLoc.getX()+0.5); - spawnLoc.setY(spawnLoc.getY()-0.1); + spawnLoc.setY(spawnLoc.getY()-0.25); spawnLoc.setZ(spawnLoc.getZ()+0.5); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); @@ -70,7 +70,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummyVel.setY(-dummyVel.getY()); dummyVel.multiply(new Vector(2, 1, 2)); - dummyVel.add(new Vector(0, 2, 0)); + dummyVel.add(new Vector(0, 1, 0)); dummy.setVelocity(dummyVel); } From 625f38dcff3298a153acc290a8c90d56c858c033 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:47:51 +0700 Subject: [PATCH 24/30] tweak --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index dedf36f..db30658 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -24,6 +24,12 @@ public class FoliaFlow extends JavaPlugin implements Listener { private int counter = 0; private final Set movingBlocks = new HashSet<>(); + public void Remove1blockinEnd() { + World WorldEnd = Bukkit.getServer().getWorld("world_the_end"); + Location LocationEnd = new Location(WorldEnd,100,48,0); + WorldEnd.getBlockAt(LocationEnd).setType(Material.AIR); + } + @Override @@ -73,6 +79,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummyVel.add(new Vector(0, 1, 0)); dummy.setVelocity(dummyVel); + Remove1blockinEnd(); } } } @@ -81,6 +88,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { @EventHandler public void onFallingBlockSpawn(EntitySpawnEvent e) { if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) { + Remove1blockinEnd(); Entity entity = e.getEntity(); Location loc = entity.getLocation(); @@ -91,6 +99,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { counter ++; Vector velocity = velocities[index]; entity.setVelocity(velocity); + Remove1blockinEnd(); // 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); From 07f559aae7f09aa22ea39e79dde6c8ce5691804b Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:51:46 +0700 Subject: [PATCH 25/30] tweak --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index db30658..6eab2cf 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -27,7 +27,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { public void Remove1blockinEnd() { World WorldEnd = Bukkit.getServer().getWorld("world_the_end"); Location LocationEnd = new Location(WorldEnd,100,48,0); - WorldEnd.getBlockAt(LocationEnd).setType(Material.AIR); + LocationEnd.getBlock().setType(Material.AIR); } From 7e6030ac2deaa4ea82bedd0870d6da865e5b9ecb Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 12 Apr 2023 23:54:10 +0700 Subject: [PATCH 26/30] tweak --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 6eab2cf..343ccd9 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -24,11 +24,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { private int counter = 0; private final Set movingBlocks = new HashSet<>(); - public void Remove1blockinEnd() { - World WorldEnd = Bukkit.getServer().getWorld("world_the_end"); - Location LocationEnd = new Location(WorldEnd,100,48,0); - LocationEnd.getBlock().setType(Material.AIR); - } @@ -79,7 +74,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummyVel.add(new Vector(0, 1, 0)); dummy.setVelocity(dummyVel); - Remove1blockinEnd(); } } } @@ -88,7 +82,9 @@ public class FoliaFlow extends JavaPlugin implements Listener { @EventHandler public void onFallingBlockSpawn(EntitySpawnEvent e) { if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) { - Remove1blockinEnd(); + World WorldEnd = Bukkit.getServer().getWorld("world_the_end"); + Location LocationEnd = new Location(WorldEnd,100,48,0); + LocationEnd.getBlock().setType(Material.AIR); Entity entity = e.getEntity(); Location loc = entity.getLocation(); @@ -99,7 +95,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { counter ++; Vector velocity = velocities[index]; entity.setVelocity(velocity); - Remove1blockinEnd(); // 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); From f3168eefa08b4397f01e3122b3832048ef51d5e5 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Thu, 13 Apr 2023 00:02:38 +0700 Subject: [PATCH 27/30] w --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 343ccd9..e260eac 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,5 +1,6 @@ package xyz.hynse.foliaflow; +import io.papermc.paper.event.entity.EntityMoveEvent; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -23,13 +24,17 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; private int counter = 0; private final Set movingBlocks = new HashSet<>(); - + private World endWorld; + private Location obsidianLocation; @Override public void onEnable() { super.onEnable(); + endWorld = getServer().getWorld("world_the_end"); // change "world_the_end" to the name of your end world + obsidianLocation = new Location(endWorld, 100, 48, 0); // change the coordinates to the location of your obsidian platform + getServer().getPluginManager().registerEvents(this, this); getServer().getConsoleSender().sendMessage(""); getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ "); @@ -48,6 +53,17 @@ public class FoliaFlow extends JavaPlugin implements Listener { debug("Plugin stopped successfully!"); } + @EventHandler + public void onEntityMove(EntityMoveEvent event) { + handleMove(event.getEntity().getLocation()); + } + + private void handleMove(Location location) { + if (location.getWorld() == endWorld && location.distance(obsidianLocation) <= 1.0) { // check if the location is in the end and within 1 block of the obsidian platform + Block obsidianBlock = obsidianLocation.getBlock(); + obsidianBlock.setType(Material.AIR); // set the block to air + } + } @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ @@ -82,9 +98,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { @EventHandler public void onFallingBlockSpawn(EntitySpawnEvent e) { if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) { - World WorldEnd = Bukkit.getServer().getWorld("world_the_end"); - Location LocationEnd = new Location(WorldEnd,100,48,0); - LocationEnd.getBlock().setType(Material.AIR); Entity entity = e.getEntity(); Location loc = entity.getLocation(); From cc112aeb293c26256952d323b80129b2bfa5baf7 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Thu, 13 Apr 2023 00:18:03 +0700 Subject: [PATCH 28/30] chunk load my best friend --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index e260eac..4e56f9b 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,6 +1,5 @@ package xyz.hynse.foliaflow; -import io.papermc.paper.event.entity.EntityMoveEvent; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -9,7 +8,7 @@ import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.world.ChunkLoadEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -54,14 +53,17 @@ public class FoliaFlow extends JavaPlugin implements Listener { } @EventHandler - public void onEntityMove(EntityMoveEvent event) { - handleMove(event.getEntity().getLocation()); + public void onChunkLoad(ChunkLoadEvent event) { + Block obsidianBlock = obsidianLocation.getBlock(); + if (event.getWorld() == endWorld && obsidianBlock.getType() == Material.OBSIDIAN) { // check if the chunk is in the end and the block is obsidian + obsidianBlock.setType(Material.AIR); // set the block to air + } } - private void handleMove(Location location) { - if (location.getWorld() == endWorld && location.distance(obsidianLocation) <= 1.0) { // check if the location is in the end and within 1 block of the obsidian platform - Block obsidianBlock = obsidianLocation.getBlock(); - obsidianBlock.setType(Material.AIR); // set the block to air + @EventHandler + public void onBlockChange(org.bukkit.event.block.BlockFromToEvent event) { + if (event.getBlock().getLocation().equals(obsidianLocation)) { // check if the block change event is for the obsidian block location + event.setCancelled(true); // cancel the event to prevent the obsidian block from changing } } @@ -96,26 +98,33 @@ public class FoliaFlow extends JavaPlugin implements Listener { @EventHandler - public void onFallingBlockSpawn(EntitySpawnEvent e) { - if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) { - Entity entity = e.getEntity(); - Location loc = entity.getLocation(); + public void onChunkLoadend(ChunkLoadEvent e) { + Chunk chunk = e.getChunk(); + World world = chunk.getWorld(); + if (world.getEnvironment() == World.Environment.THE_END) { + // 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 - int index = counter % 4; - counter ++; - Vector velocity = velocities[index]; - entity.setVelocity(velocity); + // Set the initial velocity of the falling block + int index = counter % 4; + counter ++; + Vector velocity = velocities[index]; + 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); + // 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) { double absMax = 0, max = 0; char dir = ' '; From 9bd2f3797e710bd778df54f595a090690a1fc18f Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Thu, 13 Apr 2023 00:18:40 +0700 Subject: [PATCH 29/30] comment out --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 4e56f9b..441bf74 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -52,6 +52,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { debug("Plugin stopped successfully!"); } + /* @EventHandler public void onChunkLoad(ChunkLoadEvent event) { Block obsidianBlock = obsidianLocation.getBlock(); @@ -65,7 +66,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { if (event.getBlock().getLocation().equals(obsidianLocation)) { // check if the block change event is for the obsidian block location event.setCancelled(true); // cancel the event to prevent the obsidian block from changing } - } + }*/ @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ From c5740cc2ffa6ee8a6350e1f5dbdef89d42775f40 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Thu, 13 Apr 2023 00:33:21 +0700 Subject: [PATCH 30/30] a --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 441bf74..6c31bab 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -22,18 +22,12 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Vector velocity4 = new Vector(1, 0.5, 0); private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; private int counter = 0; - private final Set movingBlocks = new HashSet<>(); - private World endWorld; - private Location obsidianLocation; - + //private final Set movingBlocks = new HashSet<>(); @Override public void onEnable() { super.onEnable(); - endWorld = getServer().getWorld("world_the_end"); // change "world_the_end" to the name of your end world - obsidianLocation = new Location(endWorld, 100, 48, 0); // change the coordinates to the location of your obsidian platform - getServer().getPluginManager().registerEvents(this, this); getServer().getConsoleSender().sendMessage(""); getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ "); @@ -117,7 +111,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { 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); + //getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(loc.getBlock().getLocation()), 20L); } } }