Wolf.getOwner()?

Discussion in 'Plugin Development' started by d3x, Apr 14, 2011.

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

    d3x

    http://pastie.org/1794200

    Looks like you can only obtain a wolf's target when it's attacking right now. Anyone know of a workaround to get the owner?
     
  2. Offline

    Edward Hand

  3. Offline

    d3x

    Code:
            getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable() {
                public void run() {
                    for (final World world : getServer().getWorlds()) {
                        for (final Entity entity : world.getLivingEntities()) {
                            final Location loc = entity.getLocation();
                            if (Math.abs(loc.getBlockX()) < radius && Math.abs(loc.getBlockZ()) < radius
                                    && entity instanceof CraftWolf) {
                                final CraftWolf craftWolf = (CraftWolf) entity;
                                final EntityWolf wolf = (EntityWolf) craftWolf.getHandle();
                                if (wolf.v().length() > 0 && getServer().getPlayer(wolf.v()) == null) {
                                    craftWolf.damage(100);
                                }
                            }
    
                        }
                    }
                }
            }, 1000L, 10000L);
    I came up with that to kill wolves between 0 and radius (X or Z) with a offline owner to stop my spawn area from piling up wolves and lagging the server. Does it look like it will function properly before I put it on my production server? It passed all the local tests I did. Not sure if I should be using Async or Sync though...
     
  4. Offline

    SpaceManiac

    Almost definitely sync - async runs it in a separate thread which can cause shenangians.
     
Thread Status:
Not open for further replies.

Share This Page