Class PaintService

java.lang.Object
dev.despical.pixelpainter.service.PaintService

public final class PaintService extends Object
Coordinates one bounded world operation and its persistent undo history.

Public operations are synchronized and a ticker on the global region drives the job. Creation validates bounds, budgets, history capacity and journal overlap. Chunk tickets are acquired incrementally and loaded asynchronously before a scan captures ordinary block data. A worker saves the complete journal before painting writes are allowed.

Block access is grouped by chunk. Each batch runs on the region scheduler of its chunk, one batch at a time, so the service works on Paper's single server thread and on Folia's regionized threads alike. Batch results are merged under the service lock.

Restoration changes only blocks that still match the intended output. Later edits and block entities are preserved; conflicts retain the journal. Cancel, disconnect and shutdown release world resources while retaining any durable record needed to restore partial work.

  • Constructor Summary

    Constructors
    Constructor
    Description
    PaintService(PixelPainter plugin, UndoStore store, List<PaintRecord> restored)
    Publishes recovered journals and registers the global-region ticker.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks whether a world job, including pending journal I/O, occupies the service.
    void
    cancel(org.bukkit.entity.Player player)
    Cancels the caller's active job, or any job for an administrator.
    void
    Cancels the ticker and releases active chunk tickets and the progress bar.
    void
    create(org.bukkit.entity.Player player, String image, PaintPlan plan, Orientation orientation, Position origin, UUID worldId, Settings settings, boolean ignoreBorder)
    Validates and queues a prepared image for incremental capture and painting.
    history(org.bukkit.entity.Player player)
    Lists journals accessible to a player in newest-first order.
    void
    quit(UUID owner)
    Stops a departing owner's job while retaining durable undo data.
    void
    undo(org.bukkit.entity.Player player, String requested)
    Queues restoration of the latest accessible or explicitly requested journal.
    boolean
    usesWorld(UUID world)
    Checks whether the active job holds resources in a world.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PaintService

      public PaintService(PixelPainter plugin, UndoStore store, List<PaintRecord> restored)
      Publishes recovered journals and registers the global-region ticker.
      Parameters:
      plugin - owning enabled plugin
      store - persistent journal storage
      restored - startup recovery records
  • Method Details

    • busy

      public boolean busy()
      Checks whether a world job, including pending journal I/O, occupies the service.
      Returns:
      whether a job is active
    • usesWorld

      public boolean usesWorld(UUID world)
      Checks whether the active job holds resources in a world.
      Parameters:
      world - queried world UUID
      Returns:
      whether that world is in use
    • history

      public List<PaintRecord> history(org.bukkit.entity.Player player)
      Lists journals accessible to a player in newest-first order.
      Parameters:
      player - owner or administrator with pp.admin
      Returns:
      copied list of accessible records
    • create

      public void create(org.bukkit.entity.Player player, String image, PaintPlan plan, Orientation orientation, Position origin, UUID worldId, Settings settings, boolean ignoreBorder)
      Validates and queues a prepared image for incremental capture and painting.
      Parameters:
      player - requesting player; command layer checks creation permission
      image - source name
      plan - prepared pixel materials
      orientation - image-to-world mapping
      origin - bottom-left image block
      worldId - world captured when preparation started
      settings - captured request limits
      ignoreBorder - whether a painting may extend past the world border
      Throws:
      PaintException - if world, bounds, capacity or overlap checks fail
    • undo

      public void undo(org.bukkit.entity.Player player, String requested)
      Queues restoration of the latest accessible or explicitly requested journal.
      Parameters:
      player - owner or administrator; command layer checks undo permission
      requested - identifier or source name, or null for the latest accessible journal
      Throws:
      PaintException - if no journal matches or restoration cannot start
    • cancel

      public void cancel(org.bukkit.entity.Player player)
      Cancels the caller's active job, or any job for an administrator.
      Parameters:
      player - requesting owner or administrator
      Throws:
      PaintException - if the player has no cancellable job
    • quit

      public void quit(UUID owner)
      Stops a departing owner's job while retaining durable undo data.
      Parameters:
      owner - departing player UUID
    • close

      public void close()
      Cancels the ticker and releases active chunk tickets and the progress bar.