Solved Entity movement event?

Discussion in 'Plugin Development' started by skore87, Sep 7, 2012.

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

    skore87

    I am looking to add another feature to my region protection plugin and came across an idea to prevent entities from entering the region (other than player). Looking on the javadocs I was unable to find an event that I could call. Does anyone know what I might be able to add an event handler to for this?
     
  2. Offline

    Seadragon91

    I think the problem is that there is not event for entities movement, because there are to much entities and that could cause big lags on the server.

    You could use the EntityTargetEvent checking if the target is a player and if the player is in a region cancel the event and use the CreateSpawnEvent checking if the entity spanws in the region and cancel it.
     
  3. Offline

    skore87

    Well, it was just an idea.. oh well. I was hoping it was just an oversight on my part looking through the jd.
     
  4. Offline

    Icyene

    You can make it yourself. Create an event and a custom entity. Make the entity fire the event on h_(). Profit :) Jacek did this in his BloodMoon plugin. The source is on github, so you can probably see how.
     
    skore87 likes this.
  5. Offline

    skore87

    I'll have to take a look for that. Thanks. It'll be funny as hell to see monsters get launched away from a region if they try to enter it XD

    Took a look at the source and it is pretty dang easy. Only nuisance is that I will have to make the custom entity for every monster. I think it's worth it =)
     
  6. Offline

    joatin37

    You could also get the entites, make some code for checking their location, and then if they walk into the wrong space use a teleport event to move them back into the allowed space.
     
  7. Offline

    Courier

    What Icyene said.

    Although it would probably be more efficient to only look in the chunks of a region that does not allow entities, every few ticks. There can be a lot of entities in a world.
     
  8. Offline

    joatin37

    Even though its possible to calulate the mob caps, it can be grately exceded. Someone could for example make a sheepfarm with 2000 sheeps.
     
  9. Offline

    Courier

    Also, there are many entities which aren't mobs. For example, a dropped ItemStack is an entity.
     
  10. Offline

    Icyene

    You only have to mod the entity you are caring about, not the base entity class. = less lag.
     
  11. Offline

    skore87

    I'm planning to do all of the hostile mobs, including new ones coming soon. I don't expect it'll be too grand of a cost to the server, but I'll probably enable/disable event listener groups if there is no region in the loaded chunks that has it's type. Of course it isn't key to my plugin, though it adds a convenient feature to people trying to block entry to their area.

    Thought I'd give an update. I got it to work. Awesome sauce! You should have linked me to your tut =\ Took forever to find that I needed to add to add the zombie to the entity types class.

    For anyone else that is looking to do something similar, here are reference threads that will help you out!
    http://forums.bukkit.org/threads/tutorial-how-to-customize-the-behaviour-of-a-mob-or-entity.54547/
    http://forums.bukkit.org/threads/tutorial-custom-entities-meteor.93899/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
Thread Status:
Not open for further replies.

Share This Page