Search in sources :

Example 1 with MUST_NOT_BE_CONVERSING

use of dte.employme.messages.MessageKey.MUST_NOT_BE_CONVERSING in project EmployMe by DavidTheExplorer.

the class EmployMe method registerCommands.

@SuppressWarnings("deprecation")
private void registerCommands() {
    BukkitCommandManager commandManager = new BukkitCommandManager(this);
    commandManager.enableUnstableAPI("help");
    // register conditions
    commandManager.getCommandConditions().addCondition(Player.class, "Not Conversing", (handler, context, payment) -> {
        if (context.getPlayer().isConversing())
            throw new InvalidCommandArgument(this.messageService.getMessage(MUST_NOT_BE_CONVERSING).first(), false);
    });
    commandManager.getCommandConditions().addCondition(Material.class, "Subscribed To Goal", (handler, context, material) -> {
        if (!this.jobSubscriptionService.isSubscribedTo(context.getPlayer().getUniqueId(), material))
            throw new InvalidCommandArgument(this.messageService.getMessage(MUST_BE_SUBSCRIBED_TO_GOAL).first(), false);
    });
    commandManager.getCommandConditions().addCondition("Global Jobs Board Not Full", context -> {
        if (this.globalJobBoard.getOfferedJobs().size() == ((6 * 9) - 26))
            throw new ConditionFailedException(this.messageService.getMessage(GLOBAL_JOB_BOARD_IS_FULL).first());
    });
    commandManager.getCommandConditions().addCondition(Player.class, "Can Offer More Jobs", (handler, context, player) -> {
        String jobPermission = PermissionUtils.findPermission(player, permission -> permission.startsWith("employme.jobs.allowed.")).orElse("employme.jobs.allowed.3");
        int allowedJobs = Integer.parseInt(jobPermission.split("\\.")[jobPermission.split("\\.").length - 1]);
        if (this.globalJobBoard.getJobsOfferedBy(player.getUniqueId()).size() >= allowedJobs)
            throw new ConditionFailedException(this.messageService.getMessage(YOU_OFFERED_TOO_MANY_JOBS).first());
    });
    // register contexts
    commandManager.getCommandContexts().registerContext(Material.class, context -> {
        Material material = Material.matchMaterial(context.popFirstArg());
        if (material == null)
            throw new InvalidCommandArgument(this.messageService.getMessage(MATERIAL_NOT_FOUND).first(), false);
        return material;
    });
    commandManager.getCommandContexts().registerContext(JobAddedNotifier.class, context -> {
        String notifierName = context.joinArgs();
        JobAddedNotifier notifier = this.jobAddedNotifierService.getByName(notifierName);
        if (notifier == null)
            throw new InvalidCommandArgument(this.messageService.getMessage(JOB_ADDED_NOTIFIER_NOT_FOUND).inject(Placeholders.JOB_ADDED_NOTIFIER, notifierName).first(), false);
        return notifier;
    });
    commandManager.getCommandContexts().registerIssuerOnlyContext(List.class, context -> {
        if (!context.hasFlag("Jobs Able To Delete"))
            return null;
        Player player = context.getPlayer();
        return player.hasPermission("employme.admin.delete") ? this.globalJobBoard.getOfferedJobs() : this.globalJobBoard.getJobsOfferedBy(player.getUniqueId());
    });
    // register commands
    InventoryBoardDisplayer inventoryBoardDisplayer = new InventoryBoardDisplayer(Job.ORDER_BY_GOAL_NAME, this.jobService, this.messageService, this.jobIconFactory);
    commandManager.registerCommand(new EmploymentCommand(this.globalJobBoard, this.playerContainerService, this.jobSubscriptionService, this.jobAddedNotifierService, this.messageService, inventoryBoardDisplayer, this.economy, this.jobIconFactory, this.rewardService, this.reloadables));
}
Also used : PermissionUtils(dte.employme.utils.PermissionUtils) MaterialSubscriptionNotifier(dte.employme.job.addnotifiers.MaterialSubscriptionNotifier) SimpleJobSubscriptionService(dte.employme.job.subscription.SimpleJobSubscriptionService) RewardService(dte.employme.job.rewards.service.RewardService) Player(org.bukkit.entity.Player) ModernJavaPlugin(dte.modernjavaplugin.ModernJavaPlugin) ConfigFileFactory(dte.employme.config.ConfigFileFactory) PlayerContainerService(dte.employme.containers.service.PlayerContainerService) SimpleJobAddedNotifierService(dte.employme.job.addnotifiers.service.SimpleJobAddedNotifierService) SimpleRewardService(dte.employme.job.rewards.service.SimpleRewardService) PlayerContainerAbuseListener(dte.employme.listeners.PlayerContainerAbuseListener) MUST_BE_SUBSCRIBED_TO_GOAL(dte.employme.messages.MessageKey.MUST_BE_SUBSCRIBED_TO_GOAL) JobRewardGiveListener(dte.employme.board.listenable.JobRewardGiveListener) EmployerNotificationListener(dte.employme.board.listenable.EmployerNotificationListener) GLOBAL_JOB_BOARD_IS_FULL(dte.employme.messages.MessageKey.GLOBAL_JOB_BOARD_IS_FULL) ColoredMessageService(dte.employme.messages.service.ColoredMessageService) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) JobCompletedMessagesListener(dte.employme.board.listenable.JobCompletedMessagesListener) AutoUpdateListeners(dte.employme.listeners.AutoUpdateListeners) Metrics(org.bstats.bukkit.Metrics) JobAddedNotifierService(dte.employme.job.addnotifiers.service.JobAddedNotifierService) SimplePlayerContainerService(dte.employme.containers.service.SimplePlayerContainerService) JobAddedNotifier(dte.employme.job.addnotifiers.JobAddedNotifier) JOB_ADDED_NOTIFIER_NOT_FOUND(dte.employme.messages.MessageKey.JOB_ADDED_NOTIFIER_NOT_FOUND) EmploymentCommand(dte.employme.commands.EmploymentCommand) JobService(dte.employme.job.service.JobService) MessageService(dte.employme.messages.service.MessageService) List(java.util.List) Stream(java.util.stream.Stream) MUST_NOT_BE_CONVERSING(dte.employme.messages.MessageKey.MUST_NOT_BE_CONVERSING) SimpleListenableJobBoard(dte.employme.board.listenable.SimpleListenableJobBoard) TranslatedMessageService(dte.employme.messages.service.TranslatedMessageService) SimpleJobBoard(dte.employme.board.SimpleJobBoard) ConfigurationSerialization(org.bukkit.configuration.serialization.ConfigurationSerialization) SimpleJob(dte.employme.job.SimpleJob) RED(org.bukkit.ChatColor.RED) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) Job(dte.employme.job.Job) YOU_OFFERED_TOO_MANY_JOBS(dte.employme.messages.MessageKey.YOU_OFFERED_TOO_MANY_JOBS) ArrayList(java.util.ArrayList) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) InventoryBoardDisplayer(dte.employme.board.displayers.InventoryBoardDisplayer) AllJobsNotifier(dte.employme.job.addnotifiers.AllJobsNotifier) ConditionFailedException(co.aikar.commands.ConditionFailedException) ListenableJobBoard(dte.employme.board.listenable.ListenableJobBoard) ConfigFile(dte.employme.config.ConfigFile) Economy(net.milkbowl.vault.economy.Economy) Messages(dte.employme.config.Messages) MoneyReward(dte.employme.job.rewards.MoneyReward) JobAddNotificationListener(dte.employme.board.listenable.JobAddNotificationListener) ServiceLocator(dte.employme.utils.java.ServiceLocator) JobIconFactory(dte.employme.items.JobIconFactory) MATERIAL_NOT_FOUND(dte.employme.messages.MessageKey.MATERIAL_NOT_FOUND) JobGoalTransferListener(dte.employme.board.listenable.JobGoalTransferListener) JobSubscriptionService(dte.employme.job.subscription.JobSubscriptionService) SimpleJobService(dte.employme.job.service.SimpleJobService) ItemsReward(dte.employme.job.rewards.ItemsReward) RegisteredServiceProvider(org.bukkit.plugin.RegisteredServiceProvider) Placeholders(dte.employme.messages.Placeholders) Reloadable(dte.employme.reloadable.Reloadable) DoNotNotify(dte.employme.job.addnotifiers.DoNotNotify) AutoUpdater(dte.employme.utils.AutoUpdater) Player(org.bukkit.entity.Player) BukkitCommandManager(co.aikar.commands.BukkitCommandManager) ConditionFailedException(co.aikar.commands.ConditionFailedException) InvalidCommandArgument(co.aikar.commands.InvalidCommandArgument) InventoryBoardDisplayer(dte.employme.board.displayers.InventoryBoardDisplayer) JobAddedNotifier(dte.employme.job.addnotifiers.JobAddedNotifier) Material(org.bukkit.Material) EmploymentCommand(dte.employme.commands.EmploymentCommand)

Aggregations

BukkitCommandManager (co.aikar.commands.BukkitCommandManager)1 ConditionFailedException (co.aikar.commands.ConditionFailedException)1 InvalidCommandArgument (co.aikar.commands.InvalidCommandArgument)1 SimpleJobBoard (dte.employme.board.SimpleJobBoard)1 InventoryBoardDisplayer (dte.employme.board.displayers.InventoryBoardDisplayer)1 EmployerNotificationListener (dte.employme.board.listenable.EmployerNotificationListener)1 JobAddNotificationListener (dte.employme.board.listenable.JobAddNotificationListener)1 JobCompletedMessagesListener (dte.employme.board.listenable.JobCompletedMessagesListener)1 JobGoalTransferListener (dte.employme.board.listenable.JobGoalTransferListener)1 JobRewardGiveListener (dte.employme.board.listenable.JobRewardGiveListener)1 ListenableJobBoard (dte.employme.board.listenable.ListenableJobBoard)1 SimpleListenableJobBoard (dte.employme.board.listenable.SimpleListenableJobBoard)1 EmploymentCommand (dte.employme.commands.EmploymentCommand)1 ConfigFile (dte.employme.config.ConfigFile)1 ConfigFileFactory (dte.employme.config.ConfigFileFactory)1 Messages (dte.employme.config.Messages)1 PlayerContainerService (dte.employme.containers.service.PlayerContainerService)1 SimplePlayerContainerService (dte.employme.containers.service.SimplePlayerContainerService)1 JobIconFactory (dte.employme.items.JobIconFactory)1 Job (dte.employme.job.Job)1