entity delay scheduler

This commit is contained in:
MidnightTale 2023-04-11 17:54:35 +07:00
commit 837f746d1b

View file

@ -1,6 +1,7 @@
package xyz.hynse.bbsdfia;
import io.papermc.paper.threadedregions.scheduler.EntityScheduler;
import io.papermc.paper.threadedregions.scheduler.ScheduledTask;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
@ -11,8 +12,11 @@ import org.bukkit.entity.FallingBlock;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityChangeBlockEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.function.Consumer;
@ -39,20 +43,49 @@ public class Bbsdfia extends JavaPlugin implements Listener {
Block movingTo = getBlockMovingTo(loc, vel);
Location loc2 = new Location(Bukkit.getWorld("world_the_end"), 100, 50, 0);
if(movingTo != null && movingTo.getType() == Material.END_PORTAL){
/*
World world = Bukkit.getServer().getWorld("world");
Location spawnLoc = new Location(world, 100, 50, 0);
*/
FallingBlock dummy = (FallingBlock) loc2.getWorld().spawnFallingBlock(loc2, ((FallingBlock) entity).getBlockData()).getScheduler().run(plu);
//Entity Scheduler Task
EntityScheduler scheduler = new EntityScheduler() {
@Override
public boolean execute(@NotNull Plugin plugin, @NotNull Runnable run, @Nullable Runnable retired, long delay) {
return false;
}
@Override
public @Nullable ScheduledTask run(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task, @Nullable Runnable retired) {
return null;
}
@Override
public @Nullable ScheduledTask runDelayed(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task, @Nullable Runnable retired, long delayTicks) {
return null;
}
@Override
public @Nullable ScheduledTask runAtFixedRate(@NotNull Plugin plugin, @NotNull Consumer<ScheduledTask> task, @Nullable Runnable retired, long initialDelayTicks, long periodTicks) {
return null;
}
};
scheduler.runDelayed(this, scheduledTask -> {
//spawn new falling block in the end dimension and have same properties entity type and material same form entity that detect near end portal
FallingBlock dummy = (FallingBlock) loc2.getWorld().spawnEntity(loc2, EntityType.FALLING_BLOCK);
Vector dummyVel = vel.clone();
dummyVel.setY(-dummyVel.getY());
dummyVel.multiply(new Vector(2, 2, 2)); // double the velocity
// add a constant downward velocity to simulate gravity
dummyVel.add(new Vector(0, 0.3, 0));
dummy.setVelocity(dummyVel);
//velocity to north
dummy.setVelocity(new Vector(0, 1, 0));
//velocity to south
dummy.setVelocity(new Vector(0, -1, 0));
//velocity to east
dummy.setVelocity(new Vector(1, 0, 0));
//velocity to west
dummy.setVelocity(new Vector(-1, 0, 0));
},null,1);
}
}