From 239774167ff333a7211e79ccb748da86cd907286 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 24 Apr 2023 21:56:09 +0700 Subject: [PATCH 01/75] 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 02/75] 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 03/75] 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 04/75] 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 05/75] 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 06/75] 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 07/75] 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 08/75] 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 09/75] 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 10/75] 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 11/75] 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 12/75] 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 13/75] 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 14/75] 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 15/75] 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 16/75] =?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 17/75] 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 18/75] 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 19/75] 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 20/75] 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 21/75] 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 22/75] 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 23/75] 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 24/75] 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 25/75] 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 26/75] 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 27/75] 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 28/75] 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 29/75] 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(); From f1ead7bb48411d494aa98dd3a89f63c74a2c4db5 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 21:36:23 +0700 Subject: [PATCH 30/75] blockdisplay --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 7cd4a20..5412d49 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,12 +1,13 @@ 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.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; @@ -71,6 +72,11 @@ public class FoliaFlow extends JavaPlugin implements Listener { }, 20L, 1L); + BlockDisplay display = (BlockDisplay) Objects.requireNonNull(getServer().getWorld("world_the_end")).spawnEntity(new Location(getServer().getWorld("world_the_end"), 100, 48, 0), EntityType.BLOCK_DISPLAY); + BlockData obsidian = Bukkit.createBlockData(Material.OBSIDIAN); + display.setBlock(obsidian); + BlockData displayedBlock = display.getBlock(); + getLogger().info("Displayed block: " + displayedBlock.getMaterial()); getServer().getPluginManager().registerEvents(this, this); } From 2b6ad01b8f0a3c2aa23c2166d611e8d0a018ea79 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 21:53:17 +0700 Subject: [PATCH 31/75] blockdisplay --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 5412d49..24927d2 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -2,7 +2,6 @@ package xyz.hynse.foliaflow; 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.BlockData; @@ -30,13 +29,11 @@ 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; @Override public void onEnable() { super.onEnable(); RegionScheduler schedulerblock = getServer().getRegionScheduler(); - blockktask = schedulerblock.runAtFixedRate(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { + 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); @@ -48,9 +45,9 @@ public class FoliaFlow extends JavaPlugin implements Listener { }, 1L, 1L); - GlobalRegionScheduler scheduler = this.getServer().getGlobalRegionScheduler(); + GlobalRegionScheduler schedulervelocity = this.getServer().getGlobalRegionScheduler(); - task = scheduler.runAtFixedRate(this, (scheduledTask) -> { + schedulervelocity.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) { @@ -72,11 +69,23 @@ public class FoliaFlow extends JavaPlugin implements Listener { }, 20L, 1L); - BlockDisplay display = (BlockDisplay) Objects.requireNonNull(getServer().getWorld("world_the_end")).spawnEntity(new Location(getServer().getWorld("world_the_end"), 100, 48, 0), EntityType.BLOCK_DISPLAY); - BlockData obsidian = Bukkit.createBlockData(Material.OBSIDIAN); - display.setBlock(obsidian); - BlockData displayedBlock = display.getBlock(); - getLogger().info("Displayed block: " + displayedBlock.getMaterial()); + RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); + + schedulerdisplay.run(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { + World endWorld = getServer().getWorld("world_the_end"); + if (endWorld == null) { + getLogger().warning("World \"world_the_end\" does not exist!"); + return; + } + + Chunk chunk = endWorld.getChunkAt(0, 0); + if (!chunk.isLoaded()) { + chunk.load(); + BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100, 48, 0), EntityType.BLOCK_DISPLAY); + BlockData obsidian = Bukkit.createBlockData(Material.OBSIDIAN); + display.setBlock(obsidian); + } + }); getServer().getPluginManager().registerEvents(this, this); } From 8e93aa01481c25fc434424f385a52cefd0ed181e Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 22:17:31 +0700 Subject: [PATCH 32/75] remove display block on disable --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 24927d2..4231295 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -13,6 +13,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.server.PluginDisableEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -70,24 +71,42 @@ public class FoliaFlow extends JavaPlugin implements Listener { RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); + String tag = "FoliaFlow_Display"; schedulerdisplay.run(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { - World endWorld = getServer().getWorld("world_the_end"); - if (endWorld == null) { - getLogger().warning("World \"world_the_end\" does not exist!"); - return; - } + World endWorld = getServer().getWorld("world_the_end"); + assert endWorld != null; + Chunk chunk = endWorld.getChunkAt(0, 0); + if (!chunk.isLoaded()) { + chunk.load(); + } - Chunk chunk = endWorld.getChunkAt(0, 0); - if (!chunk.isLoaded()) { - chunk.load(); - BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100, 48, 0), EntityType.BLOCK_DISPLAY); - BlockData obsidian = Bukkit.createBlockData(Material.OBSIDIAN); - display.setBlock(obsidian); - } + // Check if the chunk already has a display block + for (Entity entity : chunk.getEntities()) { + if (entity instanceof BlockDisplay && entity.getScoreboardTags().contains(tag)) { + return; + } + } + + BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100.0005, 48, -0.0005), EntityType.BLOCK_DISPLAY); + display.setBlock(Bukkit.createBlockData(Material.OBSIDIAN)); + display.addScoreboardTag(tag); }); - getServer().getPluginManager().registerEvents(this, this); + getServer().getPluginManager().registerEvents(new Listener() { + @EventHandler + public void onPluginDisable(PluginDisableEvent event) { + if (event.getPlugin() == FoliaFlow.this) { + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity instanceof BlockDisplay && entity.getScoreboardTags().contains(tag)) { + entity.remove(); + } + } + } + } + } + }, this); } @Override public void onDisable() { From d87eee5b8dcaecdc500751d10aa08dd0a0ba4066 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 22:40:34 +0700 Subject: [PATCH 33/75] remove display block --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 4231295..8e1c239 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -4,7 +4,6 @@ import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; import io.papermc.paper.threadedregions.scheduler.RegionScheduler; 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; @@ -13,7 +12,6 @@ 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.server.PluginDisableEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -30,6 +28,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { private int counter = 0; private final Set movingBlocks = new HashSet<>(); private final Map velocitiesMap = new HashMap<>(); + @Override public void onEnable() { super.onEnable(); @@ -72,6 +71,14 @@ public class FoliaFlow extends JavaPlugin implements Listener { RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); String tag = "FoliaFlow_Display"; + for (World world : Bukkit.getWorlds()) { + for (Entity entity : world.getEntities()) { + if (entity.getScoreboardTags().contains(tag)) { + entity.remove(); + getLogger().info("Remove BlockDisplay" + "(" + tag + ") " + entity); + } + } + } schedulerdisplay.run(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { World endWorld = getServer().getWorld("world_the_end"); @@ -79,34 +86,17 @@ public class FoliaFlow extends JavaPlugin implements Listener { Chunk chunk = endWorld.getChunkAt(0, 0); if (!chunk.isLoaded()) { chunk.load(); - } - - // Check if the chunk already has a display block - for (Entity entity : chunk.getEntities()) { - if (entity instanceof BlockDisplay && entity.getScoreboardTags().contains(tag)) { - return; - } + getLogger().info("Loaded Chunk"); } BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100.0005, 48, -0.0005), EntityType.BLOCK_DISPLAY); display.setBlock(Bukkit.createBlockData(Material.OBSIDIAN)); display.addScoreboardTag(tag); + getLogger().info("Setup BlockDisplay" + "(" + tag + ") " + display); }); - getServer().getPluginManager().registerEvents(new Listener() { - @EventHandler - public void onPluginDisable(PluginDisableEvent event) { - if (event.getPlugin() == FoliaFlow.this) { - for (World world : Bukkit.getWorlds()) { - for (Entity entity : world.getEntities()) { - if (entity instanceof BlockDisplay && entity.getScoreboardTags().contains(tag)) { - entity.remove(); - } - } - } - } - } - }, this); + + getServer().getPluginManager().registerEvents(this, this); } @Override public void onDisable() { From 86f341c2c404fbc90f4e5d0d207be8dd0ffbcf7e Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 22:47:32 +0700 Subject: [PATCH 34/75] detect exist blockdisplay --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 8e1c239..2e55693 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -71,14 +71,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); String tag = "FoliaFlow_Display"; - for (World world : Bukkit.getWorlds()) { - for (Entity entity : world.getEntities()) { - if (entity.getScoreboardTags().contains(tag)) { - entity.remove(); - getLogger().info("Remove BlockDisplay" + "(" + tag + ") " + entity); - } - } - } schedulerdisplay.run(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { World endWorld = getServer().getWorld("world_the_end"); @@ -89,10 +81,17 @@ public class FoliaFlow extends JavaPlugin implements Listener { getLogger().info("Loaded Chunk"); } - BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100.0005, 48, -0.0005), EntityType.BLOCK_DISPLAY); - display.setBlock(Bukkit.createBlockData(Material.OBSIDIAN)); - display.addScoreboardTag(tag); - getLogger().info("Setup BlockDisplay" + "(" + tag + ") " + display); + // Check if a block display entity with the specified tag already exists + boolean displayExists = endWorld.getEntitiesByClass(BlockDisplay.class).stream() + .anyMatch(entity -> entity.getScoreboardTags().contains(tag)); + + // Spawn a new block display entity only if it doesn't already exist + if (!displayExists) { + BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100.0005, 48, -0.0005), EntityType.BLOCK_DISPLAY); + display.setBlock(Bukkit.createBlockData(Material.OBSIDIAN)); + display.addScoreboardTag(tag); + getLogger().info("Setup BlockDisplay" + "(" + tag + ") " + display); + } }); From 9484c2d6677ce08e6fbbb624f7fd6884c11fc1ef Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 23:16:55 +0700 Subject: [PATCH 35/75] save info to data file --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 63 ++++++++++++------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 2e55693..58b6036 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -5,6 +5,7 @@ import io.papermc.paper.threadedregions.scheduler.RegionScheduler; import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.data.type.Slab; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.BlockDisplay; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -15,6 +16,8 @@ import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import java.io.File; +import java.io.IOException; import java.util.*; public class FoliaFlow extends JavaPlugin implements Listener { private final double vh = 0.2; @@ -69,30 +72,46 @@ public class FoliaFlow extends JavaPlugin implements Listener { }, 20L, 1L); - RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); - String tag = "FoliaFlow_Display"; + File dataFile = new File(getDataFolder(), "data.yml"); + YamlConfiguration config = YamlConfiguration.loadConfiguration(dataFile); - schedulerdisplay.run(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { - World endWorld = getServer().getWorld("world_the_end"); - assert endWorld != null; - Chunk chunk = endWorld.getChunkAt(0, 0); - if (!chunk.isLoaded()) { - chunk.load(); - getLogger().info("Loaded Chunk"); - } + // Get the existing flag value, or default to false if it doesn't exist + boolean entitySpawned = config.getBoolean("entity_spawned", false); - // Check if a block display entity with the specified tag already exists - boolean displayExists = endWorld.getEntitiesByClass(BlockDisplay.class).stream() - .anyMatch(entity -> entity.getScoreboardTags().contains(tag)); + // If the entity has not already been spawned, spawn it and set the flag to true + if (!entitySpawned) { + RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); + String tag = "FoliaFlow_Display"; - // Spawn a new block display entity only if it doesn't already exist - if (!displayExists) { - BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100.0005, 48, -0.0005), EntityType.BLOCK_DISPLAY); - display.setBlock(Bukkit.createBlockData(Material.OBSIDIAN)); - display.addScoreboardTag(tag); - getLogger().info("Setup BlockDisplay" + "(" + tag + ") " + display); - } - }); + schedulerdisplay.run(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { + World endWorld = getServer().getWorld("world_the_end"); + assert endWorld != null; + Chunk chunk = endWorld.getChunkAt(0, 0); + if (!chunk.isLoaded()) { + chunk.load(); + getLogger().info("Loaded Chunk"); + } + + boolean displayExists = endWorld.getEntitiesByClass(BlockDisplay.class).stream() + .anyMatch(entity -> entity.getScoreboardTags().contains(tag)); + getLogger().info("Exist BlockDisplay" + "(" + tag + ")"); + + if (!displayExists) { + BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100.0005, 48, -0.0005), EntityType.BLOCK_DISPLAY); + display.setBlock(Bukkit.createBlockData(Material.OBSIDIAN)); + display.addScoreboardTag(tag); + getLogger().info("Setup BlockDisplay" + "(" + tag + ") " + display); + + // Set the flag to indicate that the entity has been spawned + config.set("entity_spawned", true); + try { + config.save(dataFile); + } catch (IOException e) { + getLogger().warning("Failed to save plugin data file"); + } + } + }); + } getServer().getPluginManager().registerEvents(this, this); @@ -133,7 +152,7 @@ public class FoliaFlow extends JavaPlugin implements Listener { dummy.setVelocity(dummyVel); } } catch (NullPointerException dummy) { - getServer().getLogger().info("onFallingBlockToBlock error (likly chunky it not load)"); + getServer().getLogger().info("onFallingBlockToBlock error (likely chunky it not load)"); } } } From ab88e1485f079a086c541eb4d217e831c199b2c3 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 23:17:26 +0700 Subject: [PATCH 36/75] version bump --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 69e718c..425c4d0 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "1.6" +version = "1.7" repositories { mavenCentral() From 792c0c5f1d8a33ccece23aecebf689ba783891be Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 25 Apr 2023 23:18:42 +0700 Subject: [PATCH 37/75] optimize code --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 58b6036..bcbc5c5 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -75,10 +75,8 @@ public class FoliaFlow extends JavaPlugin implements Listener { File dataFile = new File(getDataFolder(), "data.yml"); YamlConfiguration config = YamlConfiguration.loadConfiguration(dataFile); - // Get the existing flag value, or default to false if it doesn't exist boolean entitySpawned = config.getBoolean("entity_spawned", false); - // If the entity has not already been spawned, spawn it and set the flag to true if (!entitySpawned) { RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); String tag = "FoliaFlow_Display"; @@ -102,7 +100,6 @@ public class FoliaFlow extends JavaPlugin implements Listener { display.addScoreboardTag(tag); getLogger().info("Setup BlockDisplay" + "(" + tag + ") " + display); - // Set the flag to indicate that the entity has been spawned config.set("entity_spawned", true); try { config.save(dataFile); From 2369212335055710ed392b9d9ac8fcdc3107bc31 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 26 Apr 2023 03:14:24 +0700 Subject: [PATCH 38/75] Change spawn overworld falling block to above portal --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index bcbc5c5..7dfc7e3 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -128,28 +128,20 @@ public class FoliaFlow extends JavaPlugin implements Listener { Location loc = entity.getLocation(); Vector vel = entity.getVelocity(); 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.5); + 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()); + 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, 1, 0)); - - dummy.setVelocity(dummyVel); - } - } catch (NullPointerException dummy) { - getServer().getLogger().info("onFallingBlockToBlock error (likely chunky it not load)"); + dummy.setVelocity(dummyVel); } } } From 758b5dc8fc7d43d4ee25745887f00596d0202b03 Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:40:47 +0300 Subject: [PATCH 39/75] Refactoring / Optimize project --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 179 +----------------- .../hynse/foliaflow/util/VelocityUtil.java | 19 ++ .../foliaflow/watcher/PortalWatcher.java | 45 +++++ 3 files changed, 70 insertions(+), 173 deletions(-) create mode 100644 src/main/java/xyz/hynse/foliaflow/util/VelocityUtil.java create mode 100644 src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index bcbc5c5..2d424d3 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,182 +1,15 @@ package xyz.hynse.foliaflow; -import io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler; -import io.papermc.paper.threadedregions.scheduler.RegionScheduler; -import org.bukkit.*; -import org.bukkit.block.Block; -import org.bukkit.block.data.type.Slab; -import org.bukkit.configuration.file.YamlConfiguration; -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.entity.EntityChangeBlockEvent; import org.bukkit.plugin.java.JavaPlugin; -import org.bukkit.util.Vector; +import xyz.hynse.foliaflow.watcher.PortalWatcher; -import java.io.File; -import java.io.IOException; -import java.util.*; -public class FoliaFlow extends JavaPlugin implements Listener { - private final double vh = 0.2; - private final double vt = 0.8; - private final Vector velocity1 = new Vector(0, vh, vt); - private final Vector velocity2 = new Vector(vt, vh, 0); - private final Vector velocity3 = new Vector(0, vh, -vt); - private final Vector velocity4 = new Vector(-vt, vh, 0); +public class FoliaFlow extends JavaPlugin { - private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; - private int counter = 0; - private final Set movingBlocks = new HashSet<>(); - private final Map velocitiesMap = new HashMap<>(); + public static FoliaFlow instance; @Override public void onEnable() { - super.onEnable(); - RegionScheduler schedulerblock = getServer().getRegionScheduler(); - 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); - - GlobalRegionScheduler schedulervelocity = this.getServer().getGlobalRegionScheduler(); - - schedulervelocity.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); - - - File dataFile = new File(getDataFolder(), "data.yml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(dataFile); - - boolean entitySpawned = config.getBoolean("entity_spawned", false); - - if (!entitySpawned) { - RegionScheduler schedulerdisplay = getServer().getRegionScheduler(); - String tag = "FoliaFlow_Display"; - - schedulerdisplay.run(this, Objects.requireNonNull(Bukkit.getWorld("world_the_end")), 1, 1, (schedulerTask) -> { - World endWorld = getServer().getWorld("world_the_end"); - assert endWorld != null; - Chunk chunk = endWorld.getChunkAt(0, 0); - if (!chunk.isLoaded()) { - chunk.load(); - getLogger().info("Loaded Chunk"); - } - - boolean displayExists = endWorld.getEntitiesByClass(BlockDisplay.class).stream() - .anyMatch(entity -> entity.getScoreboardTags().contains(tag)); - getLogger().info("Exist BlockDisplay" + "(" + tag + ")"); - - if (!displayExists) { - BlockDisplay display = (BlockDisplay) endWorld.spawnEntity(new Location(endWorld, 100.0005, 48, -0.0005), EntityType.BLOCK_DISPLAY); - display.setBlock(Bukkit.createBlockData(Material.OBSIDIAN)); - display.addScoreboardTag(tag); - getLogger().info("Setup BlockDisplay" + "(" + tag + ") " + display); - - config.set("entity_spawned", true); - try { - config.save(dataFile); - } catch (IOException e) { - getLogger().warning("Failed to save plugin data file"); - } - } - }); - } - - - getServer().getPluginManager().registerEvents(this, this); + instance = this; + getServer().getPluginManager().registerEvents(new PortalWatcher(), this); } - @Override - public void onDisable() { - super.onDisable(); - } - - - - - @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); - 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); - - 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)); - - dummy.setVelocity(dummyVel); - } - } catch (NullPointerException dummy) { - getServer().getLogger().info("onFallingBlockToBlock error (likely chunky it not load)"); - } - } - } - - Block getBlockMovingTo(Location loc, Vector vel) { - double absMax = 0, max = 0; - char dir = ' '; - Block relative = null; - if (Math.abs(vel.getX()) > absMax) { - max = vel.getX(); - absMax = Math.abs(vel.getX()); - dir = 'x'; - } - if (Math.abs(vel.getY()) > absMax) { - max = vel.getY(); - absMax = Math.abs(vel.getY()); - dir = 'y'; - } - if (Math.abs(vel.getZ()) > absMax) { - max = vel.getZ(); - dir = 'z'; - } - switch (dir) { - case 'x' -> relative = loc.getBlock().getRelative((int) Math.signum(max), 0, 0); - case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 0); - case 'z' -> relative = loc.getBlock().getRelative(0, 0, (int) Math.signum(max)); - } - return relative; - } -} \ No newline at end of file +} diff --git a/src/main/java/xyz/hynse/foliaflow/util/VelocityUtil.java b/src/main/java/xyz/hynse/foliaflow/util/VelocityUtil.java new file mode 100644 index 0000000..953fbee --- /dev/null +++ b/src/main/java/xyz/hynse/foliaflow/util/VelocityUtil.java @@ -0,0 +1,19 @@ +package xyz.hynse.foliaflow.util; + +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.util.Vector; + +public class VelocityUtil { + public static Block getBlockMovingTo(Location loc, Vector vel) { + double absX = Math.abs(vel.getX()); + double absY = Math.abs(vel.getY()); + double absZ = Math.abs(vel.getZ()); + if (absX > absY && absX > absZ) { + return loc.getBlock().getRelative((int) Math.signum(vel.getX()), 0, 0); + } else if (absY > absZ) { + return loc.getBlock().getRelative(0, (int) Math.signum(vel.getY()), 0); + } + return loc.getBlock().getRelative(0, 0, (int) Math.signum(vel.getZ())); + } +} diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java new file mode 100644 index 0000000..aea2833 --- /dev/null +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -0,0 +1,45 @@ +package xyz.hynse.foliaflow.watcher; + +import org.bukkit.Location; +import org.bukkit.Material; +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.util.Vector; +import xyz.hynse.foliaflow.FoliaFlow; + +import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo; + +public class PortalWatcher implements Listener { + @EventHandler + public void onFallingBlockToBlock(EntityChangeBlockEvent e){ + if(e.getEntityType() != EntityType.FALLING_BLOCK) return; + 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.add(0.5, 0.5, 0.5); + + FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); + Vector dummyVel = vel.clone(); + dummyVel.setY(-dummyVel.getY()); + dummyVel.multiply(1.3); // This seems vanilla. + dummyVel.add(new Vector(0, -0.2, 0)); + dummy.setVelocity(dummyVel); + + // Add vector seems vanilla. + dummy.getScheduler().runDelayed(FoliaFlow.instance, + task -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))), + null, + 2 + ); + } + } +} From fa83f08e572eb3494421dda6c11f417e20e176e4 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 26 Apr 2023 12:20:07 +0700 Subject: [PATCH 40/75] fix version not show in console --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 425c4d0..c928fe7 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,7 @@ processResources { def props = [version: version] inputs.properties props filteringCharset 'UTF-8' - filesMatching('plugin.yml') { + filesMatching(['plugin.yml', 'paper-plugin.yml']) { expand props } } From 94d126994439ebe3719f5fae5191b5dde9c847f3 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 26 Apr 2023 12:22:35 +0700 Subject: [PATCH 41/75] version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c928fe7..7ad4948 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "1.7" +version = "2.0" repositories { mavenCentral() From 2a84850dd6734904fa2e4c4545fa0661d0530448 Mon Sep 17 00:00:00 2001 From: Mid <125941391+MidnightTale@users.noreply.github.com> Date: Wed, 26 Apr 2023 12:35:31 +0700 Subject: [PATCH 42/75] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 83cdbb4..4bcd469 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ FoliaFlow is a Minecraft plugin that allows players to using gravity block duplication glitch again in folia (paper soon) ## How is work? -Whenever a falling sand entity comes close to or hits the end portal, a new falling sand entity is summoned with a velocity that shoots it straight into the portal. However, we encountered a problem when the entity got reset by the safe teleport paper patch - it lost its velocity. To fix this, we added the velocity back when the entity was in the end. Another issue we faced was that the entity would instantly turn into a block upon teleportation because it have block below. To solve this, we made the center block of the spawn platform a slab, ensuring that the entity stays in its falling state. +Whenever a falling sand entity comes close to or hits the end portal, a new falling sand entity is summoned with a velocity that shoots it straight into the portal. However, we encountered a problem when the entity got reset by the safe teleport paper patch - it lost its velocity. To fix this, we added the velocity back when the entity was in the end. ## Installation From c5f152fdbf9ea4b6995b781120a178cfeb61e195 Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Wed, 26 Apr 2023 12:20:02 +0300 Subject: [PATCH 43/75] Paper compatibility --- .../hynse/foliaflow/util/SchedulerUtil.java | 28 +++++++++++++++++++ .../foliaflow/watcher/PortalWatcher.java | 7 +++-- 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java diff --git a/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java new file mode 100644 index 0000000..95b2720 --- /dev/null +++ b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java @@ -0,0 +1,28 @@ +package xyz.hynse.foliaflow.util; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.Plugin; + +public class SchedulerUtil { + + private static Boolean IS_FOLIA = null; + + private static boolean tryFolia() { + try { + Bukkit.getAsyncScheduler(); + return true; + } catch (Throwable ignored) {} + return false; + } + + private static Boolean isFolia() { + if (IS_FOLIA == null) IS_FOLIA = tryFolia(); + return IS_FOLIA; + } + + public static void runLaterEntity(Entity entity, Plugin plugin, Runnable runnable, int ticks) { + if (isFolia()) entity.getScheduler().runDelayed(plugin, (task) -> runnable.run(), null, ticks); + else Bukkit.getScheduler().runTaskLater(plugin, runnable, ticks); + } +} diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index aea2833..ed7cdd5 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -10,7 +10,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityChangeBlockEvent; import org.bukkit.util.Vector; + import xyz.hynse.foliaflow.FoliaFlow; +import xyz.hynse.foliaflow.util.SchedulerUtil; import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo; @@ -35,9 +37,8 @@ public class PortalWatcher implements Listener { dummy.setVelocity(dummyVel); // Add vector seems vanilla. - dummy.getScheduler().runDelayed(FoliaFlow.instance, - task -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))), - null, + SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, + () -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))), 2 ); } From 276c1b2191a2955805d452317d198568f98729dd Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" Date: Wed, 26 Apr 2023 13:10:51 +0300 Subject: [PATCH 44/75] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4bcd469..50d61ee 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,19 @@ # FoliaFlow ![sss1](https://user-images.githubusercontent.com/125941391/231678608-9762d384-dc3a-440c-a4eb-3340cb39a3e3.png) -FoliaFlow is a Minecraft plugin that allows players to using gravity block duplication glitch again in folia (paper soon) +FoliaFlow is a Minecraft plugin that allows players to using gravity block duplication glitch again in Paper and Folia ## How is work? -Whenever a falling sand entity comes close to or hits the end portal, a new falling sand entity is summoned with a velocity that shoots it straight into the portal. However, we encountered a problem when the entity got reset by the safe teleport paper patch - it lost its velocity. To fix this, we added the velocity back when the entity was in the end. +Whenever a falling sand entity comes close to or hits the end portal, a new falling sand entity is summoned with a velocity that shoots it straight into the portal. However, we encountered a problem when the entity got reset by the safe teleport Paper patch - it lose its velocity. To fix this, we added the velocity back when the entity was in the end. ## Installation To install FoliaFlow, follow these steps: -1. Download the plugin JAR file from the [releases page](https://github.com/Hynse/FoliaFlow/releases). +1. Download the plugin JAR file from the [Modrinth](https://modrinth.com/plugin/foliaflow). 2. Copy the JAR file to the `plugins` folder of your Minecraft server. -3. Restart your server to enable the plugin. +3. Restart your server to load the plugin. ## Contributing From b6212bad982ee08f9b9b72f22478007634e6dec7 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Wed, 26 Apr 2023 18:31:31 +0700 Subject: [PATCH 45/75] version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7ad4948..eab25be 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "2.0" +version = "2.1" repositories { mavenCentral() From a370af7eb539c9a576cd4480f79aff9765ea1c2b Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:24:29 +0300 Subject: [PATCH 46/75] Vanilla parity fix on Folia --- .../java/xyz/hynse/foliaflow/util/SchedulerUtil.java | 2 +- .../java/xyz/hynse/foliaflow/watcher/PortalWatcher.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java index 95b2720..52c4038 100644 --- a/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java +++ b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java @@ -16,7 +16,7 @@ public class SchedulerUtil { return false; } - private static Boolean isFolia() { + public static Boolean isFolia() { if (IS_FOLIA == null) IS_FOLIA = tryFolia(); return IS_FOLIA; } diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index ed7cdd5..a2202ba 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -25,7 +25,7 @@ public class PortalWatcher implements Listener { Vector vel = entity.getVelocity(); Block movingTo = getBlockMovingTo(loc, vel); - if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ + if(movingTo.getType() == Material.END_PORTAL){ Location spawnLoc = movingTo.getLocation(); spawnLoc.add(0.5, 0.5, 0.5); @@ -37,8 +37,11 @@ public class PortalWatcher implements Listener { dummy.setVelocity(dummyVel); // Add vector seems vanilla. - SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, - () -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))), + SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { + // Portal teleportation on Folia is a bit below vanilla, so we teleport it above + if (SchedulerUtil.isFolia()) dummy.teleportAsync(dummy.getLocation().add(0, 0.5, 0)); + dummy.setVelocity(dummyVel.add(new Vector(0, 0.2, 0))); + }, 2 ); } From cfa36f99e5e593ea374c499d978cc8e2857c59a5 Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:24:29 +0300 Subject: [PATCH 47/75] Vanilla parity fix on Folia --- .../java/xyz/hynse/foliaflow/util/SchedulerUtil.java | 2 +- .../xyz/hynse/foliaflow/watcher/PortalWatcher.java | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java index 95b2720..52c4038 100644 --- a/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java +++ b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java @@ -16,7 +16,7 @@ public class SchedulerUtil { return false; } - private static Boolean isFolia() { + public static Boolean isFolia() { if (IS_FOLIA == null) IS_FOLIA = tryFolia(); return IS_FOLIA; } diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index ed7cdd5..b642a4d 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -25,7 +25,7 @@ public class PortalWatcher implements Listener { Vector vel = entity.getVelocity(); Block movingTo = getBlockMovingTo(loc, vel); - if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ + if(movingTo.getType() == Material.END_PORTAL){ Location spawnLoc = movingTo.getLocation(); spawnLoc.add(0.5, 0.5, 0.5); @@ -33,12 +33,14 @@ public class PortalWatcher implements Listener { Vector dummyVel = vel.clone(); dummyVel.setY(-dummyVel.getY()); dummyVel.multiply(1.3); // This seems vanilla. - dummyVel.add(new Vector(0, -0.2, 0)); dummy.setVelocity(dummyVel); // Add vector seems vanilla. - SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, - () -> dummy.setVelocity(dummyVel.add(new Vector(0, 0.45, 0))), + SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { + // Portal teleportation on Folia is a bit below vanilla, so we teleport it above + if (SchedulerUtil.isFolia()) dummy.teleportAsync(dummy.getLocation().add(0, 0.5, 0)); + dummy.setVelocity(dummyVel); + }, 2 ); } From 3bad24ab8911ea34db813c4c0fe1efb22c1fb339 Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:30:54 +0300 Subject: [PATCH 48/75] Delete Paper plugin (this is not a paper plugin) --- src/main/resources/paper-plugin.yml | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/main/resources/paper-plugin.yml diff --git a/src/main/resources/paper-plugin.yml b/src/main/resources/paper-plugin.yml deleted file mode 100644 index 19f50a9..0000000 --- a/src/main/resources/paper-plugin.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: FoliaFlow -version: '${version}' -main: xyz.hynse.foliaflow.FoliaFlow -api-version: 1.19 -folia-supported: true \ No newline at end of file From 452e8ceb23c3781493f6ea192e7620933b58af3a Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:31:23 +0300 Subject: [PATCH 49/75] Configurable coefficients and reload command --- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 17 ++++++++++++++ .../foliaflow/command/ReloadCommand.java | 23 +++++++++++++++++++ .../foliaflow/watcher/PortalWatcher.java | 5 ++-- src/main/resources/config.yml | 7 ++++++ src/main/resources/plugin.yml | 7 +++++- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java create mode 100644 src/main/resources/config.yml diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 2d424d3..0c53731 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,15 +1,32 @@ package xyz.hynse.foliaflow; import org.bukkit.plugin.java.JavaPlugin; + +import xyz.hynse.foliaflow.command.ReloadCommand; import xyz.hynse.foliaflow.watcher.PortalWatcher; public class FoliaFlow extends JavaPlugin { public static FoliaFlow instance; + public static double horizontalCoefficient; + public static double verticalCoefficient; @Override public void onEnable() { instance = this; + register(); + reload(); + } + + public void reload() { + saveDefaultConfig(); + reloadConfig(); + horizontalCoefficient = getConfig().getDouble("horizontal_coefficient"); + verticalCoefficient = getConfig().getDouble("vertical_coefficient"); + } + + private void register() { + getCommand("flowreload").setExecutor(new ReloadCommand()); getServer().getPluginManager().registerEvents(new PortalWatcher(), this); } } diff --git a/src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java b/src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java new file mode 100644 index 0000000..a81bd5d --- /dev/null +++ b/src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java @@ -0,0 +1,23 @@ +package xyz.hynse.foliaflow.command; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import xyz.hynse.foliaflow.FoliaFlow; + +public class ReloadCommand implements CommandExecutor { + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!sender.hasPermission("foliaflow.reload")) return true; + try { + FoliaFlow.instance.reload(); + sender.sendMessage(ChatColor.YELLOW + "FoliaFlow reloaded."); + } catch (Exception e) { + sender.sendMessage(ChatColor.RED + "Something went wrong reloading FoliaFlow, see the console for more."); + e.printStackTrace(); + } + return true; + } +} diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index b642a4d..219658e 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -17,6 +17,7 @@ import xyz.hynse.foliaflow.util.SchedulerUtil; import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo; public class PortalWatcher implements Listener { + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() != EntityType.FALLING_BLOCK) return; @@ -31,8 +32,8 @@ public class PortalWatcher implements Listener { FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); Vector dummyVel = vel.clone(); - dummyVel.setY(-dummyVel.getY()); - dummyVel.multiply(1.3); // This seems vanilla. + dummyVel.multiply(FoliaFlow.horizontalCoefficient); + dummyVel.setY(vel.getY() * FoliaFlow.verticalCoefficient); dummy.setVelocity(dummyVel); // Add vector seems vanilla. diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml new file mode 100644 index 0000000..ad63496 --- /dev/null +++ b/src/main/resources/config.yml @@ -0,0 +1,7 @@ +# Don't touch this file unless you know what you're doing +# Default values seems vanilla. +# If you find values that seems more vanilla please create a PR +# https://github.com/Hynse/FoliaFlow + +vertical_coefficient: -1.7 +horizontal_coefficient: 1.46 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 19f50a9..ff13291 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,4 +2,9 @@ name: FoliaFlow version: '${version}' main: xyz.hynse.foliaflow.FoliaFlow api-version: 1.19 -folia-supported: true \ No newline at end of file +folia-supported: true +commands: + flowreload: + description: Reload FoliaFlow + usage: / + permission: foliaflow.reload From ada248f72282f94724c29ae32c0e43ecf174bf11 Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Wed, 26 Apr 2023 21:59:44 +0300 Subject: [PATCH 50/75] Add configurable spawn height --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 2 ++ src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java | 2 +- src/main/resources/config.yml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 0c53731..3807b86 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -10,6 +10,7 @@ public class FoliaFlow extends JavaPlugin { public static FoliaFlow instance; public static double horizontalCoefficient; public static double verticalCoefficient; + public static double spawnHeight; @Override public void onEnable() { @@ -23,6 +24,7 @@ public class FoliaFlow extends JavaPlugin { reloadConfig(); horizontalCoefficient = getConfig().getDouble("horizontal_coefficient"); verticalCoefficient = getConfig().getDouble("vertical_coefficient"); + spawnHeight = getConfig().getDouble("spawn_height"); } private void register() { diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index 219658e..5e0f8f8 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -28,7 +28,7 @@ public class PortalWatcher implements Listener { if(movingTo.getType() == Material.END_PORTAL){ Location spawnLoc = movingTo.getLocation(); - spawnLoc.add(0.5, 0.5, 0.5); + spawnLoc.add(0.5, FoliaFlow.spawnHeight, 0.5); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); Vector dummyVel = vel.clone(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ad63496..c8e1daf 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,3 +5,4 @@ vertical_coefficient: -1.7 horizontal_coefficient: 1.46 +spawn_height: 0.08 From c9a8159ea8ccc2f8dc07b4b673cd0d842f199e9c Mon Sep 17 00:00:00 2001 From: "Sofiane H. Djerbi" <46628754+kugge@users.noreply.github.com> Date: Wed, 26 Apr 2023 23:41:22 +0300 Subject: [PATCH 51/75] Configurable FoliaOffset --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 2 ++ src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java | 2 +- src/main/resources/config.yml | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 3807b86..b66955b 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -11,6 +11,7 @@ public class FoliaFlow extends JavaPlugin { public static double horizontalCoefficient; public static double verticalCoefficient; public static double spawnHeight; + public static double foliaOffset; @Override public void onEnable() { @@ -25,6 +26,7 @@ public class FoliaFlow extends JavaPlugin { horizontalCoefficient = getConfig().getDouble("horizontal_coefficient"); verticalCoefficient = getConfig().getDouble("vertical_coefficient"); spawnHeight = getConfig().getDouble("spawn_height"); + foliaOffset = getConfig().getDouble("folia_offset"); } private void register() { diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index 5e0f8f8..7626f53 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -39,7 +39,7 @@ public class PortalWatcher implements Listener { // Add vector seems vanilla. SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { // Portal teleportation on Folia is a bit below vanilla, so we teleport it above - if (SchedulerUtil.isFolia()) dummy.teleportAsync(dummy.getLocation().add(0, 0.5, 0)); + if (SchedulerUtil.isFolia()) dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.foliaOffset, 0)); dummy.setVelocity(dummyVel); }, 2 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c8e1daf..2d26684 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,3 +6,4 @@ vertical_coefficient: -1.7 horizontal_coefficient: 1.46 spawn_height: 0.08 +folia_offset: 0.08 From 08df685a0ebc38514a23fd4858b0797eb9172eba Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Thu, 27 Apr 2023 04:28:01 +0700 Subject: [PATCH 52/75] set closet vanilla vaule horizontalCoefficient config base on folia or paper --- build.gradle | 4 +- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 40 ++++++++++++++++++- src/main/resources/config.yml | 7 +++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index eab25be..dede520 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "2.1" +version = "2.2" repositories { mavenCentral() @@ -37,7 +37,7 @@ processResources { def props = [version: version] inputs.properties props filteringCharset 'UTF-8' - filesMatching(['plugin.yml', 'paper-plugin.yml']) { + filesMatching('plugin.yml') { expand props } } diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index b66955b..5b0807b 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -1,12 +1,19 @@ package xyz.hynse.foliaflow; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; import xyz.hynse.foliaflow.command.ReloadCommand; +import xyz.hynse.foliaflow.util.SchedulerUtil; import xyz.hynse.foliaflow.watcher.PortalWatcher; -public class FoliaFlow extends JavaPlugin { +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +public class FoliaFlow extends JavaPlugin { + private boolean isFirstEnable = true; public static FoliaFlow instance; public static double horizontalCoefficient; public static double verticalCoefficient; @@ -17,9 +24,40 @@ public class FoliaFlow extends JavaPlugin { public void onEnable() { instance = this; register(); + if (isFirstEnable) { + isFirstEnable = false; + copyDefaultConfig(); + setInitialConfigValues(); + } reload(); } + private void copyDefaultConfig() { + File configFile = new File(getDataFolder(), "config.yml"); + if (!configFile.exists()) { + saveResource("config.yml", false); + } + } + + private void setInitialConfigValues() { + File configFile = new File(getDataFolder(), "config.yml"); + YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + InputStream defaultConfigStream = getResource("config.yml"); + YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defaultConfigStream)); + config.options().copyDefaults(true); + config.setDefaults(defaultConfig); + boolean isFolia = SchedulerUtil.isFolia(); + if (!config.contains("horizontal_coefficient")) { + double horizontalCoefficient = isFolia ? 1.499 : 1.3; + config.set("horizontal_coefficient", horizontalCoefficient); + } + try { + config.save(configFile); + } catch (IOException e) { + e.printStackTrace(); + } + } + public void reload() { saveDefaultConfig(); reloadConfig(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2d26684..fbe661d 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,7 +3,10 @@ # If you find values that seems more vanilla please create a PR # https://github.com/Hynse/FoliaFlow +# Optimize value for horizontal_coefficient +# - Folia (1.499) +# - Paper (1.3) +horizontal_coefficient: 1.499 vertical_coefficient: -1.7 -horizontal_coefficient: 1.46 spawn_height: 0.08 -folia_offset: 0.08 +folia_offset: 0.5 From 0c1ca62ccaddcf362268efea123d73908aafeaf7 Mon Sep 17 00:00:00 2001 From: Mid <125941391+MidnightTale@users.noreply.github.com> Date: Thu, 27 Apr 2023 04:45:17 +0700 Subject: [PATCH 53/75] Update README.md --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 50d61ee..57db981 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,24 @@ To install FoliaFlow, follow these steps: 2. Copy the JAR file to the `plugins` folder of your Minecraft server. 3. Restart your server to load the plugin. +## config.yml +```yml +# Don't touch this file unless you know what you're doing +# Default values seems vanilla. +# If you find values that seems more vanilla please create a PR +# https://github.com/Hynse/FoliaFlow + +# Optimize value for horizontal_coefficient +# - Folia (1.499) +# - Paper (1.3) +horizontal_coefficient: 1.499 +vertical_coefficient: -1.7 +spawn_height: 0.08 +folia_offset: 0.5 +``` + +## permissions +`foliaflow.reload` for using command `/flowreload` to reload config flies ## Contributing If you would like to contribute to FoliaFlow, feel free to submit a pull request with your changes. All contributions are welcome and appreciated. From 32393dbd3e430521ef5ff78ff11abd29d6268b83 Mon Sep 17 00:00:00 2001 From: Mid <125941391+MidnightTale@users.noreply.github.com> Date: Thu, 27 Apr 2023 04:46:07 +0700 Subject: [PATCH 54/75] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 57db981..b151dbf 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ To install FoliaFlow, follow these steps: 2. Copy the JAR file to the `plugins` folder of your Minecraft server. 3. Restart your server to load the plugin. -## config.yml +## Config flies (config.yml) ```yml # Don't touch this file unless you know what you're doing # Default values seems vanilla. @@ -31,8 +31,9 @@ spawn_height: 0.08 folia_offset: 0.5 ``` -## permissions +## Permissions `foliaflow.reload` for using command `/flowreload` to reload config flies + ## Contributing If you would like to contribute to FoliaFlow, feel free to submit a pull request with your changes. All contributions are welcome and appreciated. From 86bf7be44f2bbfcf1b3ec4822b64fdf9fcd2f40c Mon Sep 17 00:00:00 2001 From: Mid <125941391+MidnightTale@users.noreply.github.com> Date: Thu, 27 Apr 2023 05:26:13 +0700 Subject: [PATCH 55/75] Update README.md --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b151dbf..110a665 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,15 @@ -# FoliaFlow -![sss1](https://user-images.githubusercontent.com/125941391/231678608-9762d384-dc3a-440c-a4eb-3340cb39a3e3.png) - FoliaFlow is a Minecraft plugin that allows players to using gravity block duplication glitch again in Paper and Folia ## How is work? Whenever a falling sand entity comes close to or hits the end portal, a new falling sand entity is summoned with a velocity that shoots it straight into the portal. However, we encountered a problem when the entity got reset by the safe teleport Paper patch - it lose its velocity. To fix this, we added the velocity back when the entity was in the end. +## ⚠️If you using folia +And type of concreate factory collector that use piston full block to stop falling blocks. You should change to slab to prevent block early break follow picture below +### Top View +![topviewff](https://user-images.githubusercontent.com/125941391/234716000-8dfe3f57-b9a4-4340-8d1a-4e63fe2cdb91.png) +### Side View +![sideviewff](https://user-images.githubusercontent.com/125941391/234716115-f793602c-17f9-4689-9740-7ff25013eed4.png) + ## Installation From 9ef9f85bec37365a1a294c95c7cf4db723416913 Mon Sep 17 00:00:00 2001 From: Mid <125941391+MidnightTale@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:07:11 +0700 Subject: [PATCH 56/75] Create build.yml --- .github/workflows/build.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..336340c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,26 @@ +name: Build JAR + +on: + push: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Get project version + run: echo "version=$(grep '^version' build.gradle | cut -d' ' -f3 | tr -d '\"')" >> $GITHUB_ENV + - name: Build with Gradle + run: ./gradlew build -x test + - name: Publish artifact + uses: actions/upload-artifact@v2 + with: + name: FoliaFlow-${{ env.version }}-${{ github.sha }} + path: build/libs/FoliaFlow-${{ env.version }}.jar From 962d08c8a6f25a5a5b8ec3164b2ccb3e34b61366 Mon Sep 17 00:00:00 2001 From: Mid <125941391+MidnightTale@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:07:26 +0700 Subject: [PATCH 57/75] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 336340c..b535898 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,7 @@ name: Build JAR on: push: - branches: [ main ] + branches: [ master ] jobs: build: From 70c2fb1500f125b2b399e8c753cc899d966c29b1 Mon Sep 17 00:00:00 2001 From: Mid <125941391+MidnightTale@users.noreply.github.com> Date: Sun, 30 Apr 2023 18:09:22 +0700 Subject: [PATCH 58/75] Update build.yml --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b535898..17d1172 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,7 @@ jobs: uses: actions/setup-java@v2 with: java-version: '17' + distribution: 'adopt' - name: Grant execute permission for gradlew run: chmod +x gradlew - name: Get project version From b4e08f77781c18ff2de91a3a48f48f509d19cc10 Mon Sep 17 00:00:00 2001 From: kugge Date: Tue, 2 May 2023 10:43:25 +0200 Subject: [PATCH 59/75] Add +x permission to gradlew --- gradlew | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 gradlew diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From 211fd88d805c59a263229f126ba969df99fb10b0 Mon Sep 17 00:00:00 2001 From: xiaoyueyoqwq <71379165+xiaoyueyoqwq@users.noreply.github.com> Date: Sun, 4 Jun 2023 02:00:10 +0800 Subject: [PATCH 60/75] Update config.yml After testing, the -1 value solves many problems in the sand brushing process, such as momentum instability, obsidian platform problems, sand block rotation, jumping flight, etc --- src/main/resources/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fbe661d..4395b8a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -9,4 +9,4 @@ horizontal_coefficient: 1.499 vertical_coefficient: -1.7 spawn_height: 0.08 -folia_offset: 0.5 +folia_offset: -1 From f301f159e6d94de07bdedfec2b6125a47d906c14 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 29 Aug 2023 17:33:07 +0700 Subject: [PATCH 61/75] is happen on paper 1.20 build 169 teleportation is a bit below vanilla --- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 8 ++++++-- .../java/xyz/hynse/foliaflow/watcher/PortalWatcher.java | 4 ++-- src/main/resources/config.yml | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 5b0807b..358c98a 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -18,7 +18,7 @@ public class FoliaFlow extends JavaPlugin { public static double horizontalCoefficient; public static double verticalCoefficient; public static double spawnHeight; - public static double foliaOffset; + public static double TeleportOffset; @Override public void onEnable() { @@ -51,6 +51,10 @@ public class FoliaFlow extends JavaPlugin { double horizontalCoefficient = isFolia ? 1.499 : 1.3; config.set("horizontal_coefficient", horizontalCoefficient); } + if (!config.contains("teleport_offset")) { + double telportCoefficient = isFolia ? 0.5 : 6; + config.set("teleport_offset", telportCoefficient); + } try { config.save(configFile); } catch (IOException e) { @@ -64,7 +68,7 @@ public class FoliaFlow extends JavaPlugin { horizontalCoefficient = getConfig().getDouble("horizontal_coefficient"); verticalCoefficient = getConfig().getDouble("vertical_coefficient"); spawnHeight = getConfig().getDouble("spawn_height"); - foliaOffset = getConfig().getDouble("folia_offset"); + TeleportOffset = getConfig().getDouble("teleport_offset"); } private void register() { diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index 7626f53..d1117e8 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -38,8 +38,8 @@ public class PortalWatcher implements Listener { // Add vector seems vanilla. SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { - // Portal teleportation on Folia is a bit below vanilla, so we teleport it above - if (SchedulerUtil.isFolia()) dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.foliaOffset, 0)); + // Portal teleportation is a bit below vanilla, so we teleport it above (happen on paper 1.20 b169) + dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.TeleportOffset, 0)); dummy.setVelocity(dummyVel); }, 2 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 4395b8a..fafd32c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,7 +6,7 @@ # Optimize value for horizontal_coefficient # - Folia (1.499) # - Paper (1.3) -horizontal_coefficient: 1.499 +horizontal_coefficient: 1.3 vertical_coefficient: -1.7 spawn_height: 0.08 -folia_offset: -1 +teleport_offset: 0.5 From 79789db92c257391106e01bda2b92d2b83a38a41 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 29 Aug 2023 17:41:57 +0700 Subject: [PATCH 62/75] version bump --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index dede520..6dac75a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "2.2" +version = "2.3" repositories { mavenCentral() From 99b4c3d08caa042ab96cdd08f762ec6a015f796f Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 29 Aug 2023 17:46:32 +0700 Subject: [PATCH 63/75] for got to update config --- src/main/resources/config.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index fafd32c..ace57f2 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -7,6 +7,13 @@ # - Folia (1.499) # - Paper (1.3) horizontal_coefficient: 1.3 +# ----------------------------------------- + vertical_coefficient: -1.7 spawn_height: 0.08 + +# Optimize value for teleport_offset +# - Folia (0.5 or -1) +# - Paper (6) teleport_offset: 0.5 +# ----------------------------------------- \ No newline at end of file From d84aef8126e409e51828c80e0c37b184540d93f8 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 29 Aug 2023 19:09:05 +0700 Subject: [PATCH 64/75] Fix block disappear --- build.gradle | 2 +- src/main/java/xyz/hynse/foliaflow/FoliaFlow.java | 4 ++-- .../xyz/hynse/foliaflow/watcher/PortalWatcher.java | 2 +- src/main/resources/config.yml | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index 6dac75a..4600d3f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "2.3" +version = "2.3_a" repositories { mavenCentral() diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 358c98a..1530ad2 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -48,11 +48,11 @@ public class FoliaFlow extends JavaPlugin { config.setDefaults(defaultConfig); boolean isFolia = SchedulerUtil.isFolia(); if (!config.contains("horizontal_coefficient")) { - double horizontalCoefficient = isFolia ? 1.499 : 1.3; + double horizontalCoefficient = isFolia ? 1.499 : 2; config.set("horizontal_coefficient", horizontalCoefficient); } if (!config.contains("teleport_offset")) { - double telportCoefficient = isFolia ? 0.5 : 6; + double telportCoefficient = isFolia ? 0.5 : 2.4; config.set("teleport_offset", telportCoefficient); } try { diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index d1117e8..f3b6eef 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -42,7 +42,7 @@ public class PortalWatcher implements Listener { dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.TeleportOffset, 0)); dummy.setVelocity(dummyVel); }, - 2 + 4 ); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ace57f2..52ba810 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,17 +3,17 @@ # If you find values that seems more vanilla please create a PR # https://github.com/Hynse/FoliaFlow -# Optimize value for horizontal_coefficient +# Default value for horizontal_coefficient # - Folia (1.499) -# - Paper (1.3) -horizontal_coefficient: 1.3 +# - Paper (2) +horizontal_coefficient: 2 # ----------------------------------------- vertical_coefficient: -1.7 spawn_height: 0.08 -# Optimize value for teleport_offset -# - Folia (0.5 or -1) -# - Paper (6) -teleport_offset: 0.5 +# Default value for teleport_offset +# - Folia (0.5) +# - Paper (2.4) +teleport_offset: 2.4 # ----------------------------------------- \ No newline at end of file From 0a87ba80c608e6e34477a5996da8465f68ea67ea Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 28 May 2024 04:34:43 +0700 Subject: [PATCH 65/75] update 2.4 --- build.gradle | 6 +-- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 15 ++---- .../util/CheckSafeTeleportation.java | 49 +++++++++++++++++++ .../foliaflow/watcher/PortalWatcher.java | 11 ++--- src/main/resources/config.yml | 6 +-- src/main/resources/plugin.yml | 2 +- 6 files changed, 66 insertions(+), 23 deletions(-) create mode 100644 src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java diff --git a/build.gradle b/build.gradle index 4600d3f..1d9ef1a 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "2.3_a" +version = "2.4" repositories { mavenCentral() @@ -14,10 +14,10 @@ repositories { } dependencies { - compileOnly "dev.folia:folia-api:1.19.4-R0.1-SNAPSHOT" + compileOnly "dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT" } -def targetJavaVersion = 17 +def targetJavaVersion = 21 java { def javaVersion = JavaVersion.toVersion(targetJavaVersion) sourceCompatibility = javaVersion diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index 1530ad2..b1cbc6b 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -4,7 +4,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; import xyz.hynse.foliaflow.command.ReloadCommand; -import xyz.hynse.foliaflow.util.SchedulerUtil; +import xyz.hynse.foliaflow.util.CheckSafeTeleportation; import xyz.hynse.foliaflow.watcher.PortalWatcher; import java.io.File; @@ -14,11 +14,13 @@ import java.io.InputStreamReader; public class FoliaFlow extends JavaPlugin { private boolean isFirstEnable = true; + //public boolean isUnSafeTeleport = false; public static FoliaFlow instance; public static double horizontalCoefficient; public static double verticalCoefficient; public static double spawnHeight; public static double TeleportOffset; + //public static CheckSafeTeleportation checkSafeTeleportation; @Override public void onEnable() { @@ -46,15 +48,6 @@ public class FoliaFlow extends JavaPlugin { YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration(new InputStreamReader(defaultConfigStream)); config.options().copyDefaults(true); config.setDefaults(defaultConfig); - boolean isFolia = SchedulerUtil.isFolia(); - if (!config.contains("horizontal_coefficient")) { - double horizontalCoefficient = isFolia ? 1.499 : 2; - config.set("horizontal_coefficient", horizontalCoefficient); - } - if (!config.contains("teleport_offset")) { - double telportCoefficient = isFolia ? 0.5 : 2.4; - config.set("teleport_offset", telportCoefficient); - } try { config.save(configFile); } catch (IOException e) { @@ -73,6 +66,8 @@ public class FoliaFlow extends JavaPlugin { private void register() { getCommand("flowreload").setExecutor(new ReloadCommand()); +// checkSafeTeleportation = new CheckSafeTeleportation(); +// checkSafeTeleportation.updateSafeTeleportation(); getServer().getPluginManager().registerEvents(new PortalWatcher(), this); } } diff --git a/src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java b/src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java new file mode 100644 index 0000000..58940d3 --- /dev/null +++ b/src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java @@ -0,0 +1,49 @@ +package xyz.hynse.foliaflow.util; + +import org.yaml.snakeyaml.Yaml; +import xyz.hynse.foliaflow.FoliaFlow; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Map; + +import static org.bukkit.Bukkit.getServer; + +public class CheckSafeTeleportation { + + public boolean checkUnsafeEndPortalTeleportation() { + File configFile = new File(getServer().getWorldContainer(), "config/paper-global.yml"); + if (!configFile.exists()) { + FoliaFlow.instance.getLogger().warning("paper-global.yml not found!"); + return false; + } + + try (FileInputStream fis = new FileInputStream(configFile)) { + Yaml yaml = new Yaml(); + Map config = yaml.load(fis); + + Map unsupportedSettings = (Map) config.get("unsupported-settings"); + if (unsupportedSettings != null) { + Boolean setting = (Boolean) unsupportedSettings.get("allow-unsafe-end-portal-teleportation"); + return setting != null && setting; + } + } catch (IOException e) { + FoliaFlow.instance.getLogger().severe("Failed to read paper-global.yml: " + e.getMessage()); + } + + return false; + } + + +// public void updateSafeTeleportation() { +// boolean safeTeleportation = checkUnsafeEndPortalTeleportation(); +// if (safeTeleportation) { +// FoliaFlow.instance.isUnSafeTeleport = true; +// FoliaFlow.instance.getLogger().info("Unsafe End Portal Teleportation is true."); +// } else { +// FoliaFlow.instance.isUnSafeTeleport = false; +// FoliaFlow.instance.getLogger().info("Unsafe End Portal Teleportation is false."); +// } +// } +} diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index f3b6eef..22d26ec 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -36,13 +36,12 @@ public class PortalWatcher implements Listener { dummyVel.setY(vel.getY() * FoliaFlow.verticalCoefficient); dummy.setVelocity(dummyVel); - // Add vector seems vanilla. SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { - // Portal teleportation is a bit below vanilla, so we teleport it above (happen on paper 1.20 b169) - dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.TeleportOffset, 0)); - dummy.setVelocity(dummyVel); - }, - 4 + // Portal teleportation is a bit below vanilla, so we teleport it above + dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.TeleportOffset, 0)); + dummy.setVelocity(dummyVel); + }, + 2 ); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 52ba810..6c9c6cb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -6,7 +6,7 @@ # Default value for horizontal_coefficient # - Folia (1.499) # - Paper (2) -horizontal_coefficient: 2 +horizontal_coefficient: 1.499 # ----------------------------------------- vertical_coefficient: -1.7 @@ -15,5 +15,5 @@ spawn_height: 0.08 # Default value for teleport_offset # - Folia (0.5) # - Paper (2.4) -teleport_offset: 2.4 -# ----------------------------------------- \ No newline at end of file +teleport_offset: 0.5 +# ----------------------------------------- diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ff13291..ea45e43 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: FoliaFlow version: '${version}' main: xyz.hynse.foliaflow.FoliaFlow -api-version: 1.19 +api-version: 1.20 folia-supported: true commands: flowreload: From 672f3d2b9400577edbbfff68cf6d001e0754f2d1 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Tue, 28 May 2024 04:37:37 +0700 Subject: [PATCH 66/75] change to java 17 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1d9ef1a..23888f7 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,7 @@ dependencies { compileOnly "dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT" } -def targetJavaVersion = 21 +def targetJavaVersion = 17 java { def javaVersion = JavaVersion.toVersion(targetJavaVersion) sourceCompatibility = javaVersion From 1f26c62b31b15479998bc06b32d35dd8acfc1c34 Mon Sep 17 00:00:00 2001 From: MidnightTale <125941391+MidnightTale@users.noreply.github.com> Date: Tue, 28 May 2024 04:59:00 +0700 Subject: [PATCH 67/75] Update README.md --- README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 110a665..e37586b 100644 --- a/README.md +++ b/README.md @@ -26,13 +26,20 @@ To install FoliaFlow, follow these steps: # If you find values that seems more vanilla please create a PR # https://github.com/Hynse/FoliaFlow -# Optimize value for horizontal_coefficient +# Default value for horizontal_coefficient # - Folia (1.499) -# - Paper (1.3) +# - Paper (2) horizontal_coefficient: 1.499 +# ----------------------------------------- + vertical_coefficient: -1.7 spawn_height: 0.08 -folia_offset: 0.5 + +# Default value for teleport_offset +# - Folia (0.5) +# - Paper (2.4) +teleport_offset: 0.5 +# ----------------------------------------- ``` ## Permissions From d83991f02841a47e41d2c1baa0b5a3568d2ce865 Mon Sep 17 00:00:00 2001 From: MidnightTale <125941391+MidnightTale@users.noreply.github.com> Date: Fri, 31 May 2024 10:18:24 +0700 Subject: [PATCH 68/75] Update build.yml --- .github/workflows/build.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 17d1172..c98c027 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,9 +8,9 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up JDK 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: java-version: '17' distribution: 'adopt' @@ -21,7 +21,7 @@ jobs: - name: Build with Gradle run: ./gradlew build -x test - name: Publish artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: FoliaFlow-${{ env.version }}-${{ github.sha }} path: build/libs/FoliaFlow-${{ env.version }}.jar From 3d428ffcfa43cafc76d96ec32f036a5ad1f4beb2 Mon Sep 17 00:00:00 2001 From: MidnightTale <125941391+MidnightTale@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:48:26 +0700 Subject: [PATCH 69/75] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c98c027..76788cc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 17 uses: actions/setup-java@v3 with: From a2df8bbe7d2bafe3b3e4a637ba6126df72f4fccc Mon Sep 17 00:00:00 2001 From: MidnightTale <125941391+MidnightTale@users.noreply.github.com> Date: Mon, 3 Jun 2024 11:49:36 +0700 Subject: [PATCH 70/75] Update build.yml --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76788cc..7829495 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up JDK 17 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: '17' distribution: 'adopt' From 4f5818c272eb9af7727127a2650f86ceb87e8a72 Mon Sep 17 00:00:00 2001 From: MoRanYue Date: Sat, 4 Jul 2026 19:24:30 +0800 Subject: [PATCH 71/75] feat: update to 26.1.2 and use modern API --- build.gradle | 6 +-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../java/xyz/hynse/foliaflow/FoliaFlow.java | 5 -- .../foliaflow/command/ReloadCommand.java | 7 +-- .../util/CheckSafeTeleportation.java | 49 ------------------- .../hynse/foliaflow/util/SchedulerUtil.java | 14 ++++-- src/main/resources/plugin.yml | 2 +- 7 files changed, 18 insertions(+), 67 deletions(-) delete mode 100644 src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java diff --git a/build.gradle b/build.gradle index 23888f7..c90e10f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "2.4" +version = "3.0" repositories { mavenCentral() @@ -14,10 +14,10 @@ repositories { } dependencies { - compileOnly "dev.folia:folia-api:1.20.4-R0.1-SNAPSHOT" + compileOnly "io.papermc.paper:paper-api:26.1.2.build.+" } -def targetJavaVersion = 17 +def targetJavaVersion = 25 java { def javaVersion = JavaVersion.toVersion(targetJavaVersion) sourceCompatibility = javaVersion diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2e6e589..f50f69e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java index b1cbc6b..793eb5b 100644 --- a/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java +++ b/src/main/java/xyz/hynse/foliaflow/FoliaFlow.java @@ -4,7 +4,6 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; import xyz.hynse.foliaflow.command.ReloadCommand; -import xyz.hynse.foliaflow.util.CheckSafeTeleportation; import xyz.hynse.foliaflow.watcher.PortalWatcher; import java.io.File; @@ -14,13 +13,11 @@ import java.io.InputStreamReader; public class FoliaFlow extends JavaPlugin { private boolean isFirstEnable = true; - //public boolean isUnSafeTeleport = false; public static FoliaFlow instance; public static double horizontalCoefficient; public static double verticalCoefficient; public static double spawnHeight; public static double TeleportOffset; - //public static CheckSafeTeleportation checkSafeTeleportation; @Override public void onEnable() { @@ -66,8 +63,6 @@ public class FoliaFlow extends JavaPlugin { private void register() { getCommand("flowreload").setExecutor(new ReloadCommand()); -// checkSafeTeleportation = new CheckSafeTeleportation(); -// checkSafeTeleportation.updateSafeTeleportation(); getServer().getPluginManager().registerEvents(new PortalWatcher(), this); } } diff --git a/src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java b/src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java index a81bd5d..9ab517b 100644 --- a/src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java +++ b/src/main/java/xyz/hynse/foliaflow/command/ReloadCommand.java @@ -1,6 +1,7 @@ package xyz.hynse.foliaflow.command; -import org.bukkit.ChatColor; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -13,9 +14,9 @@ public class ReloadCommand implements CommandExecutor { if (!sender.hasPermission("foliaflow.reload")) return true; try { FoliaFlow.instance.reload(); - sender.sendMessage(ChatColor.YELLOW + "FoliaFlow reloaded."); + sender.sendMessage(Component.text("FoliaFlow reloaded.").color(NamedTextColor.YELLOW)); } catch (Exception e) { - sender.sendMessage(ChatColor.RED + "Something went wrong reloading FoliaFlow, see the console for more."); + sender.sendMessage(Component.text("Something went wrong reloading FoliaFlow, see the console for more.").color(NamedTextColor.RED)); e.printStackTrace(); } return true; diff --git a/src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java b/src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java deleted file mode 100644 index 58940d3..0000000 --- a/src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java +++ /dev/null @@ -1,49 +0,0 @@ -package xyz.hynse.foliaflow.util; - -import org.yaml.snakeyaml.Yaml; -import xyz.hynse.foliaflow.FoliaFlow; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Map; - -import static org.bukkit.Bukkit.getServer; - -public class CheckSafeTeleportation { - - public boolean checkUnsafeEndPortalTeleportation() { - File configFile = new File(getServer().getWorldContainer(), "config/paper-global.yml"); - if (!configFile.exists()) { - FoliaFlow.instance.getLogger().warning("paper-global.yml not found!"); - return false; - } - - try (FileInputStream fis = new FileInputStream(configFile)) { - Yaml yaml = new Yaml(); - Map config = yaml.load(fis); - - Map unsupportedSettings = (Map) config.get("unsupported-settings"); - if (unsupportedSettings != null) { - Boolean setting = (Boolean) unsupportedSettings.get("allow-unsafe-end-portal-teleportation"); - return setting != null && setting; - } - } catch (IOException e) { - FoliaFlow.instance.getLogger().severe("Failed to read paper-global.yml: " + e.getMessage()); - } - - return false; - } - - -// public void updateSafeTeleportation() { -// boolean safeTeleportation = checkUnsafeEndPortalTeleportation(); -// if (safeTeleportation) { -// FoliaFlow.instance.isUnSafeTeleport = true; -// FoliaFlow.instance.getLogger().info("Unsafe End Portal Teleportation is true."); -// } else { -// FoliaFlow.instance.isUnSafeTeleport = false; -// FoliaFlow.instance.getLogger().info("Unsafe End Portal Teleportation is false."); -// } -// } -} diff --git a/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java index 52c4038..5883390 100644 --- a/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java +++ b/src/main/java/xyz/hynse/foliaflow/util/SchedulerUtil.java @@ -10,10 +10,11 @@ public class SchedulerUtil { private static boolean tryFolia() { try { - Bukkit.getAsyncScheduler(); + Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); return true; - } catch (Throwable ignored) {} - return false; + } catch (ClassNotFoundException e) { + return false; + } } public static Boolean isFolia() { @@ -22,7 +23,10 @@ public class SchedulerUtil { } public static void runLaterEntity(Entity entity, Plugin plugin, Runnable runnable, int ticks) { - if (isFolia()) entity.getScheduler().runDelayed(plugin, (task) -> runnable.run(), null, ticks); - else Bukkit.getScheduler().runTaskLater(plugin, runnable, ticks); + if (isFolia()) { + entity.getScheduler().runDelayed(plugin, (task) -> runnable.run(), null, ticks); + } else { + Bukkit.getScheduler().runTaskLater(plugin, runnable, ticks); + } } } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ea45e43..5f4c253 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: FoliaFlow version: '${version}' main: xyz.hynse.foliaflow.FoliaFlow -api-version: 1.20 +api-version: '26.1.2' folia-supported: true commands: flowreload: From 6b4d10faf3e9af135f76fa70a6ba655b3222525c Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 3 Aug 2026 11:17:19 +0700 Subject: [PATCH 72/75] bump to 3.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 23888f7..722f80f 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ plugins { } group = 'xyz.hynse' -version = "2.4" +version = "3.0" repositories { mavenCentral() From 8acab4479751258691fdaa1cdb4fdc524a21c368 Mon Sep 17 00:00:00 2001 From: MidnightTale Date: Mon, 3 Aug 2026 16:46:04 +0700 Subject: [PATCH 73/75] fix: detect vertical falling blocks entering end portals --- .gitignore | 1 + .../foliaflow/watcher/PortalWatcher.java | 57 +++++++++++++------ 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 3c37caf..cdb5be5 100644 --- a/.gitignore +++ b/.gitignore @@ -116,3 +116,4 @@ run/ # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) !gradle-wrapper.jar +niri-rpc/ diff --git a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java index 22d26ec..581b07b 100644 --- a/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java +++ b/src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java @@ -9,6 +9,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.EntityPortalEnterEvent; import org.bukkit.util.Vector; import xyz.hynse.foliaflow.FoliaFlow; @@ -18,31 +19,55 @@ import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo; public class PortalWatcher implements Listener { + private static final String DUPE_TAG = "foliaflow_dupe"; + @EventHandler public void onFallingBlockToBlock(EntityChangeBlockEvent e){ if(e.getEntityType() != EntityType.FALLING_BLOCK) return; Entity entity = e.getEntity(); + if(entity.getScoreboardTags().contains(DUPE_TAG)) return; Location loc = entity.getLocation(); Vector vel = entity.getVelocity(); Block movingTo = getBlockMovingTo(loc, vel); if(movingTo.getType() == Material.END_PORTAL){ - Location spawnLoc = movingTo.getLocation(); - spawnLoc.add(0.5, FoliaFlow.spawnHeight, 0.5); - - FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); - Vector dummyVel = vel.clone(); - dummyVel.multiply(FoliaFlow.horizontalCoefficient); - dummyVel.setY(vel.getY() * FoliaFlow.verticalCoefficient); - dummy.setVelocity(dummyVel); - - SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { - // Portal teleportation is a bit below vanilla, so we teleport it above - dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.TeleportOffset, 0)); - dummy.setVelocity(dummyVel); - }, - 2 - ); + spawnDupe(entity, movingTo, false); } } + + @EventHandler + public void onPortalEnter(EntityPortalEnterEvent e){ + if(e.getEntityType() != EntityType.FALLING_BLOCK) return; + Entity entity = e.getEntity(); + if(entity.getScoreboardTags().contains(DUPE_TAG)) return; + Block portal = e.getLocation().getBlock(); + + if(portal.getType() == Material.END_PORTAL && portal.getRelative(0, -1, 0).getType().name().endsWith("_FENCE")){ + spawnDupe(entity, portal, true); + } + } + + private void spawnDupe(Entity entity, Block portal, boolean passThrough){ + Location spawnLoc = portal.getLocation(); + spawnLoc.add(0.5, FoliaFlow.spawnHeight, 0.5); + + FallingBlock dummy = entity.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); + dummy.addScoreboardTag(DUPE_TAG); + Vector dummyVel = entity.getVelocity().clone(); + dummyVel.multiply(FoliaFlow.horizontalCoefficient); + if(passThrough){ + dummyVel.setY(entity.getVelocity().getY()); + } else { + dummyVel.setY(entity.getVelocity().getY() * FoliaFlow.verticalCoefficient); + } + dummy.setVelocity(dummyVel); + + SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { + // Portal teleportation is a bit below vanilla, so we teleport it above + dummy.teleportAsync(dummy.getLocation().add(0, FoliaFlow.TeleportOffset, 0)); + dummy.setVelocity(dummyVel); + }, + 2 + ); + } } From b9c87885de5d054b4bed96cc9bc4f32b40f397a6 Mon Sep 17 00:00:00 2001 From: dvorakmortonxd Date: Tue, 4 Aug 2026 21:20:10 +0200 Subject: [PATCH 74/75] updated to 26.1.2 please work --- src/main/resources/plugin.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ea45e43..fb90a09 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: FoliaFlow version: '${version}' main: xyz.hynse.foliaflow.FoliaFlow -api-version: 1.20 +api-version: 26.1.2 folia-supported: true commands: flowreload: From 99af88ee8266d4ee73c3633977164f9e98ecb7be Mon Sep 17 00:00:00 2001 From: dvorakmortonxd Date: Tue, 4 Aug 2026 21:22:05 +0200 Subject: [PATCH 75/75] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e37586b..e1bf6f5 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +# THIS IS NOT MY PLUGIN, I JUST EDITED ONE SINGLE LINE IN PLUGIN.YML, THE ORIGINAL IS AT: https://github.com/MidnightTale/FoliaFlow + FoliaFlow is a Minecraft plugin that allows players to using gravity block duplication glitch again in Paper and Folia ## How is work?