Created
September 9, 2018 18:46
-
-
Save aikar/eb146579560deb5fca7c6a641478ea12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private boolean flee() { | |
if (runAway == null || runAway.distance(entity.getLocation()) < 5) { | |
runAway = Util.getValidRandLocMinDist(8, entity.getLocation(), 14, 5, true); | |
} | |
if (runAway != null) { | |
entity.setTarget(null); | |
fleeing = false; | |
boolean result = API.entity.setEntityDestination(entity, runAway, 1.15); | |
fleeing = true; | |
return result; | |
} | |
return false; | |
} | |
@NotNull | |
private static PotionData boostType(PotionType type) { | |
return new PotionData(type, type.isExtendable() && !type.isUpgradeable(), type.isUpgradeable()); | |
} | |
@EventHandler(ignoreCancelled = true) | |
public void onWitchReadyPotion(WitchReadyPotionEvent event) { | |
if (isFleeing()) { | |
event.setCancelled(true); | |
} | |
} | |
@EventHandler(ignoreCancelled = true) | |
public void onEntityTarget(EntityTargetEvent event) { | |
if (isFleeing() && event.getTarget() != null) { | |
event.setCancelled(true); | |
} | |
} | |
@EventHandler(ignoreCancelled = true) | |
public void onEntityPathfind(EntityPathfindEvent event) { | |
if (isFleeing() && runAway != null && runAway.distance(event.getLoc()) > 2) { | |
event.setCancelled(true); | |
} | |
} | |
@EventHandler(ignoreCancelled = true) | |
public void onEntityRandomStroll(EntityRandomStrollEvent event) { | |
if (entity.getTarget() != null || isFleeing()) { | |
event.setCancelled(true); | |
} | |
} | |
@EventHandler(ignoreCancelled = true) | |
public void onEntityPrepForRangedAttack(EntityPrepForRangedAttack event) { | |
if (isFleeing()) { | |
event.setCancelled(true); | |
} | |
} | |
@EventHandler(ignoreCancelled = true) | |
public void onEntityPathfindEnd(EntityPathfindEndEvent event) { | |
if (isFleeing()) { | |
double distance = runAway.distance(entity.getLocation()); | |
if (distance < 3) { | |
runAway = null; | |
} | |
flee(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment