use of de.Keyle.MyPet.api.util.inventory.CustomInventory in project MyPet by xXKeyleXx.
the class Pickup method schedule.
public void schedule() {
MyPetInventoryActionEvent event = new MyPetInventoryActionEvent(myPet, MyPetInventoryActionEvent.Action.Use);
Bukkit.getServer().getPluginManager().callEvent(event);
if (pickup && (event.isCancelled() || !Permissions.hasExtendedLegacy(myPet.getOwner().getPlayer(), "MyPet.extended.pickup"))) {
pickup = false;
myPet.getOwner().sendMessage(Util.formatText(Translation.getString(("Message.Skill.Pickup.StartStop"), myPet.getOwner().getPlayer()), myPet.getPetName(), Translation.getString("Name.Disabled", myPet.getOwner())));
return;
}
if (pickup && myPet.getOwner().getPlayer().getGameMode() == GameMode.CREATIVE && !Configuration.Skilltree.Skill.Inventory.OPEN_IN_CREATIVE && !Permissions.has(myPet.getOwner().getPlayer(), "MyPet.admin", false)) {
myPet.getOwner().sendMessage(Translation.getString("Message.Skill.Pickup.Creative", myPet.getOwner()));
pickup = false;
return;
}
if (range > 0 && pickup && myPet.getStatus() == PetState.Here && myPet.getSkills().isSkillActive(Inventory.class)) {
for (Entity entity : myPet.getEntity().get().getNearbyEntities(range, range, range)) {
if (!entity.isDead()) {
if (entity instanceof Item) {
Item itemEntity = (Item) entity;
ItemStack itemStack = itemEntity.getItemStack();
if (itemEntity.getPickupDelay() <= 0 && itemStack.getAmount() > 0) {
MyPetPickupItemEvent petPickupEvent = new MyPetPickupItemEvent(myPet, itemEntity);
Bukkit.getServer().getPluginManager().callEvent(petPickupEvent);
if (petPickupEvent.isCancelled()) {
continue;
}
PlayerPickupItemEvent playerPickupEvent = new PlayerPickupItemEvent(myPet.getOwner().getPlayer(), itemEntity, 0);
Bukkit.getServer().getPluginManager().callEvent(playerPickupEvent);
if (playerPickupEvent.isCancelled()) {
continue;
}
itemStack = itemEntity.getItemStack();
CustomInventory inv = myPet.getSkills().getSkill(Inventory.class).get().getInventory();
int itemAmount = inv.addItem(itemStack);
if (itemAmount == 0) {
MyPetApi.getPlatformHelper().doPickupAnimation(myPet.getEntity().get(), itemEntity);
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.9") >= 0) {
myPet.getEntity().get().getHandle().makeSound("entity.item.pickup", 0.2F, 1.0F);
} else {
myPet.getEntity().get().getHandle().makeSound("random.pop", 0.2F, 1.0F);
}
itemStack.setAmount(0);
itemEntity.remove();
} else {
itemStack.setAmount(itemAmount);
itemEntity.setItemStack(itemStack);
}
}
}
if (expPickup && entity instanceof ExperienceOrb) {
ExperienceOrb expEntity = (ExperienceOrb) entity;
myPet.getOwner().getPlayer().giveExp(expEntity.getExperience());
MyPetApi.getPlatformHelper().doPickupAnimation(myPet.getEntity().get(), expEntity);
expEntity.setExperience(0);
expEntity.remove();
}
}
}
}
}
use of de.Keyle.MyPet.api.util.inventory.CustomInventory 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()));
}
}
}
}
use of de.Keyle.MyPet.api.util.inventory.CustomInventory in project MyPet by xXKeyleXx.
the class PlayerListener method on.
@EventHandler
public void on(final PlayerDeathEvent event) {
if (MyPetApi.getPlayerManager().isMyPetPlayer(event.getEntity())) {
MyPetPlayer myPetPlayer = MyPetApi.getPlayerManager().getMyPetPlayer(event.getEntity());
if (myPetPlayer.hasMyPet()) {
final MyPet myPet = myPetPlayer.getMyPet();
if (myPet.getStatus() == MyPet.PetState.Here && Configuration.Skilltree.Skill.Inventory.DROP_WHEN_OWNER_DIES) {
if (myPet.getSkills().isSkillActive(Inventory.class)) {
CustomInventory inv = myPet.getSkills().getSkill(Inventory.class).get().getInventory();
inv.dropContentAt(myPet.getLocation().get());
}
}
myPet.removePet();
}
}
}
Aggregations