Class Session

  • All Implemented Interfaces:
    Serializable, SectionMap
    Direct Known Subclasses:
    SessionSection

    public class Session
    extends Object
    implements SectionMap
    This class is used to build better communication between Command and CommandSender. It can save something in the executing process and can be used for future.
    See Also:
    Serialized Form
    • Constructor Detail

      • Session

        public Session​(@Nullable
                       Map<String,​Object> values)
        Initializes the Session with existed key-value pairs (usually not)
        Parameters:
        values - the session key-value pairs
    • Method Detail

      • createSection

        public SessionSection createSection​(String key)
        Description copied from interface: SectionMap
        Create the section named key Note: if the section named key already exists, it will be replaced by a new section
        Specified by:
        createSection in interface SectionMap
        Parameters:
        key - the key of the Section
        Returns:
        a section named key
      • getSection

        public SectionMap getSection​(String key)
        Description copied from interface: SectionMap
        Get the section named key Note: if the section named key does not exist, it will be created
        Specified by:
        getSection in interface SectionMap
        Parameters:
        key - the key of the Section
        Returns:
        the section named key
      • containsSection

        public boolean containsSection​(String key)
        Description copied from interface: SectionMap
        Indicate there is a section named key
        Specified by:
        containsSection in interface SectionMap
        Parameters:
        key - the key of the Section
        Returns:
        true there is a section named key, false otherwise
      • set

        public void set​(String key,
                        Object value)
        Description copied from interface: SectionMap
        Store the key-value pair
        Specified by:
        set in interface SectionMap
        Parameters:
        key - the key of the key-value pair
        value - the value of the key-value pair
      • get

        public <T> T get​(String key)
        Description copied from interface: SectionMap
        Get the value of the key-value pair
        Specified by:
        get in interface SectionMap
        Type Parameters:
        T - the value type
        Parameters:
        key - the key of the key-value pair
        Returns:
        the value
      • getOrDefault

        public <T> T getOrDefault​(String key,
                                  T defaultValue)
        Description copied from interface: SectionMap
        Get the value of the key-value pair
        Specified by:
        getOrDefault in interface SectionMap
        Type Parameters:
        T - the value type
        Parameters:
        key - the key of the key-value pair
        defaultValue - the default value
        Returns:
        the value or defaultValue if there is no value
      • contains

        public boolean contains​(String key)
        Description copied from interface: SectionMap
        Indicate there is a key-value pair named key
        Specified by:
        contains in interface SectionMap
        Parameters:
        key - the key of the key-value pair
        Returns:
        true there is a key-value pair named key, false otherwise
      • remove

        public void remove​(String key)
        Description copied from interface: SectionMap
        Remove the key-value pair named key
        Specified by:
        remove in interface SectionMap
        Parameters:
        key - the key of the key-value pair
      • compute

        public void compute​(String key,
                            java.util.function.BiFunction<? super String,​? super Object,​?> remappingFunction)
        Description copied from interface: SectionMap
        compute the value of the key-value pair
        Specified by:
        compute in interface SectionMap
        Parameters:
        key - the key of the key-value pair
        remappingFunction - the remapping function