From 0fd6ebce95463ace792895676580a2a29b9725ac Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 21:24:12 +0700 Subject: [PATCH 01/30] might fix something --- build.gradle | 2 +- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 33418ae..8548dd7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { def loader = 'folia' def server = '1.19.4' group = 'xyz.hynse' -version = "1.4-${server}-${loader}" +version = "1.4a-${server}-${loader}" repositories { mavenCentral() diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 53ea95c..90ac0e0 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -18,8 +18,6 @@ import org.bukkit.util.Vector; import java.util.*; import java.util.concurrent.TimeUnit; -import static org.bukkit.Bukkit.getScheduler; - public class FoliaFlow extends JavaPlugin implements Listener { private final double vh = 0.2; private final double vt = 0.8; @@ -58,7 +56,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)"); } AsyncScheduler scheduler = getServer().getAsyncScheduler(); - task = scheduler.runAtFixedRate(this, (scheduledTask) -> getScheduler().runTask(this, () -> { + task = scheduler.runAtFixedRate(this, (scheduledTask) -> Bukkit.getScheduler().runTask(this, () -> { for (World world : Bukkit.getWorlds()) { for (Entity entity : world.getEntities()) { if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { From 239774167ff333a7211e79ccb748da86cd907286 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 21:56:09 +0700 Subject: [PATCH 02/30] change to use onspawn --- build.gradle | 2 +- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 60 ++++++++++--------- src/main/resources/plugin.yml | 5 ++ 3 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 src/main/resources/plugin.yml diff --git a/build.gradle b/build.gradle index 8548dd7..ac8ebdc 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { def loader = 'folia' def server = '1.19.4' group = 'xyz.hynse' -version = "1.4a-${server}-${loader}" +version = "1.4b-${server}-${loader}" repositories { mavenCentral() diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 90ac0e0..115a1cd 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -12,6 +12,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.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -55,34 +56,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { } catch (NullPointerException block) { getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)"); } - AsyncScheduler scheduler = getServer().getAsyncScheduler(); - task = scheduler.runAtFixedRate(this, (scheduledTask) -> Bukkit.getScheduler().runTask(this, () -> { - for (World world : Bukkit.getWorlds()) { - for (Entity entity : world.getEntities()) { - if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { - Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); - Location loc = entity.getLocation(); - if (loc.distance(centerLoc) <= 1) { - // Set the initial velocity of the falling block only if it doesn't have a velocity stored - if (!velocitiesMap.containsKey(entity)) { - try { - int index = counter % 4; - counter++; - Vector velocity = velocities[index]; - entity.setVelocity(velocity); - velocitiesMap.put(entity, velocity); // Store the velocity in the map - movingBlocks.add(entity.getLocation()); // Add the location to the set - } catch (NullPointerException e) { - // Handle the exception here, for example: - e.printStackTrace(); - getServer().getLogger().info("An error occurred: " + e.getMessage()); - } - } - } - } - } - } - }), 0L, 1L, TimeUnit.MILLISECONDS); getServer().getPluginManager().registerEvents(this, this); getServer().getConsoleSender().sendMessage(""); getServer().getConsoleSender().sendMessage(ChatColor.GREEN + " ______________ "); @@ -102,6 +75,36 @@ public class FoliaFlow extends JavaPlugin implements Listener { super.onDisable(); } + @EventHandler + public void onEntitySpawn(EntitySpawnEvent e) { + if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getLocation().getWorld().getEnvironment() == World.Environment.THE_END) { + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { + Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); + Location loc = entity.getLocation(); + if (loc.distance(centerLoc) <= 1) { + // Set the initial velocity of the falling block only if it doesn't have a velocity stored + if (!velocitiesMap.containsKey(entity)) { + try { + int index = counter % 4; + counter++; + Vector velocity = velocities[index]; + entity.setVelocity(velocity); + velocitiesMap.put(entity, velocity); // Store the velocity in the map + movingBlocks.add(entity.getLocation()); // Add the location to the set + } catch (NullPointerException x) { + // Handle the exception here, for example: + x.printStackTrace(); + getServer().getLogger().info("An error occurred: " + x.getMessage()); + } + } + } + } + } + } + } + } @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ @@ -158,7 +161,6 @@ 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 " + dir); return relative; } } \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..19f50a9 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +name: FoliaFlow +version: '${version}' +main: xyz.hynse.foliaflow.FoliaFlow +api-version: 1.19 +folia-supported: true \ No newline at end of file From 0dafe2655aa468963bb1032d71b6e900496f5419 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 22:02:11 +0700 Subject: [PATCH 03/30] on falling might work ? --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 47 +++++++------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 115a1cd..00388bc 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.threadedregions.scheduler.AsyncScheduler; import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.*; @@ -12,12 +11,10 @@ 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; import java.util.*; -import java.util.concurrent.TimeUnit; public class FoliaFlow extends JavaPlugin implements Listener { private final double vh = 0.2; @@ -31,8 +28,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { private int counter = 0; private final Set movingBlocks = new HashSet<>(); private final Map velocitiesMap = new HashMap<>(); // Create a map to store velocities - private ScheduledTask task; - private ScheduledTask blockktask; @Override @@ -70,41 +65,31 @@ public class FoliaFlow extends JavaPlugin implements Listener { @Override public void onDisable() { - task.cancel(); blockktask.cancel(); super.onDisable(); } @EventHandler - public void onEntitySpawn(EntitySpawnEvent e) { - if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getLocation().getWorld().getEnvironment() == World.Environment.THE_END) { - for (World world : Bukkit.getWorlds()) { - for (Entity entity : world.getEntities()) { - if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { - Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); - Location loc = entity.getLocation(); - if (loc.distance(centerLoc) <= 1) { - // Set the initial velocity of the falling block only if it doesn't have a velocity stored - if (!velocitiesMap.containsKey(entity)) { - try { - int index = counter % 4; - counter++; - Vector velocity = velocities[index]; - entity.setVelocity(velocity); - velocitiesMap.put(entity, velocity); // Store the velocity in the map - movingBlocks.add(entity.getLocation()); // Add the location to the set - } catch (NullPointerException x) { - // Handle the exception here, for example: - x.printStackTrace(); - getServer().getLogger().info("An error occurred: " + x.getMessage()); - } - } - } - } + public void onFallingBlockToBlockTheEnd(EntityChangeBlockEvent e) { + Entity entity = e.getEntity(); + if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { + Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); + Location loc = entity.getLocation(); + if (loc.distance(centerLoc) <= 1) { + // 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]; + entity.setVelocity(velocity); + velocitiesMap.put(entity, velocity); // Store the velocity in the map + movingBlocks.add(entity.getLocation()); // Add the location to the set } } } } + + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From b3784bc2f2e87db572219d5ec7ed1e7d779300f9 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 22:08:00 +0700 Subject: [PATCH 04/30] more range --- 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 00388bc..3c6bde4 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -75,7 +75,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); Location loc = entity.getLocation(); - if (loc.distance(centerLoc) <= 1) { + if (loc.distance(centerLoc) <= 2) { // 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; From 70a447480f2f97cc1cc1a2720ffa8cf611b8ca99 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 22:08:36 +0700 Subject: [PATCH 05/30] c --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index ac8ebdc..854b3b7 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { def loader = 'folia' def server = '1.19.4' group = 'xyz.hynse' -version = "1.4b-${server}-${loader}" +version = "1.4c-${server}-${loader}" repositories { mavenCentral() From 8721778686eccadbfcba262aa1817a526736f4bd Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 22:14:47 +0700 Subject: [PATCH 06/30] debug --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 3c6bde4..7b478e0 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -73,17 +73,25 @@ public class FoliaFlow extends JavaPlugin implements Listener { public void onFallingBlockToBlockTheEnd(EntityChangeBlockEvent e) { Entity entity = e.getEntity(); if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { + getLogger().info("found falling block main" + entity); Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); Location loc = entity.getLocation(); if (loc.distance(centerLoc) <= 2) { // Set the initial velocity of the falling block only if it doesn't have a velocity stored if (!velocitiesMap.containsKey(entity)) { + getLogger().info("add velocity falling block" + entity); int index = counter % 4; + getLogger().info("[1]" + entity); counter++; + getLogger().info("[2]" + entity); Vector velocity = velocities[index]; + getLogger().info("[3]" + entity); entity.setVelocity(velocity); + getLogger().info("[4]" + entity); velocitiesMap.put(entity, velocity); // Store the velocity in the map + getLogger().info("[5]" + entity); movingBlocks.add(entity.getLocation()); // Add the location to the set + getLogger().info("[6]" + entity); } } } From 873cc7a35686d7355a1aaea6bdde3e56a66a7f85 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 22:27:41 +0700 Subject: [PATCH 07/30] test --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 7b478e0..58d668c 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -30,9 +30,13 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Map velocitiesMap = new HashMap<>(); // Create a map to store velocities private ScheduledTask blockktask; + @Override public void onEnable() { super.onEnable(); + Location centerLocation = new Location(Bukkit.getWorld("world_the_end"), 100, 48.5, 0); + double radius = 1.0; + checkFallingBlock(centerLocation, radius); // Get the region scheduler for the server try { @@ -69,15 +73,14 @@ public class FoliaFlow extends JavaPlugin implements Listener { super.onDisable(); } - @EventHandler - public void onFallingBlockToBlockTheEnd(EntityChangeBlockEvent e) { - Entity entity = e.getEntity(); - if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { - getLogger().info("found falling block main" + entity); - Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); - Location loc = entity.getLocation(); - if (loc.distance(centerLoc) <= 2) { - // Set the initial velocity of the falling block only if it doesn't have a velocity stored + public void checkFallingBlock(Location centerLocation, double radius) { + World world = centerLocation.getWorld(); + double x = centerLocation.getX(); + double y = centerLocation.getY(); + double z = centerLocation.getZ(); + + for (Entity entity : world.getNearbyEntities(centerLocation, radius, radius, radius)) { + if (entity instanceof FallingBlock && entity.getLocation().getBlockY() == y && entity.getLocation().getBlockX() == x && entity.getLocation().getBlockZ() == z) { if (!velocitiesMap.containsKey(entity)) { getLogger().info("add velocity falling block" + entity); int index = counter % 4; @@ -98,6 +101,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { } + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From faa0cf94c81e8576f72e1c5cb7a9015f631eec8e Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 22:44:42 +0700 Subject: [PATCH 08/30] ehhh --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 91 +++++++++++-------- 1 file changed, 54 insertions(+), 37 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 58d668c..e285f22 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -34,24 +34,21 @@ public class FoliaFlow extends JavaPlugin implements Listener { @Override public void onEnable() { super.onEnable(); - Location centerLocation = new Location(Bukkit.getWorld("world_the_end"), 100, 48.5, 0); - double radius = 1.0; - checkFallingBlock(centerLocation, radius); // Get the region scheduler for the server try { - RegionScheduler schedulerblock = getServer().getRegionScheduler(); + RegionScheduler schedulerblock = getServer().getRegionScheduler(); - // Schedule a repeating task to run every tick using runAtFixedRate() method - blockktask = schedulerblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { - Block block = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getBlockAt(100, 48, 0); - if (block.getType() == Material.OBSIDIAN) { - block.setType(Material.COBBLED_DEEPSLATE_SLAB); - Slab slab = (Slab) block.getBlockData(); - slab.setType(Slab.Type.BOTTOM); - block.setBlockData(slab); - } - }, 1L, 1L); + // Schedule a repeating task to run every tick using runAtFixedRate() method + blockktask = schedulerblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { + Block block = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getBlockAt(100, 48, 0); + if (block.getType() == Material.OBSIDIAN) { + block.setType(Material.COBBLED_DEEPSLATE_SLAB); + Slab slab = (Slab) block.getBlockData(); + slab.setType(Slab.Type.BOTTOM); + block.setBlockData(slab); + } + }, 1L, 1L); } catch (NullPointerException block) { getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)"); } @@ -73,35 +70,55 @@ public class FoliaFlow extends JavaPlugin implements Listener { super.onDisable(); } - public void checkFallingBlock(Location centerLocation, double radius) { - World world = centerLocation.getWorld(); - double x = centerLocation.getX(); - double y = centerLocation.getY(); - double z = centerLocation.getZ(); +// @EventHandler +// public void onFallingBlockLand(EntityChangeBlockEvent event) { +// Entity entity = event.getEntity(); +// if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) { +// getLogger().info("found falling block" + entity); +// Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); +// Location loc = entity.getLocation(); +// if (loc.distance(centerLoc) <= 1) { +// if (!velocitiesMap.containsKey(entity)) { +// getLogger().info("add velocity falling block" + entity); +// int index = counter % 4; +// getLogger().info("[1]" + entity); +// counter++; +// getLogger().info("[2]" + entity); +// Vector velocity = velocities[index]; +// getLogger().info("[3]" + entity); +// entity.setVelocity(velocity); +// getLogger().info("[4]" + entity); +// velocitiesMap.put(entity, velocity); // Store the velocity in the map +// getLogger().info("[5]" + entity); +// movingBlocks.add(entity.getLocation()); // Add the location to the set +// getLogger().info("[6]" + entity); +// } +// } +// } +// } - for (Entity entity : world.getNearbyEntities(centerLocation, radius, radius, radius)) { - if (entity instanceof FallingBlock && entity.getLocation().getBlockY() == y && entity.getLocation().getBlockX() == x && entity.getLocation().getBlockZ() == z) { - if (!velocitiesMap.containsKey(entity)) { - getLogger().info("add velocity falling block" + entity); - int index = counter % 4; - getLogger().info("[1]" + entity); - counter++; - getLogger().info("[2]" + entity); - Vector velocity = velocities[index]; - getLogger().info("[3]" + entity); - entity.setVelocity(velocity); - getLogger().info("[4]" + entity); - velocitiesMap.put(entity, velocity); // Store the velocity in the map - getLogger().info("[5]" + entity); - movingBlocks.add(entity.getLocation()); // Add the location to the set - getLogger().info("[6]" + entity); - } - } + @EventHandler + public void onFallingBlockLand(EntityChangeBlockEvent event) { + // Check if the entity is a falling block and has landed in the End dimension + Entity entity = event.getEntity(); + if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) { + // Spawn a new falling block entity with velocity to the north and upward + World world = entity.getWorld(); + Location location = entity.getLocation(); + Vector velocity = new Vector(0, 1.2, -6); + Material material = ((FallingBlock) entity).getBlockData().getMaterial(); + byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; + FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); + newFallingBlock.setVelocity(velocity); + + // Remove the original falling block entity + entity.remove(); } } + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From 9d9d5bace60f6aa0496b050466e65e07eb14c783 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 22:58:11 +0700 Subject: [PATCH 09/30] just test --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index e285f22..2e206b8 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -11,6 +11,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.world.WorldLoadEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -29,6 +30,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Set movingBlocks = new HashSet<>(); private final Map velocitiesMap = new HashMap<>(); // Create a map to store velocities private ScheduledTask blockktask; + private World endWorld; @Override @@ -98,24 +100,22 @@ public class FoliaFlow extends JavaPlugin implements Listener { // } @EventHandler - public void onFallingBlockLand(EntityChangeBlockEvent event) { - // Check if the entity is a falling block and has landed in the End dimension - Entity entity = event.getEntity(); - if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) { - // Spawn a new falling block entity with velocity to the north and upward - World world = entity.getWorld(); - Location location = entity.getLocation(); - Vector velocity = new Vector(0, 1.2, -6); - Material material = ((FallingBlock) entity).getBlockData().getMaterial(); - byte data = ((FallingBlock) entity).getBlockData().getAsString().getBytes()[0]; - FallingBlock newFallingBlock = world.spawnFallingBlock(location, material, data); - newFallingBlock.setVelocity(velocity); - - // Remove the original falling block entity - entity.remove(); + public void onWorldLoad(WorldLoadEvent event) { + // Save reference to the End world + if (event.getWorld().getName().equals("world_the_end")) { + endWorld = event.getWorld(); } } + @EventHandler + public void onEntityChangeBlock(EntityChangeBlockEvent event) { + Entity entity = event.getEntity(); + + // Check if entity is a falling block in the End world + if (entity instanceof FallingBlock && entity.getWorld().equals(endWorld)) { + getServer().broadcastMessage(ChatColor.RED + "I found a falling block in the End!"); + } + } From 4f10521601437a9866fd34eed2e267d3ba36e419 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 23:02:23 +0700 Subject: [PATCH 10/30] please --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 2e206b8..1ee9a89 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -99,26 +99,20 @@ public class FoliaFlow extends JavaPlugin implements Listener { // } // } - @EventHandler - public void onWorldLoad(WorldLoadEvent event) { - // Save reference to the End world - if (event.getWorld().getName().equals("world_the_end")) { - endWorld = event.getWorld(); - } - } - - @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent event) { - Entity entity = event.getEntity(); - - // Check if entity is a falling block in the End world - if (entity instanceof FallingBlock && entity.getWorld().equals(endWorld)) { - getServer().broadcastMessage(ChatColor.RED + "I found a falling block in the End!"); + if (event.getEntity() instanceof FallingBlock) { + FallingBlock block = (FallingBlock) event.getEntity(); + if (block.getWorld().getEnvironment() == World.Environment.THE_END) { + // The falling block is in the End world + String message = "I found a falling block in the End!"; + Bukkit.broadcastMessage(message); + } } } + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From e40c4e0187d601b1ed4c959f22f28dde4d75b926 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 23:05:03 +0700 Subject: [PATCH 11/30] forgor evenhandle --- 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 1ee9a89..d49ee46 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -98,7 +98,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { // } // } // } - + @EventHandler public void onEntityChangeBlock(EntityChangeBlockEvent event) { if (event.getEntity() instanceof FallingBlock) { FallingBlock block = (FallingBlock) event.getEntity(); From 08772a06daf5ed1a3190e7dc427c92a0914249f1 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 23:07:45 +0700 Subject: [PATCH 12/30] on spawn --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index d49ee46..05c8fe5 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -11,6 +11,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.WorldLoadEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -99,7 +100,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { // } // } @EventHandler - public void onEntityChangeBlock(EntityChangeBlockEvent event) { + public void onEntitySpawn(EntitySpawnEvent event) { if (event.getEntity() instanceof FallingBlock) { FallingBlock block = (FallingBlock) event.getEntity(); if (block.getWorld().getEnvironment() == World.Environment.THE_END) { @@ -113,6 +114,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From f64315c638047838aee2f41a8120ef4d746a0e58 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 23:10:26 +0700 Subject: [PATCH 13/30] breakevent --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 05c8fe5..8d94f41 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -10,6 +10,7 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.event.entity.EntitySpawnEvent; import org.bukkit.event.world.WorldLoadEvent; @@ -100,11 +101,12 @@ public class FoliaFlow extends JavaPlugin implements Listener { // } // } @EventHandler - public void onEntitySpawn(EntitySpawnEvent event) { - if (event.getEntity() instanceof FallingBlock) { - FallingBlock block = (FallingBlock) event.getEntity(); - if (block.getWorld().getEnvironment() == World.Environment.THE_END) { - // The falling block is in the End world + public void onBlockBreak(BlockBreakEvent event) { + Block block = event.getBlock(); + if (block.getWorld().getEnvironment() == World.Environment.THE_END) { + // The block is in the End world + if (block.getBlockData() instanceof FallingBlock) { + // The block that was broken is a falling block String message = "I found a falling block in the End!"; Bukkit.broadcastMessage(message); } @@ -115,6 +117,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From 891ef64b631bdd0b3de9106703a36274848cba5f Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 23:53:21 +0700 Subject: [PATCH 14/30] fake block with block display --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 142 ++++++++---------- 1 file changed, 63 insertions(+), 79 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 8d94f41..1559a65 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,23 +1,26 @@ package xyz.hynse.foliaflow; +import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.*; import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Slab; +import org.bukkit.entity.BlockDisplay; 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.block.BlockBreakEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.world.WorldLoadEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import java.util.*; +import java.util.concurrent.TimeUnit; + +import static org.bukkit.Bukkit.getScheduler; public class FoliaFlow extends JavaPlugin implements Listener { private final double vh = 0.2; @@ -30,20 +33,15 @@ 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 final Map velocitiesMap = new HashMap<>(); // Create a map to store velocities + private final Map velocitiesMap = new HashMap<>(); + private ScheduledTask task; private ScheduledTask blockktask; - private World endWorld; - - + private boolean blockCreated = false; @Override public void onEnable() { super.onEnable(); - - // Get the region scheduler for the server try { RegionScheduler schedulerblock = getServer().getRegionScheduler(); - - // Schedule a repeating task to run every tick using runAtFixedRate() method blockktask = schedulerblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { Block block = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getBlockAt(100, 48, 0); if (block.getType() == Material.OBSIDIAN) { @@ -51,73 +49,59 @@ public class FoliaFlow extends JavaPlugin implements Listener { Slab slab = (Slab) block.getBlockData(); slab.setType(Slab.Type.BOTTOM); block.setBlockData(slab); + } + }, 1L, 1L); } catch (NullPointerException block) { getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)"); } + try { + AsyncScheduler scheduler = getServer().getAsyncScheduler(); + task = scheduler.runAtFixedRate(this, (scheduledTask) -> getScheduler().runTask(this, () -> { + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { + Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); + Location loc = entity.getLocation(); + if (loc.distance(centerLoc) <= 1) { + if (!velocitiesMap.containsKey(entity)) { + int index = counter % 4; + counter++; + Vector velocity = velocities[index]; + entity.setVelocity(velocity); + velocitiesMap.put(entity, velocity); + movingBlocks.add(entity.getLocation()); + } + } + } + } + } + }), 0L, 1L, TimeUnit.MILLISECONDS); + } catch (UnsupportedOperationException ignored) { + } + + Location location = new Location(Bukkit.getWorld("world_the_end"), 100, 48, 0); + if (!blockCreated) { + World world = location.getWorld(); + if (world != null) { + Block block = world.getBlockAt(location); + BlockData blockData = block.getBlockData(); + BlockDisplay blockDisplay = (BlockDisplay) world.spawnEntity(location, EntityType.BLOCK_DISPLAY); + blockDisplay.setBlock(blockData); + blockCreated = true; + } + } getServer().getPluginManager().registerEvents(this, this); - 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 public void onDisable() { + task.cancel(); blockktask.cancel(); super.onDisable(); } -// @EventHandler -// public void onFallingBlockLand(EntityChangeBlockEvent event) { -// Entity entity = event.getEntity(); -// if (entity instanceof FallingBlock && entity.getWorld().getEnvironment() == World.Environment.THE_END) { -// getLogger().info("found falling block" + entity); -// Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); -// Location loc = entity.getLocation(); -// if (loc.distance(centerLoc) <= 1) { -// if (!velocitiesMap.containsKey(entity)) { -// getLogger().info("add velocity falling block" + entity); -// int index = counter % 4; -// getLogger().info("[1]" + entity); -// counter++; -// getLogger().info("[2]" + entity); -// Vector velocity = velocities[index]; -// getLogger().info("[3]" + entity); -// entity.setVelocity(velocity); -// getLogger().info("[4]" + entity); -// velocitiesMap.put(entity, velocity); // Store the velocity in the map -// getLogger().info("[5]" + entity); -// movingBlocks.add(entity.getLocation()); // Add the location to the set -// getLogger().info("[6]" + entity); -// } -// } -// } -// } - @EventHandler - public void onBlockBreak(BlockBreakEvent event) { - Block block = event.getBlock(); - if (block.getWorld().getEnvironment() == World.Environment.THE_END) { - // The block is in the End world - if (block.getBlockData() instanceof FallingBlock) { - // The block that was broken is a falling block - String message = "I found a falling block in the End!"; - Bukkit.broadcastMessage(message); - } - } - } - - - - - - @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ @@ -127,24 +111,24 @@ public class FoliaFlow extends JavaPlugin implements Listener { Block movingTo = getBlockMovingTo(loc, vel); try { - if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ - Location spawnLoc = movingTo.getLocation(); - spawnLoc.setX(spawnLoc.getX()+0.5); - spawnLoc.setY(spawnLoc.getY()-0.25); - 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.25); + spawnLoc.setZ(spawnLoc.getZ()+0.5); - FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); - dummy.setDropItem(true); - dummy.setHurtEntities(true); - dummy.setGravity(true); - Vector dummyVel = vel.clone(); - dummyVel.setY(-dummyVel.getY()); - dummyVel.multiply(new Vector(2, 1, 2)); + FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); + dummy.setDropItem(true); + dummy.setHurtEntities(true); + dummy.setGravity(true); + Vector dummyVel = vel.clone(); + dummyVel.setY(-dummyVel.getY()); + dummyVel.multiply(new Vector(2, 1, 2)); - dummyVel.add(new Vector(0, 1, 0)); + dummyVel.add(new Vector(0, 1, 0)); - dummy.setVelocity(dummyVel); - } + dummy.setVelocity(dummyVel); + } } catch (NullPointerException dummy) { getServer().getLogger().info("onFallingBlockToBlock erorr (likly chunky it not load)"); } From 027e975a98d3ecef0d4cc31675cd036aae3ca9ff Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:04:17 +0700 Subject: [PATCH 15/30] fix blockdisplay --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 1559a65..7074242 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -36,7 +36,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Map velocitiesMap = new HashMap<>(); private ScheduledTask task; private ScheduledTask blockktask; - private boolean blockCreated = false; + private BlockDisplay display; @Override public void onEnable() { super.onEnable(); @@ -81,22 +81,24 @@ public class FoliaFlow extends JavaPlugin implements Listener { } catch (UnsupportedOperationException ignored) { } - Location location = new Location(Bukkit.getWorld("world_the_end"), 100, 48, 0); - if (!blockCreated) { - World world = location.getWorld(); - if (world != null) { - Block block = world.getBlockAt(location); - BlockData blockData = block.getBlockData(); - BlockDisplay blockDisplay = (BlockDisplay) world.spawnEntity(location, EntityType.BLOCK_DISPLAY); - blockDisplay.setBlock(blockData); - blockCreated = true; - } - } + Location loc = new Location(Bukkit.getWorld("world_the_end"), 100, 48, 0); + BlockData blockData = Material.OBSIDIAN.createBlockData(); + display = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).spawn(loc, BlockDisplay.class); + display.setBlock(blockData); + + getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable() { + if (display != null) { + display.remove(); + display = null; + } + for (Entity entity : Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getEntitiesByClass(BlockDisplay.class)) { + entity.remove(); + } task.cancel(); blockktask.cancel(); super.onDisable(); From 58a1f99cfa091ad6a6962f7e4b17e817ef2b0247 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:08:10 +0700 Subject: [PATCH 16/30] right --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 7074242..46f2484 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -84,9 +84,12 @@ public class FoliaFlow extends JavaPlugin implements Listener { Location loc = new Location(Bukkit.getWorld("world_the_end"), 100, 48, 0); BlockData blockData = Material.OBSIDIAN.createBlockData(); display = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).spawn(loc, BlockDisplay.class); + if (display == null) { + getLogger().severe("Failed to spawn BlockDisplay entity."); + return; + } display.setBlock(blockData); - - + getLogger().info("BlockDisplay entity spawned successfully."); getServer().getPluginManager().registerEvents(this, this); } @@ -99,6 +102,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { for (Entity entity : Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getEntitiesByClass(BlockDisplay.class)) { entity.remove(); } + getLogger().info("BlockDisplay entity removed successfully."); task.cancel(); blockktask.cancel(); super.onDisable(); From 88c3e15ba15c54c0803dd122f5b1f0c07884286e Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:24:15 +0700 Subject: [PATCH 17/30] =?UTF-8?q?simple=20way=20=F0=9F=92=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 46f2484..0c3b8c6 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -5,9 +5,7 @@ import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.*; import org.bukkit.block.Block; -import org.bukkit.block.data.BlockData; import org.bukkit.block.data.type.Slab; -import org.bukkit.entity.BlockDisplay; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; @@ -36,7 +34,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Map velocitiesMap = new HashMap<>(); private ScheduledTask task; private ScheduledTask blockktask; - private BlockDisplay display; @Override public void onEnable() { super.onEnable(); @@ -80,29 +77,14 @@ public class FoliaFlow extends JavaPlugin implements Listener { }), 0L, 1L, TimeUnit.MILLISECONDS); } catch (UnsupportedOperationException ignored) { } - - Location loc = new Location(Bukkit.getWorld("world_the_end"), 100, 48, 0); - BlockData blockData = Material.OBSIDIAN.createBlockData(); - display = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).spawn(loc, BlockDisplay.class); - if (display == null) { - getLogger().severe("Failed to spawn BlockDisplay entity."); - return; - } - display.setBlock(blockData); - getLogger().info("BlockDisplay entity spawned successfully."); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), + "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable() { - if (display != null) { - display.remove(); - display = null; - } - for (Entity entity : Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getEntitiesByClass(BlockDisplay.class)) { - entity.remove(); - } - getLogger().info("BlockDisplay entity removed successfully."); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); task.cancel(); blockktask.cancel(); super.onDisable(); From 934cf33c6fb1c423f6b4eb2bf59c9b622660cffb Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:38:59 +0700 Subject: [PATCH 18/30] delay scheduler task --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 0c3b8c6..be0d99b 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -77,8 +77,13 @@ public class FoliaFlow extends JavaPlugin implements Listener { }), 0L, 1L, TimeUnit.MILLISECONDS); } catch (UnsupportedOperationException ignored) { } - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), - "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); + AsyncScheduler scheduler = getServer().getAsyncScheduler(); + + scheduler.runDelayed(this, task -> { + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); + }, 10, TimeUnit.SECONDS); + + // Register the event listener getServer().getPluginManager().registerEvents(this, this); } From 2dccb60eca5e9c3fcb052868a84d9d4cb4ab5b5a Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:39:10 +0700 Subject: [PATCH 19/30] 30 s --- 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 be0d99b..e058d42 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -81,7 +81,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { scheduler.runDelayed(this, task -> { Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); - }, 10, TimeUnit.SECONDS); + }, 30, TimeUnit.SECONDS); // Register the event listener getServer().getPluginManager().registerEvents(this, this); From 53000b4c28560a05b79b90cf4356f417355bf4a6 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:44:10 +0700 Subject: [PATCH 20/30] forgot world --- 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 e058d42..665fc17 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -80,7 +80,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { AsyncScheduler scheduler = getServer().getAsyncScheduler(); scheduler.runDelayed(this, task -> { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); + getServer().dispatchCommand(getServer().getConsoleSender(), "execute in minecraft:the_end run summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); }, 30, TimeUnit.SECONDS); // Register the event listener @@ -89,7 +89,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { @Override public void onDisable() { - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); + getServer().dispatchCommand(getServer().getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); task.cancel(); blockktask.cancel(); super.onDisable(); From d6cfbf7e581be10748a4da53dbb7e79ee0a4560e Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:51:10 +0700 Subject: [PATCH 21/30] block display --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 665fc17..aca2cb4 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -34,6 +34,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Map velocitiesMap = new HashMap<>(); private ScheduledTask task; private ScheduledTask blockktask; + @Override public void onEnable() { super.onEnable(); @@ -78,9 +79,9 @@ public class FoliaFlow extends JavaPlugin implements Listener { } catch (UnsupportedOperationException ignored) { } AsyncScheduler scheduler = getServer().getAsyncScheduler(); - scheduler.runDelayed(this, task -> { getServer().dispatchCommand(getServer().getConsoleSender(), "execute in minecraft:the_end run summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); + getServer().getLogger().info("Installed Fake Block Display"); }, 30, TimeUnit.SECONDS); // Register the event listener @@ -90,6 +91,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { @Override public void onDisable() { getServer().dispatchCommand(getServer().getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); + getServer().getLogger().info("Removed Fake Block Display"); task.cancel(); blockktask.cancel(); super.onDisable(); From 149a85cde1626ce81fc4f81bfc12358e13afc825 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 00:51:30 +0700 Subject: [PATCH 22/30] not work :( --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index aca2cb4..7eead12 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -78,20 +78,11 @@ public class FoliaFlow extends JavaPlugin implements Listener { }), 0L, 1L, TimeUnit.MILLISECONDS); } catch (UnsupportedOperationException ignored) { } - AsyncScheduler scheduler = getServer().getAsyncScheduler(); - scheduler.runDelayed(this, task -> { - getServer().dispatchCommand(getServer().getConsoleSender(), "execute in minecraft:the_end run summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); - getServer().getLogger().info("Installed Fake Block Display"); - }, 30, TimeUnit.SECONDS); - - // Register the event listener getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable() { - getServer().dispatchCommand(getServer().getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); - getServer().getLogger().info("Removed Fake Block Display"); task.cancel(); blockktask.cancel(); super.onDisable(); From 39656046539d7bcf88b492d3805450aebca5e116 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 01:09:45 +0700 Subject: [PATCH 23/30] test wrong jar file all the time --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 7eead12..98b708a 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,6 +1,7 @@ package xyz.hynse.foliaflow; import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; +import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.*; @@ -78,11 +79,16 @@ public class FoliaFlow extends JavaPlugin implements Listener { }), 0L, 1L, TimeUnit.MILLISECONDS); } catch (UnsupportedOperationException ignored) { } + getServer().dispatchCommand(Bukkit.getConsoleSender(), "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); + getServer().getLogger().info("Removed Fake Block Display"); + getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable() { + getServer().dispatchCommand(getServer().getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); + getServer().getLogger().info("Removed Fake Block Display"); task.cancel(); blockktask.cancel(); super.onDisable(); From e3e25227f69381a94f7c043d98623d9942b137fa Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 01:18:05 +0700 Subject: [PATCH 24/30] GlobalRegionScheduler --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 98b708a..507ab85 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -7,6 +7,7 @@ import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.data.type.Slab; +import org.bukkit.command.CommandException; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; @@ -79,16 +80,30 @@ public class FoliaFlow extends JavaPlugin implements Listener { }), 0L, 1L, TimeUnit.MILLISECONDS); } catch (UnsupportedOperationException ignored) { } - getServer().dispatchCommand(Bukkit.getConsoleSender(), "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); - getServer().getLogger().info("Removed Fake Block Display"); + GlobalRegionScheduler scheduler = getServer().getGlobalRegionScheduler(); + scheduler.execute(this, () -> { + try { + getServer().dispatchCommand(Bukkit.getConsoleSender(), "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); + getServer().getLogger().info("Installed fake block display"); + } catch (CommandException e) { + getLogger().warning("Error while installing Fake Block Display: " + e.getMessage()); + } + }); getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable() { - getServer().dispatchCommand(getServer().getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); - getServer().getLogger().info("Removed Fake Block Display"); + GlobalRegionScheduler scheduler = getServer().getGlobalRegionScheduler(); + scheduler.execute(this, () -> { + try { + getServer().dispatchCommand(getServer().getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); + getLogger().info("Removed Fake Block Display"); + } catch (CommandException e) { + getLogger().warning("Error while removing Fake Block Display: " + e.getMessage()); + } + }); task.cancel(); blockktask.cancel(); super.onDisable(); From 16f308fe1efec8e08a473688de611d8513ddd66b Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 01:20:54 +0700 Subject: [PATCH 25/30] NVM --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 507ab85..60076e0 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -80,32 +80,16 @@ public class FoliaFlow extends JavaPlugin implements Listener { }), 0L, 1L, TimeUnit.MILLISECONDS); } catch (UnsupportedOperationException ignored) { } - GlobalRegionScheduler scheduler = getServer().getGlobalRegionScheduler(); - scheduler.execute(this, () -> { - try { - getServer().dispatchCommand(Bukkit.getConsoleSender(), "summon minecraft:block_display 100.0005 48 -0.0005 {block_state:{Name:\"minecraft:obsidian\"},Tags:[\"FoliaFlow_FakeBlock\"]}"); - getServer().getLogger().info("Installed fake block display"); - } catch (CommandException e) { - getLogger().warning("Error while installing Fake Block Display: " + e.getMessage()); - } - }); - getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable() { - GlobalRegionScheduler scheduler = getServer().getGlobalRegionScheduler(); - scheduler.execute(this, () -> { - try { - getServer().dispatchCommand(getServer().getConsoleSender(), "kill @e[tag=FoliaFlow_FakeBlock]"); - getLogger().info("Removed Fake Block Display"); - } catch (CommandException e) { - getLogger().warning("Error while removing Fake Block Display: " + e.getMessage()); - } - }); + try { task.cancel(); blockktask.cancel(); + } catch (UnsupportedOperationException ignored) { + } super.onDisable(); } From 9514f7d714116b9df7a62d0b5a3dc6f177d31313 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 01:21:31 +0700 Subject: [PATCH 26/30] version bump --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 854b3b7..ae6eb6a 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { def loader = 'folia' def server = '1.19.4' group = 'xyz.hynse' -version = "1.4c-${server}-${loader}" +version = "1.5-${server}-${loader}" repositories { mavenCentral() From 60faeba3d3143860c4e7d7b06b0b5326adc58147 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 01:24:13 +0700 Subject: [PATCH 27/30] unuse import --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 60076e0..4bec065 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,13 +1,11 @@ package xyz.hynse.foliaflow; import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; -import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.data.type.Slab; -import org.bukkit.command.CommandException; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; From 7f00245206104c913349df6fd6f760c30f92f4aa Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 12:13:22 +0700 Subject: [PATCH 28/30] fix async --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 4bec065..4f794d4 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -32,15 +32,15 @@ public class FoliaFlow extends JavaPlugin implements Listener { private int counter = 0; private final Set movingBlocks = new HashSet<>(); private final Map velocitiesMap = new HashMap<>(); - private ScheduledTask task; - private ScheduledTask blockktask; + private ScheduledTask Foliaflow_Setblock_Task; + private ScheduledTask Foliaflow_Blockvelocity_Task; @Override public void onEnable() { super.onEnable(); try { - RegionScheduler schedulerblock = getServer().getRegionScheduler(); - blockktask = schedulerblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { + RegionScheduler Foliaflow_Setblock = getServer().getRegionScheduler(); + Foliaflow_Setblock_Task = Foliaflow_Setblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { Block block = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getBlockAt(100, 48, 0); if (block.getType() == Material.OBSIDIAN) { block.setType(Material.COBBLED_DEEPSLATE_SLAB); @@ -55,8 +55,8 @@ public class FoliaFlow extends JavaPlugin implements Listener { getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)"); } try { - AsyncScheduler scheduler = getServer().getAsyncScheduler(); - task = scheduler.runAtFixedRate(this, (scheduledTask) -> getScheduler().runTask(this, () -> { + AsyncScheduler Foliaflow_Blockvelocity = getServer().getAsyncScheduler(); + Foliaflow_Blockvelocity_Task = Foliaflow_Blockvelocity.runAtFixedRate(this, (scheduledTask) -> getServer().getScheduler().runTaskAsynchronously(this, () -> { for (World world : Bukkit.getWorlds()) { for (Entity entity : world.getEntities()) { if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { @@ -84,8 +84,8 @@ public class FoliaFlow extends JavaPlugin implements Listener { @Override public void onDisable() { try { - task.cancel(); - blockktask.cancel(); + Foliaflow_Setblock_Task.cancel(); + Foliaflow_Blockvelocity_Task.cancel(); } catch (UnsupportedOperationException ignored) { } super.onDisable(); @@ -119,7 +119,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummy.setVelocity(dummyVel); } } catch (NullPointerException dummy) { - getServer().getLogger().info("onFallingBlockToBlock erorr (likly chunky it not load)"); + getServer().getLogger().info("onFallingBlockToBlock error (likly chunky it not load)"); } } } From 9e56a30ac4742441c7418e111a8b3556a7642fde Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 16:34:39 +0700 Subject: [PATCH 29/30] it has been fixed --- build.gradle | 8 +- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 80 ++++++++++++------- 2 files changed, 52 insertions(+), 36 deletions(-) diff --git a/build.gradle b/build.gradle index ae6eb6a..69e718c 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,8 @@ plugins { id 'java' } -def loader = 'folia' -def server = '1.19.4' group = 'xyz.hynse' -version = "1.5-${server}-${loader}" +version = "1.6" repositories { mavenCentral() @@ -13,10 +11,6 @@ repositories { name = "papermc-repo" url = "https://repo.papermc.io/repository/maven-public/" } - maven { - name = "sonatype" - url = "https://oss.sonatype.org/content/groups/public/" - } } dependencies { diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 4f794d4..defe95d 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,6 +1,7 @@ package xyz.hynse.foliaflow; import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; +import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import org.bukkit.*; @@ -11,7 +12,12 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; +import org.bukkit.event.entity.EntityDamageByBlockEvent; +import org.bukkit.event.entity.EntitySpawnEvent; +import org.bukkit.event.entity.EntityTeleportEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -32,31 +38,26 @@ public class FoliaFlow extends JavaPlugin implements Listener { private int counter = 0; private final Set movingBlocks = new HashSet<>(); private final Map velocitiesMap = new HashMap<>(); - private ScheduledTask Foliaflow_Setblock_Task; - private ScheduledTask Foliaflow_Blockvelocity_Task; - + private ScheduledTask task; + private ScheduledTask blockktask; + private boolean blockCreated = false; @Override public void onEnable() { super.onEnable(); - try { - RegionScheduler Foliaflow_Setblock = getServer().getRegionScheduler(); - Foliaflow_Setblock_Task = Foliaflow_Setblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { - Block block = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getBlockAt(100, 48, 0); - if (block.getType() == Material.OBSIDIAN) { - block.setType(Material.COBBLED_DEEPSLATE_SLAB); - Slab slab = (Slab) block.getBlockData(); - slab.setType(Slab.Type.BOTTOM); - block.setBlockData(slab); + RegionScheduler schedulerblock = getServer().getRegionScheduler(); + blockktask = schedulerblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { + Block block = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getBlockAt(100, 48, 0); + if (block.getType() == Material.OBSIDIAN) { + block.setType(Material.COBBLED_DEEPSLATE_SLAB); + Slab slab = (Slab) block.getBlockData(); + slab.setType(Slab.Type.BOTTOM); + block.setBlockData(slab); - } + } - }, 1L, 1L); - } catch (NullPointerException block) { - getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)"); - } - try { - AsyncScheduler Foliaflow_Blockvelocity = getServer().getAsyncScheduler(); - Foliaflow_Blockvelocity_Task = Foliaflow_Blockvelocity.runAtFixedRate(this, (scheduledTask) -> getServer().getScheduler().runTaskAsynchronously(this, () -> { + }, 1L, 1L); + /*AsyncScheduler scheduler = getServer().getAsyncScheduler(); + task = scheduler.runAtFixedRate(this, (scheduledTask) -> getScheduler().runTask(this, () -> { for (World world : Bukkit.getWorlds()) { for (Entity entity : world.getEntities()) { if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { @@ -75,22 +76,43 @@ public class FoliaFlow extends JavaPlugin implements Listener { } } } - }), 0L, 1L, TimeUnit.MILLISECONDS); - } catch (UnsupportedOperationException ignored) { - } + }), 0L, 1L, TimeUnit.MILLISECONDS);*/ + + GlobalRegionScheduler scheduler = this.getServer().getGlobalRegionScheduler(); + + task = scheduler.runAtFixedRate(this, (scheduledTask) -> { + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { + Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); + Location loc = entity.getLocation(); + if (loc.distance(centerLoc) <= 1) { + if (!velocitiesMap.containsKey(entity)) { + int index = counter % 4; + counter++; + Vector velocity = velocities[index]; + entity.setVelocity(velocity); + velocitiesMap.put(entity, velocity); + movingBlocks.add(entity.getLocation()); + } + } + } + } + } + }, 20L, 1L); + + + getServer().getPluginManager().registerEvents(this, this); } - @Override public void onDisable() { - try { - Foliaflow_Setblock_Task.cancel(); - Foliaflow_Blockvelocity_Task.cancel(); - } catch (UnsupportedOperationException ignored) { - } super.onDisable(); } + + + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() == EntityType.FALLING_BLOCK){ From 5aabb477ca799b6bc1df7a86df20ff4f01cb5f01 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 17:25:34 +0700 Subject: [PATCH 30/30] optimize --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 31 ------------------- 1 file changed, 31 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index defe95d..7cd4a20 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -12,20 +12,11 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.FallingBlock; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -import org.bukkit.event.block.BlockPhysicsEvent; -import org.bukkit.event.block.EntityBlockFormEvent; import org.bukkit.event.entity.EntityChangeBlockEvent; -import org.bukkit.event.entity.EntityDamageByBlockEvent; -import org.bukkit.event.entity.EntitySpawnEvent; -import org.bukkit.event.entity.EntityTeleportEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; import java.util.*; -import java.util.concurrent.TimeUnit; - -import static org.bukkit.Bukkit.getScheduler; - public class FoliaFlow extends JavaPlugin implements Listener { private final double vh = 0.2; private final double vt = 0.8; @@ -40,7 +31,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { private final Map velocitiesMap = new HashMap<>(); private ScheduledTask task; private ScheduledTask blockktask; - private boolean blockCreated = false; @Override public void onEnable() { super.onEnable(); @@ -56,27 +46,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { } }, 1L, 1L); - /*AsyncScheduler scheduler = getServer().getAsyncScheduler(); - task = scheduler.runAtFixedRate(this, (scheduledTask) -> getScheduler().runTask(this, () -> { - for (World world : Bukkit.getWorlds()) { - for (Entity entity : world.getEntities()) { - if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { - Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); - Location loc = entity.getLocation(); - if (loc.distance(centerLoc) <= 1) { - if (!velocitiesMap.containsKey(entity)) { - int index = counter % 4; - counter++; - Vector velocity = velocities[index]; - entity.setVelocity(velocity); - velocitiesMap.put(entity, velocity); - movingBlocks.add(entity.getLocation()); - } - } - } - } - } - }), 0L, 1L, TimeUnit.MILLISECONDS);*/ GlobalRegionScheduler scheduler = this.getServer().getGlobalRegionScheduler();