wip: added persistent data tags on items

This commit is contained in:
2024-09-03 21:35:23 +02:00
parent e35145f8ed
commit 4f4a6aef10
6 changed files with 52 additions and 53 deletions

View File

@@ -4,6 +4,8 @@ import eu.mhsl.minecraft.pixelblocks.PixelBlockItem;
import eu.mhsl.minecraft.pixelblocks.PixelBlocksPlugin;
import eu.mhsl.minecraft.pixelblocks.utils.Direction;
import eu.mhsl.minecraft.pixelblocks.utils.MinMaxUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.*;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.*;
@@ -23,7 +25,7 @@ public class PixelBlock {
public Location pixelBlockLocation;
public Direction facingDirection;
public ArrayList<Pixel> pixels = new ArrayList<>();
public List<Pixel> pixels = new ArrayList<>();
public Interaction hitbox;
public ItemDisplay barrier;
@@ -33,6 +35,8 @@ public class PixelBlock {
public UUID ownerUUID;
public UUID blockUUID;
public static final int maxPixelsPerBlock = 2000;
public static @NotNull String getWorldName(@NotNull PixelBlock pixelBlock) {
return PixelBlocksPlugin.plugin.getDataFolder().getPath() + File.separator + pixelBlock.blockUUID;
}
@@ -58,7 +62,7 @@ public class PixelBlock {
searchLocation.setYaw(0);
return PixelBlocksPlugin.pixelBlocks.stream()
.filter(block -> block.pixelBlockLocation.equals(searchLocation))
.filter(block -> Objects.equals(block.pixelBlockLocation, searchLocation))
.findFirst()
.orElse(null);
}
@@ -80,7 +84,7 @@ public class PixelBlock {
public void enterBlock(@NotNull Player player) {
if(PixelBlocksPlugin.configuration.onlyEditableByOwner() && !player.getUniqueId().equals(ownerUUID)) {
player.sendMessage("Dieser Pixelblock gehört nicht dir!");
player.sendMessage(Component.text("Dieser Pixelblock gehört nicht dir!", NamedTextColor.RED));
return;
}
@@ -169,15 +173,18 @@ public class PixelBlock {
BlockData block = blockLocation.getBlock().getBlockData();
if(block.getMaterial() != Material.AIR) {
Pixel newPixel = new Pixel(relativeLocation, block, ((double) 1 /pixelsPerBlock));
pixels.add(newPixel);
pixels.add(new Pixel(relativeLocation, block, ((double) 1/pixelsPerBlock)));
}
}
}
}
for(Pixel pixel : this.pixels) {
pixel.place(this.pixelBlockLocation);
this.pixels.stream()
.limit(maxPixelsPerBlock)
.forEach(pixel -> pixel.place(this.pixelBlockLocation));
if(this.pixels.size() > maxPixelsPerBlock) {
}
if(this.pixels.size() < 5) {
@@ -222,7 +229,7 @@ public class PixelBlock {
}
this.pixelWorld.getPlayersInWorld().forEach(p -> {
p.sendMessage("Der Pixelblock wurde von einem anderen Spieler abgebaut.");
p.sendMessage(Component.text("Der Pixelblock wurde von einem anderen Spieler abgebaut!", NamedTextColor.RED));
p.teleport(this.lastEntryLocation);
});
@@ -234,6 +241,7 @@ public class PixelBlock {
PixelBlocksPlugin.database.deletePixelBlock(this);
this.pixelBlockLocation.getWorld().playSound(this.pixelBlockLocation, Sound.BLOCK_COPPER_BULB_BREAK, 1.0F, 30);
this.pixelBlockLocation.getWorld().dropItem(this.pixelBlockLocation.add(new Vector(0.5, 0.5, 0.5)), PixelBlockItem.getBlockAsItem(this));
this.pixelBlockLocation = null;
}
private void clearEntities() {