Search in sources :

Example 6 with JobsPlayer

use of com.gamingmesh.jobs.container.JobsPlayer 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 7 with JobsPlayer

use of com.gamingmesh.jobs.container.JobsPlayer 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)

Example 8 with JobsPlayer

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

the class PlayerManager method playerJoin.

/**
     * Handles join of new player
     * @param playername
     */
public void playerJoin(Player player) {
    synchronized (players) {
        JobsPlayer jPlayer = players.get(player.getName().toLowerCase());
        if (jPlayer == null) {
            jPlayer = JobsPlayer.loadFromDao(Jobs.getJobsDAO(), player);
            players.put(player.getName().toLowerCase(), jPlayer);
        }
        jPlayer.onConnect();
        jPlayer.reloadHonorific();
        Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
    }
}
Also used : JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer)

Example 9 with JobsPlayer

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

the class PlayerManager method reload.

/**
     * Perform reload
     */
public void reload() {
    synchronized (players) {
        for (JobsPlayer jPlayer : players.values()) {
            for (JobProgression progression : jPlayer.getJobProgression()) {
                String jobName = progression.getJob().getName();
                Job job = Jobs.getJob(jobName);
                if (job != null) {
                    progression.setJob(job);
                }
            }
            if (jPlayer.isOnline()) {
                jPlayer.reloadHonorific();
                Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
            }
        }
    }
}
Also used : JobProgression(com.gamingmesh.jobs.container.JobProgression) Job(com.gamingmesh.jobs.container.Job) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer)

Example 10 with JobsPlayer

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

the class JobsCommands method grantxp.

@JobCommand
public boolean grantxp(CommandSender sender, String[] args) {
    if (args.length < 3) {
        sendUsage(sender, "grantxp");
        return true;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
    Job job = Jobs.getJob(args[1]);
    if (job == null) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    double xpGained;
    try {
        xpGained = Double.parseDouble(args[2]);
    } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
        return true;
    }
    if (xpGained <= 0) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
        return true;
    }
    // check if player already has the job
    if (jPlayer.isInJob(job)) {
        Jobs.getPlayerManager().addExperience(jPlayer, job, xpGained);
        Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
        if (player != null) {
            String message = Language.getMessage("command.grantxp.output.target");
            message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
            message = message.replace("%xpgained%", Double.valueOf(xpGained).toString());
            player.sendMessage(message);
        }
        sender.sendMessage(Language.getMessage("command.admin.success"));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) OfflinePlayer(org.bukkit.OfflinePlayer) Job(com.gamingmesh.jobs.container.Job) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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