use of net.minecraft.server.v1_15_R1.EntityPlayer in project MyPet by xXKeyleXx.
the class OwnerHurtByTarget method shouldStart.
@Override
public boolean shouldStart() {
if (!petEntity.canMove()) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
this.lastDamager = owner.getLastDamager();
if (this.lastDamager == null || !lastDamager.isAlive()) {
return false;
}
if (lastDamager instanceof EntityArmorStand) {
return false;
}
if (lastDamager == petEntity) {
return false;
}
if (lastDamager instanceof EntityPlayer) {
if (owner == lastDamager) {
return false;
}
Player targetPlayer = (Player) lastDamager.getBukkitEntity();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
return false;
}
} else if (lastDamager instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) lastDamager).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
return false;
}
} else if (lastDamager instanceof EntityTameableAnimal) {
EntityTameableAnimal tameable = (EntityTameableAnimal) lastDamager;
if (tameable.isTamed() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
return false;
}
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), lastDamager.getBukkitEntity())) {
return false;
}
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill != null && behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (lastDamager instanceof EntityTameableAnimal && ((EntityTameableAnimal) lastDamager).isTamed()) {
return false;
}
if (lastDamager instanceof EntityMyPet) {
return false;
}
if (lastDamager instanceof EntityPlayer) {
return false;
}
}
}
return true;
}
use of net.minecraft.server.v1_15_R1.EntityPlayer in project MyPet by xXKeyleXx.
the class ControlTarget method shouldStart.
@Override
public boolean shouldStart() {
if (controlPathfinderGoal == null) {
if (petEntity.getPathfinder().hasGoal("Control")) {
controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control");
}
}
if (controlPathfinderGoal == null) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (controlPathfinderGoal.moveTo != null && petEntity.canMove()) {
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
}
for (EntityLiving entityLiving : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow((double) this.range, 4.0D, (double) this.range))) {
if (entityLiving != petEntity && !(entityLiving instanceof EntityArmorStand)) {
if (entityLiving instanceof EntityPlayer) {
Player targetPlayer = (Player) entityLiving.getBukkitEntity();
if (myPet.getOwner().equals(targetPlayer)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
continue;
}
} else if (entityLiving instanceof EntityTameableAnimal) {
EntityTameableAnimal tameable = (EntityTameableAnimal) entityLiving;
if (tameable.isTamed() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
continue;
} else if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), tameableOwner, true)) {
continue;
}
}
} else if (entityLiving instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) entityLiving).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
continue;
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entityLiving.getBukkitEntity())) {
continue;
}
if (behaviorSkill != null) {
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (entityLiving instanceof EntityTameableAnimal) {
continue;
} else if (entityLiving instanceof EntityMyPet) {
continue;
} else if (entityLiving instanceof EntityPlayer) {
continue;
}
}
}
controlPathfinderGoal.stopControl();
this.target = entityLiving;
return true;
}
}
}
return false;
}
use of net.minecraft.server.v1_15_R1.EntityPlayer in project MyPet by xXKeyleXx.
the class OwnerHurtByTarget method shouldStart.
@Override
public boolean shouldStart() {
if (!petEntity.canMove()) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
this.lastDamager = owner.getLastDamager();
if (this.lastDamager == null || !lastDamager.isAlive()) {
return false;
}
if (lastDamager instanceof EntityArmorStand) {
return false;
}
if (lastDamager == petEntity) {
return false;
}
if (lastDamager instanceof EntityPlayer) {
if (owner == lastDamager) {
return false;
}
Player targetPlayer = (Player) lastDamager.getBukkitEntity();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetPlayer, true)) {
return false;
}
} else if (lastDamager instanceof EntityMyPet) {
MyPet targetMyPet = ((EntityMyPet) lastDamager).getMyPet();
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), targetMyPet.getOwner().getPlayer(), true)) {
return false;
}
} else if (lastDamager instanceof EntityTameableAnimal) {
EntityTameableAnimal tameable = (EntityTameableAnimal) lastDamager;
if (tameable.isTamed() && tameable.getOwner() != null) {
Player tameableOwner = (Player) tameable.getOwner().getBukkitEntity();
if (myPet.getOwner().equals(tameableOwner)) {
return false;
}
}
}
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), lastDamager.getBukkitEntity())) {
return false;
}
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill != null && behaviorSkill.isActive()) {
if (behaviorSkill.getBehavior() == BehaviorMode.Friendly) {
return false;
}
if (behaviorSkill.getBehavior() == BehaviorMode.Raid) {
if (lastDamager instanceof EntityTameableAnimal && ((EntityTameableAnimal) lastDamager).isTamed()) {
return false;
}
if (lastDamager instanceof EntityMyPet) {
return false;
}
if (lastDamager instanceof EntityPlayer) {
return false;
}
}
}
return true;
}
use of net.minecraft.server.v1_15_R1.EntityPlayer in project MyPet by xXKeyleXx.
the class EntityMyPig method handlePlayerInteraction.
public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
if (enumhand == EnumHand.OFF_HAND) {
if (itemStack != null) {
if (itemStack.getItem() == Items.LEAD) {
((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
entityhuman.a(EnumHand.OFF_HAND, null);
new BukkitRunnable() {
public void run() {
if (entityhuman instanceof EntityPlayer) {
entityhuman.a(EnumHand.OFF_HAND, itemStack);
Player p = (Player) entityhuman.getBukkitEntity();
if (!p.isOnline()) {
p.saveData();
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
}
}
return true;
}
if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
if (Configuration.Skilltree.Skill.Ride.RIDE_ITEM == null || Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack)) {
if (myPet.getSkills().isActive(RideImpl.class) && canMove()) {
if (itemStack != null && itemStack.getItem() == Items.LEAD) {
((WorldServer) this.world).getTracker().a(this, new PacketPlayOutAttachEntity(this, null));
entityhuman.a(EnumHand.MAIN_HAND, null);
new BukkitRunnable() {
public void run() {
if (entityhuman instanceof EntityPlayer) {
entityhuman.a(EnumHand.MAIN_HAND, itemStack);
Player p = (Player) entityhuman.getBukkitEntity();
if (!p.isOnline()) {
p.saveData();
}
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
}
getOwner().sendMessage("Unfortunately, pigs can not be ridden (Minecraft limitation)", 5000);
return true;
}
}
}
if (super.handlePlayerInteraction(entityhuman, enumhand, itemStack)) {
return true;
}
if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
if (itemStack.getItem() == Items.SADDLE && !getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
getMyPet().setSaddle(CraftItemStack.asBukkitCopy(itemStack));
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
return true;
} else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasSaddle() && getOwner().getPlayer().isSneaking()) {
EntityItem entityitem = new EntityItem(this.world, this.locX, this.locY + 1, this.locZ, CraftItemStack.asNMSCopy(getMyPet().getSaddle()));
entityitem.pickupDelay = 10;
entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
this.world.addEntity(entityitem);
makeSound("entity.sheep.shear", 1.0F, 1.0F);
getMyPet().setSaddle(null);
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.damage(1, entityhuman);
}
return true;
} else if (Configuration.MyPet.Pig.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
if (!entityhuman.abilities.canInstantlyBuild) {
if (--itemStack.count <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
}
}
getMyPet().setBaby(false);
return true;
}
}
return false;
}
use of net.minecraft.server.v1_15_R1.EntityPlayer in project Citizens2 by CitizensDev.
the class NMSImpl method removeFromServerPlayerList.
@Override
public void removeFromServerPlayerList(Player player) {
EntityPlayer handle = (EntityPlayer) NMSImpl.getHandle(player);
((CraftServer) Bukkit.getServer()).getHandle().players.remove(handle);
}
Aggregations