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: