Class DataScope

java.lang.Object
com.ultikits.ultitools.manager.DataScope

public final class DataScope extends Object
A framework-issued credential identifying the caller of a DataStore method.

Unlike a raw File, a DataScope cannot be constructed outside this package: both the constructor and the static factories are package-private, so the only way to obtain one is through PluginManager (internal modules) or DataStoreManager / the external plugin registration path (external plugins). UltiTools#getDataStore() being public in the published jar is therefore no longer a bypass: a caller outside the framework has no way to mint the token DataStore.getOperator(DataScope, Class) requires.

Since:
6.3.0
Author:
wisdomme
  • Field Details

    • pluginName

      private final String pluginName
    • dataFolder

      private final File dataFolder
    • ownedEntities

      private final Set<Class<?>> ownedEntities
  • Constructor Details

  • Method Details

    • forPlugin

      static DataScope forPlugin(UltiToolsPlugin plugin, Set<Class<?>> ownedEntities)
      Mints a scope for an internal UltiToolsPlugin module.

      ownedEntities is the result of PluginManager's D-19 scan of the plugin's own JAR (classes carrying @Table), unioned with anything declared via @UltiToolsModule#additionalEntities().

      Parameters:
      plugin - the internal plugin module
      ownedEntities - the entity classes this plugin owns
      Returns:
      a scope identifying that plugin
    • forExternal

      static DataScope forExternal(String pluginName, File dataFolder, Set<Class<?>> ownedEntities)
      Mints a scope for an external Bukkit plugin borrowing the framework via UltiToolsAPI.connect(...).
      Parameters:
      pluginName - the external plugin's name
      dataFolder - the external plugin's own data folder
      ownedEntities - the entity classes this plugin owns
      Returns:
      a scope identifying that external plugin
    • owns

      public boolean owns(Class<?> entityClass)
      Whether the given entity class belongs to this scope.
      Parameters:
      entityClass - the entity class to check
      Returns:
      true if this scope owns the entity
    • refusalFor

      public DataAccessException refusalFor(Class<?> dataEntity)
      Builds the refusal for a caller in this scope requesting dataEntity, which this scope does not own (D-14, D-15). Framework-internal; the single source every getOperator overload routes through so the refusal is identical regardless of which one a caller reaches. When another loaded module's scope is known to own the entity, the message names it -- "confirmed to belong to another module"; otherwise it says the entity is not registered to the requester and no owner is known -- "not registered to you" (D-15). The message carries only the entity's fully-qualified name, the requesting plugin's name, and the route (the owning module's exposed service or the EventBus) -- never a table name, column name, row count, or file path, so a refusal cannot be used to enumerate another module's schema.
      Parameters:
      dataEntity - the entity class this scope does not own
      Returns:
      the exception to throw
    • getPluginName

      public String getPluginName()
    • getDataFolder

      public File getDataFolder()
    • getOwnedEntities

      public Set<Class<?>> getOwnedEntities()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object