use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class CommandSendAway method onCommand.
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length == 0 && !(sender instanceof Player)) {
sender.sendMessage("You can't use this command from server console!");
return true;
}
String playerName = sender.getName();
String lang = "en_en";
if (args.length > 0) {
if (sender instanceof Player) {
if (Permissions.has((Player) sender, "MyPet.admin", false)) {
playerName = args[0];
lang = MyPetApi.getPlatformHelper().getPlayerLanguage((Player) sender);
}
} else {
playerName = args[0];
}
}
if (!MyPetApi.getPlayerManager().isMyPetPlayer(playerName)) {
if (args.length == 0) {
sender.sendMessage(Translation.getString("Message.No.HasPet", (Player) sender));
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", lang), args[0]));
}
return true;
}
MyPetPlayer petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(playerName);
if (petOwner != null && !petOwner.isOnline()) {
sender.sendMessage(Translation.getString("Message.No.PlayerOnline", lang));
return true;
}
if (petOwner != null && petOwner.hasMyPet()) {
MyPet myPet = petOwner.getMyPet();
if (myPet.getStatus() == PetState.Here) {
myPet.removePet(false);
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.SendAway.Success", petOwner), myPet.getPetName()));
} else if (myPet.getStatus() == PetState.Despawned) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.SendAway.AlreadyAway", petOwner), myPet.getPetName()));
} else if (myPet.getStatus() == PetState.Dead) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Call.Dead", petOwner), myPet.getPetName(), myPet.getRespawnTime()));
}
} else {
if (args.length == 0) {
sender.sendMessage(Translation.getString("Message.No.HasPet", lang));
} else {
sender.sendMessage(Util.formatText(Translation.getString("Message.No.UserHavePet", lang), args[0]));
}
}
return true;
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class CommandStore method onCommand.
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("You can't use this command from server console!");
return true;
}
final Player player = (Player) sender;
if (!Permissions.hasLegacy(player, "MyPet.command.switch")) {
player.sendMessage(Translation.getString("Message.No.Allowed", player));
return true;
}
if (MyPetApi.getPlayerManager().isMyPetPlayer(player)) {
final MyPetPlayer owner = MyPetApi.getPlayerManager().getMyPetPlayer(player);
final int maxPetCount = getMaxPetCount(owner.getPlayer());
if (maxPetCount == 0) {
player.sendMessage(Translation.getString("Message.No.Allowed", player));
return true;
}
if (owner.hasMyPet()) {
MyPetApi.getRepository().getMyPets(owner, new RepositoryCallback<List<StoredMyPet>>() {
@Override
public void callback(List<StoredMyPet> pets) {
MyPet myPet = owner.getMyPet();
String worldGroup = myPet.getWorldGroup();
// -1 for active pet
int inactivePetCount = getInactivePetCount(pets, worldGroup) - 1;
if (inactivePetCount >= maxPetCount) {
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Switch.Limit", player), maxPetCount));
return;
}
if (MyPetApi.getMyPetManager().deactivateMyPet(owner, true)) {
owner.setMyPetForWorldGroup(worldGroup, null);
sender.sendMessage(Util.formatText(Translation.getString("Message.Command.Switch.Success", player), myPet.getPetName()));
}
}
});
return true;
}
}
player.sendMessage(Translation.getString("Message.Command.Switch.NoPet", player));
return true;
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class CommandOptionRemove method onCommandOption.
@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
String lang = MyPetApi.getPlatformHelper().getCommandSenderLanguage(sender);
if (args.length >= 1) {
Player player = Bukkit.getPlayer(args[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)) {
MyPetPlayer petOwner = MyPetApi.getPlayerManager().getMyPetPlayer(player);
if (petOwner.hasMyPet()) {
MyPet myPet = petOwner.getMyPet();
MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.AdminCommand);
Bukkit.getServer().getPluginManager().callEvent(removeEvent);
myPet.getOwner().setMyPetForWorldGroup(WorldGroup.getGroupByWorld(player.getWorld().getName()), null);
MyPetApi.getMyPetManager().deactivateMyPet(myPet.getOwner(), false);
MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
sender.sendMessage("[" + ChatColor.AQUA + "MyPet" + ChatColor.RESET + "] You removed the MyPet of: " + ChatColor.YELLOW + petOwner.getName());
}
}
}
return true;
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class CommandSettingsPetLivingSound method onCommandOption.
@Override
public boolean onCommandOption(CommandSender sender, String[] args) {
if (sender instanceof Player && MyPetApi.getPlayerManager().isMyPetPlayer((Player) sender)) {
if (args.length > 0 && Util.isInt(args[0])) {
float volume = Math.min(Math.max(Integer.parseInt(args[0]), 0f), 100f) / 100f;
MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer((Player) sender);
myPetPlayer.setPetLivingSoundVolume(volume);
sender.sendMessage(Translation.getString("Message.Command.Success", sender));
return true;
}
}
sender.sendMessage(Translation.getString("Message.Command.Fail", sender));
return true;
}
use of de.Keyle.MyPet.api.player.MyPetPlayer in project MyPet by xXKeyleXx.
the class EntityListener method onMyPet.
@EventHandler
public void onMyPet(final EntityDeathEvent event) {
LivingEntity deadEntity = event.getEntity();
if (deadEntity instanceof MyPetBukkitEntity) {
MyPet myPet = ((MyPetBukkitEntity) deadEntity).getMyPet();
if (// check health for death events where the pet isn't really dead (/killall)
myPet == null || myPet.getHealth() > 0) {
return;
}
final MyPetPlayer owner = myPet.getOwner();
if (Configuration.Misc.RELEASE_PETS_ON_DEATH && !owner.isMyPetAdmin()) {
MyPetRemoveEvent removeEvent = new MyPetRemoveEvent(myPet, MyPetRemoveEvent.Source.Death);
Bukkit.getServer().getPluginManager().callEvent(removeEvent);
if (myPet.getSkills().isSkillActive(Inventory.class)) {
CustomInventory inv = myPet.getSkills().getSkill(Inventory.class).get().getInventory();
inv.dropContentAt(myPet.getLocation().get());
}
if (myPet instanceof MyPetEquipment) {
((MyPetEquipment) myPet).dropEquipment();
}
myPet.removePet();
owner.setMyPetForWorldGroup(WorldGroup.getGroupByWorld(owner.getPlayer().getWorld().getName()), null);
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Release.Dead", owner), myPet.getPetName()));
MyPetApi.getMyPetManager().deactivateMyPet(owner, false);
MyPetApi.getRepository().removeMyPet(myPet.getUUID(), null);
return;
}
myPet.setRespawnTime((Configuration.Respawn.TIME_FIXED + MyPetApi.getMyPetInfo().getCustomRespawnTimeFixed(myPet.getPetType())) + (myPet.getExperience().getLevel() * (Configuration.Respawn.TIME_FACTOR + MyPetApi.getMyPetInfo().getCustomRespawnTimeFactor(myPet.getPetType()))));
myPet.setStatus(PetState.Dead);
if (deadEntity.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) deadEntity.getLastDamageCause();
if (e.getDamager() instanceof Player) {
myPet.setRespawnTime((Configuration.Respawn.TIME_PLAYER_FIXED + MyPetApi.getMyPetInfo().getCustomRespawnTimeFixed(myPet.getPetType())) + (myPet.getExperience().getLevel() * (Configuration.Respawn.TIME_PLAYER_FACTOR + MyPetApi.getMyPetInfo().getCustomRespawnTimeFactor(myPet.getPetType()))));
} else if (e.getDamager() instanceof MyPetBukkitEntity) {
MyPet killerMyPet = ((MyPetBukkitEntity) e.getDamager()).getMyPet();
if (myPet.getSkills().isSkillActive(Behavior.class) && killerMyPet.getSkills().isSkillActive(Behavior.class)) {
Behavior killerBehaviorSkill = killerMyPet.getSkills().getSkill(Behavior.class).get();
Behavior deadBehaviorSkill = myPet.getSkills().getSkill(Behavior.class).get();
if (deadBehaviorSkill.getBehavior() == BehaviorState.Duel && killerBehaviorSkill.getBehavior() == BehaviorState.Duel) {
MyPetMinecraftEntity myPetEntity = ((MyPetBukkitEntity) deadEntity).getHandle();
if (e.getDamager().equals(myPetEntity.getTarget())) {
myPet.setRespawnTime(10);
killerMyPet.setHealth(killerMyPet.getMaxHealth());
}
}
}
}
}
event.setDroppedExp(0);
if (Configuration.LevelSystem.Experience.LOSS_FIXED > 0 || Configuration.LevelSystem.Experience.LOSS_PERCENT > 0) {
double lostExpirience = Configuration.LevelSystem.Experience.LOSS_FIXED;
lostExpirience += myPet.getExperience().getRequiredExp() * Configuration.LevelSystem.Experience.LOSS_PERCENT / 100;
if (lostExpirience > myPet.getExperience().getCurrentExp()) {
lostExpirience = myPet.getExperience().getCurrentExp();
}
if (myPet.getSkilltree() != null) {
int requiredLevel = myPet.getSkilltree().getRequiredLevel();
if (requiredLevel > 1) {
double minExp = myPet.getExperience().getExpByLevel(requiredLevel);
lostExpirience = myPet.getExp() - lostExpirience < minExp ? myPet.getExp() - minExp : lostExpirience;
}
}
if (Configuration.LevelSystem.Experience.DROP_LOST_EXP) {
event.setDroppedExp((int) (lostExpirience + 0.5));
}
myPet.getExperience().removeCurrentExp(lostExpirience);
}
if (myPet.getSkills().isSkillActive(Inventory.class)) {
Inventory inventorySkill = myPet.getSkills().getSkill(Inventory.class).get();
inventorySkill.closeInventory();
if (inventorySkill.dropOnDeath() && !owner.isMyPetAdmin()) {
inventorySkill.getInventory().dropContentAt(myPet.getLocation().get());
}
}
sendDeathMessage(event);
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Spawn.Respawn.In", owner.getPlayer()), myPet.getPetName(), myPet.getRespawnTime()));
if (MyPetApi.getPluginHookManager().isHookActive(EconomyHook.class) && owner.hasAutoRespawnEnabled() && myPet.getRespawnTime() >= owner.getAutoRespawnMin() && Permissions.hasLegacy(owner.getPlayer(), "MyPet.command.respawn")) {
double costs = myPet.getRespawnTime() * Configuration.Respawn.COSTS_FACTOR + Configuration.Respawn.COSTS_FIXED;
if (MyPetApi.getHookHelper().getEconomy().canPay(owner, costs)) {
MyPetApi.getHookHelper().getEconomy().pay(owner, costs);
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Respawn.Paid", owner.getPlayer()), myPet.getPetName(), costs + " " + MyPetApi.getHookHelper().getEconomy().currencyNameSingular()));
myPet.setRespawnTime(1);
} else {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Command.Respawn.NoMoney", owner.getPlayer()), myPet.getPetName(), costs + " " + MyPetApi.getHookHelper().getEconomy().currencyNameSingular()));
}
}
}
}
Aggregations