import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; public class ImageBoard { private final CanvasModule module; private final int width; private final int height; private final Location location; private final ImageDirection direction; private final UUID playerId; private final ImageFrame[][] frames; private BaseImage image; public ImageBoard(CanvasModule module, int width, int height, Location location, ImageDirection direction, UUID playerId) { this.module = module; this.width = width; this.height = height; this.location = location; this.playerId = playerId; this.direction = direction; frames = new ImageFrame[width][height]; for(int x = 0; x < width; x++) { for(int y = 0; y < height; y++) { ImageFrame frame = frames[x][y] = new ImageFrame(this, new Point(x, y)); frame.setImageSupplier(() -> { if(image == null) { return null; } int startPixelX = frame.getPosition().getX() * 128; int startPixelY = frame.getPosition().getY() * 128; int endPixelX = Math.min(startPixelX + 128, image.getWidth()); int endPixelY = Math.min(startPixelY + 128, image.getHeight()); return image.getFinalImage().getSubimage(startPixelX, startPixelY, endPixelX, endPixelY); }); } } } public Player getPlayer() { return Bukkit.getPlayer(playerId); } public void draw() { for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { frames[x][y].draw(); } } } public void setImage(BaseImage image) { this.image = image; draw(); } public Location getFrameLocation(ImageFrame frame) { return direction.getFrameLocation(this, frame.getPosition()); } public Location getCornerLocation() { return location; } public ImageDirection getDirection() { return direction; } }