problems with entities not loading correctly
This commit is contained in:
parent
79790dae8d
commit
c6f0c0ba4b
src/main/java/eu/mhsl/minecraft/pixelblocks
@ -36,6 +36,7 @@ public final class PixelBlocks extends JavaPlugin {
|
||||
getServer().getPluginManager().registerEvents(new BlockExplodeListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerPortalListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new InventoryListener(), this);
|
||||
// getServer().getPluginManager().registerEvents(new ChunkLoadListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerChangeWorldListener(), this);
|
||||
|
||||
Objects.requireNonNull(getCommand("createpixelblock")).setExecutor(new CreatePixelBlockCommand());
|
||||
|
@ -21,7 +21,7 @@ public class ExitWorldCommand implements CommandExecutor {
|
||||
|
||||
if(!Arrays.stream(standardWorlds).toList().contains(playerWorld)) {
|
||||
|
||||
List<PixelBlock> ownedBlocks = PixelBlock.placedBlocks.stream()
|
||||
List<PixelBlock> ownedBlocks = PixelBlock.placedPixelBlocks.stream()
|
||||
.filter(pixelBlock -> pixelBlock.ownerUID.equals(p.getUniqueId()))
|
||||
.sorted(Comparator.comparing(pixelBlock -> pixelBlock.lastEntryTime))
|
||||
.toList();
|
||||
|
@ -12,7 +12,7 @@ public class BlockBreakListener implements Listener {
|
||||
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromWorld(event.getBlock().getLocation().getWorld());
|
||||
|
||||
assert pixelBlock != null;
|
||||
pixelBlock.handleBlockBreak(event, true);
|
||||
pixelBlock.handleBlockBreak(event, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public class BlockPlaceListener implements Listener {
|
||||
PixelBlock pixelBlock = PixelBlock.getPixelBlockFromWorld(event.getBlock().getLocation().getWorld());
|
||||
|
||||
assert pixelBlock != null;
|
||||
pixelBlock.handleBlockPlace(event, true);
|
||||
pixelBlock.handleBlockPlace(event, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
|
||||
public class ChunkLoadListener implements Listener {
|
||||
@EventHandler
|
||||
static void onChunkLoad(ChunkLoadEvent event) {
|
||||
PixelBlock.placedPixelBlocks.forEach(pixelBlock -> {
|
||||
if(pixelBlock.hitbox == null) {
|
||||
pixelBlock.update();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
static void onChunkUnload(ChunkUnloadEvent event) {
|
||||
PixelBlock.placedPixelBlocks.forEach(pixelBlock -> {
|
||||
if(pixelBlock.hitbox != null) {
|
||||
pixelBlock.clearEntities();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,17 +1,20 @@
|
||||
package eu.mhsl.minecraft.pixelblocks.listeners;
|
||||
|
||||
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static eu.mhsl.minecraft.pixelblocks.PixelBlocks.plugin;
|
||||
|
||||
public class PlayerChangeWorldListener implements Listener {
|
||||
@EventHandler
|
||||
static void onPlayerChangeWorld(PlayerChangedWorldEvent event) {
|
||||
if(CommonEventHandlers.isInPixelWorld(event.getFrom())) {
|
||||
Objects.requireNonNull(PixelBlock.getPixelBlockFromWorld(event.getFrom())).update();
|
||||
Bukkit.getScheduler().runTaskLater(plugin, () -> Objects.requireNonNull(PixelBlock.getPixelBlockFromWorld(event.getFrom())).update(), 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import java.util.*;
|
||||
import static eu.mhsl.minecraft.pixelblocks.PixelBlocks.*;
|
||||
|
||||
public class PixelBlock {
|
||||
public static List<PixelBlock> placedBlocks = new ArrayList<>();
|
||||
public static List<PixelBlock> placedPixelBlocks = new ArrayList<>();
|
||||
public static float hitboxOffset = 0.005F;
|
||||
public static int worldGrassBorderWidth = 5;
|
||||
public static int pixelsPerBlock = 16;
|
||||
@ -34,7 +34,6 @@ public class PixelBlock {
|
||||
public UUID uuid;
|
||||
|
||||
public PixelBlock(Location originLocation, UUID ownerUID, UUID blockUUID) {
|
||||
PixelBlock.placedBlocks.add(this);
|
||||
this.uuid = blockUUID;
|
||||
|
||||
this.pixelBlockLocation = originLocation.toBlockLocation();
|
||||
@ -47,7 +46,7 @@ public class PixelBlock {
|
||||
|
||||
public static PixelBlock getPixelBlockFromWorld(World world) {
|
||||
String blockUUID = Arrays.stream(world.getName().split(pathSeparator)).toList().getLast();
|
||||
List<PixelBlock> pixelBlocks = placedBlocks.stream().filter(block -> block.uuid.toString().equals(blockUUID)).toList();
|
||||
List<PixelBlock> pixelBlocks = placedPixelBlocks.stream().filter(block -> block.uuid.toString().equals(blockUUID)).toList();
|
||||
|
||||
if(!pixelBlocks.isEmpty()) {
|
||||
return pixelBlocks.getFirst();
|
||||
@ -61,7 +60,7 @@ public class PixelBlock {
|
||||
loc.setPitch(0);
|
||||
loc.setYaw(0);
|
||||
|
||||
List<PixelBlock> pixelBlocks = placedBlocks.stream()
|
||||
List<PixelBlock> pixelBlocks = placedPixelBlocks.stream()
|
||||
.filter(block -> block.pixelBlockLocation.equals(loc))
|
||||
.toList();
|
||||
|
||||
@ -289,7 +288,7 @@ public class PixelBlock {
|
||||
|
||||
public void update() {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
clearEntities();
|
||||
this.clearEntities();
|
||||
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
@ -336,17 +335,22 @@ public class PixelBlock {
|
||||
}
|
||||
|
||||
public void clearEntities() {
|
||||
System.out.println("Clear Entities");
|
||||
|
||||
if(!pixels.isEmpty()) {
|
||||
System.out.println("Clear Pixels");
|
||||
this.pixels.forEach(Pixel::remove);
|
||||
pixels.clear();
|
||||
this.pixels.clear();
|
||||
}
|
||||
|
||||
if(hitbox != null) {
|
||||
hitbox.remove();
|
||||
hitbox = null;
|
||||
System.out.println("Clear Hitbox");
|
||||
this.hitbox.remove();
|
||||
this.hitbox = null;
|
||||
}
|
||||
|
||||
if(barrier != null) {
|
||||
System.out.println("Clear Barrier");
|
||||
this.barrier.remove();
|
||||
this.barrier = null;
|
||||
}
|
||||
@ -361,6 +365,7 @@ public class PixelBlock {
|
||||
this.pixelBlockLocation = newLocation;
|
||||
update();
|
||||
dataBase.savePixelBlock(this);
|
||||
placedPixelBlocks.add(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -370,7 +375,7 @@ public class PixelBlock {
|
||||
dataBase.removePixelBlock(this);
|
||||
|
||||
clearEntities();
|
||||
placedBlocks.remove(this);
|
||||
placedPixelBlocks.remove(this);
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user