Merge pull request #16 from KaiijuMC/master

Add configurable coefficients and reload command
This commit is contained in:
Mid 2023-04-27 01:44:44 +07:00 • committed by GitHub
commit 5ca0f1ec39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 10 deletions

View file

@ -1,15 +1,32 @@
package xyz.hynse.foliaflow; package xyz.hynse.foliaflow;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import xyz.hynse.foliaflow.command.ReloadCommand;
import xyz.hynse.foliaflow.watcher.PortalWatcher; import xyz.hynse.foliaflow.watcher.PortalWatcher;
public class FoliaFlow extends JavaPlugin { public class FoliaFlow extends JavaPlugin {
public static FoliaFlow instance; public static FoliaFlow instance;
public static double horizontalCoefficient;
public static double verticalCoefficient;
@Override @Override
public void onEnable() { public void onEnable() {
instance = this; 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); getServer().getPluginManager().registerEvents(new PortalWatcher(), this);
} }
} }

View file

@ -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;
}
}

View file

@ -17,6 +17,7 @@ import xyz.hynse.foliaflow.util.SchedulerUtil;
import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo; import static xyz.hynse.foliaflow.util.VelocityUtil.getBlockMovingTo;
public class PortalWatcher implements Listener { public class PortalWatcher implements Listener {
@EventHandler @EventHandler
public void onFallingBlockToBlock(EntityChangeBlockEvent e){ public void onFallingBlockToBlock(EntityChangeBlockEvent e){
if(e.getEntityType() != EntityType.FALLING_BLOCK) return; if(e.getEntityType() != EntityType.FALLING_BLOCK) return;
@ -31,16 +32,15 @@ public class PortalWatcher implements Listener {
FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData());
Vector dummyVel = vel.clone(); Vector dummyVel = vel.clone();
dummyVel.setY(-dummyVel.getY()); dummyVel.multiply(FoliaFlow.horizontalCoefficient);
dummyVel.multiply(1.3); // This seems vanilla. dummyVel.setY(vel.getY() * FoliaFlow.verticalCoefficient);
dummyVel.add(new Vector(0, -0.2, 0));
dummy.setVelocity(dummyVel); dummy.setVelocity(dummyVel);
// Add vector seems vanilla. // Add vector seems vanilla.
SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> { SchedulerUtil.runLaterEntity(dummy, FoliaFlow.instance, () -> {
// Portal teleportation on Folia is a bit below vanilla, so we teleport it above // 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, 0.5, 0));
dummy.setVelocity(dummyVel.add(new Vector(0, 0.2, 0))); dummy.setVelocity(dummyVel);
}, },
2 2
); );

View file

@ -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

View file

@ -1,5 +0,0 @@
name: FoliaFlow
version: '${version}'
main: xyz.hynse.foliaflow.FoliaFlow
api-version: 1.19
folia-supported: true

View file

@ -3,3 +3,8 @@ version: '${version}'
main: xyz.hynse.foliaflow.FoliaFlow main: xyz.hynse.foliaflow.FoliaFlow
api-version: 1.19 api-version: 1.19
folia-supported: true folia-supported: true
commands:
flowreload:
description: Reload FoliaFlow
usage: /<command>
permission: foliaflow.reload