Class PluginContext

java.lang.Object
me.pauleff.converter.api.PluginContext

public final class PluginContext extends Object
Holds shared state for a conversion run and is passed to each MOOCPlugin.

Created from ParsedArguments, it resolves the server and world folders, optionally a conversion-only folder from -customFolder or file from -customFile, and accumulates detection results (server type, folder structure, save format) plus UUID remappings produced during conversion.

  • Method Details

    • from

      public static PluginContext from(ParsedArguments parsedArgs) throws PathNotValidException
      Builds a PluginContext from successfully parsed CLI arguments.

      Resolves the server folder (defaulting to the current directory), requires server.properties, derives the world folder from level-name, resolves -customFolder or -customFile when present, and sets the conversion target from the online/offline flags (offline when absent).

      Parameters:
      parsedArgs - the parsed CLI arguments
      Returns:
      a new context ready for plugin execution
      Throws:
      PathNotValidException - if the server folder, server.properties, world folder, conversion folder, or conversion file is missing
      NullPointerException - if parsedArgs is null
    • putUuidMapping

      public void putUuidMapping(UUID from, UUID to)
      Records a UUID remapping from an original player UUID to its converted counterpart.
      Parameters:
      from - the original UUID
      to - the remapped UUID
      Throws:
      NullPointerException - if from or to is null
    • getTargetUuid

      public UUID getTargetUuid(UUID from)
      Returns the remapped UUID previously stored for the given original UUID.
      Parameters:
      from - the original UUID to look up
      Returns:
      the remapped UUID, or null if no mapping exists
      Throws:
      NullPointerException - if from is null
    • serverFolder

      public Path serverFolder()
      Returns the absolute, normalized path to the server root folder.
      Returns:
      the server folder path
    • worldFolder

      public Path worldFolder()
      Returns the path to the world folder resolved from server.properties.
      Returns:
      the world folder path
    • conversionFolder

      public Optional<Path> conversionFolder()
      Returns the folder conversion is limited to, if -customFolder was set.
      Returns:
      the absolute conversion folder, or empty when converting the whole server
    • conversionFile

      public Optional<Path> conversionFile()
      Returns the file conversion is limited to, if -customFile was set.
      Returns:
      the absolute conversion file, or empty when converting more than one file
    • isFolderScopedConversion

      public boolean isFolderScopedConversion()
      Indicates whether conversion is limited to conversionFolder().
      Returns:
      true if -customFolder was set; false otherwise
    • isFileScopedConversion

      public boolean isFileScopedConversion()
      Indicates whether conversion is limited to conversionFile().
      Returns:
      true if -customFile was set; false otherwise
    • isScopedConversion

      public boolean isScopedConversion()
      Indicates whether conversion is limited to a custom folder or file.
      Returns:
      true if -customFolder or -customFile was set
    • isInConversionScope

      public boolean isInConversionScope(Path path)
      Indicates whether path may be modified by a conversion plugin.

      When no custom folder or file is set, every path is in scope. For -customFolder, the path must be that folder or something inside it. For -customFile, the path must be that file or an ancestor directory of it (so a plugin that targets a parent folder can still filter down to the file).

      Parameters:
      path - the candidate file or directory
      Returns:
      true if conversion may touch path; false otherwise
      Throws:
      NullPointerException - if path is null
    • conversionTarget

      public ConversionTarget conversionTarget()
      Returns whether this run converts toward online or offline mode.
      Returns:
      the conversion target
    • serverType

      public ServerType serverType()
      Returns the detected server type, if set by a detection plugin.
      Returns:
      the server type, or null if not yet detected
    • worldFolderStructure

      public WorldFolderStructure worldFolderStructure()
      Returns the detected world folder structure, if set by a detection plugin.
      Returns:
      the world folder structure, or null if not yet detected
    • saveFileFormat

      public SaveFileFormat saveFileFormat()
      Returns the detected save file format, if set by a detection plugin.
      Returns:
      the save file format, or null if not yet detected
    • uuidMap

      public Map<UUID,UUID> uuidMap()
      Returns the live map of original-to-remapped player UUIDs.

      Mutations via putUuidMapping(UUID, UUID) are visible through this map.

      Returns:
      the UUID remapping map; never null
    • setServerType

      public void setServerType(ServerType serverType)
      Sets the detected server type for this conversion run.
      Parameters:
      serverType - the detected ServerType
    • setWorldFolderStructure

      public void setWorldFolderStructure(WorldFolderStructure worldFolderStructure)
      Sets the detected world folder structure for this conversion run.
      Parameters:
      worldFolderStructure - the detected WorldFolderStructure
    • setSaveFileFormat

      public void setSaveFileFormat(SaveFileFormat saveFileFormat)
      Sets the detected save file format for this conversion run.
      Parameters:
      saveFileFormat - the detected SaveFileFormat
    • parsedArguments

      public ParsedArguments parsedArguments()
      Returns the parsed CLI arguments for this run.
      Returns:
      the ParsedArguments used to build this context
    • isConversionOperation

      public boolean isConversionOperation()
      Indicates whether an online/offline conversion was requested on the command line.
      Returns:
      true if a conversion operation was requested; false otherwise
    • toString

      public String toString()
      Returns a string representation of this context for debugging.
      Overrides:
      toString in class Object
      Returns:
      a string including folders, conversion target, detection fields, and UUID map