Solved Lock entity to a location?(done with wg but any other way?)

Discussion in 'Plugin Development' started by Goty_Metal, Jun 4, 2013.

Thread Status:
Not open for further replies.
  1. As i said i know how to lock a entity to a worldguard region for example, make a scheduler to check mob location and if it's out just teleport it back, but there's any way to cancel the entity move? like... prevent it for moving, lock it by some way to it nevers WANT to move instead of waiting for it to move, thanks!
     
  2. I know bergerkiller his amazing BKCommonLib has an EntityMoveEvent so maybe you can use that...
     
  3. Thanks by i want to avoid using other libraries, thanks anyway :)
     
  4. You can make use of maven shading, so people will not have to download it... Or you can create a system like the lib does it (since it's open source and bergerkiller wants to give you the permission to use it)
     
  5. Offline

    timtower Administrator Administrator Moderator

  6. Erm... really any alternative? XD
     
  7. Offline

    bergerkiller

    timtower
    Shame on you, hehe. Nah it's fine, anyone is free to copy code from BKCommonLib for own uses. The move event calling code is in common/internal/CommonPlugin in the MoveEventHandler task. It is executed every tick and re-uses the same move event instance. It only changes the loc/lastloc position of the Entity.

    Handling it is easy, after depending on BKC:
    Code:
    @EventHandler(priority = EventPriority.MONITOR)
    public void onEntityMove(EntityMoveEvent event) {
      // Etc.
    }
    Goty_Metal
    Alternative is starting your own tick task and checking up on the entity positions there. The entity has a 'last' x/y/z/yaw/pitch position, but you need to access NMS/use reflection to get it.
     
    timtower likes this.
  8. That's what i thought... i just want to lock it in the same x y z, thanks pal.
     
  9. Offline

    Jnorr44

    Add it to an HashMap<Entity, Location> (entity, where you want to lock it), start a scheduler that runs every tick, and teleport it to it to the location. It will glitch a bit, but it still works. Probably the cleanest way without using NMS or CB.

    If you do ever change your mind to using NMS, there is a method in every entity class for movement every tick.
     
  10. Offline

    bergerkiller

    Jnorr44
    Yep, move method is also available in BKCommonLib:
    Code:
    CommonEntity<?> entity = CommonEntity.get(bukkitEntity);
    entity.setController(new EntityController<CommonEntity<?>>() {
        @Override
        public void onMove(double dx, double dy, double dz) {
            // You can cancel here to freeze movement
            super.onMove(dx, dy, dz);
        }
    });
     
    TheGreenGamerHD likes this.
  11. Yea but checking each tick the location of the entity is super laggy that's why i dont' like that way, i though there was some way to change mob ai to prevent it from moving, to make it static, but as i see nope XD
     
  12. Offline

    Jnorr44

    It's not actually very laggy. Think of it this way: There are hundreds of methods in NMS and CB that are running while your plugin is and are called every tick. (And they probably do a whole lot more)
     
  13. Offline

    bergerkiller

    It's not slow unless you do silly things with Location objects. Watch out with how much memory you allocate per run and how much memory you store persistently, and it'll be fine. It is also not advisable to perform things such as Block objects in there, with getRelative and etc. methods you easily end up with a lot of garbage. Then the memory can increase fairly rapidly (and you end up with a memory leak), which does degrade performance (garbage collector is busy a lot)
     
  14. I just don't like events like player movement or mob movement which means listening each tick, just do that: make any plugin that listens mob or player movement, then create a test server just whith that listener, cpu usage is increased 4% just for that listener, so yes, it's not a GREAT lag, but significant for a single plugin. Anyway thanks to all guys you're always really helpful :)
     
Thread Status:
Not open for further replies.

Share This Page