added logging
This commit is contained in:
parent
39af3589e3
commit
156b7e6b61
@ -92,6 +92,8 @@ public class PixelBlock {
|
||||
player.sendMessage(Component.text("Dieser Pixelblock gehört nicht dir!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
|
||||
Main.plugin.getLogger().info(String.format("'%s' entered PixelBlock '%s' at %s", player.getName(), this.blockUUID, this.pixelBlockLocation.toString()));
|
||||
getBlockTaskChain()
|
||||
.async(() -> {
|
||||
this.lastEntryLocation = player.getLocation();
|
||||
@ -103,6 +105,7 @@ public class PixelBlock {
|
||||
}
|
||||
|
||||
public void exitBlock(@NotNull Player player) {
|
||||
Main.plugin.getLogger().info(String.format("%s exited PixelBlock", player.getName()));
|
||||
player.teleport(this.lastEntryLocation);
|
||||
}
|
||||
|
||||
@ -168,52 +171,54 @@ public class PixelBlock {
|
||||
|
||||
public void updateEntities() {
|
||||
this.getBlockTaskChain()
|
||||
.sync(this::clearEntities)
|
||||
.async(() -> {
|
||||
for (int x = 0; x < pixelsPerBlock; x++) {
|
||||
for (int y = 0; y < pixelsPerBlock; y++) {
|
||||
for (int z = 0; z < pixelsPerBlock; z++) {
|
||||
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), x, y, z);
|
||||
Location blockLocation = this.pixelWorld.getBuildOrigin();
|
||||
switch (this.facingDirection) {
|
||||
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 east -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.z(), relativeLocation.y(), relativeLocation.x());
|
||||
case west -> blockLocation.add(relativeLocation.z(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.x());
|
||||
}
|
||||
BlockData block = blockLocation.getBlock().getBlockData();
|
||||
.sync(this::clearEntities)
|
||||
.async(() -> {
|
||||
for (int x = 0; x < pixelsPerBlock; x++) {
|
||||
for (int y = 0; y < pixelsPerBlock; y++) {
|
||||
for (int z = 0; z < pixelsPerBlock; z++) {
|
||||
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), x, y, z);
|
||||
Location blockLocation = this.pixelWorld.getBuildOrigin();
|
||||
switch (this.facingDirection) {
|
||||
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 east -> blockLocation.add((pixelsPerBlock-1)-relativeLocation.z(), relativeLocation.y(), relativeLocation.x());
|
||||
case west -> blockLocation.add(relativeLocation.z(), relativeLocation.y(), (pixelsPerBlock-1)-relativeLocation.x());
|
||||
}
|
||||
BlockData block = blockLocation.getBlock().getBlockData();
|
||||
|
||||
if(block.getMaterial() != Material.AIR) {
|
||||
pixels.add(new Pixel(relativeLocation, block, ((double) 1/pixelsPerBlock)));
|
||||
}
|
||||
if(block.getMaterial() != Material.AIR) {
|
||||
pixels.add(new Pixel(relativeLocation, block, ((double) 1/pixelsPerBlock)));
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.sync(() -> this.pixels.stream()
|
||||
.limit(maxPixelsPerBlock)
|
||||
.forEach(pixel -> pixel.place(this.pixelBlockLocation)))
|
||||
.sync(() -> {
|
||||
if(this.pixels.size() < 5) {
|
||||
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), 0, 0, 0);
|
||||
BlockData block = Material.GRAY_STAINED_GLASS.createBlockData();
|
||||
Pixel newPixel = new Pixel(relativeLocation, block, 1);
|
||||
pixels.add(newPixel);
|
||||
newPixel.place(this.pixelBlockLocation);
|
||||
}
|
||||
})
|
||||
.sync(() -> this.pixels.stream()
|
||||
.limit(maxPixelsPerBlock)
|
||||
.forEach(pixel -> pixel.place(this.pixelBlockLocation)))
|
||||
.sync(() -> {
|
||||
if(this.pixels.size() < 5) {
|
||||
Location relativeLocation = new Location(pixelBlockLocation.getWorld(), 0, 0, 0);
|
||||
BlockData block = Material.GRAY_STAINED_GLASS.createBlockData();
|
||||
Pixel newPixel = new Pixel(relativeLocation, block, 1);
|
||||
pixels.add(newPixel);
|
||||
newPixel.place(this.pixelBlockLocation);
|
||||
|
||||
Location itemDisplayLocation = this.pixelBlockLocation.clone().add(0.5, 0.5, 0.5);
|
||||
this.barrier = (ItemDisplay) this.pixelBlockLocation.getWorld().spawnEntity(
|
||||
itemDisplayLocation,
|
||||
EntityType.ITEM_DISPLAY
|
||||
);
|
||||
this.barrier.setItemStack(ItemStack.of(Material.BARRIER));
|
||||
Location itemDisplayLocation = this.pixelBlockLocation.clone().add(0.5, 0.5, 0.5);
|
||||
this.barrier = (ItemDisplay) this.pixelBlockLocation.getWorld().spawnEntity(
|
||||
itemDisplayLocation,
|
||||
EntityType.ITEM_DISPLAY
|
||||
);
|
||||
this.barrier.setItemStack(ItemStack.of(Material.BARRIER));
|
||||
|
||||
spawnInteraction(true);
|
||||
} else {
|
||||
spawnInteraction(false);
|
||||
}
|
||||
})
|
||||
.execute();
|
||||
spawnInteraction(true);
|
||||
} else {
|
||||
spawnInteraction(false);
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -224,6 +229,7 @@ public class PixelBlock {
|
||||
@Nullable PixelBlock blockAtLocation = PixelBlock.getPixelBlockFromPlacedLocation(newLocation);
|
||||
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.facingDirection = direction;
|
||||
updateEntities();
|
||||
@ -241,6 +247,8 @@ public class PixelBlock {
|
||||
p.teleport(this.lastEntryLocation);
|
||||
});
|
||||
|
||||
Main.plugin.getLogger().info(String.format("Destroying PixelBlock '%s' at %s", this.blockUUID, pixelBlockLocation));
|
||||
|
||||
this.pixelWorld.getEntitiesInWorld().stream()
|
||||
.filter(entity -> entity instanceof Item)
|
||||
.forEach(entity -> entity.teleport(this.lastEntryLocation));
|
||||
@ -259,6 +267,7 @@ public class PixelBlock {
|
||||
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.clear();
|
||||
|
||||
@ -273,15 +282,15 @@ public class PixelBlock {
|
||||
}
|
||||
|
||||
this.pixelBlockLocation.getWorld().getEntities().stream()
|
||||
.filter(this::isRelevantEntity)
|
||||
.filter(entity -> entity.getLocation()
|
||||
.add(0, hitboxOffset, 0)
|
||||
.toBlockLocation()
|
||||
.equals(this.pixelBlockLocation))
|
||||
.forEach(Entity::remove);
|
||||
.filter(this::isPixelBlockComponent)
|
||||
.filter(entity -> entity.getLocation()
|
||||
.add(0, hitboxOffset, 0)
|
||||
.toBlockLocation()
|
||||
.equals(this.pixelBlockLocation))
|
||||
.forEach(Entity::remove);
|
||||
}
|
||||
|
||||
private boolean isRelevantEntity(Entity entity) {
|
||||
private boolean isPixelBlockComponent(Entity entity) {
|
||||
return entity.getType().equals(EntityType.BLOCK_DISPLAY)
|
||||
|| entity.getType().equals(EntityType.INTERACTION)
|
||||
|| entity.getType().equals(EntityType.ITEM_DISPLAY);
|
||||
|
Loading…
x
Reference in New Issue
Block a user