Search in sources :

Example 1 with AnvilInventory

use of org.bukkit.inventory.AnvilInventory in project Jobs by GamingMesh.

the class JobsPaymentListener method onInventoryRepair.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryRepair(InventoryClickEvent event) {
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    Inventory inv = event.getInventory();
    // If event is nothing or place, do nothing
    switch(event.getAction()) {
        case NOTHING:
        case PLACE_ONE:
        case PLACE_ALL:
        case PLACE_SOME:
            return;
        default:
            break;
    }
    // must be anvil inventory
    if (!(inv instanceof AnvilInventory))
        return;
    // Must be "container" slot 9
    if (!event.getSlotType().equals(SlotType.CONTAINER) || event.getSlot() != 2)
        return;
    if (!(event.getWhoClicked() instanceof Player))
        return;
    Player player = (Player) event.getWhoClicked();
    ItemStack resultStack = event.getCurrentItem();
    if (resultStack == null)
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    // check if in creative
    if (player.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
        return;
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
    Jobs.action(jPlayer, new ItemActionInfo(resultStack, ActionType.REPAIR), multiplier);
}
Also used : Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) ItemActionInfo(com.gamingmesh.jobs.actions.ItemActionInfo) AnvilInventory(org.bukkit.inventory.AnvilInventory) ItemStack(org.bukkit.inventory.ItemStack) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) CraftingInventory(org.bukkit.inventory.CraftingInventory) Inventory(org.bukkit.inventory.Inventory) EnchantingInventory(org.bukkit.inventory.EnchantingInventory) AnvilInventory(org.bukkit.inventory.AnvilInventory) EventHandler(org.bukkit.event.EventHandler)

Aggregations

ItemActionInfo (com.gamingmesh.jobs.actions.ItemActionInfo)1 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 AnvilInventory (org.bukkit.inventory.AnvilInventory)1 CraftingInventory (org.bukkit.inventory.CraftingInventory)1 EnchantingInventory (org.bukkit.inventory.EnchantingInventory)1 Inventory (org.bukkit.inventory.Inventory)1 ItemStack (org.bukkit.inventory.ItemStack)1