Class PEVersion
java.lang.Object
com.github.retrooper.packetevents.util.PEVersion
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionPEVersion(int... version) Deprecated.PEVersion(int major, int minor, int patch) Constructs aPEVersioninstance with snapshot defaulted to false.PEVersion(int major, int minor, int patch, boolean snapshot) Constructs aPEVersioninstance.Constructs aPEVersioninstance.Constructs aPEVersioninstance.Deprecated.usefromString(String)instead. -
Method Summary
Modifier and TypeMethodDescriptionint[]asArray()Deprecated.sincePEVersioninstances now always use Semantic Versioning, and thus, returning an "amorphous" array, with no definitive size, seems redundant.clone()Creates and returns a copy of thisPEVersion.intbooleanChecks if the provided object is equal to thisPEVersion.static PEVersionfromString(@NotNull String version) Constructs aPEVersioninstance from a version string.inthashCode()Returns a hash code value for thisPEVersion.booleanisNewerThan(@NotNull PEVersion otherVersion) Checks if this version is newer than the provided version.booleanisOlderThan(@NotNull PEVersion otherVersion) Checks if this version is older than the provided version.intmajor()Gets the major version number.intminor()Gets the minor version number.intpatch()Gets the patch version number.booleansnapshot()Checks if the version is a snapshot.@Nullable StringGets the snapshot commit hash of the PacketEvents snapshot version.toString()Converts thePEVersionto a string representation.Converts thePEVersionto a string representation with guarantee that it will not have the commit attached to it.
-
Constructor Details
-
PEVersion
public PEVersion(int major, int minor, int patch, boolean snapshot, @Nullable @Nullable String snapshotCommit) Constructs aPEVersioninstance.- 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
Constructs aPEVersioninstance.- 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 aPEVersioninstance.- 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 aPEVersioninstance with snapshot defaulted to false.- Parameters:
major- the major version number.minor- the minor version number.patch- the patch version number.
-
PEVersion
Deprecated.usePEVersion(int, int, int)orPEVersion(int, int, int, boolean)instead.Constructs aPEVersioninstance from an array of version numbers.- Parameters:
version- the version numbers (e.g., {1, 8, 9}).
-
PEVersion
Deprecated.usefromString(String)instead.Constructs aPEVersioninstance 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
Constructs aPEVersioninstance 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
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
- Specified by:
compareToin interfaceComparable<PEVersion>- Parameters:
other- the otherPEVersion.- 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
Checks if the provided object is equal to thisPEVersion. -
isNewerThan
Checks if this version is newer than the provided version.- Parameters:
otherVersion- the otherPEVersion.- Returns:
- true if this version is newer, false otherwise.
-
isOlderThan
Checks if this version is older than the provided version.- Parameters:
otherVersion- the otherPEVersion.- Returns:
- true if this version is older, false otherwise.
-
hashCode
public int hashCode()Returns a hash code value for thisPEVersion. -
clone
Creates and returns a copy of thisPEVersion. -
toString
Converts thePEVersionto a string representation. If this is a stable release, the snapshot and the commit will not be included in the representation. -
toStringWithoutSnapshot
Converts thePEVersionto 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.sincePEVersioninstances now always use Semantic Versioning, and thus, returning an "amorphous" array, with no definitive size, seems redundant.Converts thePEVersionto an array of version numbers.- Returns:
- an array of version numbers.
-
PEVersion(int, int, int)orPEVersion(int, int, int, boolean)instead.