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 1/3] 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 2/3] 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 3/3] 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