Class PEVersion

java.lang.Object
com.github.retrooper.packetevents.util.PEVersion
All Implemented Interfaces:
Comparable<PEVersion>

public class PEVersion extends Object implements Comparable<PEVersion>
Represents a PacketEvents version using Semantic Versioning. Supports version comparison, cloning, and provides a string representation. Snapshot versioning is also supported. Generally a snapshot version is published before the release version, and thus, is considered "older" than the release version.
  • Constructor Details

    • PEVersion

      public PEVersion(int major, int minor, int patch, boolean snapshot, @Nullable @Nullable String snapshotCommit)
      Constructs a PEVersion instance.
      Parameters:
      major - the major version number.
      minor - the minor version number.
      patch - the patch version number.
      snapshot - whether the version is a snapshot.
      snapshotCommit - the snapshot commit hash, if available.
    • PEVersion

      public PEVersion(int major, int minor, int patch, @Nullable @Nullable String snapshotCommit)
      Constructs a PEVersion instance.
      Parameters:
      major - the major version number.
      minor - the minor version number.
      patch - the patch version number.
      snapshotCommit - the snapshot commit hash, if available.
    • PEVersion

      public PEVersion(int major, int minor, int patch, boolean snapshot)
      Constructs a PEVersion instance.
      Parameters:
      major - the major version number.
      minor - the minor version number.
      patch - the patch version number.
      snapshot - whether the version is a snapshot.
    • PEVersion

      public PEVersion(int major, int minor, int patch)
      Constructs a PEVersion instance with snapshot defaulted to false.
      Parameters:
      major - the major version number.
      minor - the minor version number.
      patch - the patch version number.
    • PEVersion

      @Deprecated public PEVersion(int... version)
      Constructs a PEVersion instance from an array of version numbers.
      Parameters:
      version - the version numbers (e.g., {1, 8, 9}).
    • PEVersion

      @Deprecated public PEVersion(@NotNull @NotNull String version)
      Deprecated.
      use fromString(String) instead.
      Constructs a PEVersion instance from a version string.
      Parameters:
      version - the version string (e.g., "1.8.9-SNAPSHOT").
      Throws:
      IllegalArgumentException - if the version string format is incorrect.
  • Method Details

    • fromString

      public static PEVersion fromString(@NotNull @NotNull String version)
      Constructs a PEVersion instance from a version string.
      Parameters:
      version - the version string (e.g., "1.8.9-SNAPSHOT").
      Throws:
      IllegalArgumentException - if the version string format is incorrect.
    • major

      public int major()
      Gets the major version number.
      Returns:
      the major version number.
    • minor

      public int minor()
      Gets the minor version number.
      Returns:
      the minor version number.
    • patch

      public int patch()
      Gets the patch version number.
      Returns:
      the patch version number.
    • snapshot

      public boolean snapshot()
      Checks if the version is a snapshot.
      Returns:
      true if snapshot, false otherwise.
    • snapshotCommit

      @Nullable public @Nullable String snapshotCommit()
      Gets the snapshot commit hash of the PacketEvents snapshot version. May be of any length. Availability is not guaranteed since it is contingent on how the program was built. Generally speaking, the commit hash can only be available if the PacketEvents version is a snapshot version.
      Returns:
      the snapshot commit hash, if available.
    • compareTo

      public int compareTo(@NotNull @NotNull PEVersion other)
      Compares this PEVersion with another PEVersion.
      Specified by:
      compareTo in interface Comparable<PEVersion>
      Parameters:
      other - the other PEVersion.
      Returns:
      a negative integer, zero, or a positive integer as this version can be less than, equal to, or greater than the specified version.
    • equals

      public boolean equals(@NotNull @NotNull Object obj)
      Checks if the provided object is equal to this PEVersion.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare.
      Returns:
      true if the provided object is equal to this PEVersion, false otherwise.
    • isNewerThan

      public boolean isNewerThan(@NotNull @NotNull PEVersion otherVersion)
      Checks if this version is newer than the provided version.
      Parameters:
      otherVersion - the other PEVersion.
      Returns:
      true if this version is newer, false otherwise.
    • isOlderThan

      public boolean isOlderThan(@NotNull @NotNull PEVersion otherVersion)
      Checks if this version is older than the provided version.
      Parameters:
      otherVersion - the other PEVersion.
      Returns:
      true if this version is older, false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for this PEVersion.
      Overrides:
      hashCode in class Object
      Returns:
      a hash code value.
    • clone

      public PEVersion clone()
      Creates and returns a copy of this PEVersion.
      Overrides:
      clone in class Object
      Returns:
      a clone of this instance.
    • toString

      public String toString()
      Converts the PEVersion to a string representation. If this is a stable release, the snapshot and the commit will not be included in the representation.
      Overrides:
      toString in class Object
      Returns:
      string representation of the version.
    • toStringWithoutSnapshot

      public String toStringWithoutSnapshot()
      Converts the PEVersion to a string representation with guarantee that it will not have the commit attached to it. Useful for accessing the string representation for metrics as detailed information, such as the commit, is not required.
      Returns:
      guaranteed string representation without commit.
    • asArray

      @Deprecated public int[] asArray()
      Deprecated.
      since PEVersion instances now always use Semantic Versioning, and thus, returning an "amorphous" array, with no definitive size, seems redundant.
      Converts the PEVersion to an array of version numbers.
      Returns:
      an array of version numbers.