Klasse PipeService

java.lang.Object
de.delinkedde.pipes.PipeService

public final class PipeService extends Object
Coordinates the lifecycle of pipe signs across the registry, the database and the sign block itself.

This is the single place that keeps the three representations of a sign in step: the in-memory PipeRuntime, the persisted PipeSignData, and the physical sign block (its text, its waxed state and the pipe id stored in its persistent data container). Event listeners and the GUI call into this service rather than touching persistence directly.

All methods run on the main server thread. Reads and writes are handed to the StorageExecutor; writes are fire-and-forget, the registry being the source of truth.

Seit:
0.1.0
  • Felddetails

    • PIPE_ID_KEY

      public static final String PIPE_ID_KEY
      Key under which a sign stores its pipe id in its persistent data container.
      Siehe auch:
  • Konstruktordetails

    • PipeService

      public PipeService(org.bukkit.plugin.Plugin plugin, PipeRegistry registry, StorageExecutor storageExecutor, NetworkStorage networkStorage, PipeStorage pipeStorage, FilterStorage filterStorage, TrustStorage trustStorage)
      Creates the service.
      Parameter:
      plugin - the owning plugin; never null
      registry - the in-memory registry; never null
      storageExecutor - the storage thread; never null
      networkStorage - network persistence; never null
      pipeStorage - sign persistence; never null
      filterStorage - filter persistence; never null
      trustStorage - trust persistence; never null
  • Methodendetails

    • pipeIdKey

      public org.bukkit.NamespacedKey pipeIdKey()
      Returns the namespaced key under which pipe ids are stored on sign blocks.
      Gibt zurück:
      the pipe-id key; never null
    • loadAll

      public void loadAll()
      Loads all networks and signs from the database into the registry.

      Runs the queries on the storage thread and builds the registry on the calling (main) thread. Signs whose network is missing are skipped and reported rather than failing the whole load. Containers are not resolved here; that happens lazily, since worlds and chunks may not be loaded yet.

      Löst aus:
      StorageException - if a query fails
    • createSign

      public PipeRuntime createSign(UUID ownerId, org.bukkit.block.Block signBlock, ResolvedContainer container)
      Creates and registers a new pipe sign owned by a player, persisting it asynchronously.

      If the owner has no network yet, a default one ("Lager1") is created first. The sign is created with the default configuration: output, whitelist, priority 1, enabled. The physical sign block is not touched here; call finalizeSignLater(Block, PipeRuntime) afterwards to stamp it.

      Parameter:
      ownerId - the owning player's UUID; never null
      signBlock - the sign block; never null
      container - the resolved bound container; never null
      Gibt zurück:
      the newly registered runtime sign
    • createCollector

      public PipeRuntime createCollector(UUID ownerId, org.bukkit.block.Block signBlock)
      Creates a collector sign: a networked source that vacuums ground items instead of draining a container. It has no bound container and starts unfiltered (picks up everything), in the owner's default network (created if needed).
      Parameter:
      ownerId - the owning player; never null
      signBlock - the sign block; never null
      Gibt zurück:
      the newly created collector runtime
    • removeSign

      public void removeSign(PipeRuntime pipe)
      Removes a sign from the registry and deletes it from the database asynchronously.
      Parameter:
      pipe - the sign to remove; never null
    • setContainerDirection

      public void setContainerDirection(PipeRuntime pipe, ContainerDirection direction)
      Binds a sign to a different adjacent container (the player's chat selection), clears its cached container so the new one is resolved next tick, and persists and re-renders it.
      Parameter:
      pipe - the sign; never null
      direction - the chosen container direction; never null
    • revalidate

      public void revalidate(PipeRuntime pipe, ResolvedContainer container)
      Re-checks and reactivates a previously-invalid sign whose sign block and container are back.
      Parameter:
      pipe - the sign to reactivate; never null
      container - the freshly-resolved container the sign is bound to; never null
    • networkById

      public NetworkRuntime networkById(UUID networkId)
      Looks up a network by id alone, across all owners.
      Parameter:
      networkId - the network id; never null
      Gibt zurück:
      the network, or null if not found
    • signCount

      public int signCount(UUID ownerId)
      Returns the total number of signs an owner has across all their networks.
      Parameter:
      ownerId - the owning player's UUID; never null
      Gibt zurück:
      the owner's total sign count
    • networkOf

      public NetworkRuntime networkOf(PipeRuntime pipe)
      Returns the network a sign belongs to.
      Parameter:
      pipe - the sign; never null
      Gibt zurück:
      the sign's network, or null if it is not registered
    • networksOf

      public List<NetworkRuntime> networksOf(UUID ownerId)
      Returns all networks owned by a player, in insertion order.
      Parameter:
      ownerId - the owning player's UUID; never null
      Gibt zurück:
      a fresh list of the owner's networks; never null
    • invalidPipesOf

      public List<PipeRuntime> invalidPipesOf(UUID ownerId)
      Returns the currently-invalid signs owned by a player.
      Parameter:
      ownerId - the owning player's UUID; never null
      Gibt zurück:
      a fresh list of the owner's invalid signs (possibly empty); never null
    • setMode

      public void setMode(PipeRuntime pipe, PipeMode mode)
      Sets a sign's transport direction, persisting and re-rendering it.
      Parameter:
      pipe - the sign; never null
      mode - the new mode; never null
    • setFilterMode

      public void setFilterMode(PipeRuntime pipe, FilterMode filterMode)
      Sets a sign's input filter mode, persisting and re-rendering it.
      Parameter:
      pipe - the sign; never null
      filterMode - the new filter mode; never null
    • setPriority

      public void setPriority(PipeRuntime pipe, int priority)
      Sets a sign's delivery priority, persisting and re-rendering it.
      Parameter:
      pipe - the sign; never null
      priority - the new priority (>= 1)
    • setEnabled

      public void setEnabled(PipeRuntime pipe, boolean enabled)
      Enables or disables a sign, persisting the change.
      Parameter:
      pipe - the sign; never null
      enabled - the new enabled state
    • saveFilters

      public void saveFilters(PipeRuntime pipe)
      Persists a sign's current filter items (whole-list replace).
      Parameter:
      pipe - the sign; never null
    • can

      public boolean can(org.bukkit.entity.Player player, PipeRuntime pipe, TrustPermission permission)
      Returns whether a player may perform an action on a sign: always for the sign's owner and for admins, otherwise only if the player is trusted in the sign's network with that permission.
      Parameter:
      player - the acting player; never null
      pipe - the sign; never null
      permission - the permission required; never null
      Gibt zurück:
      true if the action is allowed
    • isOwnerOrAdmin

      public boolean isOwnerOrAdmin(org.bukkit.entity.Player player, PipeRuntime pipe)
      Gibt whether a player owns a sign or is an admin zurück. Owner-only actions (breaking regardless of trust flags is not owner-only; reassigning the network is).
      Parameter:
      player - the acting player; never null
      pipe - the sign; never null
      Gibt zurück:
      whether a player owns a sign or is an admin
    • assignToSharedNetwork

      public void assignToSharedNetwork(PipeRuntime pipe, NetworkRuntime target)
      Moves a sign into a shared network owned by someone else, transferring ownership to that owner. After this the original builder can no longer reassign it.
      Parameter:
      pipe - the sign; never null
      target - the shared network to move into; never null
    • sharedNetworksFor

      public List<NetworkRuntime> sharedNetworksFor(UUID playerId, TrustPermission permission)
      Returns the networks a player is trusted in, with the given permission granted.
      Parameter:
      playerId - the player; never null
      permission - the permission the player must hold in the network; never null
      Gibt zurück:
      a fresh list of matching networks; never null
    • trust

      public boolean trust(NetworkRuntime network, UUID playerId)
      Trusts a player in a network (with no permissions) and persists it.
      Parameter:
      network - the network; never null
      playerId - the player to trust; never null
      Gibt zurück:
      true if the player was newly trusted
    • untrust

      public boolean untrust(NetworkRuntime network, UUID playerId)
      Removes a player's trust from a network and persists it.
      Parameter:
      network - the network; never null
      playerId - the player to untrust; never null
      Gibt zurück:
      true if the player was trusted and is now removed
    • setTrustFlags

      public void setTrustFlags(NetworkRuntime network, UUID playerId, int flags)
      Sets a trusted player's permission bitmask in a network and persists it.
      Parameter:
      network - the network; never null
      playerId - the trusted player; never null
      flags - the new permission bitmask
    • setNetworkEnabled

      public int setNetworkEnabled(NetworkRuntime network, boolean enabled)
      Enables or disables every sign in a network in one go.
      Parameter:
      network - the network; never null
      enabled - the new enabled state for all its signs
      Gibt zurück:
      the number of signs whose state actually changed
    • assignNetwork

      public void assignNetwork(PipeRuntime pipe, UUID newNetworkId)
      Reassigns a sign to another of its owner's networks, persisting and re-rendering it.
      Parameter:
      pipe - the sign; never null
      newNetworkId - the target network id; must belong to the same owner
    • createNetwork

      public NetworkRuntime createNetwork(UUID ownerId)
      Creates a new network for an owner with an auto-generated, collision-free name ("LagerN" with the lowest free N) and persists it.
      Parameter:
      ownerId - the owning player's UUID; never null
      Gibt zurück:
      the newly created and registered network
    • createNetwork

      public NetworkRuntime createNetwork(UUID ownerId, String name)
      Creates a new network for an owner with the given display name and persists it.
      Parameter:
      ownerId - the owning player's UUID; never null
      name - the display name; never null
      Gibt zurück:
      the newly created and registered network
    • findNetworkByName

      public NetworkRuntime findNetworkByName(UUID ownerId, String name)
      Finds an owner's network by display name, case-insensitively.
      Parameter:
      ownerId - the owning player's UUID; never null
      name - the display name to match; never null
      Gibt zurück:
      the matching network, or null if none matches
    • renameNetwork

      public void renameNetwork(NetworkRuntime network, String newName)
      Renames a network, persisting the change and re-rendering the network's signs (whose second line shows the network name).
      Parameter:
      network - the network to rename; never null
      newName - the new display name; never null
    • deleteNetworkIfEmpty

      public boolean deleteNetworkIfEmpty(NetworkRuntime network)
      Deletes a network if it has no signs. A network that still has signs is left untouched, so a delete never silently relocates anything — the caller offers a force-delete instead.
      Parameter:
      network - the network to delete; never null
      Gibt zurück:
      true if it was empty and is now deleted, false if it still has signs
    • deleteNetworkForce

      public int deleteNetworkForce(NetworkRuntime network)
      Force-deletes a network together with all its signs. The signs are removed from the system (registry and database, open GUIs closed); their physical sign blocks stay in the world as inert, ordinary signs that can be broken normally.
      Parameter:
      network - the network to delete; never null
      Gibt zurück:
      the number of signs that were removed with it
    • runNextTick

      public void runNextTick(Runnable task)
      Runs a task on the next server tick. Used by GUIs to open a follow-up inventory outside of the click event that triggered it.
      Parameter:
      task - the task to run; never null
    • finalizeSignLater

      public void finalizeSignLater(org.bukkit.block.Block signBlock, PipeRuntime pipe)
      Schedules stamping of the physical sign block one tick later.

      The block state is only final after the SignChangeEvent completes, so the pipe id, the waxed flag and the rendered text are applied on the next tick.

      Parameter:
      signBlock - the sign block; never null
      pipe - the runtime sign backing it; never null
    • updateSignText

      public void updateSignText(org.bukkit.block.Block signBlock, PipeRuntime pipe)
      Renders the current text of a sign and pushes it to the physical block immediately.

      Used after a GUI edit. Does nothing if the block is no longer a sign.

      Parameter:
      signBlock - the sign block; never null
      pipe - the runtime sign; never null