use of de.Keyle.MyPet.api.event.MyPetInventoryActionEvent in project MyPet by xXKeyleXx.
the class EntityMyPet method canUseItem.
public boolean canUseItem() {
MyPetInventoryActionEvent event = new MyPetInventoryActionEvent(myPet, MyPetInventoryActionEvent.Action.Use);
Bukkit.getServer().getPluginManager().callEvent(event);
return !event.isCancelled();
}
use of de.Keyle.MyPet.api.event.MyPetInventoryActionEvent 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.event.MyPetInventoryActionEvent in project MyPet by xXKeyleXx.
the class Inventory method activate.
public boolean activate() {
if (rows > 0) {
if (myPet.getOwner().getPlayer().isSleeping()) {
myPet.getOwner().sendMessage(Translation.getString("Message.No.CanUse", myPet.getOwner()));
return false;
}
if (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.Inventory.Creative", myPet.getOwner()));
return false;
}
MyPetInventoryActionEvent event = new MyPetInventoryActionEvent(myPet, MyPetInventoryActionEvent.Action.Open);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.No.AllowedHere", myPet.getOwner()), myPet.getPetName()));
return false;
}
if (!myPet.getLocation().get().getBlock().isLiquid()) {
inv.setName(myPet.getPetName());
openInventory(myPet.getOwner().getPlayer());
return true;
} else {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skill.Inventory.Swimming", myPet.getOwner()), myPet.getPetName()));
return false;
}
} else {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skill.Inventory.NotAvailable", myPet.getOwner()), myPet.getPetName()));
return false;
}
}
use of de.Keyle.MyPet.api.event.MyPetInventoryActionEvent in project MyPet by xXKeyleXx.
the class Pickup method activate.
public boolean activate() {
if (range > 0) {
if (myPet.getSkills().isSkillActive(Inventory.class)) {
if (pickup) {
pickup = false;
} else {
MyPetInventoryActionEvent event = new MyPetInventoryActionEvent(myPet, MyPetInventoryActionEvent.Action.Pickup);
Bukkit.getServer().getPluginManager().callEvent(event);
if (!event.isCancelled()) {
pickup = true;
}
}
String mode = pickup ? Translation.getString("Name.Enabled", myPet.getOwner()) : Translation.getString("Name.Disabled", myPet.getOwner());
myPet.getOwner().sendMessage(Util.formatText(Translation.getString(("Message.Skill.Pickup.StartStop"), myPet.getOwner().getPlayer()), myPet.getPetName(), mode));
return true;
} else {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.Skill.Pickup.NoInventory", myPet.getOwner().getLanguage()), myPet.getPetName()));
return false;
}
} else {
myPet.getOwner().sendMessage(Util.formatText(Translation.getString("Message.No.Skill", myPet.getOwner().getLanguage()), myPet.getPetName(), this.getName(myPet.getOwner().getLanguage())));
return false;
}
}
use of de.Keyle.MyPet.api.event.MyPetInventoryActionEvent in project MyPet by xXKeyleXx.
the class EntityMyPet method canUseItem.
public boolean canUseItem() {
MyPetInventoryActionEvent event = new MyPetInventoryActionEvent(myPet, MyPetInventoryActionEvent.Action.Use);
Bukkit.getServer().getPluginManager().callEvent(event);
return !event.isCancelled();
}
Aggregations