1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-25 20:16:13 +01:00

Default behavior for default jobs command

This commit is contained in:
Zrips 2022-11-15 13:16:17 +02:00
parent fb5a520f1a
commit e4ca78fa57
3 changed files with 1128 additions and 1081 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -24,6 +25,7 @@ import com.gamingmesh.jobs.container.Title;
import com.gamingmesh.jobs.stuff.Util; import com.gamingmesh.jobs.stuff.Util;
import net.Zrips.CMILib.ActionBar.CMIActionBar; import net.Zrips.CMILib.ActionBar.CMIActionBar;
import net.Zrips.CMILib.Container.CMIArray;
import net.Zrips.CMILib.Container.PageInfo; import net.Zrips.CMILib.Container.PageInfo;
import net.Zrips.CMILib.Locale.LC; import net.Zrips.CMILib.Locale.LC;
import net.Zrips.CMILib.Messages.CMIMessages; import net.Zrips.CMILib.Messages.CMIMessages;
@ -40,202 +42,219 @@ public class JobsCommands implements CommandExecutor {
protected Jobs plugin; protected Jobs plugin;
public JobsCommands(Jobs plugin) { public JobsCommands(Jobs plugin) {
this.plugin = plugin; this.plugin = plugin;
} }
public Set<String> getCommands() { public Set<String> getCommands() {
return commandList; return commandList;
} }
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player && !Jobs.getGCManager().canPerformActionInWorld(((Player) sender).getWorld()) if (sender instanceof Player && !Jobs.getGCManager().canPerformActionInWorld(((Player) sender).getWorld())
&& !sender.hasPermission("jobs.disabledworld.commands")) { && !sender.hasPermission("jobs.disabledworld.commands")) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled")); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.worldisdisabled"));
return true; return true;
} }
if (args.length == 0) helpBrake: if (args.length == 0) {
return help(sender, 1);
if ((args.length == 1 || args.length == 2) && (args[0].equals("?") || args[0].equalsIgnoreCase("help"))) { if (!Jobs.getGeneralConfigManager().helpPageBehavior.isEmpty() && sender instanceof Player) {
int page = 1; if (Jobs.getGeneralConfigManager().helpPageBehavior.get(0).equals("browse")) {
if (args.length == 2) args = CMIArray.addLast(args, "browse");
try { break helpBrake;
page = Integer.parseInt(args[1]); }
} catch (NumberFormatException e) {
CMIMessages.sendMessage(sender, LC.info_UseInteger);
return true;
}
return help(sender, page);
}
String cmd = args[0].toLowerCase(); boolean result = false;
Cmd cmdClass = getCmdClass(cmd); for (String one : Jobs.getGeneralConfigManager().helpPageBehavior) {
if (cmdClass == null) { one = one.replace("[playerName]", sender.getName());
CMIMessages.sendMessage(sender, LC.info_NoCommand); if (Bukkit.dispatchCommand(Bukkit.getConsoleSender(), one))
return true; result = true;
} }
return result;
}
if (!hasCommandPermission(sender, cmd)) { return help(sender, 1);
if (sender instanceof Player) { }
new RawMessage().addText(LC.info_NoPermission.getLocale())
.addHover("&2" + label + ".command." + cmd).show(sender);
} else
CMIMessages.sendMessage(sender, LC.info_NoPermission);
return true;
}
String[] myArgs = reduceArgs(args); if ((args.length == 1 || args.length == 2) && (args[0].equals("?") || args[0].equalsIgnoreCase("help"))) {
if (myArgs.length > 0 && myArgs[myArgs.length - 1].equals("?")) { int page = 1;
sendUsage(sender, cmd); if (args.length == 2)
return true; try {
} page = Integer.parseInt(args[1]);
} catch (NumberFormatException e) {
CMIMessages.sendMessage(sender, LC.info_UseInteger);
return true;
}
return help(sender, page);
}
return cmdClass.perform(plugin, sender, myArgs) || help(sender, 1); String cmd = args[0].toLowerCase();
Cmd cmdClass = getCmdClass(cmd);
if (cmdClass == null) {
CMIMessages.sendMessage(sender, LC.info_NoCommand);
return true;
}
if (!hasCommandPermission(sender, cmd)) {
if (sender instanceof Player) {
new RawMessage().addText(LC.info_NoPermission.getLocale())
.addHover("&2" + label + ".command." + cmd).show(sender);
} else
CMIMessages.sendMessage(sender, LC.info_NoPermission);
return true;
}
String[] myArgs = reduceArgs(args);
if (myArgs.length > 0 && myArgs[myArgs.length - 1].equals("?")) {
sendUsage(sender, cmd);
return true;
}
return cmdClass.perform(plugin, sender, myArgs) || help(sender, 1);
} }
private static String[] reduceArgs(String[] args) { private static String[] reduceArgs(String[] args) {
return args.length <= 1 ? new String[0] : Arrays.copyOfRange(args, 1, args.length); return args.length <= 1 ? new String[0] : Arrays.copyOfRange(args, 1, args.length);
} }
private static boolean hasCommandPermission(CommandSender sender, String cmd) { private static boolean hasCommandPermission(CommandSender sender, String cmd) {
return sender.hasPermission("jobs.command." + cmd); return sender.hasPermission("jobs.command." + cmd);
} }
private static String getUsage(String cmd) { private static String getUsage(String cmd) {
String cmdString = Jobs.getLanguage().getMessage("command.help.output.cmdFormat", "[command]", Jobs.getLanguage().getMessage("command.help.output.label") + " " + cmd); String cmdString = Jobs.getLanguage().getMessage("command.help.output.cmdFormat", "[command]", Jobs.getLanguage().getMessage("command.help.output.label") + " " + cmd);
String msg = Jobs.getLanguage().getMessage("command." + cmd + ".help.args"); String msg = Jobs.getLanguage().getMessage("command." + cmd + ".help.args");
cmdString = cmdString.replace("[arguments]", !msg.isEmpty() ? msg : ""); cmdString = cmdString.replace("[arguments]", !msg.isEmpty() ? msg : "");
return cmdString; return cmdString;
} }
public void sendUsage(CommandSender sender, String cmd) { public void sendUsage(CommandSender sender, String cmd) {
String message = Jobs.getLanguage().getMessage("command.help.output.cmdUsage"); String message = Jobs.getLanguage().getMessage("command.help.output.cmdUsage");
message = message.replace("[command]", getUsage(cmd)); message = message.replace("[command]", getUsage(cmd));
sender.sendMessage(message); sender.sendMessage(message);
sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.helpPageDescription", "[description]", Jobs.getLanguage().getMessage("command." + cmd + ".help.info"))); sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.helpPageDescription", "[description]", Jobs.getLanguage().getMessage("command." + cmd + ".help.info")));
} }
protected boolean help(CommandSender sender, int page) { protected boolean help(CommandSender sender, int page) {
Set<String> commands = getCommands(sender); Set<String> commands = getCommands(sender);
if (commands.isEmpty()) { if (commands.isEmpty()) {
CMIMessages.sendMessage(sender, LC.info_NoPermission); CMIMessages.sendMessage(sender, LC.info_NoPermission);
return true; return true;
} }
if (page < 1) { if (page < 1) {
CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage")); CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage"));
return true; return true;
} }
PageInfo pi = new PageInfo(10, commands.size(), page); PageInfo pi = new PageInfo(10, commands.size(), page);
if (page > pi.getTotalPages()) { if (page > pi.getTotalPages()) {
CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage")); CMIActionBar.send(sender, Jobs.getLanguage().getMessage("general.error.noHelpPage"));
return true; return true;
} }
RawMessage rm = new RawMessage(); RawMessage rm = new RawMessage();
rm.addText(Jobs.getLanguage().getMessage("command.help.output.title")); rm.addText(Jobs.getLanguage().getMessage("command.help.output.title"));
boolean pl = sender instanceof Player; boolean pl = sender instanceof Player;
// Old format // Old format
// sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.title")); // sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.title"));
for (String one : commands) { for (String one : commands) {
if (!pi.isEntryOk()) if (!pi.isEntryOk())
continue; continue;
if (pi.isBreak()) if (pi.isBreak())
break; break;
// Old format // Old format
// sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one // sender.sendMessage(Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one
// + ".help.info"))); // + ".help.info")));
if (pl) { if (pl) {
rm.addText("\n" + getUsage(one)); rm.addText("\n" + getUsage(one));
rm.addHover(Jobs.getLanguage().getMessage("command." + one + ".help.info")); rm.addHover(Jobs.getLanguage().getMessage("command." + one + ".help.info"));
rm.addSuggestion("/" + Jobs.getLanguage().getMessage("command.help.output.label").toLowerCase() + " " + one + " "); rm.addSuggestion("/" + Jobs.getLanguage().getMessage("command.help.output.label").toLowerCase() + " " + one + " ");
} else { } else {
rm.addText("\n" + Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one rm.addText("\n" + Jobs.getLanguage().getMessage("command.help.output.cmdInfoFormat", "[command]", getUsage(one), "[description]", Jobs.getLanguage().getMessage("command." + one
+ ".help.info"))); + ".help.info")));
} }
} }
rm.show(sender); rm.show(sender);
plugin.showPagination(sender, pi, LABEL + " ?"); plugin.showPagination(sender, pi, LABEL + " ?");
return true; return true;
} }
public Set<String> getCommands(CommandSender sender) { public Set<String> getCommands(CommandSender sender) {
Set<String> temp = new TreeSet<>(); Set<String> temp = new TreeSet<>();
boolean senderIsPlayer = sender instanceof Player; boolean senderIsPlayer = sender instanceof Player;
for (String cmd : commandList) { for (String cmd : commandList) {
if (senderIsPlayer && !hasCommandPermission(sender, cmd)) if (senderIsPlayer && !hasCommandPermission(sender, cmd))
continue; continue;
temp.add(cmd); temp.add(cmd);
} }
return temp; return temp;
} }
public void fillCommands() { public void fillCommands() {
List<String> lm = new ArrayList<>(); List<String> lm = new ArrayList<>();
try { try {
lm = Util.getFilesFromPackage(PACKAGEPATH); lm = Util.getFilesFromPackage(PACKAGEPATH);
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
} }
for (String one : lm) { for (String one : lm) {
Class<?> newClass = getClass(one); Class<?> newClass = getClass(one);
if (newClass != null) if (newClass != null)
commandList.add(newClass.getSimpleName()); commandList.add(newClass.getSimpleName());
} }
} }
private static Class<?> getClass(String cmd) { private static Class<?> getClass(String cmd) {
try { try {
return Class.forName(PACKAGEPATH + "." + cmd.toLowerCase()); return Class.forName(PACKAGEPATH + "." + cmd.toLowerCase());
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
} }
return null; return null;
} }
private static Cmd getCmdClass(String cmd) { private static Cmd getCmdClass(String cmd) {
try { try {
Class<?> nmsClass = getClass(cmd); Class<?> nmsClass = getClass(cmd);
if (nmsClass != null && Cmd.class.isAssignableFrom(nmsClass)) { if (nmsClass != null && Cmd.class.isAssignableFrom(nmsClass)) {
return (Cmd) nmsClass.getConstructor().newInstance(); return (Cmd) nmsClass.getConstructor().newInstance();
} }
} catch (Exception e) { } catch (Exception e) {
} }
return null; return null;
} }
/** /**
* Check Job joining permission * Check Job joining permission
*/ */
public boolean hasJobPermission(CommandSender sender, Job job) { public boolean hasJobPermission(CommandSender sender, Job job) {
return sender.hasPermission("jobs.use") && sender.hasPermission("jobs.join." + job.getName().toLowerCase()); return sender.hasPermission("jobs.use") && sender.hasPermission("jobs.join." + job.getName().toLowerCase());
} }
public void sendValidActions(CommandSender sender) { public void sendValidActions(CommandSender sender) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
boolean first = true; boolean first = true;
for (ActionType action : ActionType.values()) { for (ActionType action : ActionType.values()) {
if (!first) if (!first)
builder.append(','); builder.append(',');
builder.append(action.getName()); builder.append(action.getName());
first = false; first = false;
} }
sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.actions", "%actions%", builder.toString())); sender.sendMessage(Jobs.getLanguage().getMessage("command.info.help.actions", "%actions%", builder.toString()));
} }
/** /**
@ -246,76 +265,76 @@ public class JobsCommands implements CommandExecutor {
* @return the message * @return the message
*/ */
public void jobInfoMessage(CommandSender sender, JobsPlayer player, Job job, String type, int page) { public void jobInfoMessage(CommandSender sender, JobsPlayer player, Job job, String type, int page) {
if (job == null) { if (job == null) {
// job doesn't exist // job doesn't exist
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job")); sender.sendMessage(Jobs.getLanguage().getMessage("general.error.job"));
return; return;
} }
type = type == null ? "" : type.toLowerCase(); type = type == null ? "" : type.toLowerCase();
List<String> message = new ArrayList<>(); List<String> message = new ArrayList<>();
if (job.getBoost().get(CurrencyType.EXP) != 0D) if (job.getBoost().get(CurrencyType.EXP) != 0D)
message.add(Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.EXP)) + 1)); message.add(Jobs.getLanguage().getMessage("command.expboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.EXP)) + 1));
if (job.getBoost().get(CurrencyType.MONEY) != 0D) if (job.getBoost().get(CurrencyType.MONEY) != 0D)
message.add(Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.MONEY)) + 1)); message.add(Jobs.getLanguage().getMessage("command.moneyboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.MONEY)) + 1));
if (job.getBoost().get(CurrencyType.POINTS) != 0D) if (job.getBoost().get(CurrencyType.POINTS) != 0D)
message.add(Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.POINTS)) + 1)); message.add(Jobs.getLanguage().getMessage("command.pointboost.output.infostats", "%boost%", (job.getBoost().get(CurrencyType.POINTS)) + 1));
if (Jobs.getGCManager().useDynamicPayment) { if (Jobs.getGCManager().useDynamicPayment) {
int bonus = (int) ((job.getBonus() * 100) / 100.0); int bonus = (int) ((job.getBonus() * 100) / 100.0);
if (bonus != 0) { if (bonus != 0) {
if (bonus < 0) if (bonus < 0)
message.add(Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", (int) (job.getBonus() * 100) / 100.0 * -1)); message.add(Jobs.getLanguage().getMessage("command.info.help.penalty", "[penalty]", (int) (job.getBonus() * 100) / 100.0 * -1));
else else
message.add(Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", bonus)); message.add(Jobs.getLanguage().getMessage("command.info.help.bonus", "[bonus]", bonus));
} }
} }
for (ActionType actionType : ActionType.values()) { for (ActionType actionType : ActionType.values()) {
if (type.isEmpty() || type.startsWith(actionType.getName().toLowerCase())) { if (type.isEmpty() || type.startsWith(actionType.getName().toLowerCase())) {
List<JobInfo> info = job.getJobInfo(actionType); List<JobInfo> info = job.getJobInfo(actionType);
if (info != null && !info.isEmpty()) { if (info != null && !info.isEmpty()) {
String m = jobInfoMessage(player, job, actionType); String m = jobInfoMessage(player, job, actionType);
if (m.contains("\n")) if (m.contains("\n"))
message.addAll(Arrays.asList(m.split("\n"))); message.addAll(Arrays.asList(m.split("\n")));
else else
message.add(m); message.add(m);
} else if (!type.isEmpty()) { } else if (!type.isEmpty()) {
message.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".none", "%jobname%", job.getDisplayName())); message.add(Jobs.getLanguage().getMessage("command.info.output." + actionType.getName().toLowerCase() + ".none", "%jobname%", job.getDisplayName()));
} }
} }
} }
PageInfo pi = new PageInfo(15, message.size(), page); PageInfo pi = new PageInfo(15, message.size(), page);
if (page > pi.getTotalPages()) { if (page > pi.getTotalPages()) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.info.invalidPage")); sender.sendMessage(Jobs.getLanguage().getMessage("general.info.invalidPage"));
return; return;
} }
boolean isPlayer = sender instanceof Player; boolean isPlayer = sender instanceof Player;
for (String one : message) { for (String one : message) {
if (isPlayer && !pi.isEntryOk()) if (isPlayer && !pi.isEntryOk())
continue; continue;
if (isPlayer && pi.isBreak()) if (isPlayer && pi.isBreak())
break; break;
sender.sendMessage(one); sender.sendMessage(one);
} }
if (isPlayer) { if (isPlayer) {
String t = type.isEmpty() ? "" : " " + type; String t = type.isEmpty() ? "" : " " + type;
String pName = player.getName(); String pName = player.getName();
if (sender.getName().equalsIgnoreCase(pName)) if (sender.getName().equalsIgnoreCase(pName))
plugin.showPagination(sender, pi, "jobs info " + job.getName() + t); plugin.showPagination(sender, pi, "jobs info " + job.getName() + t);
else else
plugin.showPagination(sender, pi, "jobs playerinfo " + pName + " " + job.getName() + t); plugin.showPagination(sender, pi, "jobs playerinfo " + pName + " " + job.getName() + t);
} }
} }
/** /**
@ -326,67 +345,67 @@ public class JobsCommands implements CommandExecutor {
* @return the message * @return the message
*/ */
public static String jobInfoMessage(JobsPlayer player, Job job, ActionType type) { public static String jobInfoMessage(JobsPlayer player, Job job, ActionType type) {
// money exp boost // money exp boost
Boost boost = Jobs.getPlayerManager().getFinalBonus(player, job, true); Boost boost = Jobs.getPlayerManager().getFinalBonus(player, job, true);
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
message.append(Jobs.getLanguage().getMessage("command.info.output." + type.getName().toLowerCase() + ".info")); message.append(Jobs.getLanguage().getMessage("command.info.output." + type.getName().toLowerCase() + ".info"));
message.append(":\n"); message.append(":\n");
JobProgression prog = player.getJobProgression(job); JobProgression prog = player.getJobProgression(job);
int level = prog != null ? prog.getLevel() : 1; int level = prog != null ? prog.getLevel() : 1;
int numjobs = player.progression.size(); int numjobs = player.progression.size();
for (JobInfo info : job.getJobInfo(type)) { for (JobInfo info : job.getJobInfo(type)) {
String materialName = info.getRealisticName(); String materialName = info.getRealisticName();
double income = info.getIncome(level, numjobs, player.maxJobsEquation); double income = info.getIncome(level, numjobs, player.maxJobsEquation);
income = boost.getFinalAmount(CurrencyType.MONEY, income); income = boost.getFinalAmount(CurrencyType.MONEY, income);
String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString(); String incomeColor = income >= 0 ? "" : ChatColor.DARK_RED.toString();
double xp = info.getExperience(level, numjobs, player.maxJobsEquation); double xp = info.getExperience(level, numjobs, player.maxJobsEquation);
xp = boost.getFinalAmount(CurrencyType.EXP, xp); xp = boost.getFinalAmount(CurrencyType.EXP, xp);
String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString(); String xpColor = xp >= 0 ? "" : ChatColor.GRAY.toString();
double points = info.getPoints(level, numjobs, player.maxJobsEquation); double points = info.getPoints(level, numjobs, player.maxJobsEquation);
points = boost.getFinalAmount(CurrencyType.POINTS, points); points = boost.getFinalAmount(CurrencyType.POINTS, points);
String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString(); String pointsColor = xp >= 0 ? "" : ChatColor.RED.toString();
if (income == 0D && points == 0D && xp == 0D) if (income == 0D && points == 0D && xp == 0D)
continue; continue;
message.append(" "); message.append(" ");
message.append(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", materialName)); message.append(Jobs.getLanguage().getMessage("command.info.help.material", "%material%", materialName));
if (prog != null && !info.isInLevelRange(prog.getLevel())) if (prog != null && !info.isInLevelRange(prog.getLevel()))
message.append(ChatColor.RED + " -> "); message.append(ChatColor.RED + " -> ");
else else
message.append(" -> "); message.append(" -> ");
if (income != 0.0) if (income != 0.0)
message.append(Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor + String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income))); message.append(Jobs.getLanguage().getMessage("command.info.help.money", "%money%", incomeColor + String.format(Jobs.getGCManager().getDecimalPlacesMoney(), income)));
if (points != 0.0) if (points != 0.0)
message.append(Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor + String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points))); message.append(Jobs.getLanguage().getMessage("command.info.help.points", "%points%", pointsColor + String.format(Jobs.getGCManager().getDecimalPlacesPoints(), points)));
if (xp != 0.0) if (xp != 0.0)
message.append(Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor + String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp))); message.append(Jobs.getLanguage().getMessage("command.info.help.exp", "%exp%", xpColor + String.format(Jobs.getGCManager().getDecimalPlacesExp(), xp)));
if (info.getFromLevel() > 1 && info.getUntilLevel() != -1) if (info.getFromLevel() > 1 && info.getUntilLevel() != -1)
message.append(Jobs.getLanguage().getMessage("command.info.help.levelRange", "%levelFrom%", info.getFromLevel(), "%levelUntil%", info.getUntilLevel())); message.append(Jobs.getLanguage().getMessage("command.info.help.levelRange", "%levelFrom%", info.getFromLevel(), "%levelUntil%", info.getUntilLevel()));
if (info.getFromLevel() > 1 && info.getUntilLevel() == -1) if (info.getFromLevel() > 1 && info.getUntilLevel() == -1)
message.append(Jobs.getLanguage().getMessage("command.info.help.levelFrom", "%levelFrom%", info.getFromLevel())); message.append(Jobs.getLanguage().getMessage("command.info.help.levelFrom", "%levelFrom%", info.getFromLevel()));
if (info.getFromLevel() == 1 && info.getUntilLevel() != -1) if (info.getFromLevel() == 1 && info.getUntilLevel() != -1)
message.append(Jobs.getLanguage().getMessage("command.info.help.levelUntil", "%levelUntil%", info.getUntilLevel())); message.append(Jobs.getLanguage().getMessage("command.info.help.levelUntil", "%levelUntil%", info.getUntilLevel()));
message.append('\n'); message.append('\n');
} }
return message.toString(); return message.toString();
} }
/** /**
@ -395,46 +414,46 @@ public class JobsCommands implements CommandExecutor {
* @return the message * @return the message
*/ */
public String jobStatsMessage(JobProgression jobProg) { public String jobStatsMessage(JobProgression jobProg) {
boolean isMaxLevelReached = jobProg.getLevel() == jobProg.getJob().getMaxLevel(); boolean isMaxLevelReached = jobProg.getLevel() == jobProg.getJob().getMaxLevel();
String path = "command.stats.output." + (isMaxLevelReached ? "max-level" String path = "command.stats.output." + (isMaxLevelReached ? "max-level"
: "message"); : "message");
Title title = Jobs.getTitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName()); Title title = Jobs.getTitleManager().getTitle(jobProg.getLevel(), jobProg.getJob().getName());
String message = Jobs.getLanguage().getMessage(path, String message = Jobs.getLanguage().getMessage(path,
"%joblevel%", jobProg.getLevelFormatted(), "%joblevel%", jobProg.getLevelFormatted(),
"%jobname%", jobProg.getJob().getDisplayName(), "%jobname%", jobProg.getJob().getDisplayName(),
"%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0, "%jobxp%", Math.round(jobProg.getExperience() * 100.0) / 100.0,
"%jobmaxxp%", jobProg.getMaxExperience(), "%jobmaxxp%", jobProg.getMaxExperience(),
"%titlename%", title == null ? "Unknown" : title.getName()); "%titlename%", title == null ? "Unknown" : title.getName());
return " " + (isMaxLevelReached ? "" : jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience())) + " " + message; return " " + (isMaxLevelReached ? "" : jobProgressMessage(jobProg.getMaxExperience(), jobProg.getExperience())) + " " + message;
} }
private String pos = ChatColor.DARK_GREEN + "\u258F"; private String pos = ChatColor.DARK_GREEN + "\u258F";
private String pros = ChatColor.YELLOW + "\u258F"; private String pros = ChatColor.YELLOW + "\u258F";
public String jobProgressMessage(double max, double current) { public String jobProgressMessage(double max, double current) {
if (current < 0) if (current < 0)
current = 0; current = 0;
if (max < current) if (max < current)
max = current; max = current;
if (max < 1) if (max < 1)
max = 2; max = 2;
StringBuilder message = new StringBuilder(); StringBuilder message = new StringBuilder();
int percentage = (int) ((current * 50.0) / max); int percentage = (int) ((current * 50.0) / max);
for (int i = 0; i < percentage; i++) { for (int i = 0; i < percentage; i++) {
message.append(pos); message.append(pos);
} }
if (50 - percentage < 0) if (50 - percentage < 0)
percentage = 50; percentage = 50;
for (int i = 0; i < 50 - percentage; i++) { for (int i = 0; i < 50 - percentage; i++) {
message.append(pros); message.append(pros);
} }
return message.toString(); return message.toString();
} }
/** /**
@ -443,15 +462,15 @@ public class JobsCommands implements CommandExecutor {
* @return the message * @return the message
*/ */
public String jobStatsMessageArchive(JobsPlayer jPlayer, JobProgression jobProg) { public String jobStatsMessageArchive(JobsPlayer jPlayer, JobProgression jobProg) {
int level = jPlayer.getLevelAfterRejoin(jobProg); int level = jPlayer.getLevelAfterRejoin(jobProg);
double exp = jPlayer.getExpAfterRejoin(jobProg, level); double exp = jPlayer.getExpAfterRejoin(jobProg, level);
int maxExperience = jobProg.getMaxExperience(level); int maxExperience = jobProg.getMaxExperience(level);
String message = Jobs.getLanguage().getMessage("command.stats.output.message", String message = Jobs.getLanguage().getMessage("command.stats.output.message",
"%joblevel%", level, "%joblevel%", level,
"%jobname%", jobProg.getJob().getDisplayName(), "%jobname%", jobProg.getJob().getDisplayName(),
"%jobxp%", Math.round(exp * 100.0) / 100.0, "%jobxp%", Math.round(exp * 100.0) / 100.0,
"%jobmaxxp%", maxExperience); "%jobmaxxp%", maxExperience);
return " " + jobProgressMessage(maxExperience, exp) + " " + message; return " " + jobProgressMessage(maxExperience, exp) + " " + message;
} }
} }

View File

@ -39,6 +39,7 @@ import com.gamingmesh.jobs.CMILib.CMIEnchantment;
import com.gamingmesh.jobs.container.CurrencyLimit; import com.gamingmesh.jobs.container.CurrencyLimit;
import com.gamingmesh.jobs.container.CurrencyType; import com.gamingmesh.jobs.container.CurrencyType;
import net.Zrips.CMILib.Container.CMIArray;
import net.Zrips.CMILib.Container.CMIList; import net.Zrips.CMILib.Container.CMIList;
import net.Zrips.CMILib.Equations.Parser; import net.Zrips.CMILib.Equations.Parser;
import net.Zrips.CMILib.FileHandler.ConfigReader; import net.Zrips.CMILib.FileHandler.ConfigReader;
@ -50,6 +51,8 @@ public class GeneralConfigManager {
public List<Integer> BroadcastingLevelUpLevels = new ArrayList<>(); public List<Integer> BroadcastingLevelUpLevels = new ArrayList<>();
public List<String> DisabledWorldsList = new ArrayList<>(); public List<String> DisabledWorldsList = new ArrayList<>();
public List<String> helpPageBehavior = new ArrayList<>();
public final Map<CMIMaterial, Map<Enchantment, Integer>> whiteListedItems = new HashMap<>(); public final Map<CMIMaterial, Map<Enchantment, Integer>> whiteListedItems = new HashMap<>();
private final Map<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>(); private final Map<CurrencyType, CurrencyLimit> currencyLimitUse = new HashMap<>();
@ -1041,6 +1044,27 @@ public class GeneralConfigManager {
c.addComment("JobsGUI.SkipAmount", "Defines by how many slots we need to skip after group"); c.addComment("JobsGUI.SkipAmount", "Defines by how many slots we need to skip after group");
JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2); JobsGUISkipAmount = c.get("JobsGUI.SkipAmount", 2);
c.addComment("Commands.Jobs", "What should happen when performing clean /jobs command", "Options:",
"Default - behaves like before and will open jobs help page with list of commands player can access",
"Browse - will open jobs browse GUI where player can check existing jobs and their actions",
"Last option is to define command you want to perform, use [playerName] variable to replace it with players name who performed it. Multiple commands can be provided too. Commands will be performed from console.");
helpPageBehavior.clear();
if (c.getC().isList("Commands.Jobs")) {
helpPageBehavior.addAll(c.get("Commands.Jobs", Arrays.asList("Default")));
} else {
helpPageBehavior.add(c.get("Commands.Jobs", "Default"));
}
if (!helpPageBehavior.isEmpty()) {
if (helpPageBehavior.size() == 1 && helpPageBehavior.get(0).equalsIgnoreCase("Default"))
helpPageBehavior.clear();
if (helpPageBehavior.size() == 1 && helpPageBehavior.get(0).equalsIgnoreCase("Browse")) {
helpPageBehavior.clear();
helpPageBehavior.add("browse");
}
}
c.addComment("Commands.PageRow.JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop"); c.addComment("Commands.PageRow.JobsTop.AmountToShow", "Defines amount of players to be shown in one page for /jobs top & /jobs gtop");
JobsTopAmount = c.get("Commands.PageRow.JobsTop.AmountToShow", 15); JobsTopAmount = c.get("Commands.PageRow.JobsTop.AmountToShow", 15);
c.addComment("Commands.PageRow.Placeholders.AmountToShow", "Defines amount of placeholders to be shown in one page for /jobs placeholders"); c.addComment("Commands.PageRow.Placeholders.AmountToShow", "Defines amount of placeholders to be shown in one page for /jobs placeholders");