@EventHandler public void onEntityTarget(EntityTargetEvent event) { if (event.getReason() == TargetReason.TARGET_DIED) return; PetInstance pet = null; for (PetInstance p : PetInstance.getList()) { if (p.getEntity() == null) continue; if (p.getEntity().getUniqueId().equals(event.getEntity().getUniqueId())) { pet = p; break; } } if (pet != null) event.setCancelled(true); }
public void onTarget(EntityTargetEvent event) { if (event.isCancelled()) { return; } if ((event.getReason().equals(TargetReason.CLOSEST_PLAYER) || event.getReason().equals(TargetReason.OWNER_ATTACKED_TARGET)) && (event.getTarget() instanceof Player)) { double followRange = this.getFollowRange(); double distance = event.getEntity().getLocation().distance(event.getTarget().getLocation()); if ((distance-0.5) <= followRange) { this.targetName = ((Player)event.getTarget()).getName(); this.lastLocation = event.getEntity().getLocation(); } } else { this.targetName = null; this.lastLocation = null; } }
@SuppressWarnings("unchecked") @Override protected boolean canStart() { final List<EntityLiving> entities = new ArrayList<EntityLiving>(); for(Class<? extends EntityLiving> targetClass: this.targetClasses) { if(targetClass==EntityHuman.class) { this.findNearbyPlayersOptimized(this.entity, entities); } else { entities.addAll(NativeInterfaces.WORLD.METHOD_SEARCHENTITIES.invoke(this.entity.world, targetClass, this.entity.boundingBox.grow(this.searchDistance, this.searchDistance/4.0, this.searchDistance), this.entitySelector)); } } if(entities.size()>1) Collections.sort(entities, this.comparator); for(EntityLiving possibleTarget: entities) { if(this.target(possibleTarget, TargetReason.CLOSEST_PLAYER)) return true; } return false; }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEntityTarget(final EntityTargetEvent event) { final Entity entity = event.getTarget(); if (entity == null) { return; } if (entity.getType() == EntityType.PLAYER) { final Player user = (Player)event.getTarget(); if ((event.getReason() == TargetReason.CLOSEST_PLAYER || event.getReason() == TargetReason.TARGET_ATTACKED_ENTITY || event.getReason() == TargetReason.PIG_ZOMBIE_TARGET || event.getReason() == TargetReason.RANDOM_TARGET || event.getReason() == TargetReason.TARGET_ATTACKED_OWNER || event.getReason() == TargetReason.OWNER_ATTACKED_TARGET) && !prot.getSettings().getData().getPrevent().isEntitytarget() && !Permissions.ENTITY_TARGET_BYPASS.isAuthorized( user, event.getEntity().getType().getName().toLowerCase())) { event.setCancelled(true); } } }
public TNTSheep(Location location, Player target) { super(((CraftWorld) location.getWorld()).getHandle()); this.world = location.getWorld(); this.locX = location.getX(); this.locY = location.getY(); this.locZ = location.getZ(); try { Field b = this.goalSelector.getClass().getDeclaredField("b"); b.setAccessible(true); Set<?> goals = (Set<?>) b.get(this.goalSelector); goals.clear(); // Clears the goals this.getAttributeInstance(GenericAttributes.FOLLOW_RANGE).setValue(128D); this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED) .setValue( BedwarsRel.getInstance().getConfig().getDouble("specials.tntsheep.speed", 0.4D)); } catch (Exception e) { BedwarsRel.getInstance().getBugsnag().notify(e); e.printStackTrace(); } this.goalSelector.a(0, new PathfinderGoalBedwarsPlayer(this, 1D, false)); // Add bedwars player // goal try { this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle()), TargetReason.TARGET_ATTACKED_ENTITY, false); } catch (Exception ex) { // newer spigot builds if (ex instanceof NoSuchMethodException) { BedwarsRel.getInstance().getBugsnag().notify(ex); this.setGoalTarget((EntityLiving) (((CraftPlayer) target).getHandle())); } } ((Creature) this.getBukkitEntity()).setTarget((LivingEntity) target); }
@Override public void onTarget(EntityTargetEvent event) { super.onTarget(event); if (event.getReason().equals(TargetReason.FORGOT_TARGET) || event.getReason().equals(TargetReason.TARGET_DIED)) { this.angry = false; for (Entity e : minions) { e.getBukkitEntity().remove(); } } }
@Override public void onTarget(EntityTargetEvent event) { super.onTarget(event); if (event.getReason().equals(TargetReason.FORGOT_TARGET) || event.getReason().equals(TargetReason.TARGET_DIED)) { event.getEntity().remove(); } }
@Override public boolean setGoalTarget(EntityLiving entityliving, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fire) { if (!super.setGoalTarget(entityliving, reason, fire)) { return false; } entityliving = getGoalTarget(); if (entityliving == null) { this.setAngry(false); } else if (!this.isTamed()) { this.setAngry(true); } return true; }
public EntityTargetEvent(Entity entity, Entity target, EntityTargetEvent.TargetReason reason) { }
public EntityTargetEvent.TargetReason getReason() { return null; }
public EntityTargetLivingEntityEvent(Entity entity, LivingEntity target, EntityTargetEvent.TargetReason reason) { super(entity, target, reason); }
public boolean a(EntityHuman entityhuman, EnumHand enumhand, @Nullable ItemStack itemstack) { if (this.isTamed()) { if (itemstack != null) { if (itemstack.getItem() instanceof ItemFood) { ItemFood itemfood = (ItemFood) itemstack.getItem(); if (itemfood.g() && ((Float) this.datawatcher.get(EntityWolf.DATA_HEALTH)).floatValue() < 20.0F) { if (!entityhuman.abilities.canInstantlyBuild) { --itemstack.count; } this.heal((float) itemfood.getNutrition(itemstack), org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit return true; } } else if (itemstack.getItem() == Items.DYE) { EnumColor enumcolor = EnumColor.fromInvColorIndex(itemstack.getData()); if (enumcolor != this.getCollarColor()) { this.setCollarColor(enumcolor); if (!entityhuman.abilities.canInstantlyBuild) { --itemstack.count; } return true; } } } if (this.d((EntityLiving) entityhuman) && !this.world.isClientSide && !this.e(itemstack)) { this.goalSit.setSitting(!this.isSitting()); this.bd = false; this.navigation.o(); this.setGoalTarget((EntityLiving) null, TargetReason.FORGOT_TARGET, true); // CraftBukkit - reason } } else if (itemstack != null && itemstack.getItem() == Items.BONE && !this.isAngry()) { if (!entityhuman.abilities.canInstantlyBuild) { --itemstack.count; } if (!this.world.isClientSide) { // CraftBukkit - added event call and isCancelled check. if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) { this.setTamed(true); this.navigation.o(); this.setGoalTarget((EntityLiving) null); this.goalSit.setSitting(true); this.setHealth(20.0F); this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth() this.setOwnerUUID(entityhuman.getUniqueID()); this.o(true); this.world.broadcastEntityEffect(this, (byte) 7); } else { this.o(false); this.world.broadcastEntityEffect(this, (byte) 6); } } return true; } return super.a(entityhuman, enumhand, itemstack); }