Search in sources :

Example 1 with CraftItemEvent

use of org.bukkit.event.inventory.CraftItemEvent in project Jobs by GamingMesh.

the class JobsPaymentListener method onInventoryCraft.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onInventoryCraft(InventoryClickEvent e) {
    if (!(e instanceof CraftItemEvent))
        return;
    CraftItemEvent event = (CraftItemEvent) e;
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    // 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;
    }
    if (event.getAction() == InventoryAction.NOTHING)
        return;
    CraftingInventory inv = event.getInventory();
    if (!(inv instanceof CraftingInventory) || !event.getSlotType().equals(SlotType.RESULT))
        return;
    Recipe recipe = event.getRecipe();
    if (recipe == null)
        return;
    if (!(event.getWhoClicked() instanceof Player))
        return;
    Player player = (Player) event.getWhoClicked();
    ItemStack resultStack = recipe.getResult();
    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.CRAFT), multiplier);
}
Also used : CraftingInventory(org.bukkit.inventory.CraftingInventory) Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Recipe(org.bukkit.inventory.Recipe) ItemActionInfo(com.gamingmesh.jobs.actions.ItemActionInfo) CraftItemEvent(org.bukkit.event.inventory.CraftItemEvent) ItemStack(org.bukkit.inventory.ItemStack) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) 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 CraftItemEvent (org.bukkit.event.inventory.CraftItemEvent)1 CraftingInventory (org.bukkit.inventory.CraftingInventory)1 ItemStack (org.bukkit.inventory.ItemStack)1 Recipe (org.bukkit.inventory.Recipe)1