#lets stop polluting the main chat

1 messages · Page 1 of 1 (latest)

fair kite
#
public class SentryTask extends BukkitRunnable
{
  private LivingEntity sentry;

  public SentryTask(LivingEntity entity)
  {
    sentry = entity;
  }

  @Override
  public void run()
  {
    if(sentry==null || sentry.isDead())
      this.cancel();
    else
      detectNearestEntity(sentry);
  }
}
#

this has a constructor instead of an init method.
now you can say things like:

SentryTask sentryTask = new SentryTask(myEntity);
ancient moss
#

I need more Java and vocabulary study nah

fair kite
#

also, instead of using isDead() i recommend probably using isValid() instead

#

because isValid() detects death as well as other despawn cases

#

so this line:

if(sentry==null || sentry.isDead())

would be:

if(sentry==null || !sentry.isValid())

instead

#

(i added the null check just in case you ever accidentally construct a SentryTask with a null entity, but you can skip this if you would rather see null pointer exceptions)

ancient moss
#

Since this is my first project on Java and plugins, I want to say thanks

fair kite
#

np, glad to help out

ancient moss
#

can i get your github link?

fair kite
#

i don't use github, i host my own svn server that i use, srry

#

i just prefer svn over git