#lets stop polluting the main chat
1 messages · Page 1 of 1 (latest)
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);
I need more Java and vocabulary study nah
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)
Since this is my first project on Java and plugins, I want to say thanks
np, glad to help out
can i get your github link?