Search in sources :

Example 21 with JobsPlayer

use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.

the class JobsListener method onPlayerWorldChange.

@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerWorldChange(PlayerChangedWorldEvent event) {
    if (!plugin.isEnabled())
        return;
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(event.getPlayer());
    Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
}
Also used : JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 22 with JobsPlayer

use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.

the class JobsPaymentListener method onEntityDeath.

@EventHandler(priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) {
    // Entity that died must be living
    if (!(event.getEntity() instanceof LivingEntity))
        return;
    LivingEntity lVictim = (LivingEntity) event.getEntity();
    // mob spawner, no payment or experience
    if (lVictim.hasMetadata(mobSpawnerMetadata)) {
        lVictim.removeMetadata(mobSpawnerMetadata, plugin);
        return;
    }
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event.getEntity().getLastDamageCause();
        org.bukkit.entity.Player pDamager = null;
        if (e.getDamager() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) e.getDamager();
        } else if (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof org.bukkit.entity.Player) {
            pDamager = (org.bukkit.entity.Player) ((Projectile) e.getDamager()).getShooter();
        } else if (e.getDamager() instanceof Tameable) {
            Tameable t = (Tameable) e.getDamager();
            if (t.isTamed() && t.getOwner() instanceof org.bukkit.entity.Player) {
                pDamager = (org.bukkit.entity.Player) t.getOwner();
            }
        }
        if (pDamager != null) {
            // check if in creative
            if (pDamager.getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
                return;
            if (!Jobs.getPermissionHandler().hasWorldPermission(pDamager, pDamager.getLocation().getWorld().getName()))
                return;
            // restricted area multiplier
            double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(pDamager);
            // pay
            JobsPlayer jDamager = Jobs.getPlayerManager().getJobsPlayer(pDamager);
            Jobs.action(jDamager, new EntityActionInfo(lVictim.getType(), ActionType.KILL), multiplier);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Tameable(org.bukkit.entity.Tameable) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) Player(org.bukkit.entity.Player) EntityActionInfo(com.gamingmesh.jobs.actions.EntityActionInfo) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Projectile(org.bukkit.entity.Projectile) EventHandler(org.bukkit.event.EventHandler)

Example 23 with JobsPlayer

use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.

the class JobsPaymentListener method onBlockPlace.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();
    if (block == null)
        return;
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    // check to make sure you can build
    if (!event.canBuild())
        return;
    Player player = event.getPlayer();
    if (!player.isOnline())
        return;
    // check if in creative
    if (event.getPlayer().getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    // restricted area multiplier
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
    Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.PLACE), multiplier);
}
Also used : Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Block(org.bukkit.block.Block) BlockActionInfo(com.gamingmesh.jobs.actions.BlockActionInfo) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 24 with JobsPlayer

use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.

the class JobsPaymentListener method onBlockBreak.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    // remove furnace metadata for broken block
    Block block = event.getBlock();
    if (block == null)
        return;
    if (block.getType().equals(Material.FURNACE) && block.hasMetadata(furnaceOwnerMetadata))
        block.removeMetadata(furnaceOwnerMetadata, plugin);
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    Player player = event.getPlayer();
    if (!player.isOnline())
        return;
    // check if in creative
    if (event.getPlayer().getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    // restricted area multiplier
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
    Jobs.action(jPlayer, new BlockActionInfo(block, ActionType.BREAK), multiplier);
}
Also used : Player(org.bukkit.entity.Player) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Block(org.bukkit.block.Block) BlockActionInfo(com.gamingmesh.jobs.actions.BlockActionInfo) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) EventHandler(org.bukkit.event.EventHandler)

Example 25 with JobsPlayer

use of com.gamingmesh.jobs.container.JobsPlayer in project Jobs by GamingMesh.

the class JobsPaymentListener method onPlayerFish.

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) {
    // make sure plugin is enabled
    if (!plugin.isEnabled())
        return;
    Player player = event.getPlayer();
    // check if in creative
    if (event.getPlayer().getGameMode().equals(GameMode.CREATIVE) && !ConfigManager.getJobsConfiguration().payInCreative())
        return;
    if (!Jobs.getPermissionHandler().hasWorldPermission(player, player.getLocation().getWorld().getName()))
        return;
    // restricted area multiplier
    double multiplier = ConfigManager.getJobsConfiguration().getRestrictedMultiplier(player);
    if (event.getState().equals(PlayerFishEvent.State.CAUGHT_FISH) && event.getCaught() instanceof Item) {
        JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(player);
        ItemStack items = ((Item) event.getCaught()).getItemStack();
        Jobs.action(jPlayer, new ItemActionInfo(items, ActionType.FISH), multiplier);
    }
}
Also used : Item(org.bukkit.entity.Item) 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) EventHandler(org.bukkit.event.EventHandler)

Aggregations

JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)33 Player (org.bukkit.entity.Player)26 OfflinePlayer (org.bukkit.OfflinePlayer)15 Job (com.gamingmesh.jobs.container.Job)14 EventHandler (org.bukkit.event.EventHandler)12 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 JobProgression (com.gamingmesh.jobs.container.JobProgression)7 ItemActionInfo (com.gamingmesh.jobs.actions.ItemActionInfo)6 Block (org.bukkit.block.Block)4 ItemStack (org.bukkit.inventory.ItemStack)4 CraftingInventory (org.bukkit.inventory.CraftingInventory)3 BlockActionInfo (com.gamingmesh.jobs.actions.BlockActionInfo)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 EntityActionInfo (com.gamingmesh.jobs.actions.EntityActionInfo)1 JobPermission (com.gamingmesh.jobs.container.JobPermission)1 Title (com.gamingmesh.jobs.container.Title)1