Class ParserInstance

java.lang.Object
ch.njol.skript.lang.parser.ParserInstance
All Implemented Interfaces:
Experimented

public final class ParserInstance extends Object implements Experimented
  • Constructor Details

    • ParserInstance

      public ParserInstance()
  • Method Details

    • get

      public static ParserInstance get()
      Returns:
      The ParserInstance for this thread.
    • setInactive

      @Internal public void setInactive()
      Internal method for updating a ParserInstance's isActive() status! You probably don't need to use this method!
    • setActive

      @Internal public void setActive(Script script)
      Internal method for updating a ParserInstance's isActive() status! You probably don't need to use this method!
    • isActive

      public boolean isActive()
      Returns:
      Whether this ParserInstance is currently active. An active ParserInstance may be loading, parsing, or unloading scripts. Please note that some methods may be unavailable if this method returns false. You should consult the documentation of the method you are calling.
    • reset

      public void reset()
      Resets this ParserInstance to its default state. The only data retained is getCurrentScript() and any Logging API.
    • getCurrentScript

      public Script getCurrentScript()
      Returns:
      The Script currently being handled by this ParserInstance.
      Throws:
      SkriptAPIException - If this ParserInstance is not isActive().
    • setCurrentStructure

      public void setCurrentStructure(@Nullable @Nullable Structure structure)
      Updates the Structure currently being handled by this ParserInstance.
      Parameters:
      structure - The new Structure to be handled.
    • getCurrentStructure

      @Nullable public @Nullable Structure getCurrentStructure()
      Returns:
      The Structure currently being handled by this ParserInstance.
    • isCurrentStructure

      public boolean isCurrentStructure(Class<? extends Structure> structureClass)
      Returns:
      Whether getCurrentStructure() is an instance of the given Structure class.
    • isCurrentStructure

      @SafeVarargs public final boolean isCurrentStructure(Class<? extends Structure>... structureClasses)
      Returns:
      Whether getCurrentStructure() is an instance of one of the given Structure classes.
    • setCurrentEventName

      public void setCurrentEventName(@Nullable @Nullable String currentEventName)
    • getCurrentEventName

      @Nullable public @Nullable String getCurrentEventName()
    • setCurrentEvents

      public void setCurrentEvents(Class<? extends org.bukkit.event.Event> @Nullable [] currentEvents)
      Parameters:
      currentEvents - The events that may be present during execution. An instance of the events present in the provided array MUST be used to execute any loaded items.
    • setCurrentEvent

      @SafeVarargs public final void setCurrentEvent(String name, @Nullable @Nullable Class<? extends org.bukkit.event.Event>... events)
    • deleteCurrentEvent

      public void deleteCurrentEvent()
    • getCurrentEvents

      public Class<? extends org.bukkit.event.Event> @Nullable [] getCurrentEvents()
    • isCurrentEvent

      public boolean isCurrentEvent(Class<? extends org.bukkit.event.Event> event)
      This method checks whether at least one of the current event classes is covered by the argument event class (i.e. equal to the class or a subclass of it).
      Using this method in an event-specific syntax element requires a runtime check, for example
      if (!(e instanceof BlockBreakEvent)) return null;
      This check is required because there can be more than 1 event class at parse-time, but this method only checks if one of them matches the argument class.

      See also isCurrentEvent(Class[]) for checking with multiple argument classes
    • isCurrentEvent

      @SafeVarargs public final boolean isCurrentEvent(Class<? extends org.bukkit.event.Event>... events)
      Same as isCurrentEvent(Class), but allows for plural argument input.
      This means that this method will return whether any of the current event classes is covered by any of the argument classes.
      Using this method in an event-specific syntax element requires a runtime check, you can use CollectionUtils.isAnyInstanceOf(Object, Class[]) for this, for example:
      if (!CollectionUtils.isAnyInstanceOf(e, BlockBreakEvent.class, BlockPlaceEvent.class)) return null;
      See Also:
    • setCurrentSections

      public void setCurrentSections(List<TriggerSection> currentSections)
      Updates the list of sections currently being handled by this ParserInstance.
      Parameters:
      currentSections - A new list of sections to handle.
    • getCurrentSections

      public List<TriggerSection> getCurrentSections()
      Returns:
      A list of all sections this ParserInstance is currently within.
    • getCurrentSection

      @Nullable public <T extends TriggerSection> T getCurrentSection(Class<T> sectionClass)
      Returns:
      The outermost section which is an instance of the given class. Returns null if isCurrentSection(Class) returns false.
      See Also:
    • getCurrentSections

      @NotNull public <T extends TriggerSection> @NotNull List<T> getCurrentSections(Class<T> sectionClass)
      Returns:
      a List of current sections that are an instance of the given class. Modifications to the returned list are not saved.
      See Also:
    • isCurrentSection

      public boolean isCurrentSection(Class<? extends TriggerSection> sectionClass)
      Returns:
      Whether getCurrentSections() contains a section instance of the given class (or subclass).
    • isCurrentSection

      @SafeVarargs public final boolean isCurrentSection(Class<? extends TriggerSection>... sectionClasses)
      Returns:
      Whether getCurrentSections() contains a section instance of one of the given classes (or subclasses).
    • setHasDelayBefore

      public void setHasDelayBefore(Kleenean hasDelayBefore)
      This method should be called to indicate that the trigger will (possibly) be delayed from this point on.
      See Also:
    • getHasDelayBefore

      public Kleenean getHasDelayBefore()
      Returns:
      whether this trigger has had delays before. Any syntax elements that modify event-values, should use this (or the Kleenean provided to in SyntaxElement.init(Expression[], int, Kleenean, SkriptParser.ParseResult)) to make sure the event can't be modified when it has passed.
    • getHandlers

      public HandlerList getHandlers()
      You probably shouldn't use this method.
      Returns:
      The HandlerList containing all active log handlers.
    • setNode

      public void setNode(@Nullable @Nullable Node node)
      Parameters:
      node - The node to mark as being handled. This is mainly used for logging. Null means to mark it as no node currently being handled (that the ParserInstance is aware of).
    • getNode

      @Nullable public @Nullable Node getNode()
      Returns:
      The node currently marked as being handled. This is mainly used for logging. Null indicates no node is currently being handled (that the ParserInstance is aware of).
    • setIndentation

      public void setIndentation(String indentation)
    • getIndentation

      public String getIndentation()
    • hasExperiment

      public boolean hasExperiment(String featureName)
      Specified by:
      hasExperiment in interface Experimented
      Parameters:
      featureName - The name of the experimental feature to test.
      Returns:
      Whether this has a feature with the given name.
    • hasExperiment

      public boolean hasExperiment(Experiment experiment)
      Specified by:
      hasExperiment in interface Experimented
      Parameters:
      experiment - The experimental feature to test.
      Returns:
      Whether this uses the given feature.
    • addExperiment

      @Internal public void addExperiment(Experiment experiment)
      Marks this as using an experimental feature.
      Parameters:
      experiment - The feature to register.
    • removeExperiment

      @Internal public void removeExperiment(Experiment experiment)
      Marks this as no longer using an experimental feature (e.g. during de-registration or reload).
      Parameters:
      experiment - The feature to unregister.
    • experimentSnapshot

      public Experimented experimentSnapshot()
      A snapshot of the experiments this script is currently known to be using. This is safe to retain during runtime (e.g. to defer a check) but will not see changes, such as if a script subsequently 'uses' another experiment.
      Returns:
      A snapshot of the current experiment flags in use
    • registerData

      public static <T extends ParserInstance.Data> void registerData(Class<T> dataClass, Function<ParserInstance,T> dataFunction)
      Registers a data class to all ParserInstances.
      Parameters:
      dataClass - the data class to register.
      dataFunction - an instance creator for the data class.
    • isRegistered

      public static boolean isRegistered(Class<? extends ParserInstance.Data> dataClass)
    • getData

      public <T extends ParserInstance.Data> T getData(Class<T> dataClass)
      Returns:
      the data object for the given class from this ParserInstance, or null (after false has been asserted) if the given data class isn't registered.
    • backup

      public ParserInstance.Backup backup()
      Creates a backup of this ParserInstance, which represents its current state (excluding any Logging API).
      Returns:
      A backup of this ParserInstance.
      See Also:
    • restoreBackup

      public void restoreBackup(ParserInstance.Backup backup)
      Restores a backup onto this ParserInstance. That is, this entire ParserInstance, except any Logging API, will be overridden.
      Parameters:
      backup - The backup to apply.
      See Also:
    • getCurrentOptions

      @Deprecated public HashMap<String,String> getCurrentOptions()
      Deprecated.
      Use Script.getData(Class) instead. The StructOptions.OptionsData class should be obtained. Example: script.getData(OptionsData.class)
    • getCurrentSkriptEvent

      @Nullable @Deprecated public @Nullable SkriptEvent getCurrentSkriptEvent()
      Deprecated.
    • setCurrentSkriptEvent

      @Deprecated public void setCurrentSkriptEvent(@Nullable @Nullable SkriptEvent currentSkriptEvent)
    • deleteCurrentSkriptEvent

      @Deprecated public void deleteCurrentSkriptEvent()
      Deprecated.
    • setCurrentScript

      @Deprecated public void setCurrentScript(@Nullable @Nullable Config currentScript)
      Deprecated.
      Addons should no longer be modifying this.