use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class BehaviorFarmTarget method shouldFinish.
@Override
public boolean shouldFinish() {
if (!petEntity.canMove()) {
return true;
}
if (!this.petEntity.hasTarget()) {
return true;
}
EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
if (!target.isAlive()) {
return true;
}
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.getBehavior() != BehaviorMode.Farm) {
return true;
} else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return true;
} else if (target.world != petEntity.world) {
return true;
} else if (petEntity.h(target) > 400) {
return true;
} else if (petEntity.h(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600) {
return true;
}
return false;
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class EntityMyPet method handlePlayerInteraction.
// Obfuscated Method handler ------------------------------------------------------------------------------------
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
public boolean handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
new BukkitRunnable() {
public void run() {
EntityPlayer player = ((EntityPlayer) entityhuman);
if (player.getBukkitEntity().isOnline()) {
player.updateInventory(entityhuman.defaultContainer);
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
if (itemStack != null && itemStack.getItem() == Items.LEAD) {
((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, null));
}
if (enumhand == EnumHand.OFF_HAND) {
return true;
}
Player owner = this.getOwner().getPlayer();
if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
if ((Configuration.Skilltree.Skill.Ride.RIDE_ITEM == null && !canEat(itemStack) && !owner.isSneaking()) || (Configuration.Skilltree.Skill.Ride.RIDE_ITEM != null && Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack))) {
if (myPet.getSkills().isActive(RideImpl.class) && canMove()) {
if (Permissions.hasExtended(owner, "MyPet.extended.ride")) {
((CraftPlayer) owner).getHandle().startRiding(this);
return true;
} else {
getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner().getLanguage()), 2000);
}
}
}
if (Configuration.Skilltree.Skill.CONTROL_ITEM.compare(itemStack)) {
if (myPet.getSkills().isActive(ControlImpl.class)) {
return true;
}
}
if (itemStack != null) {
if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasName()) {
if (Permissions.has(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) {
final String name = itemStack.getName();
getMyPet().setPetName(name);
EntityMyPet.super.setCustomName("-");
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Name.New", myPet.getOwner()), name));
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
}
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
}
new BukkitRunnable() {
public void run() {
updateNameTag();
}
}.runTaskLater(MyPetApi.getPlugin(), 1L);
return true;
}
}
if (canEat(itemStack) && canUseItem()) {
if (owner != null && !Permissions.hasExtended(owner, "MyPet.extended.feed")) {
return false;
}
if (this.petTargetSelector.hasGoal("DuelTarget")) {
BehaviorDuelTarget duelTarget = (BehaviorDuelTarget) this.petTargetSelector.getGoal("DuelTarget");
if (duelTarget.getDuelOpponent() != null) {
return true;
}
}
boolean used = false;
double saturation = Configuration.HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED;
if (saturation > 0) {
if (myPet.getSaturation() < 100) {
MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Eat);
Bukkit.getPluginManager().callEvent(feedEvent);
if (!feedEvent.isCancelled()) {
saturation = feedEvent.getSaturation();
double missingSaturation = 100 - myPet.getSaturation();
myPet.setSaturation(myPet.getSaturation() + saturation);
saturation = Math.max(0, saturation - missingSaturation);
used = true;
}
}
}
if (saturation > 0) {
if (getHealth() < myPet.getMaxHealth()) {
MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Heal);
Bukkit.getPluginManager().callEvent(feedEvent);
if (!feedEvent.isCancelled()) {
saturation = feedEvent.getSaturation();
float missingHealth = (float) (myPet.getMaxHealth() - getHealth());
this.heal(Math.min((float) saturation, missingHealth), RegainReason.EATING);
used = true;
}
}
}
if (used) {
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.a);
}
}
MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getHeadHeight(), 0), ParticleCompat.HEART.get(), 0.5F, 0.5F, 0.5F, 0.5F, 5, 20);
return true;
}
}
}
if (!owner.isSneaking() && !Configuration.Misc.RIGHT_CLICK_COMMAND.isEmpty()) {
String command = Configuration.Misc.RIGHT_CLICK_COMMAND;
command = command.replaceAll("%pet_name%", myPet.getPetName());
command = command.replaceAll("%pet_owner%", myPet.getOwner().getName());
command = command.replaceAll("%pet_level%", "" + myPet.getExperience().getLevel());
command = command.replaceAll("%pet_status%", "" + myPet.getStatus().name());
command = command.replaceAll("%pet_type%", myPet.getPetType().name());
command = command.replaceAll("%pet_uuid%", myPet.getUUID().toString());
command = command.replaceAll("%pet_world_group%", myPet.getWorldGroup());
command = command.replaceAll("%pet_skilltree_name%", myPet.getSkilltree() != null ? myPet.getSkilltree().getName() : "");
return owner.performCommand(command);
}
} else {
if (itemStack != null) {
if (itemStack.getItem() == Items.NAME_TAG) {
if (itemStack.hasName()) {
EntityMyPet.super.setCustomName("-");
new BukkitRunnable() {
public void run() {
updateNameTag();
}
}.runTaskLater(MyPetApi.getPlugin(), 1L);
return false;
}
}
}
}
return false;
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class BehaviorDuelTarget method shouldFinish.
@Override
public boolean shouldFinish() {
if (!petEntity.canMove()) {
return true;
} else if (!petEntity.hasTarget()) {
return true;
}
EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.getBehavior() != BehaviorMode.Duel) {
return true;
} else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return true;
} else if (target.world != petEntity.world) {
return true;
} else if (petEntity.h(target) > 400) {
return true;
} else if (petEntity.h(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600) {
return true;
}
return false;
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class EntityMyPet method handlePlayerInteraction.
// Obfuscated Method handler ------------------------------------------------------------------------------------
/**
* Is called when player rightclicks this MyPet
* return:
* true: there was a reaction on rightclick
* false: no reaction on rightclick
*/
public EnumInteractionResult handlePlayerInteraction(final EntityHuman entityhuman, EnumHand enumhand, final ItemStack itemStack) {
new BukkitRunnable() {
@Override
public void run() {
EntityPlayer player = ((EntityPlayer) entityhuman);
if (player.getBukkitEntity().isOnline()) {
player.updateInventory(entityhuman.defaultContainer);
}
}
}.runTaskLater(MyPetApi.getPlugin(), 5);
if (itemStack != null && itemStack.getItem() == Items.LEAD) {
((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(this, null));
}
if (enumhand == EnumHand.OFF_HAND) {
return EnumInteractionResult.SUCCESS;
}
Player owner = this.getOwner().getPlayer();
if (isMyPet() && myPet.getOwner().equals(entityhuman)) {
if ((Configuration.Skilltree.Skill.Ride.RIDE_ITEM == null && !canEat(itemStack) && !owner.isSneaking()) || (Configuration.Skilltree.Skill.Ride.RIDE_ITEM != null && Configuration.Skilltree.Skill.Ride.RIDE_ITEM.compare(itemStack))) {
if (myPet.getSkills().isActive(RideImpl.class) && canMove()) {
if (Permissions.hasExtended(owner, "MyPet.extended.ride")) {
((CraftPlayer) owner).getHandle().startRiding(this);
return EnumInteractionResult.CONSUME;
} else {
getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner()), 2000);
}
}
}
if (Configuration.Skilltree.Skill.CONTROL_ITEM.compare(itemStack)) {
if (myPet.getSkills().isActive(ControlImpl.class)) {
return EnumInteractionResult.CONSUME;
}
}
if (itemStack != null) {
if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasName()) {
if (Permissions.has(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) {
final String name = itemStack.getName().getString();
getMyPet().setPetName(name);
EntityMyPet.super.setCustomName(CraftChatMessage.fromStringOrNull("-"));
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Name.New", myPet.getOwner()), name));
if (!entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
}
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
new BukkitRunnable() {
public void run() {
updateNameTag();
}
}.runTaskLater(MyPetApi.getPlugin(), 1L);
return EnumInteractionResult.CONSUME;
}
}
if (canEat(itemStack) && canUseItem()) {
if (owner != null && !Permissions.hasExtended(owner, "MyPet.extended.feed")) {
return EnumInteractionResult.CONSUME;
}
if (this.petTargetSelector.hasGoal("DuelTarget")) {
BehaviorDuelTarget duelTarget = (BehaviorDuelTarget) this.petTargetSelector.getGoal("DuelTarget");
if (duelTarget.getDuelOpponent() != null) {
return EnumInteractionResult.CONSUME;
}
}
boolean used = false;
double saturation = Configuration.HungerSystem.HUNGER_SYSTEM_SATURATION_PER_FEED;
if (saturation > 0) {
if (myPet.getSaturation() < 100) {
MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Eat);
Bukkit.getPluginManager().callEvent(feedEvent);
if (!feedEvent.isCancelled()) {
saturation = feedEvent.getSaturation();
double missingSaturation = 100 - myPet.getSaturation();
myPet.setSaturation(myPet.getSaturation() + saturation);
saturation = Math.max(0, saturation - missingSaturation);
used = true;
}
}
}
if (saturation > 0) {
if (getHealth() < myPet.getMaxHealth()) {
MyPetFeedEvent feedEvent = new MyPetFeedEvent(getMyPet(), CraftItemStack.asCraftMirror(itemStack), saturation, MyPetFeedEvent.Result.Heal);
Bukkit.getPluginManager().callEvent(feedEvent);
if (!feedEvent.isCancelled()) {
saturation = feedEvent.getSaturation();
double missingHealth = myPet.getMaxHealth() - getHealth();
this.heal((float) Math.min(saturation, missingHealth), RegainReason.EATING);
used = true;
}
}
}
if (used) {
if (itemStack != ItemStack.b && !entityhuman.abilities.canInstantlyBuild) {
itemStack.subtract(1);
if (itemStack.getCount() <= 0) {
entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, ItemStack.b);
}
}
MyPetApi.getPlatformHelper().playParticleEffect(myPet.getLocation().get().add(0, getHeadHeight(), 0), ParticleCompat.HEART.get(), 0.5F, 0.5F, 0.5F, 0.5F, 5, 20);
return EnumInteractionResult.CONSUME;
}
}
}
if (!owner.isSneaking() && !Configuration.Misc.RIGHT_CLICK_COMMAND.isEmpty()) {
String command = Configuration.Misc.RIGHT_CLICK_COMMAND;
command = command.replaceAll("%pet_name%", myPet.getPetName());
command = command.replaceAll("%pet_owner%", myPet.getOwner().getName());
command = command.replaceAll("%pet_level%", "" + myPet.getExperience().getLevel());
command = command.replaceAll("%pet_status%", "" + myPet.getStatus().name());
command = command.replaceAll("%pet_type%", myPet.getPetType().name());
command = command.replaceAll("%pet_uuid%", myPet.getUUID().toString());
command = command.replaceAll("%pet_world_group%", myPet.getWorldGroup());
command = command.replaceAll("%pet_skilltree_name%", myPet.getSkilltree() != null ? myPet.getSkilltree().getName() : "");
return owner.performCommand(command) ? EnumInteractionResult.CONSUME : EnumInteractionResult.PASS;
}
} else {
if (itemStack != null) {
if (itemStack.getItem() == Items.NAME_TAG) {
if (itemStack.hasName()) {
EntityMyPet.super.setCustomName(CraftChatMessage.fromStringOrNull("-"));
new BukkitRunnable() {
@Override
public void run() {
updateNameTag();
}
}.runTaskLater(MyPetApi.getPlugin(), 1L);
return EnumInteractionResult.PASS;
}
}
}
}
return EnumInteractionResult.PASS;
}
use of org.bukkit.craftbukkit.v1_18_R2.entity.CraftPlayer in project MyPet by xXKeyleXx.
the class BehaviorDuelTarget method shouldFinish.
@Override
public boolean shouldFinish() {
if (!petEntity.canMove()) {
return true;
} else if (!petEntity.hasTarget()) {
return true;
}
EntityLiving target = ((CraftLivingEntity) this.petEntity.getMyPetTarget()).getHandle();
Behavior behaviorSkill = myPet.getSkills().get(Behavior.class);
if (behaviorSkill.getBehavior() != BehaviorMode.Duel) {
return true;
} else if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return true;
} else if (target.world != petEntity.world) {
return true;
} else if (petEntity.h(target) > 400) {
return true;
} else if (petEntity.h(((CraftPlayer) petEntity.getOwner().getPlayer()).getHandle()) > 600) {
return true;
}
return false;
}
Aggregations