check on spawn for fastest detection
This commit is contained in:
parent
d8fdd77879
commit
0e49b85358
1 changed files with 31 additions and 24 deletions
|
|
@ -3,11 +3,11 @@ package xyz.hynse.foliaflow;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
|
||||||
import org.bukkit.entity.FallingBlock;
|
import org.bukkit.entity.FallingBlock;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||||
|
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
|
@ -40,32 +40,39 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFallingBlockToBlock(EntityChangeBlockEvent e) {
|
public void onEntitySpawn(EntitySpawnEvent event) {
|
||||||
if (e.getEntityType() == EntityType.FALLING_BLOCK) {
|
Entity entity = event.getEntity();
|
||||||
Entity entity = e.getEntity();
|
if (!(entity instanceof FallingBlock)) {
|
||||||
Location loc = entity.getLocation();
|
return;
|
||||||
Vector vel = entity.getVelocity();
|
}
|
||||||
Block movingTo = getBlockMovingTo(loc, vel);
|
if (entity.getWorld().getEnvironment() != World.Environment.THE_END) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
debug("Falling block spawned in the end at location " + entity.getLocation());
|
||||||
|
Location loc = entity.getLocation();
|
||||||
|
Vector vel = entity.getVelocity();
|
||||||
|
Block movingTo = getBlockMovingTo(loc, vel);
|
||||||
|
|
||||||
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.5);
|
spawnLoc.setY(spawnLoc.getY() + 0.5);
|
||||||
spawnLoc.setZ(spawnLoc.getZ() + 0.5);
|
spawnLoc.setZ(spawnLoc.getZ() + 0.5);
|
||||||
|
|
||||||
debug("Creating dummy falling block at location " + spawnLoc + " with velocity " + vel);
|
debug("Creating dummy falling block at location " + spawnLoc + " with velocity " + vel);
|
||||||
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.setY(-dummyVel.getY());
|
||||||
dummyVel.multiply(new Vector(2, 2, 2));
|
dummyVel.multiply(new Vector(2, 2, 2));
|
||||||
|
|
||||||
dummyVel.add(new Vector(0, -0.2, 0));
|
dummyVel.add(new Vector(0, -0.2, 0));
|
||||||
|
|
||||||
dummy.setVelocity(dummyVel);
|
dummy.setVelocity(dummyVel);
|
||||||
}
|
entity.remove();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
public void onEntityChangeBlock(EntityChangeBlockEvent event) {
|
||||||
Entity entity = event.getEntity();
|
Entity entity = event.getEntity();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue