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
ConstructorDescriptionPEVersion
(int... version) Deprecated.PEVersion
(int major, int minor, int patch) Constructs aPEVersion
instance with snapshot defaulted to false.PEVersion
(int major, int minor, int patch, boolean snapshot) Constructs aPEVersion
instance.Constructs aPEVersion
instance.Constructs aPEVersion
instance.Deprecated.usefromString(String)
instead. -
Method Summary
Modifier and TypeMethodDescriptionint[]
asArray()
Deprecated.sincePEVersion
instances 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
.int
boolean
Checks if the provided object is equal to thisPEVersion
.static PEVersion
fromString
(@NotNull String version) Constructs aPEVersion
instance from a version string.int
hashCode()
Returns a hash code value for thisPEVersion
.boolean
isNewerThan
(@NotNull PEVersion otherVersion) Checks if this version is newer than the provided version.boolean
isOlderThan
(@NotNull PEVersion otherVersion) Checks if this version is older than the provided version.int
major()
Gets the major version number.int
minor()
Gets the minor version number.int
patch()
Gets the patch version number.boolean
snapshot()
Checks if the version is a snapshot.@Nullable String
Gets the snapshot commit hash of the PacketEvents snapshot version.toString()
Converts thePEVersion
to a string representation.Converts thePEVersion
to 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 aPEVersion
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
Constructs aPEVersion
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 aPEVersion
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 aPEVersion
instance 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 aPEVersion
instance from an array of version numbers.- Parameters:
version
- the version numbers (e.g., {1, 8, 9}).
-
PEVersion
Deprecated.usefromString(String)
instead.Constructs aPEVersion
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
Constructs aPEVersion
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
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:
compareTo
in 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 thePEVersion
to a string representation. If this is a stable release, the snapshot and the commit will not be included in the representation. -
toStringWithoutSnapshot
Converts thePEVersion
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.sincePEVersion
instances now always use Semantic Versioning, and thus, returning an "amorphous" array, with no definitive size, seems redundant.Converts thePEVersion
to an array of version numbers.- Returns:
- an array of version numbers.
-
PEVersion(int, int, int)
orPEVersion(int, int, int, boolean)
instead.