diff --git a/build.gradle b/build.gradle index 9986472..25d1fe7 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group 'sh.okx' -version '3.11.1' +version '3.11.2' repositories { mavenCentral() diff --git a/src/main/java/sh/okx/rankup/RankupPlugin.java b/src/main/java/sh/okx/rankup/RankupPlugin.java index 6cf9f45..f7a042f 100644 --- a/src/main/java/sh/okx/rankup/RankupPlugin.java +++ b/src/main/java/sh/okx/rankup/RankupPlugin.java @@ -519,15 +519,19 @@ public class RankupPlugin extends JavaPlugin { public MessageBuilder getMessage(CommandSender player, Message message, Rank oldRank, Rank rankName) { String oldRankName; + String oldRankDisplayName; if (oldRank instanceof Prestige && oldRank.getRank() == null) { oldRankName = ((Prestige) oldRank).getFrom(); + oldRankDisplayName = rankups.getTree().last().getRank().getDisplayName(); } else { oldRankName = oldRank.getRank(); + oldRankDisplayName = oldRank.getDisplayName(); } return replaceMoneyRequirements(getMessage(oldRank, message) .replaceRanks(player, rankName) - .replace(Variable.OLD_RANK, oldRankName), player, oldRank) + .replace(Variable.OLD_RANK, oldRankName) + .replace(Variable.OLD_RANK_NAME, oldRankDisplayName), player, oldRank) .replaceFromTo(oldRank); } diff --git a/src/main/java/sh/okx/rankup/commands/InfoCommand.java b/src/main/java/sh/okx/rankup/commands/InfoCommand.java index 31cbef9..0e7d3b2 100644 --- a/src/main/java/sh/okx/rankup/commands/InfoCommand.java +++ b/src/main/java/sh/okx/rankup/commands/InfoCommand.java @@ -201,7 +201,7 @@ public class InfoCommand implements TabExecutor { element = next; } return true; - } else if (args[0].equalsIgnoreCase("playtime") && sender.hasPermission("rankup.playtime")) { + } else if (args[0].equalsIgnoreCase("playtime") && (sender.hasPermission("rankup.playtime.get") || sender.hasPermission("rankup.playtime.set"))) { Statistic playOneTick; try { playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE"); @@ -211,7 +211,7 @@ public class InfoCommand implements TabExecutor { } if (args.length > 1) { - if (args[1].equalsIgnoreCase("get")) { + if (args[1].equalsIgnoreCase("get") && sender.hasPermission("rankup.playtime.get")) { Player player; if (args.length > 2) { // pru playtime get Okx @@ -241,7 +241,7 @@ public class InfoCommand implements TabExecutor { } player.sendMessage(ChatColor.LIGHT_PURPLE + who + " played for " + minutes + " minutes."); return true; - } else if (args[1].equalsIgnoreCase("set")) { + } else if (args[1].equalsIgnoreCase("set") && sender.hasPermission("rankup.playtime.set")) { if (args.length < 4) { sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " set " + ChatColor.YELLOW + " Update the playtime statistic for a player"); return true; @@ -266,8 +266,16 @@ public class InfoCommand implements TabExecutor { return true; } } - sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " get [player] " + ChatColor.YELLOW + " Get amount of minutes played"); - sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " set " + ChatColor.YELLOW + " Update the playtime statistic for a player"); + if (sender.hasPermission("rankup.playtime.get")) { + sender.sendMessage( + ChatColor.GREEN + "/" + label + " " + args[0] + " get [player] " + ChatColor.YELLOW + + " Get amount of minutes played"); + } + if (sender.hasPermission("rankup.playtime.set")) { + sender.sendMessage( + ChatColor.GREEN + "/" + label + " " + args[0] + " set " + + ChatColor.YELLOW + " Update the playtime statistic for a player"); + } return true; } } diff --git a/src/main/java/sh/okx/rankup/ranks/RankList.java b/src/main/java/sh/okx/rankup/ranks/RankList.java index a7d1848..f0546d8 100644 --- a/src/main/java/sh/okx/rankup/ranks/RankList.java +++ b/src/main/java/sh/okx/rankup/ranks/RankList.java @@ -5,7 +5,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; -import java.util.Set; import java.util.function.Function; import lombok.Getter; import org.bukkit.configuration.ConfigurationSection; @@ -28,11 +27,14 @@ public abstract class RankList { List> rankElements = new ArrayList<>(); for (Map.Entry entry : config.getValues(false).entrySet()) { ConfigurationSection rankSection = (ConfigurationSection) entry.getValue(); - validateSection(rankSection); - T apply = deserializer.apply(rankSection); - if (apply != null) { - // find next - rankElements.add(findNext(apply, rankElements)); + if (validateSection(rankSection)) { + T apply = deserializer.apply(rankSection); + if (apply != null) { + // find next + rankElements.add(findNext(apply, rankElements)); + } + } else { + plugin.getLogger().warning("Ignoring rank: " + entry.getKey()); } } @@ -70,23 +72,19 @@ public abstract class RankList { return currentElement; } - protected void validateSection(ConfigurationSection section) { + protected boolean validateSection(ConfigurationSection section) { String name = "'" + section.getName() + "'"; - /*if (section.getConfigurationSection("requirements") != null) { - throw new IllegalArgumentException( - "Rankup/prestige section " + name + " is using the old requirements system.\n" + - "Instead of a configuration section, it is now a list of strings.\n" + - "For example, instead of \"requirements: money: 1000\" you should use \"requirements: - 'money 1000'\"."); - }*/ - Set keys = section.getKeys(false); - if (keys.size() == 1 && keys.iterator().next().equalsIgnoreCase("rank")) { - throw new IllegalArgumentException( - "Having a final rank (for example: \"Z: rank: 'Z'\") from 3.4.2 or earlier should no longer be used.\n" - + - "It is safe to just delete the final rank " + name + ""); + String nextField = section.getString("next"); + if (nextField == null || nextField.isEmpty()) { + plugin.getLogger().warning("Rankup section " + name + " does not have a 'next' field."); + plugin.getLogger().warning("Having a final rank (for example: \"Z: rank: 'Z'\") from 3.4.2 or earlier should no longer be used."); + plugin.getLogger().warning("If this is intended as a final rank, you should delete " + name); + return false; } else if (!section.contains("requirements")) { - throw new IllegalArgumentException("Rank " + name + " does not have any requirements."); + plugin.getLogger().warning("Rank " + name + " does not have any requirements."); + return false; } + return true; } public T getFirst() { diff --git a/src/main/java/sh/okx/rankup/ranks/Rankup.java b/src/main/java/sh/okx/rankup/ranks/Rankup.java index cdb1b1e..1709e12 100644 --- a/src/main/java/sh/okx/rankup/ranks/Rankup.java +++ b/src/main/java/sh/okx/rankup/ranks/Rankup.java @@ -14,8 +14,8 @@ public class Rankup extends Rank { String displayName = section.getString("display-name"); if (next == null || next.isEmpty()) { - plugin.getLogger().warning("Having a final rank (for example: \"Z: rank: 'Z'\") from 3.4.2 or earlier should no longer be used.\n" - + "It is safe to just delete the final rank " + section.getName() + ""); + plugin.getLogger().warning("Having a final rank (for example: \"Z: rank: 'Z'\") from 3.4.2 or earlier should no longer be used."); + plugin.getLogger().warning("It is safe to just delete the final rank " + section.getName() + ""); plugin.getLogger().warning("Rankup section '" + section.getName() + "' has a blank 'next' field, will be ignored."); return null; } diff --git a/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java b/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java index b041ee2..bd31872 100644 --- a/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java +++ b/src/main/java/sh/okx/rankup/ranksgui/RanksGui.java @@ -69,7 +69,7 @@ public class RanksGui { rowIndex += 9; index += 9 - width; } - if (index >= rows * 9) { + if (index > rows * 9) { throw new IllegalArgumentException("Ranks GUI is too small for the number of ranks. Increase the number of rows on the ranks GUI."); } rankElement = rankElement.getNext(); diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 20e5cf7..a666f17 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -46,6 +46,7 @@ permissions: rankup.force: true # if a player receives notifications to update rankup when they log in. rankup.notify: true + rankup.playtime: true default: op rankup.rankup: default: true @@ -58,4 +59,9 @@ permissions: rankup.auto: default: true rankup.maxrankup: - default: true \ No newline at end of file + default: true + rankup.playtime: + children: + rankup.playtime.get: true + rankup.playtime.set: true + default: op \ No newline at end of file