added logging

This commit is contained in:
Elias Müller 2024-10-05 19:24:36 +02:00
parent 39af3589e3
commit 156b7e6b61

@ -92,6 +92,8 @@ public class PixelBlock {
player.sendMessage(Component.text("Dieser Pixelblock gehört nicht dir!", NamedTextColor.RED)); player.sendMessage(Component.text("Dieser Pixelblock gehört nicht dir!", NamedTextColor.RED));
return; return;
} }
Main.plugin.getLogger().info(String.format("'%s' entered PixelBlock '%s' at %s", player.getName(), this.blockUUID, this.pixelBlockLocation.toString()));
getBlockTaskChain() getBlockTaskChain()
.async(() -> { .async(() -> {
this.lastEntryLocation = player.getLocation(); this.lastEntryLocation = player.getLocation();
@ -103,6 +105,7 @@ public class PixelBlock {
} }
public void exitBlock(@NotNull Player player) { public void exitBlock(@NotNull Player player) {
Main.plugin.getLogger().info(String.format("%s exited PixelBlock", player.getName()));
player.teleport(this.lastEntryLocation); player.teleport(this.lastEntryLocation);
} }
@ -168,52 +171,54 @@ public class PixelBlock {
public void updateEntities() { public void updateEntities() {
this.getBlockTaskChain() this.getBlockTaskChain()
.sync(this::clearEntities) .sync(this::clearEntities)
.async(() -> { .async(() -> {
for (int x = 0; x < pixelsPerBlock; x++) { for (int x = 0; x < pixelsPerBlock; x++) {
for (int y = 0; y < pixelsPerBlock; y++) { for (int y = 0; y < pixelsPerBlock; y++) {
for (int z = 0; z < pixelsPerBlock; z++) { for (int z = 0; z < pixelsPerBlock; z++) {
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), x, y, z); Location relativeLocation = new Location(pixelBlockLocation.getWorld(), x, y, z);
Location blockLocation = this.pixelWorld.getBuildOrigin(); Location blockLocation = this.pixelWorld.getBuildOrigin();
switch (this.facingDirection) { switch (this.facingDirection) {
case south -> blockLocation.add(relativeLocation.x(), relativeLocation.y(), relativeLocation.z()); case south -> blockLocation.add(relativeLocation.x(), relativeLocation.y(), relativeLocation.z());
case north -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.x(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.z()); case north -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.x(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.z());
case east -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.z(), relativeLocation.y(), relativeLocation.x()); case east -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.z(), relativeLocation.y(), relativeLocation.x());
case west -> blockLocation.add(relativeLocation.z(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.x()); case west -> blockLocation.add(relativeLocation.z(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.x());
} }
BlockData block = blockLocation.getBlock().getBlockData(); BlockData block = blockLocation.getBlock().getBlockData();
if(block.getMaterial() != Material.AIR) { if(block.getMaterial() != Material.AIR) {
pixels.add(new Pixel(relativeLocation, block, ((double) 1/pixelsPerBlock))); pixels.add(new Pixel(relativeLocation, block, ((double) 1/pixelsPerBlock)));
}
} }
} }
} }
}) }
.sync(() -> this.pixels.stream() })
.limit(maxPixelsPerBlock) .sync(() -> this.pixels.stream()
.forEach(pixel -> pixel.place(this.pixelBlockLocation))) .limit(maxPixelsPerBlock)
.sync(() -> { .forEach(pixel -> pixel.place(this.pixelBlockLocation)))
if(this.pixels.size() < 5) { .sync(() -> {
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), 0, 0, 0); if(this.pixels.size() < 5) {
BlockData block = Material.GRAY_STAINED_GLASS.createBlockData(); Location relativeLocation = new Location(pixelBlockLocation.getWorld(), 0, 0, 0);
Pixel newPixel = new Pixel(relativeLocation, block, 1); BlockData block = Material.GRAY_STAINED_GLASS.createBlockData();
pixels.add(newPixel); Pixel newPixel = new Pixel(relativeLocation, block, 1);
newPixel.place(this.pixelBlockLocation); pixels.add(newPixel);
newPixel.place(this.pixelBlockLocation);
Location itemDisplayLocation = this.pixelBlockLocation.clone().add(0.5, 0.5, 0.5); Location itemDisplayLocation = this.pixelBlockLocation.clone().add(0.5, 0.5, 0.5);
this.barrier = (ItemDisplay) this.pixelBlockLocation.getWorld().spawnEntity( this.barrier = (ItemDisplay) this.pixelBlockLocation.getWorld().spawnEntity(
itemDisplayLocation, itemDisplayLocation,
EntityType.ITEM_DISPLAY EntityType.ITEM_DISPLAY
); );
this.barrier.setItemStack(ItemStack.of(Material.BARRIER)); this.barrier.setItemStack(ItemStack.of(Material.BARRIER));
spawnInteraction(true); spawnInteraction(true);
} else { } else {
spawnInteraction(false); spawnInteraction(false);
} }
})
.execute(); Main.plugin.getLogger().info(String.format("Placed %d entities for PixelBlock '%s'", this.pixels.size(), this.blockUUID));
})
.execute();
} }
public void place(Location placeLocation, Direction direction) { public void place(Location placeLocation, Direction direction) {
@ -224,6 +229,7 @@ public class PixelBlock {
@Nullable PixelBlock blockAtLocation = PixelBlock.getPixelBlockFromPlacedLocation(newLocation); @Nullable PixelBlock blockAtLocation = PixelBlock.getPixelBlockFromPlacedLocation(newLocation);
if(blockAtLocation != null && blockAtLocation != this) throw new IllegalArgumentException("Es können nicht mehrere Pixelblöcke ineinander platziert werden."); if(blockAtLocation != null && blockAtLocation != this) throw new IllegalArgumentException("Es können nicht mehrere Pixelblöcke ineinander platziert werden.");
Main.plugin.getLogger().info(String.format("Placing PixelBlock '%s' at %s", this.blockUUID, placeLocation));
this.pixelBlockLocation = newLocation; this.pixelBlockLocation = newLocation;
this.facingDirection = direction; this.facingDirection = direction;
updateEntities(); updateEntities();
@ -241,6 +247,8 @@ public class PixelBlock {
p.teleport(this.lastEntryLocation); p.teleport(this.lastEntryLocation);
}); });
Main.plugin.getLogger().info(String.format("Destroying PixelBlock '%s' at %s", this.blockUUID, pixelBlockLocation));
this.pixelWorld.getEntitiesInWorld().stream() this.pixelWorld.getEntitiesInWorld().stream()
.filter(entity -> entity instanceof Item) .filter(entity -> entity instanceof Item)
.forEach(entity -> entity.teleport(this.lastEntryLocation)); .forEach(entity -> entity.teleport(this.lastEntryLocation));
@ -259,6 +267,7 @@ public class PixelBlock {
chunk.getEntities(); chunk.getEntities();
} }
Main.plugin.getLogger().info(String.format("Removing %d entities for PixelBlock '%s'", this.pixels.size(), this.blockUUID));
this.pixels.forEach(Pixel::destroy); this.pixels.forEach(Pixel::destroy);
this.pixels.clear(); this.pixels.clear();
@ -273,15 +282,15 @@ public class PixelBlock {
} }
this.pixelBlockLocation.getWorld().getEntities().stream() this.pixelBlockLocation.getWorld().getEntities().stream()
.filter(this::isRelevantEntity) .filter(this::isPixelBlockComponent)
.filter(entity -> entity.getLocation() .filter(entity -> entity.getLocation()
.add(0, hitboxOffset, 0) .add(0, hitboxOffset, 0)
.toBlockLocation() .toBlockLocation()
.equals(this.pixelBlockLocation)) .equals(this.pixelBlockLocation))
.forEach(Entity::remove); .forEach(Entity::remove);
} }
private boolean isRelevantEntity(Entity entity) { private boolean isPixelBlockComponent(Entity entity) {
return entity.getType().equals(EntityType.BLOCK_DISPLAY) return entity.getType().equals(EntityType.BLOCK_DISPLAY)
|| entity.getType().equals(EntityType.INTERACTION) || entity.getType().equals(EntityType.INTERACTION)
|| entity.getType().equals(EntityType.ITEM_DISPLAY); || entity.getType().equals(EntityType.ITEM_DISPLAY);