Package com.ranull.graves.listener
Class PlayerJoinListener
java.lang.Object
com.ranull.graves.listener.PlayerJoinListener
- All Implemented Interfaces:
org.bukkit.event.Listener
Listener for handling PlayerJoinEvent to notify players about plugin updates.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPlayerJoinListener(Graves plugin) Constructs a PlayerJoinListener with the specified Graves plugin. -
Method Summary
Modifier and TypeMethodDescriptionprivate intcompareVersions(String version1, String version2) Compares two version strings.private booleanisDifferentVersion(String currentVersion, String latestVersion) Checks if the current version is different from the latest version.private voidnotifyPlayerIfOutdated(org.bukkit.entity.Player player) Notifies the player if their plugin version is outdated.voidonPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) Handles the PlayerJoinEvent to notify players about available plugin updates.private voidsendDevelopmentVersionMessage(org.bukkit.entity.Player player, double currentVersion) Sends a message to the player indicating that they are using a development version of the plugin.private voidsendOutdatedVersionMessage(org.bukkit.entity.Player player, double currentVersion, double latestVersion) Sends a message to the player indicating that their plugin version is outdated.private voidsendOutdatedVersionMessage(org.bukkit.entity.Player player, String currentVersion, String latestVersion) Sends a message to the player indicating that their plugin version is outdated.private booleanshouldCheckForUpdates(org.bukkit.entity.Player player) Checks if updates should be checked for the player.
-
Field Details
-
plugin
-
-
Constructor Details
-
PlayerJoinListener
Constructs a PlayerJoinListener with the specified Graves plugin.- Parameters:
plugin- The Graves plugin instance.
-
-
Method Details
-
onPlayerJoin
public void onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event) Handles the PlayerJoinEvent to notify players about available plugin updates. This method checks if the plugin's update check is enabled and if the player has the permission to receive update notifications. If so, it runs an asynchronous task to fetch the latest version of the plugin and compares it with the player's current version. If the player's version is outdated, a message is sent to the player indicating the current version, the latest version, and a link to the Spigot resource page. The comparison is handled carefully to ensure proper handling of version format errors.- Parameters:
event- The PlayerJoinEvent to handle.
-
shouldCheckForUpdates
private boolean shouldCheckForUpdates(org.bukkit.entity.Player player) Checks if updates should be checked for the player.- Parameters:
player- The player to check.- Returns:
- True if updates should be checked, false otherwise.
-
notifyPlayerIfOutdated
private void notifyPlayerIfOutdated(org.bukkit.entity.Player player) Notifies the player if their plugin version is outdated.- Parameters:
player- The player to notify.
-
compareVersions
Compares two version strings.- Parameters:
version1- The first version string.version2- The second version string.- Returns:
- A negative integer, zero, or a positive integer as the first version is less than, equal to, or greater than the second version.
-
sendOutdatedVersionMessage
private void sendOutdatedVersionMessage(org.bukkit.entity.Player player, double currentVersion, double latestVersion) Sends a message to the player indicating that their plugin version is outdated.- Parameters:
player- The player to notify.currentVersion- The current version of the plugin.latestVersion- The latest version of the plugin.
-
sendDevelopmentVersionMessage
private void sendDevelopmentVersionMessage(org.bukkit.entity.Player player, double currentVersion) Sends a message to the player indicating that they are using a development version of the plugin.- Parameters:
player- The player to notify.currentVersion- The current version of the plugin.
-
sendOutdatedVersionMessage
private void sendOutdatedVersionMessage(org.bukkit.entity.Player player, String currentVersion, String latestVersion) Sends a message to the player indicating that their plugin version is outdated.- Parameters:
player- The player to notify.currentVersion- The current version of the plugin.latestVersion- The latest version of the plugin.
-
isDifferentVersion
Checks if the current version is different from the latest version.- Parameters:
currentVersion- The current version.latestVersion- The latest version.- Returns:
- True if the versions are different, false otherwise.
-