how to get the player in onEnable()

Discussion in 'Plugin Development' started by EssentialsPissesMeOff, Nov 13, 2019.

Thread Status:
Not open for further replies.
  1. as title says, how do i? there has to be a way.
  2. Offline


    What do you mean? OnEnable() occurs when the plugin is started up. There is no player involved.
  3. Offline

    timtower Moderator Moderator

    What are you trying to make?
  4. Offline


    Do you mean when a player joins the server? There is an event for that
  5. Im looking for a way to constantly update particles on a player so they run forever if they are enabled, the only way i know how to do this is by using a Bukkit Scheduler and running it every certain interval, but to run the particles inside the scheduler, i need the player instance, but the scheduler is comming from onEnable() so i cant use any of the normal means of getting the player instance. someone told me to put this inside the scheduler but i do not know what to do next, do i just merely plug my player particle method inside it?

            for(Player online : Bukkit.getOnlinePlayers()) {
    this is the code i want to use that needs the player
            Location location = player.getLocation();
            location.setY(location.getY() - 2);
            if (cloud.contains(player.getUniqueId())) {
                player.spawnParticle(Particle.CLOUD, location.getX(), location.getY(), location.getZ(), 1);
    "cloud" comes from an arraylist that is connected to UUID.
  6. Offline


    @EssentialsPissesMeOff That's an enhanced for loop, it's getting a collection of all the online players, and then iterating over them, which means you now have a player instance.
    Then you check if they should have the particles, and finally you spawn the particles.
    I'm not sure i explained that well enough, let me know if you don't understand what i mean.
  7. i can somewhat understand but im stupid so...
  8. Offline


    Well, give it a shot. If it fails to work as you expect, post the code you tried.
Thread Status:
Not open for further replies.

Share This Page