1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-12-11 19:58:39 +01:00
Jobs/com/gamingmesh/jobs/commands/list/browse.java

86 lines
2.9 KiB
Java
Raw Normal View History

2016-03-30 15:42:36 +02:00
package com.gamingmesh.jobs.commands.list;
import java.util.ArrayList;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2016-04-03 16:22:44 +02:00
import org.bukkit.inventory.Inventory;
2016-03-30 15:42:36 +02:00
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.JobsPlugin;
import com.gamingmesh.jobs.commands.Cmd;
import com.gamingmesh.jobs.commands.JobCommand;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.stuff.ChatColor;
import com.gamingmesh.jobs.stuff.Perm;
public class browse implements Cmd {
2016-06-25 17:56:59 +02:00
@Override
2016-03-30 15:42:36 +02:00
@JobCommand(200)
public boolean perform(JobsPlugin plugin, final CommandSender sender, final String[] args) {
ArrayList<String> lines = new ArrayList<String>();
for (Job job : Jobs.getJobs()) {
if (Jobs.getGCManager().getHideJobsWithoutPermission()) {
if (!Jobs.getCommandManager().hasJobPermission(sender, job))
continue;
}
StringBuilder builder = new StringBuilder();
builder.append(" ");
builder.append(job.getChatColor().toString());
builder.append(job.getName());
if (job.getMaxLevel() > 0) {
builder.append(ChatColor.WHITE.toString());
builder.append(Jobs.getLanguage().getMessage("command.info.help.max"));
if (Perm.hasPermission(sender, "jobs." + job.getName() + ".vipmaxlevel") && job.getVipMaxLevel() != 0)
builder.append(job.getVipMaxLevel());
else
builder.append(job.getMaxLevel());
}
if (Jobs.getGCManager().ShowTotalWorkers)
builder.append(Jobs.getLanguage().getMessage("command.browse.output.totalWorkers", "[amount]", job.getTotalPlayers()));
if (Jobs.getGCManager().useDynamicPayment && Jobs.getGCManager().ShowPenaltyBonus)
if (job.getBonus() < 0)
builder.append(Jobs.getLanguage().getMessage("command.browse.output.penalty", "[amount]", (int) (job.getBonus() * 100) / 100.0 * -1));
else
builder.append(Jobs.getLanguage().getMessage("command.browse.output.bonus", "[amount]", (int) (job.getBonus() * 100) / 100.0));
lines.add(builder.toString());
if (!job.getDescription().isEmpty()) {
lines.add(" - " + job.getDescription().replace("/n", ""));
}
}
if (lines.size() == 0) {
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("command.browse.error.nojobs"));
return true;
}
if (sender instanceof Player && Jobs.getGCManager().JobsGUIOpenOnBrowse) {
2016-04-03 16:22:44 +02:00
Inventory inv = null;
try {
inv = Jobs.getGUIManager().CreateJobsGUI((Player) sender);
} catch (Exception e) {
((Player) sender).closeInventory();
Jobs.getGUIManager().GuiList.remove(((Player) sender).getName());
return true;
}
if (inv == null)
return true;
((Player) sender).openInventory(inv);
2016-03-30 15:42:36 +02:00
}
if (Jobs.getGCManager().JobsGUIShowChatBrowse) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.header"));
for (String line : lines) {
sender.sendMessage(line);
}
sender.sendMessage(Jobs.getLanguage().getMessage("command.browse.output.footer"));
}
return true;
}
}