Polling via API or Runnable?

Discussion in 'Plugin Development' started by tamarok, May 13, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    tamarok

    I am writing a plugin that will poll at intervals to check the server’s public IP address and then publish it to a service. At the moment I am simply looking to create a new thread and in a run() statement just loop, with a sleep, until the plugin is disabled. Is this the way to go or is there an alternative way I should be approaching this, using the API?

    Also, is there a data cache that can be used, so I can store the last IP address discovered, between restarts? I only want to publish the IP if it has changed.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @tamarok You want to make a tool as a plugin that should be a standalone instead.
     
  3. Offline

    tamarok

    This won't be the only feature of the plugin, so it just made sense to bundle the functionality. Doing this way has a few benefits:

    - Platform agnostic (Windows, Linux, macOS)
    - Simplifies the support burden, since
    - Not everyone is technical
    - It is consistent across platforms.
    - Don't need to deal with multiple approaches​
    - Only notifies while the MC server is running

    BTW the plugin is this one: https://github.com/ajmas/DiscordWebhookX
     
  4. Offline

    timtower Administrator Administrator Moderator

    @tamarok Why would it need to publish it to a service? IP won't change while running I assume (otherwise the machine is really messed up)
    Do it just on startup, let it update the service anyways or store it in the config.
     
  5. Offline

    tamarok

    Ideally it should not, but that is not the reality we are dealing with.

    The server is running on a friend’s home network, unattended, shared amongst friends remotely. Periodically the router resets, the ISP runs into issues and the assigned external IP changes. BTW the machine’s IP is not the issue here, just the external IP of the network.

    Anyhow at this point I have just gone with a thread that starts when the plugin is enabled and terminated when the plugin is disabled. It is working for our needs.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @tamarok BukkitRunnable#runTaskTimerAsync
     
Thread Status:
Not open for further replies.

Share This Page