Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
update 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
MidnightTale committed May 27, 2024
1 parent d84aef8 commit 0a87ba8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 23 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'xyz.hynse'
version = "2.3_a"
version = "2.4"

repositories {
mavenCentral()
Expand All @@ -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
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/xyz/hynse/foliaflow/FoliaFlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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;
Expand All @@ -14,11 +14,13 @@

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() {
Expand Down Expand Up @@ -46,15 +48,6 @@ private void setInitialConfigValues() {
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) {
Expand All @@ -73,6 +66,8 @@ public void reload() {

private void register() {
getCommand("flowreload").setExecutor(new ReloadCommand());
// checkSafeTeleportation = new CheckSafeTeleportation();
// checkSafeTeleportation.updateSafeTeleportation();
getServer().getPluginManager().registerEvents(new PortalWatcher(), this);
}
}
49 changes: 49 additions & 0 deletions src/main/java/xyz/hynse/foliaflow/util/CheckSafeTeleportation.java
Original file line number Diff line number Diff line change
@@ -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<String, Object> config = yaml.load(fis);

Map<String, Object> unsupportedSettings = (Map<String, Object>) 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.");
// }
// }
}
11 changes: 5 additions & 6 deletions src/main/java/xyz/hynse/foliaflow/watcher/PortalWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ public void onFallingBlockToBlock(EntityChangeBlockEvent e){
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
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,5 +15,5 @@ spawn_height: 0.08
# Default value for teleport_offset
# - Folia (0.5)
# - Paper (2.4)
teleport_offset: 2.4
# -----------------------------------------
teleport_offset: 0.5
# -----------------------------------------
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 0a87ba8

Please sign in to comment.