1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-30 14:33:35 +01:00
Jobs/com/gamingmesh/jobs/commands/list/browse.java
2016-04-03 17:22:44 +03:00

85 lines
2.9 KiB
Java

package com.gamingmesh.jobs.commands.list;
import java.util.ArrayList;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
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 {
@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) {
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);
}
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;
}
}