use of de.keyle.fanciful.FancyMessage in project MyPet by xXKeyleXx.
the class CommandOptionSwitch method onCommandOption.
@Override
public boolean onCommandOption(final CommandSender sender, String[] parameter) {
boolean show = true;
MyPetPlayer o = null;
UUID petUUID = null;
final String lang = MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender);
if (parameter.length == 0) {
if (sender instanceof Player) {
Player petOwner = (Player) sender;
if (MyPetApi.getPlayerManager().isMyPetPlayer(petOwner)) {
o = MyPetApi.getPlayerManager().getMyPetPlayer(petOwner);
}
} else {
sender.sendMessage("You can't use this command from server console!");
return true;
}
} else if (parameter.length == 1) {
Player player = Bukkit.getPlayer(parameter[0]);
if (player == null || !player.isOnline()) {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Translation.getString("Message.No.PlayerOnline", lang));
return true;
}
if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
o = MyPetApi.getPlayerManager().getMyPetPlayer(player);
}
if (o == null) {
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] " + Util.formatText(Translation.getString("Message.No.UserHavePet", lang), o.getName()));
}
} else if (parameter.length == 2) {
show = false;
try {
o = MyPetApi.getPlayerManager().getMyPetPlayer(UUID.fromString(parameter[0]));
petUUID = UUID.fromString(parameter[1]);
} catch (IllegalArgumentException ignored) {
}
}
final MyPetPlayer owner = o;
if (show && owner != null) {
MyPetApi.getRepository().getMyPets(owner, new RepositoryCallback<List<StoredMyPet>>() {
@Override
public void callback(List<StoredMyPet> value) {
sender.sendMessage("Select the MyPet you want the player to switch to:");
boolean doComma = false;
FancyMessage message = new FancyMessage("");
for (StoredMyPet mypet : value) {
if (doComma) {
message.then(", ");
}
message.then(mypet.getPetName()).color(ChatColor.AQUA).command("/petadmin switch " + owner.getInternalUUID() + " " + mypet.getUUID()).itemTooltip(Util.myPetToItemTooltip(mypet, lang));
if (!doComma) {
doComma = true;
}
}
MyPetApi.getPlatformHelper().sendMessageRaw((Player) sender, message.toJSONString());
}
});
} else if (!show && owner != null && petUUID != null) {
MyPetApi.getRepository().getMyPet(petUUID, new RepositoryCallback<StoredMyPet>() {
@Override
public void callback(StoredMyPet newPet) {
if (newPet != null) {
if (owner.hasMyPet()) {
MyPetApi.getMyPetManager().deactivateMyPet(owner, true);
}
Optional<MyPet> myPet = MyPetApi.getMyPetManager().activateMyPet(newPet);
sender.sendMessage(Translation.getString("Message.Command.Success", sender));
if (myPet.isPresent()) {
WorldGroup worldGroup = WorldGroup.getGroupByWorld(owner.getPlayer().getWorld().getName());
newPet.setWorldGroup(worldGroup.getName());
newPet.getOwner().setMyPetForWorldGroup(worldGroup, newPet.getUUID());
owner.sendMessage(Util.formatText(Translation.getString("Message.MultiWorld.NowActivePet", owner), myPet.get().getPetName()));
switch(myPet.get().createEntity()) {
case Success:
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Call.Success", owner), myPet.get().getPetName()));
break;
case Canceled:
sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Prevent", owner), myPet.get().getPetName()));
break;
case NoSpace:
sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.NoSpace", owner), myPet.get().getPetName()));
break;
case NotAllowed:
sender.sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", owner), myPet.get().getPetName()));
break;
case Dead:
sender.sendMessage(Util.formatText(Translation.getString("Message.Call.Dead", owner), myPet.get().getPetName(), myPet.get().getRespawnTime()));
break;
case Flying:
sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Flying", owner), myPet.get().getPetName()));
break;
}
}
}
}
});
}
return true;
}
use of de.keyle.fanciful.FancyMessage in project MyPet by xXKeyleXx.
the class CommandList method onCommand.
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
final String lang;
if (sender instanceof Player) {
lang = MyPetApi.getPlatformHelper().getPlayerLanguage((Player) sender);
} else {
lang = "en";
}
final Player petOwner;
if (args.length <= 0) {
if (sender instanceof Player) {
petOwner = (Player) sender;
} else {
sender.sendMessage("You can't use this command from server console!");
return true;
}
} else {
if (sender instanceof Player) {
if (Permissions.has((Player) sender, "MyPet.admin", false)) {
petOwner = Bukkit.getPlayer(args[0]);
} else {
petOwner = (Player) sender;
}
} else {
sender.sendMessage("You can't use this command from server console!");
return true;
}
}
if (petOwner == null || !petOwner.isOnline()) {
sender.sendMessage(Translation.getString("Message.No.PlayerOnline", lang));
return true;
}
final MyPetPlayer owner;
if (MyPetApi.getPlayerManager().isMyPetPlayer(petOwner)) {
owner = MyPetApi.getPlayerManager().getMyPetPlayer(petOwner);
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", lang), petOwner.getName()));
return true;
}
if (owner != null) {
MyPetApi.getRepository().getMyPets(owner, new RepositoryCallback<List<StoredMyPet>>() {
@Override
public void callback(List<StoredMyPet> value) {
if (petOwner == sender) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.List.Yours", lang), owner.getName()));
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.List.Player", lang), owner.getName()));
}
boolean doComma = false;
FancyMessage message = new FancyMessage("");
for (StoredMyPet mypet : value) {
if (doComma) {
message.then(", ");
}
message.then(mypet.getPetName()).color(ChatColor.AQUA).itemTooltip(Util.myPetToItemTooltip(mypet, lang));
if (!doComma) {
doComma = true;
}
}
MyPetApi.getPlatformHelper().sendMessageRaw((Player) sender, message.toJSONString());
}
});
}
return true;
}
use of de.keyle.fanciful.FancyMessage 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.fanciful.FancyMessage in project MyPet by xXKeyleXx.
the class CommandRelease method onCommand.
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player petOwner = (Player) sender;
if (MyPetApi.getMyPetManager().hasActiveMyPet(petOwner)) {
MyPet myPet = MyPetApi.getMyPetManager().getMyPet(petOwner);
if (!Permissions.hasLegacy(petOwner, "MyPet.command.release")) {
return true;
}
if (myPet.getStatus() == PetState.Despawned) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Call.First", petOwner), myPet.getPetName()));
return true;
} else if (myPet.getStatus() == PetState.Dead) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", petOwner), myPet.getPetName(), myPet.getRespawnTime()));
return true;
}
String name = "";
if (args.length > 0) {
for (String arg : args) {
if (!name.equals("")) {
name += " ";
}
name += arg;
}
}
if (ChatColor.stripColor(myPet.getPetName()).trim().equalsIgnoreCase(name.trim())) {
MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.Release);
Bukkit.getServer().getPluginManager().callEvent(removeEvent);
if (myPet.getSkills().isSkillActive(Inventory.class)) {
myPet.getSkills().getSkill(Inventory.class).get().getInventory().dropContentAt(myPet.getLocation().get());
}
if (myPet instanceof MyPetEquipment) {
((MyPetEquipment) myPet).dropEquipment();
}
if (!Configuration.Misc.REMOVE_PETS_AFTER_RELEASE) {
LivingEntity normalEntity = (LivingEntity) myPet.getLocation().get().getWorld().spawnEntity(myPet.getLocation().get(), EntityType.valueOf(myPet.getPetType().getBukkitName()));
Optional<EntityConverterService> converter = MyPetApi.getServiceManager().getService(EntityConverterService.class);
if (converter.isPresent()) {
converter.get().convertEntity(myPet, normalEntity);
}
}
myPet.removePet();
myPet.getOwner().setMyPetForWorldGroup(WorldGroup.getGroupByWorld(petOwner.getWorld().getName()), null);
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Release.Success", petOwner), myPet.getPetName()));
MyPetApi.getMyPetManager().deactivateMyPet(myPet.getOwner(), false);
MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
return true;
} else {
FancyMessage message = new FancyMessage(Translation.getString("Message.Command.Release.Confirm", petOwner) + " ");
List<String> lore = new ArrayList<>();
lore.add(RESET + Translation.getString("Name.Hunger", petOwner) + ": " + GOLD + Math.round(myPet.getSaturation()));
if (myPet.getRespawnTime() > 0) {
lore.add(RESET + Translation.getString("Name.Respawntime", petOwner) + ": " + GOLD + myPet.getRespawnTime() + "sec");
} else {
lore.add(RESET + Translation.getString("Name.HP", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getHealth()));
}
lore.add(RESET + Translation.getString("Name.Exp", petOwner) + ": " + GOLD + String.format("%1.2f", myPet.getExp()));
lore.add(RESET + Translation.getString("Name.Type", petOwner) + ": " + GOLD + Translation.getString("Name." + myPet.getPetType().name(), petOwner));
lore.add(RESET + Translation.getString("Name.Skilltree", petOwner) + ": " + GOLD + (myPet.getSkilltree() != null ? myPet.getSkilltree().getDisplayName() : "-"));
message.then(myPet.getPetName()).color(ChatColor.AQUA).command("/petrelease " + ChatColor.stripColor(myPet.getPetName())).itemTooltip(new ItemTooltip().setMaterial(Material.MONSTER_EGG).addLore(lore).setTitle(myPet.getPetName()));
MyPetApi.getPlatformHelper().sendMessageRaw((Player) sender, message.toJSONString());
return true;
}
} else {
sender.sendMessage(Translation.getString("Message.No.HasPet", petOwner));
}
return true;
}
sender.sendMessage("You can't use this command from server console!");
return false;
}
use of de.keyle.fanciful.FancyMessage in project MyPet by xXKeyleXx.
the class EntityListener method onMyPet.
@EventHandler
public void onMyPet(final EntityDamageByEntityEvent event) {
if (event.getEntity() instanceof MyPetBukkitEntity) {
MyPetBukkitEntity craftMyPet = (MyPetBukkitEntity) event.getEntity();
MyPet myPet = craftMyPet.getMyPet();
if (event.getDamager() instanceof Player || (event.getDamager() instanceof Projectile && ((Projectile) event.getDamager()).getShooter() instanceof Player)) {
Player damager;
if (event.getDamager() instanceof Projectile) {
damager = (Player) ((Projectile) event.getDamager()).getShooter();
} else {
damager = (Player) event.getDamager();
}
ItemStack leashItem;
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
leashItem = damager.getEquipment().getItemInMainHand();
} else {
leashItem = damager.getItemInHand();
}
if (MyPetApi.getMyPetInfo().getLeashItem(myPet.getPetType()).compare(leashItem)) {
boolean infoShown = false;
if (CommandInfo.canSee(PetInfoDisplay.Name.adminOnly, damager, myPet)) {
damager.sendMessage(ChatColor.AQUA + myPet.getPetName() + ChatColor.RESET + ":");
infoShown = true;
}
if (CommandInfo.canSee(PetInfoDisplay.Owner.adminOnly, damager, myPet) && myPet.getOwner().getPlayer() != damager) {
damager.sendMessage(" " + Translation.getString("Name.Owner", damager) + ": " + myPet.getOwner().getName());
infoShown = true;
}
if (CommandInfo.canSee(PetInfoDisplay.HP.adminOnly, damager, myPet)) {
String msg;
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());
damager.sendMessage(" " + Translation.getString("Name.HP", damager) + ": " + msg);
infoShown = true;
}
if (myPet.getStatus() == PetState.Dead && CommandInfo.canSee(PetInfoDisplay.RespawnTime.adminOnly, damager, myPet)) {
damager.sendMessage(" " + Translation.getString("Name.Respawntime", damager) + ": " + myPet.getRespawnTime());
infoShown = true;
}
if (!myPet.isPassiv() && CommandInfo.canSee(PetInfoDisplay.Damage.adminOnly, damager, myPet)) {
double damage = (myPet.getSkills().isSkillActive(Damage.class) ? myPet.getSkills().getSkill(Damage.class).get().getDamage() : 0);
damager.sendMessage(" " + Translation.getString("Name.Damage", damager) + ": " + String.format("%1.2f", damage));
infoShown = true;
}
if (myPet.getRangedDamage() > 0 && CommandInfo.canSee(PetInfoDisplay.RangedDamage.adminOnly, damager, myPet)) {
double damage = myPet.getRangedDamage();
damager.sendMessage(" " + Translation.getString("Name.RangedDamage", damager) + ": " + String.format("%1.2f", damage));
infoShown = true;
}
if (myPet.getSkills().hasSkill(Behavior.class) && CommandInfo.canSee(PetInfoDisplay.Behavior.adminOnly, damager, myPet)) {
Behavior behavior = myPet.getSkills().getSkill(Behavior.class).get();
damager.sendMessage(" " + Translation.getString("Name.Skill.Behavior", damager) + ": " + Translation.getString("Name." + behavior.getBehavior().name(), damager));
infoShown = true;
}
if (Configuration.HungerSystem.USE_HUNGER_SYSTEM && CommandInfo.canSee(PetInfoDisplay.Hunger.adminOnly, damager, myPet)) {
damager.sendMessage(" " + Translation.getString("Name.Hunger", damager) + ": " + Math.round(myPet.getSaturation()));
FancyMessage m = new FancyMessage(" " + Translation.getString("Name.Food", damager) + ": ");
boolean comma = false;
for (ConfigItem material : MyPetApi.getMyPetInfo().getFood(myPet.getPetType())) {
ItemStack is = material.getItem();
if (is == null) {
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 for \"" + myPet.getPetType().name() + "\" 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(damager, m.toJSONString());
infoShown = true;
}
if (CommandInfo.canSee(PetInfoDisplay.Skilltree.adminOnly, damager, myPet) && myPet.getSkilltree() != null) {
damager.sendMessage(" " + Translation.getString("Name.Skilltree", damager) + ": " + myPet.getSkilltree().getName());
infoShown = true;
}
if (CommandInfo.canSee(PetInfoDisplay.Level.adminOnly, damager, myPet)) {
int lvl = myPet.getExperience().getLevel();
damager.sendMessage(" " + Translation.getString("Name.Level", damager) + ": " + lvl);
infoShown = true;
}
int maxLevel = myPet.getSkilltree() != null ? myPet.getSkilltree().getMaxLevel() : Configuration.LevelSystem.Experience.LEVEL_CAP;
if (CommandInfo.canSee(PetInfoDisplay.Exp.adminOnly, damager, myPet) && myPet.getExperience().getLevel() < maxLevel) {
double exp = myPet.getExperience().getCurrentExp();
double reqEXP = myPet.getExperience().getRequiredExp();
damager.sendMessage(" " + Translation.getString("Name.Exp", damager) + ": " + 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(), damager) + " ";
donationMessage += myPet.getOwner().getDonationRank().getDefaultIcon();
damager.sendMessage(" " + donationMessage);
}
if (!infoShown) {
damager.sendMessage(Translation.getString("Message.No.NothingToSeeHere", myPet.getOwner().getLanguage()));
}
event.setCancelled(true);
} else if (myPet.getOwner().equals(damager) && (!Configuration.Misc.OWNER_CAN_ATTACK_PET)) {
event.setCancelled(true);
} else if (!myPet.getOwner().equals(damager) && !MyPetApi.getHookHelper().canHurt(damager, myPet.getOwner().getPlayer(), true)) {
event.setCancelled(true);
}
}
if (event.getDamager() instanceof CraftMyPetProjectile) {
EntityMyPetProjectile projectile = ((CraftMyPetProjectile) event.getDamager()).getMyPetProjectile();
if (myPet == projectile.getShooter().getMyPet()) {
event.setCancelled(true);
}
if (!MyPetApi.getHookHelper().canHurt(projectile.getShooter().getOwner().getPlayer(), myPet.getOwner().getPlayer(), true)) {
event.setCancelled(true);
}
}
if (!event.isCancelled() && event.getDamager() instanceof LivingEntity) {
LivingEntity damager = (LivingEntity) event.getDamager();
if (damager instanceof Player) {
if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), (Player) damager, true)) {
return;
}
}
if (myPet.getSkills().isSkillActive(Thorns.class)) {
if (damager instanceof Creeper) {
return;
}
Thorns thornsSkill = myPet.getSkills().getSkill(Thorns.class).get();
if (thornsSkill.activate()) {
isSkillActive = true;
thornsSkill.reflectDamage(damager, event.getDamage());
isSkillActive = false;
}
}
}
}
}
Aggregations