Class PlayerJoinListener

java.lang.Object
com.ranull.graves.listener.PlayerJoinListener
All Implemented Interfaces:
org.bukkit.event.Listener

public class PlayerJoinListener extends Object implements org.bukkit.event.Listener
Listener for handling PlayerJoinEvent to notify players about plugin updates.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final Graves
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a PlayerJoinListener with the specified Graves plugin.
  • Method Summary

    Modifier and Type
    Method
    Description
    private int
    compareVersions(String version1, String version2)
    Compares two version strings.
    private boolean
    isDifferentVersion(String currentVersion, String latestVersion)
    Checks if the current version is different from the latest version.
    private void
    notifyPlayerIfOutdated(org.bukkit.entity.Player player)
    Notifies the player if their plugin version is outdated.
    void
    onPlayerJoin(org.bukkit.event.player.PlayerJoinEvent event)
    Handles the PlayerJoinEvent to notify players about available plugin updates.
    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.
    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.
    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.
    private boolean
    shouldCheckForUpdates(org.bukkit.entity.Player player)
    Checks if updates should be checked for the player.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • plugin

      private final Graves plugin
  • Constructor Details

    • PlayerJoinListener

      public PlayerJoinListener(Graves plugin)
      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

      private int compareVersions(String version1, String version2)
      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

      private boolean isDifferentVersion(String currentVersion, String latestVersion)
      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.