Merge pull request #10 from Hynse/master

upstream
This commit is contained in:
Mid 2023-04-25 17:27:06 +07:00 • committed by GitHub
commit 9cbe95bfbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 75 deletions

View file

@ -2,10 +2,8 @@ plugins {
id 'java' id 'java'
} }
def loader = 'folia'
def server = '1.19.4'
group = 'xyz.hynse' group = 'xyz.hynse'
version = "1.4-${server}-${loader}" version = "1.6"
repositories { repositories {
mavenCentral() mavenCentral()
@ -13,10 +11,6 @@ repositories {
name = "papermc-repo" name = "papermc-repo"
url = "https://repo.papermc.io/repository/maven-public/" url = "https://repo.papermc.io/repository/maven-public/"
} }
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
}
} }
dependencies { dependencies {

View file

@ -1,6 +1,7 @@
package xyz.hynse.foliaflow; package xyz.hynse.foliaflow;
import io.papermc.paper.threadedregions.scheduler.AsyncScheduler; 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.RegionScheduler;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask; import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.*; import org.bukkit.*;
@ -16,10 +17,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit;
import static org.bukkit.Bukkit.getScheduler;
public class FoliaFlow extends JavaPlugin implements Listener { public class FoliaFlow extends JavaPlugin implements Listener {
private final double vh = 0.2; private final double vh = 0.2;
private final double vt = 0.8; private final double vt = 0.8;
@ -31,20 +28,13 @@ public class FoliaFlow extends JavaPlugin implements Listener {
private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4}; private final Vector[] velocities = {velocity1, velocity2, velocity3, velocity4};
private int counter = 0; private int counter = 0;
private final Set<Location> movingBlocks = new HashSet<>(); private final Set<Location> movingBlocks = new HashSet<>();
private final Map<Entity, Vector> velocitiesMap = new HashMap<>(); // Create a map to store velocities private final Map<Entity, Vector> velocitiesMap = new HashMap<>();
private ScheduledTask task; private ScheduledTask task;
private ScheduledTask blockktask; private ScheduledTask blockktask;
@Override @Override
public void onEnable() { public void onEnable() {
super.onEnable(); super.onEnable();
// 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) -> { 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); Block block = Objects.requireNonNull(Bukkit.getWorld("world_the_end")).getBlockAt(100, 48, 0);
if (block.getType() == Material.OBSIDIAN) { if (block.getType() == Material.OBSIDIAN) {
@ -52,58 +42,46 @@ public class FoliaFlow extends JavaPlugin implements Listener {
Slab slab = (Slab) block.getBlockData(); Slab slab = (Slab) block.getBlockData();
slab.setType(Slab.Type.BOTTOM); slab.setType(Slab.Type.BOTTOM);
block.setBlockData(slab); block.setBlockData(slab);
} }
}, 1L, 1L); }, 1L, 1L);
} catch (NullPointerException block) {
getServer().getLogger().info("Region Scheduler erorr (likly chunky it not load)"); GlobalRegionScheduler scheduler = this.getServer().getGlobalRegionScheduler();
}
AsyncScheduler scheduler = getServer().getAsyncScheduler(); task = scheduler.runAtFixedRate(this, (scheduledTask) -> {
task = scheduler.runAtFixedRate(this, (scheduledTask) -> getScheduler().runTask(this, () -> { for (World world : Bukkit.getWorlds()) {
for (World world : Bukkit.getWorlds()) { for (Entity entity : world.getEntities()) {
for (Entity entity : world.getEntities()) { if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) {
if (entity.getType() == EntityType.FALLING_BLOCK && entity.getWorld().getEnvironment() == World.Environment.THE_END) { Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0);
Location centerLoc = new Location(entity.getWorld(), 100, 48.5, 0); Location loc = entity.getLocation();
Location loc = entity.getLocation(); if (loc.distance(centerLoc) <= 1) {
if (loc.distance(centerLoc) <= 1) { if (!velocitiesMap.containsKey(entity)) {
// Set the initial velocity of the falling block only if it doesn't have a velocity stored int index = counter % 4;
if (!velocitiesMap.containsKey(entity)) { counter++;
try { Vector velocity = velocities[index];
int index = counter % 4; entity.setVelocity(velocity);
counter++; velocitiesMap.put(entity, velocity);
Vector velocity = velocities[index]; movingBlocks.add(entity.getLocation());
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); }, 20L, 1L);
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("");
}
getServer().getPluginManager().registerEvents(this, this);
}
@Override @Override
public void onDisable() { public void onDisable() {
task.cancel();
blockktask.cancel();
super.onDisable(); super.onDisable();
} }
@EventHandler @EventHandler
public void onFallingBlockToBlock(EntityChangeBlockEvent e){ public void onFallingBlockToBlock(EntityChangeBlockEvent e){
if(e.getEntityType() == EntityType.FALLING_BLOCK){ if(e.getEntityType() == EntityType.FALLING_BLOCK){
@ -113,26 +91,26 @@ public class FoliaFlow extends JavaPlugin implements Listener {
Block movingTo = getBlockMovingTo(loc, vel); Block movingTo = getBlockMovingTo(loc, vel);
try { try {
if(movingTo != null && movingTo.getType() == Material.END_PORTAL){ if(movingTo != null && movingTo.getType() == Material.END_PORTAL){
Location spawnLoc = movingTo.getLocation(); Location spawnLoc = movingTo.getLocation();
spawnLoc.setX(spawnLoc.getX()+0.5); spawnLoc.setX(spawnLoc.getX()+0.5);
spawnLoc.setY(spawnLoc.getY()-0.25); spawnLoc.setY(spawnLoc.getY()-0.25);
spawnLoc.setZ(spawnLoc.getZ()+0.5); spawnLoc.setZ(spawnLoc.getZ()+0.5);
FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData()); FallingBlock dummy = loc.getWorld().spawnFallingBlock(spawnLoc, ((FallingBlock) entity).getBlockData());
dummy.setDropItem(true); dummy.setDropItem(true);
dummy.setHurtEntities(true); dummy.setHurtEntities(true);
dummy.setGravity(true); dummy.setGravity(true);
Vector dummyVel = vel.clone(); Vector dummyVel = vel.clone();
dummyVel.setY(-dummyVel.getY()); dummyVel.setY(-dummyVel.getY());
dummyVel.multiply(new Vector(2, 1, 2)); 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) { } catch (NullPointerException dummy) {
getServer().getLogger().info("onFallingBlockToBlock erorr (likly chunky it not load)"); getServer().getLogger().info("onFallingBlockToBlock error (likly chunky it not load)");
} }
} }
} }
@ -160,7 +138,6 @@ public class FoliaFlow extends JavaPlugin implements Listener {
case 'y' -> relative = loc.getBlock().getRelative(0, (int) Math.signum(max), 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)); 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; return relative;
} }
} }

View file

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