use of de.Keyle.MyPet.skill.skills.Behavior 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 = null;
if (myPet.getSkills().isSkillActive(Behavior.class)) {
behaviorSkill = myPet.getSkills().getSkill(Behavior.class).get();
if (behaviorSkill.getBehavior() == Behavior.BehaviorState.Friendly) {
return false;
}
}
for (Object entityObj : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow((double) this.range, 4.0D, (double) this.range))) {
EntityLiving entityLiving = (EntityLiving) entityObj;
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() == BehaviorState.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 de.Keyle.MyPet.skill.skills.Behavior in project MyPet by xXKeyleXx.
the class BehaviorDuelTarget method shouldStart.
@Override
public boolean shouldStart() {
if (behaviorSkill == null || !behaviorSkill.isActive() || behaviorSkill.getBehavior() != BehaviorState.Duel) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (!petEntity.canMove()) {
return false;
}
if (petEntity.hasTarget()) {
return false;
}
if (duelOpponent != null) {
this.target = duelOpponent;
return true;
}
for (Object entityObj : this.petEntity.world.a(EntityMyPet.class, this.petOwnerEntity.getBoundingBox().grow((double) range, (double) range, (double) range))) {
EntityMyPet entityMyPet = (EntityMyPet) entityObj;
MyPet targetMyPet = entityMyPet.getMyPet();
if (entityMyPet != petEntity && entityMyPet.isAlive()) {
if (!targetMyPet.getSkills().isSkillActive(Behavior.class) || !targetMyPet.getEntity().get().canMove()) {
continue;
}
Behavior targetbehavior = targetMyPet.getSkills().getSkill(Behavior.class).get();
if (targetbehavior.getBehavior() != BehaviorState.Duel) {
continue;
}
if (targetMyPet.getDamage() == 0) {
continue;
}
this.target = entityMyPet;
return true;
}
}
return false;
}
use of de.Keyle.MyPet.skill.skills.Behavior 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 = null;
if (myPet.getSkills().isSkillActive(Behavior.class)) {
behaviorSkill = myPet.getSkills().getSkill(Behavior.class).get();
if (behaviorSkill.getBehavior() == Behavior.BehaviorState.Friendly) {
return false;
}
}
for (Object entityObj : this.petEntity.world.a(EntityLiving.class, this.petEntity.getBoundingBox().grow((double) this.range, 4.0D, (double) this.range))) {
EntityLiving entityLiving = (EntityLiving) entityObj;
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() == BehaviorState.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 de.Keyle.MyPet.skill.skills.Behavior in project MyPet by xXKeyleXx.
the class CommandInfo method onCommand.
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player player = (Player) sender;
MyPetPlayer petOwner;
if (args.length == 0) {
if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(player);
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", player));
return true;
}
} else if (Permissions.hasLegacy(player, "MyPet.command.info.other")) {
Player p = Bukkit.getServer().getPlayer(args[0]);
if (p == null || !p.isOnline()) {
sender.sendMessage(Translation.getString("Message.No.PlayerOnline", player));
return true;
}
if (MyPetApi.getPlayerManager().isMyPetPlayer(args[0])) {
petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(args[0]);
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", player), args[0]));
return true;
}
} else {
sender.sendMessage(Translation.getString("Message.No.Allowed", player));
return true;
}
if (petOwner.hasMyPet()) {
boolean infoShown = false;
MyPet myPet = petOwner.getMyPet();
if (canSee(PetInfoDisplay.Name.adminOnly, player, myPet)) {
player.sendMessage(ChatColor.AQUA + myPet.getPetName() + ChatColor.RESET + ":");
infoShown = true;
}
if (!petOwner.equals(player) && canSee(!PetInfoDisplay.Owner.adminOnly, player, myPet)) {
player.sendMessage(" " + Translation.getString("Name.Owner", player) + ": " + myPet.getOwner().getName());
infoShown = true;
}
if (canSee(PetInfoDisplay.HP.adminOnly, player, myPet)) {
String msg;
if (myPet.getStatus() == PetState.Dead) {
msg = ChatColor.RED + Translation.getString("Name.Dead", player);
} else {
if (myPet.getHealth() > myPet.getMaxHealth() / 3 * 2) {
msg = "" + ChatColor.GREEN;
} else if (myPet.getHealth() > myPet.getMaxHealth() / 3) {
msg = "" + ChatColor.YELLOW;
} else {
msg = "" + ChatColor.RED;
}
msg += String.format("%1.2f", myPet.getHealth()) + ChatColor.WHITE + "/" + String.format("%1.2f", myPet.getMaxHealth());
}
player.sendMessage(" " + Translation.getString("Name.HP", player) + ": " + msg);
infoShown = true;
}
if (canSee(PetInfoDisplay.RespawnTime.adminOnly, player, myPet)) {
if (myPet.getStatus() == PetState.Dead) {
player.sendMessage(" " + Translation.getString("Name.Respawntime", player) + ": " + myPet.getRespawnTime());
infoShown = true;
}
}
if (!myPet.isPassiv() && canSee(PetInfoDisplay.Damage.adminOnly, player, myPet)) {
double damage = (myPet.getSkills().isSkillActive(Damage.class) ? myPet.getSkills().getSkill(Damage.class).get().getDamage() : 0);
player.sendMessage(" " + Translation.getString("Name.Damage", player) + ": " + String.format("%1.2f", damage));
infoShown = true;
}
if (myPet.getRangedDamage() > 0 && CommandInfo.canSee(PetInfoDisplay.RangedDamage.adminOnly, player, myPet)) {
double damage = myPet.getRangedDamage();
player.sendMessage(" " + Translation.getString("Name.RangedDamage", player) + ": " + String.format("%1.2f", damage));
infoShown = true;
}
if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && canSee(PetInfoDisplay.Hunger.adminOnly, player, myPet)) {
player.sendMessage(" " + Translation.getString("Name.Hunger", player) + ": " + Math.round(myPet.getSaturation()));
FancyMessage m = new FancyMessage(" " + Translation.getString("Name.Food", player) + ": ");
boolean comma = false;
for (ConfigItem material : MyPetApi.getMyPetInfo().getFood(myPet.getPetType())) {
ItemStack is = material.getItem();
if (is == null || is.getType() == Material.AIR) {
continue;
}
if (comma) {
m.then(", ");
}
if (is.hasItemMeta() && is.getItemMeta().hasDisplayName()) {
m.then(is.getItemMeta().getDisplayName());
} else {
try {
m.thenTranslate(MyPetApi.getPlatformHelper().getVanillaName(is) + ".name");
} catch (Exception e) {
MyPetApi.getLogger().warning("A food item caused an error. If you think this is a bug please report it to the MyPet developer.");
MyPetApi.getLogger().warning("" + is);
e.printStackTrace();
continue;
}
}
m.color(ChatColor.GOLD);
ItemTooltip it = new ItemTooltip();
it.setMaterial(is.getType());
if (is.hasItemMeta()) {
if (is.getItemMeta().hasDisplayName()) {
it.setTitle(is.getItemMeta().getDisplayName());
}
if (is.getItemMeta().hasLore()) {
it.setLore(is.getItemMeta().getLore().toArray(new String[is.getItemMeta().getLore().size()]));
}
}
m.itemTooltip(it);
comma = true;
}
MyPetApi.getPlatformHelper().sendMessageRaw(player, m.toJSONString());
infoShown = true;
}
if (canSee(PetInfoDisplay.Behavior.adminOnly, player, myPet)) {
if (myPet.getSkills().hasSkill(Behavior.class)) {
Behavior behavior = myPet.getSkills().getSkill(Behavior.class).get();
player.sendMessage(" " + Translation.getString("Name.Skill.Behavior", player) + ": " + Translation.getString("Name." + behavior.getBehavior().name(), player));
infoShown = true;
}
}
if (canSee(PetInfoDisplay.Skilltree.adminOnly, player, myPet) && myPet.getSkilltree() != null) {
player.sendMessage(" " + Translation.getString("Name.Skilltree", player) + ": " + myPet.getSkilltree().getName());
infoShown = true;
}
if (canSee(PetInfoDisplay.Level.adminOnly, player, myPet)) {
int lvl = myPet.getExperience().getLevel();
player.sendMessage(" " + Translation.getString("Name.Level", player) + ": " + lvl);
infoShown = true;
}
int maxLevel = myPet.getSkilltree() != null ? myPet.getSkilltree().getMaxLevel() : Configuration.LevelSystem.Experience.LEVEL_CAP;
if (canSee(PetInfoDisplay.Exp.adminOnly, player, myPet) && myPet.getExperience().getLevel() < maxLevel) {
double exp = myPet.getExperience().getCurrentExp();
double reqEXP = myPet.getExperience().getRequiredExp();
player.sendMessage(" " + Translation.getString("Name.Exp", player) + ": " + String.format("%1.2f", exp) + "/" + String.format("%1.2f", reqEXP));
infoShown = true;
}
if (myPet.getOwner().getDonationRank() != DonateCheck.DonationRank.None) {
infoShown = true;
String donationMessage = "" + ChatColor.GOLD;
donationMessage += myPet.getOwner().getDonationRank().getDefaultIcon();
donationMessage += " " + Translation.getString("Name.Title." + myPet.getOwner().getDonationRank().name(), player) + " ";
donationMessage += myPet.getOwner().getDonationRank().getDefaultIcon();
sender.sendMessage(" " + donationMessage);
}
if (!infoShown) {
sender.sendMessage(Translation.getString("Message.CantViewPetInfo", player));
}
return true;
} else {
if (args.length > 0) {
sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", player), args[0]));
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", player));
}
}
return true;
}
sender.sendMessage("You can't use this command from server console!");
return true;
}
use of de.Keyle.MyPet.skill.skills.Behavior in project MyPet by xXKeyleXx.
the class BehaviorDuelTarget method shouldStart.
@Override
public boolean shouldStart() {
if (behaviorSkill == null || !behaviorSkill.isActive() || behaviorSkill.getBehavior() != BehaviorState.Duel) {
return false;
}
if (myPet.getDamage() <= 0 && myPet.getRangedDamage() <= 0) {
return false;
}
if (!petEntity.canMove()) {
return false;
}
if (petEntity.hasTarget()) {
return false;
}
if (duelOpponent != null) {
this.target = duelOpponent;
return true;
}
for (Object entityObj : this.petEntity.world.a(EntityMyPet.class, this.petOwnerEntity.getBoundingBox().grow((double) range, (double) range, (double) range))) {
EntityMyPet entityMyPet = (EntityMyPet) entityObj;
MyPet targetMyPet = entityMyPet.getMyPet();
if (entityMyPet != petEntity && entityMyPet.isAlive()) {
if (!targetMyPet.getSkills().isSkillActive(Behavior.class) || !targetMyPet.getEntity().get().canMove()) {
continue;
}
Behavior targetbehavior = targetMyPet.getSkills().getSkill(Behavior.class).get();
if (targetbehavior.getBehavior() != BehaviorState.Duel) {
continue;
}
if (targetMyPet.getDamage() == 0) {
continue;
}
this.target = entityMyPet;
return true;
}
}
return false;
}
Aggregations