use of de.Keyle.MyPet.api.event.MyPetPickupItemEvent 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();
}
}
}
}
}
Aggregations