Search in sources :

Example 1 with ItemActionInfo

use of com.gamingmesh.jobs.actions.ItemActionInfo in project Jobs by GamingMesh.

the class JobsPaymentListener method onBrewEvent.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBrewEvent(BrewEvent event) {
    if (!plugin.isEnabled())
        return;
    Block block = event.getBlock();
    if (block == null)
        return;
    if (!block.hasMetadata(brewingOwnerMetadata))
        return;
    List<MetadataValue> data = block.getMetadata(brewingOwnerMetadata);
    if (data.isEmpty())
        return;
    // only care about first
    MetadataValue value = data.get(0);
    String playerName = value.asString();
    Player player = Bukkit.getServer().getPlayerExact(playerName);
    if (player == null || !player.isOnline())
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
    Jobs.action(jPlayer, new ItemActionInfo(event.getContents().getIngredient(), ActionType.BREW), multiplier);
}
Also used : FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MetadataValue(org.bukkit.metadata.MetadataValue) Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) ItemActionInfo(com.gamingmesh.jobs.actions.ItemActionInfo) Block(org.bukkit.block.Block) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 2 with ItemActionInfo

use of com.gamingmesh.jobs.actions.ItemActionInfo 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)

Example 3 with ItemActionInfo

use of com.gamingmesh.jobs.actions.ItemActionInfo in project Jobs by GamingMesh.

the class JobsPaymentListener method onEnchantItem.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onEnchantItem(EnchantItemEvent event) {
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    Inventory inv = event.getInventory();
    if (!(inv instanceof EnchantingInventory))
        return;
    Player player = event.getEnchanter();
    ItemStack resultStack = ((EnchantingInventory) inv).getItem();
    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.ENCHANT), multiplier);
}
Also used : Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) ItemActionInfo(com.gamingmesh.jobs.actions.ItemActionInfo) 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) EnchantingInventory(org.bukkit.inventory.EnchantingInventory) EventHandler(org.bukkit.event.EventHandler)

Example 4 with ItemActionInfo

use of com.gamingmesh.jobs.actions.ItemActionInfo in project Jobs by GamingMesh.

the class JobsPaymentListener method onFurnaceSmelt.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onFurnaceSmelt(FurnaceSmeltEvent event) {
    if (!plugin.isEnabled())
        return;
    Block block = event.getBlock();
    if (block == null)
        return;
    if (!block.hasMetadata(furnaceOwnerMetadata))
        return;
    List<MetadataValue> data = block.getMetadata(furnaceOwnerMetadata);
    if (data.isEmpty())
        return;
    // only care about first
    MetadataValue value = data.get(0);
    String playerName = value.asString();
    Player player = Bukkit.getServer().getPlayerExact(playerName);
    if (player == null || !player.isOnline())
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
    Jobs.action(jPlayer, new ItemActionInfo(event.getResult(), ActionType.SMELT), multiplier);
}
Also used : FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MetadataValue(org.bukkit.metadata.MetadataValue) Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) ItemActionInfo(com.gamingmesh.jobs.actions.ItemActionInfo) Block(org.bukkit.block.Block) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ItemActionInfo

use of com.gamingmesh.jobs.actions.ItemActionInfo 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)6 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)6 Player (org.bukkit.entity.Player)6 EventHandler (org.bukkit.event.EventHandler)6 ItemStack (org.bukkit.inventory.ItemStack)4 CraftingInventory (org.bukkit.inventory.CraftingInventory)3 Block (org.bukkit.block.Block)2 AnvilInventory (org.bukkit.inventory.AnvilInventory)2 EnchantingInventory (org.bukkit.inventory.EnchantingInventory)2 Inventory (org.bukkit.inventory.Inventory)2 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)2 MetadataValue (org.bukkit.metadata.MetadataValue)2 Item (org.bukkit.entity.Item)1 CraftItemEvent (org.bukkit.event.inventory.CraftItemEvent)1 Recipe (org.bukkit.inventory.Recipe)1