1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-30 06:23:31 +01:00
Jobs/com/gamingmesh/jobs/commands/JobsCommands.java

612 lines
21 KiB
Java
Raw Normal View History

2015-08-21 15:10:08 +02:00
package com.gamingmesh.jobs.commands;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
2016-03-30 15:42:36 +02:00
import java.net.URL;
import java.net.URLClassLoader;
2015-08-21 15:10:08 +02:00
import java.util.ArrayList;
import java.util.Arrays;
2016-03-30 15:42:36 +02:00
import java.util.Collections;
import java.util.Comparator;
import java.util.Enumeration;
import java.util.HashMap;
2016-03-30 15:42:36 +02:00
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
2015-08-21 15:10:08 +02:00
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
2016-03-30 15:42:36 +02:00
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
2015-08-21 15:10:08 +02:00
import org.bukkit.Bukkit;
2016-03-30 15:42:36 +02:00
import org.bukkit.ChatColor;
2015-08-21 15:10:08 +02:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2016-03-30 15:42:36 +02:00
import com.gamingmesh.jobs.Jobs;
import com.gamingmesh.jobs.container.ActionType;
import com.gamingmesh.jobs.container.BoostMultiplier;
import com.gamingmesh.jobs.container.Job;
import com.gamingmesh.jobs.container.JobInfo;
import com.gamingmesh.jobs.container.JobProgression;
import com.gamingmesh.jobs.container.JobsPlayer;
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
public class JobsCommands implements CommandExecutor {
private static final String label = "jobs";
private static final String packagePath = "com.gamingmesh.jobs.commands.list";
private static final List<String> hidenCommands = new ArrayList<String>();
2016-03-30 15:42:36 +02:00
Map<String, Integer> CommandList = new HashMap<String, Integer>();
2015-08-21 15:10:08 +02:00
protected Jobs plugin;
2016-03-30 15:42:36 +02:00
public JobsCommands(Jobs plugin) {
2016-03-30 15:42:36 +02:00
this.plugin = plugin;
2015-09-10 12:41:19 +02:00
}
2016-03-30 15:42:36 +02:00
public Map<String, Integer> getCommands() {
return CommandList;
}
2015-08-21 15:10:08 +02:00
2016-06-25 17:56:59 +02:00
@Override
2016-03-30 15:42:36 +02:00
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (sender instanceof Player) {
if (!Jobs.getGCManager().canPerformActionInWorld(((Player) sender).getWorld()) && !sender.hasPermission("jobs.disabledworld.commands")) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled"));
return true;
2015-09-10 12:41:19 +02:00
}
}
2016-03-30 15:42:36 +02:00
if (args.length == 0)
return help(sender, 1);
if ((args.length == 1 || args.length == 2) && (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help"))) {
int page = 1;
if (args.length == 2)
try {
page = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.notNumber"));
return true;
}
return help(sender, page);
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
String cmd = args[0].toLowerCase();
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
if (!hasCommandPermission(sender, cmd)) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission"));
2015-09-10 12:41:19 +02:00
return true;
}
2016-03-30 15:42:36 +02:00
String[] myArgs = reduceArgs(args);
if (myArgs.length > 0) {
if (myArgs[myArgs.length - 1].equals("?")) {
sendUsage(sender, cmd);
return true;
2015-09-10 12:41:19 +02:00
}
}
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
Cmd cmdClass = getCmdClass(cmd);
if (cmdClass == null) {
return help(sender, 1);
2015-09-10 12:41:19 +02:00
}
2016-03-30 15:42:36 +02:00
boolean back = cmdClass.perform(plugin, sender, myArgs);
if (back)
2015-09-10 12:41:19 +02:00
return true;
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
if (!(sender instanceof Player))
2016-03-30 15:42:36 +02:00
return help(sender, 1);
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
return help(sender, 1);
}
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
private static String[] reduceArgs(String[] args) {
return args.length <= 1 ? new String[0] : Arrays.copyOfRange(args, 1, args.length);
2016-03-30 15:42:36 +02:00
}
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
private static boolean hasCommandPermission(CommandSender sender, String cmd) {
return sender.hasPermission("jobs.command." + cmd);
}
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
private static String getUsage(String cmd) {
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.GREEN.toString());
builder.append('/').append(label).append(' ');
builder.append(cmd);
builder.append(ChatColor.YELLOW);
String key = "command." + cmd + ".help.args";
if (Jobs.getLanguage().containsKey(key)) {
builder.append(' ');
builder.append(Jobs.getLanguage().getMessage(key));
}
return builder.toString();
}
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
public static String getUsageNoCmd(String cmd) {
StringBuilder builder = new StringBuilder();
builder.append(ChatColor.GREEN.toString());
builder.append('/').append(label).append(' ');
builder.append(ChatColor.YELLOW);
String key = "command." + cmd + ".help.args";
if (Jobs.getLanguage().containsKey(key)) {
builder.append(' ');
builder.append(Jobs.getLanguage().getMessage(key));
2015-09-10 12:41:19 +02:00
}
2016-03-30 15:42:36 +02:00
return builder.toString();
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
public void sendUsage(CommandSender sender, String cmd) {
String message = ChatColor.YELLOW + Jobs.getLanguage().getMessage("command.help.output.usage");
message = message.replace("%usage%", getUsage(cmd));
sender.sendMessage(message);
sender.sendMessage(ChatColor.YELLOW + "* " + Jobs.getLanguage().getMessage("command." + cmd + ".help.info"));
}
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
protected boolean help(CommandSender sender, int page) {
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
Map<String, Integer> commands = GetCommands(sender);
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
if (commands.size() == 0) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.permission"));
2015-09-10 12:41:19 +02:00
return true;
}
2016-03-30 15:42:36 +02:00
commands = sort(commands);
int amountToShow = 7;
int start = page * amountToShow - amountToShow;
int end = page * amountToShow;
2016-06-25 15:27:01 +02:00
int TotalPages = commands.size() / amountToShow;
2016-03-30 15:42:36 +02:00
if (((commands.size() * 1.0) / (amountToShow * 1.0)) - TotalPages > 0)
TotalPages++;
if (start >= commands.size()) {
start = page * amountToShow;
end = start + amountToShow;
2015-08-21 15:10:08 +02:00
}
2016-04-03 16:22:44 +02:00
if (page > TotalPages || page < 1) {
Jobs.getActionBar().send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage"));
return true;
}
2016-03-30 15:42:36 +02:00
sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.title"));
sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.page", "[1]", page, "[2]", TotalPages));
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
int i = -1;
for (Entry<String, Integer> one : commands.entrySet()) {
i++;
if (i < start)
continue;
if (i >= end)
break;
sender.sendMessage(getUsage(one.getKey()) + " - " + Jobs.getLanguage().getMessage("command." + one.getKey() + ".help.info"));
}
2015-09-10 12:41:19 +02:00
String prevCmd = "/" + label + " ? " + (page - 1);
2016-03-30 15:42:36 +02:00
String prev = "[\"\",{\"text\":\"" + Jobs.getLanguage().getMessage("command.help.output.prev") + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\""
+ prevCmd
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + "<<<" + "\"}]}}}";
String nextCmd = "/" + label + " ? " + (page + 1);
2016-03-30 15:42:36 +02:00
String next = " {\"text\":\"" + Jobs.getLanguage().getMessage("command.help.output.next") + "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + nextCmd
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ">>>" + "\"}]}}}]";
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + sender.getName() + " " + prev + "," + next);
2015-09-10 12:41:19 +02:00
return true;
}
2015-08-21 15:10:08 +02:00
private static List<String> getClassesFromPackage(String pckgname) throws ClassNotFoundException {
2016-03-30 15:42:36 +02:00
List<String> result = new ArrayList<String>();
try {
for (URL jarURL : ((URLClassLoader) Jobs.class.getClassLoader()).getURLs()) {
try {
result.addAll(getClassesInSamePackageFromJar(pckgname, jarURL.toURI().getPath()));
} catch (URISyntaxException e) {
}
2016-03-30 15:42:36 +02:00
}
} catch (NullPointerException x) {
throw new ClassNotFoundException(pckgname + " does not appear to be a valid package (Null pointer exception)");
2015-08-21 15:10:08 +02:00
}
2016-03-30 15:42:36 +02:00
return result;
}
private static List<String> getClassesInSamePackageFromJar(String packageName, String jarPath) {
JarFile jarFile = null;
List<String> listOfCommands = new ArrayList<String>();
try {
jarFile = new JarFile(jarPath);
Enumeration<JarEntry> en = jarFile.entries();
while (en.hasMoreElements()) {
JarEntry entry = en.nextElement();
String entryName = entry.getName();
packageName = packageName.replace(".", "/");
if (entryName != null && entryName.endsWith(".class") && entryName.startsWith(packageName)) {
String name = entryName.replace(packageName, "").replace(".class", "").replace("/", "");
if (name.contains("$"))
name = name.split("\\$")[0];
listOfCommands.add(name);
2015-09-10 12:41:19 +02:00
}
}
2016-03-30 15:42:36 +02:00
} catch (Exception e) {
} finally {
2016-06-25 15:27:01 +02:00
if (jarFile != null)
try {
2016-03-30 15:42:36 +02:00
jarFile.close();
2016-06-25 15:27:01 +02:00
} catch (Exception e) {
2015-09-10 12:41:19 +02:00
}
}
2016-03-30 15:42:36 +02:00
return listOfCommands;
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
public Map<String, Integer> GetCommands(CommandSender sender) {
Map<String, Integer> temp = new HashMap<String, Integer>();
for (Entry<String, Integer> cmd : CommandList.entrySet()) {
if (!hasCommandPermission(sender, cmd.getKey()))
continue;
temp.put(cmd.getKey(), cmd.getValue());
2015-08-21 15:10:08 +02:00
}
2016-03-30 15:42:36 +02:00
return temp;
2015-09-10 12:41:19 +02:00
}
2016-03-30 15:42:36 +02:00
public void fillCommands() {
List<String> lm = new ArrayList<String>();
HashMap<String, Class<?>> classes = new HashMap<String, Class<?>>();
try {
lm = getClassesFromPackage(packagePath);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
2016-03-30 15:42:36 +02:00
for (String one : lm) {
Class<?> newclass = getClass(one);
if (newclass != null)
classes.put(one, newclass);
}
2016-03-30 15:42:36 +02:00
for (Entry<String, Class<?>> OneClass : classes.entrySet()) {
for (Method met : OneClass.getValue().getMethods()) {
if (!met.isAnnotationPresent(JobCommand.class))
continue;
String cmd = OneClass.getKey();
if (hidenCommands.contains(met.getName().toLowerCase()))
continue;
CommandList.put(cmd, met.getAnnotation(JobCommand.class).value());
break;
}
}
2016-03-30 15:42:36 +02:00
}
2016-06-25 17:56:59 +02:00
private static Class<?> getClass(String cmd) {
2016-03-30 15:42:36 +02:00
Class<?> nmsClass = null;
try {
nmsClass = Class.forName(packagePath + "." + cmd.toLowerCase());
} catch (ClassNotFoundException | IllegalArgumentException | SecurityException e) {
2016-03-30 15:42:36 +02:00
}
return nmsClass;
}
2016-06-25 17:56:59 +02:00
private static Cmd getCmdClass(String cmd) {
2016-03-30 15:42:36 +02:00
Cmd cmdClass = null;
try {
Class<?> nmsClass;
nmsClass = Class.forName(packagePath + "." + cmd.toLowerCase());
if (Cmd.class.isAssignableFrom(nmsClass)) {
cmdClass = (Cmd) nmsClass.getConstructor().newInstance();
}
} catch (ClassNotFoundException | InstantiationException | IllegalArgumentException | IllegalAccessException | NoSuchMethodException | InvocationTargetException
| SecurityException e) {
}
2016-03-30 15:42:36 +02:00
return cmdClass;
}
2016-03-30 15:42:36 +02:00
private static Map<String, Integer> sort(Map<String, Integer> unsortMap) {
List<Map.Entry<String, Integer>> list = new LinkedList<Map.Entry<String, Integer>>(unsortMap.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Integer>>() {
2016-06-25 17:56:59 +02:00
@Override
2016-03-30 15:42:36 +02:00
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return (o1.getValue()).compareTo(o2.getValue());
}
2016-03-30 15:42:36 +02:00
});
Map<String, Integer> sortedMap = new LinkedHashMap<String, Integer>();
for (Iterator<Map.Entry<String, Integer>> it = list.iterator(); it.hasNext();) {
Map.Entry<String, Integer> entry = it.next();
sortedMap.put(entry.getKey(), entry.getValue());
}
2016-03-30 15:42:36 +02:00
return sortedMap;
}
2016-03-30 15:42:36 +02:00
/**
* Check Job joining permission
*/
public boolean hasJobPermission(Player sender, Job job) {
return hasJobPermission((CommandSender) sender, job);
}
2016-03-30 15:42:36 +02:00
public boolean hasJobPermission(CommandSender sender, Job job) {
if (!sender.hasPermission("jobs.use")) {
return false;
}
2016-06-25 15:27:01 +02:00
return sender.hasPermission("jobs.join." + job.getName().toLowerCase());
2016-03-30 15:42:36 +02:00
}
2016-03-30 15:42:36 +02:00
public void sendValidActions(CommandSender sender) {
StringBuilder builder = new StringBuilder();
boolean first = true;
for (ActionType action : ActionType.values()) {
if (!first)
builder.append(',');
builder.append(action.getName());
first = false;
2016-03-30 15:42:36 +02:00
}
sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.actions", "%actions%", builder.toString()));
}
2015-09-10 12:41:19 +02:00
/**
* Displays info about a job
* @param player - the player of the job
* @param job - the job we are displaying info about
* @param type - type of info
* @return the message
*/
public void jobInfoMessage(CommandSender sender, JobsPlayer player, Job job, String type, int page) {
2015-09-10 12:41:19 +02:00
if (job == null) {
// job doesn't exist
sender.sendMessage(ChatColor.RED + Jobs.getLanguage().getMessage("general.error.job"));
return;
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
if (type == null) {
type = "";
} else {
type = type.toLowerCase();
}
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
StringBuilder message = new StringBuilder();
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
int showAllTypes = 1;
for (ActionType actionType : ActionType.values()) {
if (type.startsWith(actionType.getName().toLowerCase())) {
showAllTypes = 0;
break;
}
}
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
if (job.getExpBoost() != 1.0)
2016-03-30 15:42:36 +02:00
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", job.getExpBoost()) + "\n");
2015-09-10 12:41:19 +02:00
if (job.getMoneyBoost() != 1.0)
2016-03-30 15:42:36 +02:00
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", job.getMoneyBoost()) + "\n");
2015-09-10 12:41:19 +02:00
2016-03-30 15:42:36 +02:00
if (job.getPointBoost() != 1.0)
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", job.getPointBoost()) + "\n");
if (Jobs.getGCManager().useDynamicPayment)
2015-09-10 12:41:19 +02:00
if (job.getBonus() < 0)
2016-03-30 15:42:36 +02:00
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", (int) (job.getBonus() * 100) / 100.0 * -1)
2015-09-10 12:41:19 +02:00
+ "\n");
2016-03-30 15:42:36 +02:00
else
message.append(ChatColor.GOLD + Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", (int) (job.getBonus() * 100) / 100.0) + "\n");
2015-09-10 12:41:19 +02:00
for (ActionType actionType : ActionType.values()) {
if (showAllTypes == 1 || type.startsWith(actionType.getName().toLowerCase())) {
List<JobInfo> info = job.getJobInfo(actionType);
if (info != null && !info.isEmpty()) {
message.append(jobInfoMessage(player, job, actionType));
} else if (showAllTypes == 0) {
2016-03-30 15:42:36 +02:00
String myMessage = Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".none");
2015-09-10 12:41:19 +02:00
myMessage = myMessage.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
message.append(myMessage);
}
}
2015-08-21 15:10:08 +02:00
}
StringBuilder message2 = new StringBuilder();
int perPage = 20;
int start = (page - 1) * perPage;
int end = start + perPage;
int pagecount = (int) Math.ceil((double) message.toString().split("\n").length / (double) perPage);
if (pagecount == 0)
pagecount = 1;
if (page > pagecount) {
player.getPlayer().sendMessage("Invalid page");
return;
}
if (message.toString().split("\n").length > perPage && sender instanceof Player) {
int i = 0;
for (String one : message.toString().split("\n")) {
i++;
if (i <= start)
continue;
if (i > end)
break;
message2.append(one);
message2.append("\n");
}
message = message2;
}
sender.sendMessage(message.toString().split("\n"));
String t = type == "" ? "" : " " + type;
if (sender instanceof Player)
if (sender.getName().equalsIgnoreCase(player.getUserName()))
ShowPagination(sender.getName(), pagecount, page, "jobs info " + job.getName() + t);
else
ShowPagination(sender.getName(), pagecount, page, "jobs playerinfo " + player.getUserName() + " " + job.getName() + t);
}
public static void ShowPagination(String target, int pageCount, int CurrentPage, String cmd) {
if (target.equalsIgnoreCase("console"))
return;
// String separator = ChatColor.GOLD + "";
// String simbol = "\u25AC";
// for (int i = 0; i < 10; i++) {
// separator += simbol;
// }
if (pageCount == 1)
return;
int NextPage = CurrentPage + 1;
NextPage = CurrentPage < pageCount ? NextPage : CurrentPage;
int Prevpage = CurrentPage - 1;
Prevpage = CurrentPage > 1 ? Prevpage : CurrentPage;
String prevCmd = "/" + cmd + " " + Prevpage;
String prev = "\"\",{\"text\":\" " + Jobs.getLanguage().getMessage("command.help.output.prev")
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"" + prevCmd
+ "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + "<<<" + "\"}]}}}";
String nextCmd = "/" + cmd + " " + NextPage;
String next = " {\"text\":\"" + Jobs.getLanguage().getMessage("command.help.output.next") + " "
+ "\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\""
+ nextCmd + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + ">>>" + "\"}]}}}";
if (CurrentPage >= pageCount)
next = "{\"text\":\"" + Jobs.getLanguage().getMessage("command.help.output.next") + " \"}";
if (CurrentPage <= 1)
prev = "{\"text\":\" " + Jobs.getLanguage().getMessage("command.help.output.prev") + "\"}";
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "tellraw " + target + " [" + prev + "," + next + "]");
2015-09-10 12:41:19 +02:00
}
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
/**
* Displays info about a particular action
* @param player - the player of the job
* @param prog - the job we are displaying info about
* @param type - the type of action
* @return the message
*/
public static String jobInfoMessage(JobsPlayer player, Job job, ActionType type) {
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
// money exp boost
BoostMultiplier finalBoost = Jobs.getPlayerManager().getFinalBonus(player, job);
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
StringBuilder message = new StringBuilder();
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
message.append(Jobs.getLanguage().getMessage("command.info.output." + type.getName().toLowerCase() + ".info"));
2015-09-10 12:41:19 +02:00
message.append(":\n");
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
int level = 1;
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
JobProgression prog = player.getJobProgression(job);
if (prog != null)
level = prog.getLevel();
int numjobs = player.getJobProgression().size();
List<JobInfo> jobInfo = job.getJobInfo(type);
for (JobInfo info : jobInfo) {
2016-03-30 15:42:36 +02:00
2015-09-10 12:41:19 +02:00
String materialName = info.getName().toLowerCase().replace('_', ' ');
materialName = Character.toUpperCase(materialName.charAt(0)) + materialName.substring(1);
2016-03-30 15:42:36 +02:00
materialName = Jobs.getNameTranslatorManager().Translate(materialName, info);
2015-09-10 12:41:19 +02:00
materialName = org.bukkit.ChatColor.translateAlternateColorCodes('&', materialName);
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
double income = info.getIncome(level, numjobs);
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
// Jobs.getPlayerManager().getFinalBonus(player, prog)
2015-08-21 15:10:08 +02:00
2016-04-03 16:22:44 +02:00
income = income + (income * finalBoost.getMoneyBoost() / 100);
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
2015-08-21 15:10:08 +02:00
2015-09-10 12:41:19 +02:00
double xp = info.getExperience(level, numjobs);
2016-04-03 16:22:44 +02:00
xp = xp + (xp * finalBoost.getExpBoost() / 100);
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
double points = info.getPoints(level, numjobs);
2016-04-03 16:22:44 +02:00
points = points + (points * finalBoost.getPointsBoost() / 100);
String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString();
2016-03-30 15:42:36 +02:00
if (income == 0D && points == 0D && xp == 0D)
continue;
2015-09-10 12:41:19 +02:00
message.append(" ");
2015-08-21 15:10:08 +02:00
2016-03-30 15:42:36 +02:00
message.append(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", materialName));
if (prog != null && !info.isInLevelRange(prog.getLevel()))
2016-01-22 13:42:25 +01:00
message.append(org.bukkit.ChatColor.RED + " -> ");
else
message.append(" -> ");
2015-08-21 15:10:08 +02:00
2016-04-03 16:22:44 +02:00
if (income != 0.0)
message.append(Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor + String.format("%.2f", income)));
2016-03-30 15:42:36 +02:00
2016-04-03 16:22:44 +02:00
if (points != 0.0)
message.append(Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor + String.format("%.2f", points)));
2016-03-30 15:42:36 +02:00
2016-04-03 16:22:44 +02:00
if (xp != 0.0)
message.append(Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor + String.format("%.2f", xp)));
2015-08-21 15:10:08 +02:00
2016-01-22 13:42:25 +01:00
if (info.getFromLevel() > 1 && info.getUntilLevel() != -1)
2016-03-30 15:42:36 +02:00
message.append(Jobs.getLanguage().getMessage("command.info.help.levelRange", "%levelFrom%", info.getFromLevel(), "%levelUntil%", info.getUntilLevel()));
2016-01-22 13:42:25 +01:00
if (info.getFromLevel() > 1 && info.getUntilLevel() == -1)
2016-03-30 15:42:36 +02:00
message.append(Jobs.getLanguage().getMessage("command.info.help.levelFrom", "%levelFrom%", info.getFromLevel()));
2016-01-22 13:42:25 +01:00
if (info.getFromLevel() == 1 && info.getUntilLevel() != -1)
2016-03-30 15:42:36 +02:00
message.append(Jobs.getLanguage().getMessage("command.info.help.levelUntil", "%levelUntil%", info.getUntilLevel()));
2016-01-22 13:42:25 +01:00
2015-09-10 12:41:19 +02:00
message.append('\n');
}
return message.toString();
}
/**
* Displays job stats about a particular player's job
* @param jobProg - the job progress of the players job
* @return the message
*/
2016-03-30 15:42:36 +02:00
public String jobStatsMessage(JobProgression jobProg) {
String message = Jobs.getLanguage().getMessage("command.stats.output",
"%joblevel%", Integer.valueOf(jobProg.getLevel()).toString(),
"%jobname%", jobProg.getJob().getChatColor() + jobProg.getJob().getName() + ChatColor.WHITE,
2016-06-25 15:27:01 +02:00
"%jobxp%", Double.toString(Math.round(jobProg.getExperience() * 100.0) / 100.0),
2016-03-30 15:42:36 +02:00
"%jobmaxxp%", Integer.toString(jobProg.getMaxExperience()));
return " " + jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience()) + " " + message;
}
public String jobProgressMessage(double max, double current) {
String message = "";
String pos = ChatColor.DARK_GREEN + "\u258F";
String pros = ChatColor.YELLOW + "\u258F";
2016-04-03 16:22:44 +02:00
if (current < 0)
current = 0;
2016-06-09 17:35:24 +02:00
if (max < current)
max = current;
2016-03-30 15:42:36 +02:00
int percentage = (int) ((current * 50.0) / max);
for (int i = 0; i < percentage; i++) {
message += pos;
}
2016-06-09 17:35:24 +02:00
if (50 - percentage < 0)
percentage = 50;
2016-03-30 15:42:36 +02:00
for (int i = 0; i < 50 - percentage; i++) {
message += pros;
}
2015-09-10 12:41:19 +02:00
return message;
}
/**
* Displays job stats about a particular player's job from archive
* @param jobInfo - jobinfo string line
* @return the message
*/
2016-03-30 15:42:36 +02:00
public String jobStatsMessage(String jobInfo) {
2015-09-10 12:41:19 +02:00
String[] splited = jobInfo.split(":");
if (Jobs.getJob(splited[0]) == null)
return "";
2016-03-30 15:42:36 +02:00
String message = Jobs.getLanguage().getMessage("command.archive.output",
"%joblevel%", Integer.valueOf(splited[1]).toString(),
"%getbackjoblevel%", Integer.valueOf(splited[2]).toString(),
"%jobname%", Jobs.getJob(splited[0]).getChatColor() + splited[0] + ChatColor.WHITE,
2016-06-25 15:27:01 +02:00
"%jobxp%", Double.toString(Math.round(Double.valueOf(splited[3]) * 100.0) / 100.0));
2015-09-10 12:41:19 +02:00
return message;
}
2015-08-21 15:10:08 +02:00
}