Search in sources :

Example 16 with JobsPlayer

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

the class JobsCommands method demote.

@JobCommand
public boolean demote(CommandSender sender, String[] args) {
    if (args.length < 3) {
        sendUsage(sender, "demote");
        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;
    }
    try {
        // check if player already has the job
        if (jPlayer.isInJob(job)) {
            Integer levelsLost = Integer.parseInt(args[2]);
            Jobs.getPlayerManager().demoteJob(jPlayer, job, levelsLost);
            Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
            if (player != null) {
                String message = Language.getMessage("command.demote.output.target");
                message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
                message = message.replace("%levelslost%", Integer.valueOf(levelsLost).toString());
                player.sendMessage(message);
            }
            sender.sendMessage(Language.getMessage("command.admin.success"));
        }
    } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
    }
    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)

Example 17 with JobsPlayer

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

the class JobsCommands method join.

@JobCommand
public boolean join(CommandSender sender, String[] args) {
    if (!(sender instanceof Player))
        return false;
    if (args.length < 1) {
        sendUsage(sender, "join");
        return true;
    }
    Player pSender = (Player) sender;
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
    String jobName = args[0];
    Job job = Jobs.getJob(jobName);
    if (job == null) {
        // job does not exist
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    if (!hasJobPermission(pSender, job)) {
        // you do not have permission to join the job
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.permission"));
        return true;
    }
    if (jPlayer.isInJob(job)) {
        // already in job message
        String message = ChatColor.RED + Language.getMessage("command.join.error.alreadyin");
        message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.RED);
        sender.sendMessage(message);
        return true;
    }
    if (job.getMaxSlots() != null && Jobs.getUsedSlots(job) >= job.getMaxSlots()) {
        String message = ChatColor.RED + Language.getMessage("command.join.error.fullslots");
        message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.RED);
        sender.sendMessage(message);
        return true;
    }
    int confMaxJobs = ConfigManager.getJobsConfiguration().getMaxJobs();
    if (confMaxJobs > 0 && jPlayer.getJobProgression().size() >= confMaxJobs) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.join.error.maxjobs"));
        return true;
    }
    Jobs.getPlayerManager().joinJob(jPlayer, job);
    String message = Language.getMessage("command.join.success");
    message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
    sender.sendMessage(message);
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Job(com.gamingmesh.jobs.container.Job) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer)

Example 18 with JobsPlayer

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

the class JobsCommands method info.

@JobCommand
public boolean info(CommandSender sender, String[] args) {
    if (!(sender instanceof Player))
        return false;
    if (args.length < 1) {
        sendUsage(sender, "info");
        sendValidActions(sender);
        return true;
    }
    Player pSender = (Player) sender;
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayer(pSender);
    String jobName = args[0];
    Job job = Jobs.getJob(jobName);
    if (job == null) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    String type = "";
    if (args.length >= 2) {
        type = args[1];
    }
    sender.sendMessage(jobInfoMessage(jPlayer, job, type).split("\n"));
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) Job(com.gamingmesh.jobs.container.Job) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer)

Example 19 with JobsPlayer

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

the class JobsCommands method transfer.

@JobCommand
public boolean transfer(CommandSender sender, String[] args) {
    if (args.length < 3) {
        sendUsage(sender, "transfer");
        return true;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
    Job oldjob = Jobs.getJob(args[1]);
    Job newjob = Jobs.getJob(args[2]);
    if (oldjob == null) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    if (newjob == null) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.error.job"));
        return true;
    }
    try {
        if (jPlayer.isInJob(oldjob) && !jPlayer.isInJob(newjob)) {
            Jobs.getPlayerManager().transferJob(jPlayer, oldjob, newjob);
            Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
            if (player != null) {
                String message = Language.getMessage("command.transfer.output.target");
                message = message.replace("%oldjobname%", oldjob.getChatColor() + oldjob.getName() + ChatColor.WHITE);
                message = message.replace("%newjobname%", newjob.getChatColor() + newjob.getName() + ChatColor.WHITE);
                player.sendMessage(message);
            }
            sender.sendMessage(Language.getMessage("command.admin.success"));
        }
    } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
    }
    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)

Example 20 with JobsPlayer

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

the class JobsCommands method fireall.

@JobCommand
public boolean fireall(CommandSender sender, String[] args) {
    if (args.length < 1) {
        sendUsage(sender, "fireall");
        return true;
    }
    OfflinePlayer offlinePlayer = Bukkit.getServer().getOfflinePlayer(args[0]);
    JobsPlayer jPlayer = Jobs.getPlayerManager().getJobsPlayerOffline(offlinePlayer);
    List<JobProgression> jobs = jPlayer.getJobProgression();
    if (jobs.size() == 0) {
        sender.sendMessage(Language.getMessage("command.fireall.error.nojobs"));
        return true;
    }
    try {
        Jobs.getPlayerManager().leaveAllJobs(jPlayer);
        Player player = Bukkit.getServer().getPlayer(offlinePlayer.getUniqueId());
        if (player != null) {
            player.sendMessage(Language.getMessage("command.fireall.output.target"));
        }
        sender.sendMessage(Language.getMessage("command.admin.success"));
    } catch (Exception e) {
        sender.sendMessage(ChatColor.RED + Language.getMessage("command.admin.error"));
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) JobProgression(com.gamingmesh.jobs.container.JobProgression) OfflinePlayer(org.bukkit.OfflinePlayer) 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