chunk load my best friend
This commit is contained in:
parent
f3168eefa0
commit
cc112aeb29
1 changed files with 32 additions and 23 deletions
|
|
@ -1,6 +1,5 @@
|
|||
package xyz.hynse.foliaflow;
|
||||
|
||||
import io.papermc.paper.event.entity.EntityMoveEvent;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
|
@ -9,7 +8,7 @@ import org.bukkit.entity.FallingBlock;
|
|||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityChangeBlockEvent;
|
||||
import org.bukkit.event.entity.EntitySpawnEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
|
|
@ -54,14 +53,17 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
|||
}
|
||||
|
||||
@EventHandler
|
||||
public void onEntityMove(EntityMoveEvent event) {
|
||||
handleMove(event.getEntity().getLocation());
|
||||
public void onChunkLoad(ChunkLoadEvent event) {
|
||||
Block obsidianBlock = obsidianLocation.getBlock();
|
||||
if (event.getWorld() == endWorld && obsidianBlock.getType() == Material.OBSIDIAN) { // check if the chunk is in the end and the block is obsidian
|
||||
obsidianBlock.setType(Material.AIR); // set the block to air
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMove(Location location) {
|
||||
if (location.getWorld() == endWorld && location.distance(obsidianLocation) <= 1.0) { // check if the location is in the end and within 1 block of the obsidian platform
|
||||
Block obsidianBlock = obsidianLocation.getBlock();
|
||||
obsidianBlock.setType(Material.AIR); // set the block to air
|
||||
@EventHandler
|
||||
public void onBlockChange(org.bukkit.event.block.BlockFromToEvent event) {
|
||||
if (event.getBlock().getLocation().equals(obsidianLocation)) { // check if the block change event is for the obsidian block location
|
||||
event.setCancelled(true); // cancel the event to prevent the obsidian block from changing
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,9 +98,13 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
|||
|
||||
|
||||
@EventHandler
|
||||
public void onFallingBlockSpawn(EntitySpawnEvent e) {
|
||||
if (e.getEntityType() == EntityType.FALLING_BLOCK && e.getEntity().getWorld().getEnvironment() == World.Environment.THE_END) {
|
||||
Entity entity = e.getEntity();
|
||||
public void onChunkLoadend(ChunkLoadEvent e) {
|
||||
Chunk chunk = e.getChunk();
|
||||
World world = chunk.getWorld();
|
||||
if (world.getEnvironment() == World.Environment.THE_END) {
|
||||
// Iterate through all the entities in the chunk
|
||||
for (Entity entity : chunk.getEntities()) {
|
||||
if (entity.getType() == EntityType.FALLING_BLOCK) {
|
||||
Location loc = entity.getLocation();
|
||||
|
||||
debug("Falling block spawned at location " + loc);
|
||||
|
|
@ -113,6 +119,9 @@ public class FoliaFlow extends JavaPlugin implements Listener {
|
|||
getServer().getScheduler().runTaskLater(this, () -> movingBlocks.remove(loc.getBlock().getLocation()), 20L);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue