1
0
mirror of https://github.com/Zrips/Jobs.git synced 2024-11-26 04:25:15 +01:00

Fix gtop & top sent wrong error message about usage

- Fixed gtop pagination when reached the maximum pages, but added one more

Closes #977
This commit is contained in:
montlikadani 2020-10-24 16:46:05 +02:00
parent 21673860c7
commit 35fb74e2e3
12 changed files with 38 additions and 49 deletions

View File

@ -35,7 +35,7 @@ public class JobsCommands implements CommandExecutor {
private static final String packagePath = "com.gamingmesh.jobs.commands.list";
private Map<String, Integer> CommandList = new HashMap<>();
private final Map<String, Integer> CommandList = new HashMap<>();
protected Jobs plugin;
@ -57,7 +57,7 @@ public class JobsCommands implements CommandExecutor {
if (args.length == 0)
return help(sender, 1);
if ((args.length == 1 || args.length == 2) && (args[0].equalsIgnoreCase("?") || args[0].equalsIgnoreCase("help"))) {
if ((args.length == 1 || args.length == 2) && (args[0].equals("?") || args[0].equalsIgnoreCase("help"))) {
int page = 1;
if (args.length == 2)
try {
@ -184,13 +184,12 @@ public class JobsCommands implements CommandExecutor {
classes.put(one, newclass);
}
for (Entry<String, Class<?>> OneClass : classes.entrySet()) {
for (Method met : OneClass.getValue().getMethods()) {
for (Entry<String, Class<?>> oneClass : classes.entrySet()) {
for (Method met : oneClass.getValue().getMethods()) {
if (!met.isAnnotationPresent(JobCommand.class))
continue;
String cmd = OneClass.getKey();
CommandList.put(cmd, met.getAnnotation(JobCommand.class).value());
CommandList.put(oneClass.getKey(), met.getAnnotation(JobCommand.class).value());
break;
}
}
@ -198,35 +197,29 @@ public class JobsCommands implements CommandExecutor {
}
private static Class<?> getClass(String cmd) {
Class<?> nmsClass = null;
try {
nmsClass = Class.forName(packagePath + "." + cmd.toLowerCase());
return Class.forName(packagePath + "." + cmd.toLowerCase());
} catch (ClassNotFoundException e) {
}
return nmsClass;
return null;
}
private static Cmd getCmdClass(String cmd) {
Cmd cmdClass = null;
try {
Class<?> nmsClass;
nmsClass = Class.forName(packagePath + "." + cmd.toLowerCase());
Class<?> nmsClass = Class.forName(packagePath + "." + cmd.toLowerCase());
if (Cmd.class.isAssignableFrom(nmsClass)) {
cmdClass = (Cmd) nmsClass.getConstructor().newInstance();
return (Cmd) nmsClass.getConstructor().newInstance();
}
} catch (Exception e) {
}
return cmdClass;
return null;
}
/**
* Check Job joining permission
*/
public boolean hasJobPermission(CommandSender sender, Job job) {
if (!sender.hasPermission("jobs.use"))
return false;
return sender.hasPermission("jobs.join." + job.getName().toLowerCase());
return sender.hasPermission("jobs.use") && sender.hasPermission("jobs.join." + job.getName().toLowerCase());
}
public void sendValidActions(CommandSender sender) {

View File

@ -10,7 +10,7 @@ import com.gamingmesh.jobs.container.PlayerPoints;
public class editpoints implements Cmd {
@Override
@JobCommand(475)
@JobCommand(477)
public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
if (args.length != 3) {
Jobs.getCommandManager().sendUsage(sender, "editpoints");

View File

@ -16,17 +16,17 @@ import com.gamingmesh.jobs.stuff.PageInfo;
public class gtop implements Cmd {
@Override
@JobCommand(600)
@JobCommand(601)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
int amount = Jobs.getGCManager().JobsTopAmount;
if (args.length != 1 && args.length != 0) {
sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.help.info"));
return true;
if (!(sender instanceof Player)) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
return false;
}
if (!(sender instanceof Player))
return false;
if (args.length > 1) {
Jobs.getCommandManager().sendUsage(sender, "gtop");
return true;
}
Player player = (Player) sender;
int page = 1;
@ -47,6 +47,7 @@ public class gtop implements Cmd {
if (page < 1)
page = 1;
int amount = Jobs.getGCManager().JobsTopAmount;
PageInfo pi = new PageInfo(amount, Jobs.getPlayerManager().getPlayersCache().size(), page);
List<TopList> FullList = Jobs.getJobsDAO().getGlobalTopList(pi.getStart() - 1);
@ -60,7 +61,7 @@ public class gtop implements Cmd {
int i = 0;
for (TopList One : FullList) {
if (i > amount)
if (i >= amount)
break;
sender.sendMessage(Jobs.getLanguage().getMessage("command.gtop.output.list",
@ -74,7 +75,7 @@ public class gtop implements Cmd {
List<String> ls = new ArrayList<>();
int i = 0;
for (TopList one : FullList) {
if (i > amount)
if (i >= amount)
break;
ls.add(Jobs.getLanguage().getMessage("scoreboard.line",

View File

@ -11,7 +11,7 @@ import com.gamingmesh.jobs.container.Job;
public class moneyboost implements Cmd {
@Override
@JobCommand(2300)
@JobCommand(2320)
public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
if (args.length > 3 || args.length <= 1) {
Jobs.getCommandManager().sendUsage(sender, "moneyboost");

View File

@ -11,7 +11,7 @@ import com.gamingmesh.jobs.container.Job;
public class pointboost implements Cmd {
@Override
@JobCommand(2300)
@JobCommand(2303)
public boolean perform(Jobs plugin, CommandSender sender, String[] args) {
if (args.length > 3 || args.length <= 1) {
Jobs.getCommandManager().sendUsage(sender, "pointboost");

View File

@ -13,7 +13,7 @@ import com.gamingmesh.jobs.container.JobsPlayer;
public class stats implements Cmd {
@Override
@JobCommand(400)
@JobCommand(401)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
JobsPlayer jPlayer = null;
if (args.length >= 1) {

View File

@ -17,20 +17,19 @@ import com.gamingmesh.jobs.stuff.PageInfo;
public class top implements Cmd {
@Override
@JobCommand(500)
@JobCommand(526)
public boolean perform(Jobs plugin, final CommandSender sender, final String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage(Jobs.getLanguage().getMessage("general.error.ingame"));
return false;
}
Player player = (Player) sender;
if (args.length != 1 && args.length != 2) {
player.sendMessage(Jobs.getLanguage().getMessage("command.top.error.nojob"));
Jobs.getCommandManager().sendUsage(sender, "top");
return false;
}
Player player = (Player) sender;
if (args[0].equalsIgnoreCase("clear")) {
player.getScoreboard().clearSlot(DisplaySlot.SIDEBAR);
plugin.getCMIScoreboardManager().removeScoreBoard(player);

View File

@ -59,7 +59,7 @@ public class GeneralConfigManager {
private final HashMap<String, List<String>> commandArgs = new HashMap<>();
protected Locale locale;
private ConfigReader c = null;
private ConfigReader c;
protected boolean economyAsync, isBroadcastingSkillups, isBroadcastingLevelups, payInCreative, payExploringWhenFlying,
addXpPlayer, hideJobsWithoutPermission, payNearSpawner, modifyChat, saveOnDisconnect, MultiServerCompatability;

View File

@ -509,7 +509,7 @@ public class LanguageManager {
c.get("command.employ.output.target", "You have been employed as a %jobname%.");
c.get("command.top.help.info", "Shows top players by jobs name.");
c.get("command.top.help.args", "[jobname]");
c.get("command.top.help.args", "[jobname]/clear pageNumber");
Jobs.getGCManager().getCommandArgs().put("top", Arrays.asList("[jobname]"));
c.get("command.top.error.nojob", "Can't find any job with this name.");
c.get("command.top.output.topline", "&aTop&e %amount% &aplayers by &e%jobname% &ajob");
@ -519,7 +519,7 @@ public class LanguageManager {
c.get("command.top.output.show", "&2Show from &e[from] &2until &e[until] &2top list");
c.get("command.gtop.help.info", "Shows top players by global jobs level.");
c.get("command.gtop.help.args", "");
c.get("command.gtop.help.args", "clear/pageNumber");
c.get("command.gtop.error.nojob", "Can't find any information.");
c.get("command.gtop.output.topline", "&aTop&e %amount% &aplayers by global job level");
c.get("command.gtop.output.list", "&e%number%&a. &e%playername% &alvl &e%level% &awith&e %exp% &aexp");

View File

@ -20,6 +20,7 @@ package com.gamingmesh.jobs.economy;
import org.bukkit.OfflinePlayer;
@SuppressWarnings("deprecation")
public class VaultEconomy implements Economy {
private net.milkbowl.vault.economy.Economy vault;
@ -32,7 +33,6 @@ public class VaultEconomy implements Economy {
return vault.depositPlayer(offlinePlayer, money).transactionSuccess();
}
@SuppressWarnings("deprecation")
@Override
public boolean depositPlayer(String PlayerName, double money) {
return vault.depositPlayer(PlayerName, money).transactionSuccess();
@ -43,7 +43,6 @@ public class VaultEconomy implements Economy {
return vault.withdrawPlayer(offlinePlayer, money).transactionSuccess();
}
@SuppressWarnings("deprecation")
@Override
public boolean withdrawPlayer(String PlayerName, double money) {
return vault.withdrawPlayer(PlayerName, money).transactionSuccess();
@ -51,12 +50,9 @@ public class VaultEconomy implements Economy {
@Override
public boolean hasMoney(OfflinePlayer offlinePlayer, double money) {
if (offlinePlayer.getName() == null)
return false;
return vault.has(offlinePlayer, money);
return offlinePlayer.getName() != null && vault.has(offlinePlayer, money);
}
@SuppressWarnings("deprecation")
@Override
public boolean hasMoney(String PlayerName, double money) {
return vault.has(PlayerName, money);

View File

@ -42,7 +42,7 @@ public class PageInfo {
public boolean isEntryOk() {
currentEntry++;
return currentEntry - 1 >= start && currentEntry - 1 <= end;
return isContinueNoAdd();
}
public boolean isContinue() {
@ -62,7 +62,7 @@ public class PageInfo {
}
public boolean isPageOk(int page) {
return totalPages < page || page < 1 ? false : true;
return (totalPages < page || page < 1) ? false : true;
}
public int getStart() {

View File

@ -117,7 +117,7 @@ public class Util {
}
Material material = block.getType();
if (ignoreNoneSolids && !block.getType().isSolid())
if (ignoreNoneSolids && !material.isSolid())
continue;
if (lookingFor == null) {
@ -228,7 +228,7 @@ public class Util {
packageName = packageName.replace('.', '/');
if (entryName != null && entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) {
if (entryName.endsWith("." + fileType) && entryName.startsWith(packageName)) {
String name = entryName.replace(packageName, "").replace("." + fileType, "").replace("/", "");
if (name.contains("$"))
name = name.split("\\$")[0];