use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditor_v1_11_R1 method updatePlayer.
@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final UUID uuid = player.getUniqueId();
PacketPlayOutEntityDestroy destroyPacket = new PacketPlayOutEntityDestroy(entityPlayer.getId());
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!p.getUniqueId().equals(uuid)) {
PacketHelper_v1_11_R1.sendPacket(p, destroyPacket);
}
}
new BukkitRunnable() {
@Override
public void run() {
PacketPlayOutPlayerInfo playerInfo = new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.ADD_PLAYER, entityPlayer);
PacketPlayOutNamedEntitySpawn spawnPacket = new PacketPlayOutNamedEntitySpawn(entityPlayer);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
PacketHelper_v1_11_R1.sendPacket(player, playerInfo);
if (!player.getUniqueId().equals(uuid)) {
PacketHelper_v1_11_R1.sendPacket(player, spawnPacket);
} else {
if (isSkinChanging) {
boolean isFlying = player.isFlying();
PacketHelper_v1_11_R1.sendPacket(player, new PacketPlayOutRespawn(player.getWorld().getEnvironment().getId(), entityPlayer.getWorld().getDifficulty(), entityPlayer.getWorld().worldData.getType(), entityPlayer.playerInteractManager.getGameMode()));
player.teleport(player.getLocation(), PlayerTeleportEvent.TeleportCause.PLUGIN);
player.setFlying(isFlying);
}
player.updateInventory();
}
}
}
}.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_8_R3 method follow.
@Override
public void follow(final Entity target, final Entity follower, final double speed, final double lead, final double maxRange, final boolean allowWander) {
if (target == null || follower == null) {
return;
}
final net.minecraft.server.v1_8_R3.Entity nmsEntityFollower = ((CraftEntity) follower).getHandle();
if (!(nmsEntityFollower instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsFollower = (EntityInsentient) nmsEntityFollower;
final NavigationAbstract followerNavigation = nmsFollower.getNavigation();
UUID uuid = follower.getUniqueId();
if (followTasks.containsKey(uuid)) {
followTasks.get(uuid).cancel();
}
final int locationNearInt = (int) Math.floor(lead);
final boolean hasMax = maxRange > lead;
followTasks.put(follower.getUniqueId(), new BukkitRunnable() {
private boolean inRadius = false;
public void run() {
if (!target.isValid() || !follower.isValid()) {
this.cancel();
}
followerNavigation.a(2F);
Location targetLocation = target.getLocation();
PathEntity path;
if (hasMax && !Utilities.checkLocation(targetLocation, follower.getLocation(), maxRange) && !target.isDead() && target.isOnGround()) {
if (!inRadius) {
follower.teleport(Utilities.getWalkableLocationNear(targetLocation, locationNearInt));
} else {
inRadius = false;
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
}
} else if (!inRadius && !Utilities.checkLocation(targetLocation, follower.getLocation(), lead)) {
path = followerNavigation.a(targetLocation.getX(), targetLocation.getY(), targetLocation.getZ());
if (path != null) {
followerNavigation.a(path, 1D);
followerNavigation.a(2D);
}
} else {
inRadius = true;
}
if (inRadius && !allowWander) {
followerNavigation.n();
}
nmsFollower.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 0, 10));
}
use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_8_R3 method walkTo.
@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
net.minecraft.server.v1_8_R3.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();
final PathEntity path;
final boolean aiDisabled = isAIDisabled(entity);
if (aiDisabled) {
toggleAI(entity, true);
nmsEntity.onGround = true;
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
if (path != null) {
entityNavigation.a(path, 1D);
entityNavigation.a(2D);
final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b();
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
new BukkitRunnable() {
@Override
public void run() {
if (entityNavigation.m() || path.b()) {
if (callback != null) {
callback.run();
}
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
if (aiDisabled) {
toggleAI(entity, false);
}
cancel();
}
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
} else //if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
// TODO: generate waypoints to the target location?
{
entity.teleport(location);
}
}
use of org.bukkit.scheduler.BukkitRunnable in project Denizen-For-Bukkit by DenizenScript.
the class EntityHelper_v1_11_R1 method walkTo.
@Override
public void walkTo(final Entity entity, Location location, double speed, final Runnable callback) {
if (entity == null || location == null) {
return;
}
net.minecraft.server.v1_11_R1.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof EntityInsentient)) {
return;
}
final EntityInsentient nmsEntity = (EntityInsentient) nmsEntityEntity;
final NavigationAbstract entityNavigation = nmsEntity.getNavigation();
final PathEntity path;
final boolean aiDisabled = isAIDisabled(entity);
if (aiDisabled) {
toggleAI(entity, true);
nmsEntity.onGround = true;
}
path = entityNavigation.a(location.getX(), location.getY(), location.getZ());
if (path != null) {
entityNavigation.a(path, 1D);
entityNavigation.a(2D);
final double oldSpeed = nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).b();
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(speed);
new BukkitRunnable() {
@Override
public void run() {
if (entityNavigation.n() || path.b()) {
if (callback != null) {
callback.run();
}
nmsEntity.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(oldSpeed);
if (aiDisabled) {
toggleAI(entity, false);
}
cancel();
}
}
}.runTaskTimer(NMSHandler.getJavaPlugin(), 1, 1);
} else //if (!Utilities.checkLocation(location, entity.getLocation(), 20)) {
// TODO: generate waypoints to the target location?
{
entity.teleport(location);
}
}
use of org.bukkit.scheduler.BukkitRunnable in project EliteMobs by MagmaGuy.
the class MinorPowerPowerStance method itemEffect.
//Secondary effect particle processing
// private void particleEffect(Entity entity, Particle particle, int particleAmount, double v, double v1, double v2, double v3) {
// if (ConfigValues.defaultConfig.getBoolean("Turn on visual effects for natural or plugin-spawned EliteMobs")) {
//
// if (ConfigValues.defaultConfig.getBoolean("Turn off visual effects for non-natural or non-plugin-spawned EliteMobs")
// && !entity.hasMetadata(MetadataHandler.NATURAL_MOB_MD)) {
//
// return;
//
// }
//
// processID = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
//
// float counter = 0;
//
// public void run() {
//
// List<Location> particleLocations = powerStanceMath.cylindricalPowerStance(entity, radiusHorizontal, radiusVertical, speedHorizontal, speedVertical, counter);
//
// Location location1 = particleLocations.get(0);
// Location location2 = particleLocations.get(1);
//
// entity.getWorld().spawnParticle(particle, location1, particleAmount, v, v1, v2, v3);
// entity.getWorld().spawnParticle(particle, location2, particleAmount, v, v1, v2, v3);
//
// if (!entity.isValid()) {
//
// Bukkit.getScheduler().cancelTask(processID);
//
// }
//
// counter++;
//
// }
//
// }, 1L, 1L);
//
// }
//
// }
// public void attackConfusing(Entity entity) {
//
// particleEffect(entity, Particle.SPELL_MOB, 5, 0, 0, 0, 0.01);
//
// }
//
// public void invulnerabilityFireEffect(Entity entity) {
//
// particleEffect(entity, Particle.FLAME, 5, 0, 0, 0, 0.01);
//
// }
//Secondary effect item processing
public void itemEffect(Entity entity) {
if (ConfigValues.defaultConfig.getBoolean("Turn on visual effects for natural or plugin-spawned EliteMobs")) {
if (ConfigValues.defaultConfig.getBoolean("Turn off visual effects for non-natural or non-plugin-spawned EliteMobs") && !entity.hasMetadata(MetadataHandler.NATURAL_MOB_MD)) {
return;
}
if (entity.hasMetadata(MetadataHandler.VISUAL_EFFECT_MD)) {
return;
}
entity.setMetadata("VisualEffect", new FixedMetadataValue(plugin, true));
//contains all items around a given entity
HashMap<Integer, HashMap<Integer, List<Item>>> powerItemLocationTracker = new HashMap<>();
new BukkitRunnable() {
int attackArrowCounter = 0;
int attackBlindingCounter = 0;
int attackFireCounter = 0;
int attackFireballCounter = 0;
int attackFreezeCounter = 0;
int attackGravityCounter = 0;
int attackPoisonCounter = 0;
int attackPushCounter = 0;
int attackWeaknessCounter = 0;
int attackWebCounter = 0;
int attackWitherCounter = 0;
int bonusLootCounter = 0;
int doubleDamageCounter = 0;
int doubleHealthCounter = 0;
int invisibilityCounter = 0;
int invulnerabilityArrowCounter = 0;
int invulnerabilityFallDamageCounter = 0;
int invulnerabilityKnockbackCounter = 0;
int movementSpeedCounter = 0;
int tauntCounter = 0;
public void run() {
// int effectQuantity = 0;
int effectIteration = 0;
//apply new positioning
if (entity.hasMetadata(MetadataHandler.ATTACK_ARROW_MD)) {
ItemStack itemStack = new ItemStack(Material.ARROW, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackArrowCounter);
effectIteration++;
attackArrowCounter++;
if (attackArrowCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackArrowCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_BLINDING_MD)) {
ItemStack itemStack = new ItemStack(Material.EYE_OF_ENDER, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackBlindingCounter);
effectIteration++;
attackBlindingCounter++;
if (attackBlindingCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackBlindingCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_FIRE_MD)) {
ItemStack itemStack = new ItemStack(Material.LAVA_BUCKET, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackFireCounter);
effectIteration++;
attackFireCounter++;
if (attackFireCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackFireCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_FIREBALL_MD)) {
ItemStack itemStack = new ItemStack(Material.FIREBALL, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackFireballCounter);
effectIteration++;
attackFireballCounter++;
if (attackFireballCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackFireballCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_FREEZE_MD)) {
ItemStack itemStack = new ItemStack(Material.PACKED_ICE, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackFreezeCounter);
effectIteration++;
attackFreezeCounter++;
if (attackFreezeCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackFreezeCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_GRAVITY_MD)) {
ItemStack itemStack = new ItemStack(Material.ELYTRA, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackGravityCounter);
effectIteration++;
attackGravityCounter++;
if (attackGravityCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackGravityCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_POISON_MD)) {
ItemStack itemStack = new ItemStack(Material.EMERALD, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackPoisonCounter);
effectIteration++;
attackPoisonCounter++;
if (attackPoisonCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackPoisonCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_PUSH_MD)) {
ItemStack itemStack = new ItemStack(Material.PISTON_BASE, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackPushCounter);
effectIteration++;
attackPushCounter++;
if (attackPushCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackPushCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_WEAKNESS_MD)) {
ItemStack itemStack = new ItemStack(Material.TOTEM, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackWeaknessCounter);
effectIteration++;
attackWeaknessCounter++;
if (attackWeaknessCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackWeaknessCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_WEB_MD)) {
ItemStack itemStack = new ItemStack(Material.WEB, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackWebCounter);
effectIteration++;
attackWebCounter++;
if (attackWebCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackWebCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.ATTACK_WITHER_MD)) {
ItemStack itemStack = new ItemStack(Material.SKULL_ITEM, 1, (short) 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, attackWitherCounter);
effectIteration++;
attackWitherCounter++;
if (attackWitherCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
attackWitherCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.BONUS_LOOT_MD)) {
ItemStack itemStack = new ItemStack(Material.CHEST, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, bonusLootCounter);
effectIteration++;
bonusLootCounter++;
if (bonusLootCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
bonusLootCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.DOUBLE_DAMAGE_MD)) {
ItemStack itemStack = new ItemStack(Material.GOLD_SWORD, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, doubleDamageCounter);
effectIteration++;
doubleDamageCounter++;
if (doubleDamageCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
doubleDamageCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.DOUBLE_HEALTH_MD)) {
ItemStack itemStack = new ItemStack(Material.SHIELD, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, doubleHealthCounter);
effectIteration++;
doubleHealthCounter++;
if (doubleHealthCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
doubleHealthCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.INVISIBILITY_MD)) {
ItemStack itemStack = new ItemStack(Material.THIN_GLASS, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, invisibilityCounter);
effectIteration++;
invisibilityCounter++;
if (invisibilityCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
invisibilityCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.INVULNERABILITY_ARROW_MD)) {
ItemStack itemStack = new ItemStack(Material.SPECTRAL_ARROW, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, invulnerabilityArrowCounter);
effectIteration++;
invulnerabilityArrowCounter++;
if (invulnerabilityArrowCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
invulnerabilityArrowCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.INVULNERABILITY_FALL_DAMAGE_MD)) {
ItemStack itemStack = new ItemStack(Material.FEATHER, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, invulnerabilityFallDamageCounter);
effectIteration++;
invulnerabilityFallDamageCounter++;
if (invulnerabilityFallDamageCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
invulnerabilityFallDamageCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.INVULNERABILITY_KNOCKBACK_MD)) {
ItemStack itemStack = new ItemStack(Material.ANVIL, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, invulnerabilityKnockbackCounter);
effectIteration++;
invulnerabilityKnockbackCounter++;
if (invulnerabilityKnockbackCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
invulnerabilityKnockbackCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.MOVEMENT_SPEED_MD)) {
ItemStack itemStack = new ItemStack(Material.GOLD_BOOTS, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, movementSpeedCounter);
effectIteration++;
movementSpeedCounter++;
if (movementSpeedCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
movementSpeedCounter = 0;
}
}
if (entity.hasMetadata(MetadataHandler.TAUNT_MD)) {
ItemStack itemStack = new ItemStack(Material.JUKEBOX, 1);
itemProcessor(powerItemLocationTracker, itemStack, effectIteration, entity, tauntCounter);
effectIteration++;
tauntCounter++;
if (tauntCounter >= MinorPowerStanceMath.NUMBER_OF_POINTS_PER_FULL_ROTATION) {
tauntCounter = 0;
}
}
if (!entity.isValid() || entity.isDead()) {
for (int i = 0; i < powerItemLocationTracker.size(); i++) {
for (int j = 0; j < trackAmount; j++) {
for (int h = 0; h < itemsPerTrack; h++) {
powerItemLocationTracker.get(i).get(j).get(h).remove();
powerItemLocationTracker.get(i).get(j).get(h).removeMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, plugin);
}
}
}
entity.removeMetadata(MetadataHandler.MAJOR_VISUAL_EFFECT_MD, plugin);
cancel();
return;
}
}
}.runTaskTimer(plugin, 0, 5);
}
}
Aggregations