Solved Removing an entity when the server is shutting down

Discussion in 'Spigot Plugin Development' started by WiseHollow, Jun 3, 2017.

Thread Status:
Not open for further replies.
  1. Hi, I need help removing an entity when the server is shutting down. I have a reference to the entity. However, on shutdown entity#remove doesn't help. When I start the server back up, its still there. I also tried listening to the WorldUnloadEvent, and its still not working. The entity I'm referring to is a
    AreaEffectCloud.

    Any assistance is appreciated.
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    Are you you're putting the code in the onDisable()? It should work. You may also want to use the UUID of the entity and use Bukkit.getEntity(UUID) instead of saving the entity instance.

    If that doesn't work, you could always save the UUID to a config and remove it onEnable. That way, it'll remove the entity even when the server crashes.
     
    • Useful Useful x 2
  3. I would like to try removing by UUID, but I cannot find the method you spoke of (Bukkit.getEntity(UUID)) isn't anywhere I look. Do I have to use the Shaded version of the API? @ScarabCoder
     

  4. it's World#getEntity
     
  5. I'm looking in "World" as well and do not see it. Can you provide a screenshot that shows this? The only thing I see is, World.getEntities(). @ChefJava
     
  6. You keep a list of all your entity's you're controlling. As the server shuts down (onDisable) loop through that list and remove it
     
  7. Just loop over the entities in the world world.getEntities() and if it's your entity remove it ?
     
  8. That's what I did. Read the thread's first message.
    I'll give that a try and see.
     
  9. Code (Text):
            for(Entity ent : world.getEntities()) {
                if(ent.getUniqueId().equals("blab")) {
                    ent.remove();
                }
            }
     
  10. Interestingly enough, even a direct way like this doesn't seem to work. I come back on and the particle effect is still there. xD
    Code (Text):

    @Override
    public void onDisable()
    {
        for (Dungeon dungeon : Dungeon.getDungeonList())
            for (EntitySpawnPoint entitySpawnPoint : dungeon.getEntitySpawnPointList())
                if (entitySpawnPoint.getAreaEffectCloudUUID() != null)
                    for (Entity e : entitySpawnPoint.getLocation().getWorld().getEntities())
                        if (e.getUniqueId().equals(entitySpawnPoint.getAreaEffectCloudUUID()))
                        {
                            e.remove();
                            getLogger().info("Removing entity from dungeon.");
                        }

        getLogger().info(getDescription().getName() + " is now disabled.");
    }
     
    Showing that it tried to... here is the log.
     
  11. Are you sure it's not getting started up again upon restart? Creating the illusion that it never stopped?
     
  12. The code is on onDisable, why would it be executed during startup, and why should it matter if its a restart or a full shutdown and power on?
     
    • Agree Agree x 1
  13. I made a local server with just my plugins on it, and the entity removes perfectly fine with my original code. Time to figure out which plugin is causing this mess. (sad)

    Thank you, @ChefJava @ScarabCoder @Bobcatsss @ButterMuffin

    Edit: Actually its not a plugin. It's because of Multicraft. When I use the "Stop" or "Restart" button, it doesn't remove the entity; however, if I use '/Stop' command, it removes the entity fine.
     
    #13 WiseHollow, Jun 3, 2017
    Last edited: Jun 3, 2017
  14. I don't think you read my reply correctly, I was saying would it be possible on start up that the particle would be created again...


    Are you sure it's not getting started up again upon restart? Creating the illusion that it never stopped?
     
    #14 NavyDev, Jun 3, 2017
    Last edited: Jun 3, 2017
  15. Your sentence structure is horrible and grammatically flawed. He isn't the only one who reads your posts and isn't sure if you know what you're talking about. You were trying to help, but it turned into you insisting you know more than others. Just because someone is asking for help on here, doesn't mean you know more. Especially when the only things you suggest, are things the OP has already tried, or things that do not make sense.

    I have no code that auto spawns any entities.
     
    • Optimistic Optimistic x 1
Thread Status:
Not open for further replies.