This commit is contained in:
okx-code
2021-02-06 17:53:45 +00:00
parent b00e7c965a
commit 4e4c9ebc0a
7 changed files with 47 additions and 31 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
} }
group 'sh.okx' group 'sh.okx'
version '3.11.1' version '3.11.2'
repositories { repositories {
mavenCentral() mavenCentral()
@@ -519,15 +519,19 @@ public class RankupPlugin extends JavaPlugin {
public MessageBuilder getMessage(CommandSender player, Message message, Rank oldRank, Rank rankName) { public MessageBuilder getMessage(CommandSender player, Message message, Rank oldRank, Rank rankName) {
String oldRankName; String oldRankName;
String oldRankDisplayName;
if (oldRank instanceof Prestige && oldRank.getRank() == null) { if (oldRank instanceof Prestige && oldRank.getRank() == null) {
oldRankName = ((Prestige) oldRank).getFrom(); oldRankName = ((Prestige) oldRank).getFrom();
oldRankDisplayName = rankups.getTree().last().getRank().getDisplayName();
} else { } else {
oldRankName = oldRank.getRank(); oldRankName = oldRank.getRank();
oldRankDisplayName = oldRank.getDisplayName();
} }
return replaceMoneyRequirements(getMessage(oldRank, message) return replaceMoneyRequirements(getMessage(oldRank, message)
.replaceRanks(player, rankName) .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); .replaceFromTo(oldRank);
} }
@@ -201,7 +201,7 @@ public class InfoCommand implements TabExecutor {
element = next; element = next;
} }
return true; 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; Statistic playOneTick;
try { try {
playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE"); playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE");
@@ -211,7 +211,7 @@ public class InfoCommand implements TabExecutor {
} }
if (args.length > 1) { if (args.length > 1) {
if (args[1].equalsIgnoreCase("get")) { if (args[1].equalsIgnoreCase("get") && sender.hasPermission("rankup.playtime.get")) {
Player player; Player player;
if (args.length > 2) { if (args.length > 2) {
// pru playtime get Okx // pru playtime get Okx
@@ -241,7 +241,7 @@ public class InfoCommand implements TabExecutor {
} }
player.sendMessage(ChatColor.LIGHT_PURPLE + who + " played for " + minutes + " minutes."); player.sendMessage(ChatColor.LIGHT_PURPLE + who + " played for " + minutes + " minutes.");
return true; return true;
} else if (args[1].equalsIgnoreCase("set")) { } else if (args[1].equalsIgnoreCase("set") && sender.hasPermission("rankup.playtime.set")) {
if (args.length < 4) { if (args.length < 4) {
sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " set <player> <minutes>" + ChatColor.YELLOW + " Update the playtime statistic for a player"); sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " set <player> <minutes>" + ChatColor.YELLOW + " Update the playtime statistic for a player");
return true; return true;
@@ -266,8 +266,16 @@ public class InfoCommand implements TabExecutor {
return true; return true;
} }
} }
sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " get [player] " + ChatColor.YELLOW + " Get amount of minutes played"); if (sender.hasPermission("rankup.playtime.get")) {
sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " set <player> <minutes>" + ChatColor.YELLOW + " Update the playtime statistic for a player"); 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 <player> <minutes>"
+ ChatColor.YELLOW + " Update the playtime statistic for a player");
}
return true; return true;
} }
} }
+18 -20
View File
@@ -5,7 +5,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import lombok.Getter; import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@@ -28,11 +27,14 @@ public abstract class RankList<T extends Rank> {
List<RankElement<T>> rankElements = new ArrayList<>(); List<RankElement<T>> rankElements = new ArrayList<>();
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) { for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue(); ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
validateSection(rankSection); if (validateSection(rankSection)) {
T apply = deserializer.apply(rankSection); T apply = deserializer.apply(rankSection);
if (apply != null) { if (apply != null) {
// find next // find next
rankElements.add(findNext(apply, rankElements)); rankElements.add(findNext(apply, rankElements));
}
} else {
plugin.getLogger().warning("Ignoring rank: " + entry.getKey());
} }
} }
@@ -70,23 +72,19 @@ public abstract class RankList<T extends Rank> {
return currentElement; return currentElement;
} }
protected void validateSection(ConfigurationSection section) { protected boolean validateSection(ConfigurationSection section) {
String name = "'" + section.getName() + "'"; String name = "'" + section.getName() + "'";
/*if (section.getConfigurationSection("requirements") != null) { String nextField = section.getString("next");
throw new IllegalArgumentException( if (nextField == null || nextField.isEmpty()) {
"Rankup/prestige section " + name + " is using the old requirements system.\n" + plugin.getLogger().warning("Rankup section " + name + " does not have a 'next' field.");
"Instead of a configuration section, it is now a list of strings.\n" + plugin.getLogger().warning("Having a final rank (for example: \"Z: rank: 'Z'\") from 3.4.2 or earlier should no longer be used.");
"For example, instead of \"requirements: money: 1000\" you should use \"requirements: - 'money 1000'\"."); plugin.getLogger().warning("If this is intended as a final rank, you should delete " + name);
}*/ return false;
Set<String> 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 + "");
} else if (!section.contains("requirements")) { } 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() { public T getFirst() {
@@ -14,8 +14,8 @@ public class Rankup extends Rank {
String displayName = section.getString("display-name"); String displayName = section.getString("display-name");
if (next == null || next.isEmpty()) { 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" plugin.getLogger().warning("Having a final rank (for example: \"Z: rank: 'Z'\") from 3.4.2 or earlier should no longer be used.");
+ "It is safe to just delete the final rank " + section.getName() + ""); 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."); plugin.getLogger().warning("Rankup section '" + section.getName() + "' has a blank 'next' field, will be ignored.");
return null; return null;
} }
@@ -69,7 +69,7 @@ public class RanksGui {
rowIndex += 9; rowIndex += 9;
index += 9 - width; 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."); 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(); rankElement = rankElement.getNext();
+7 -1
View File
@@ -46,6 +46,7 @@ permissions:
rankup.force: true rankup.force: true
# if a player receives notifications to update rankup when they log in. # if a player receives notifications to update rankup when they log in.
rankup.notify: true rankup.notify: true
rankup.playtime: true
default: op default: op
rankup.rankup: rankup.rankup:
default: true default: true
@@ -58,4 +59,9 @@ permissions:
rankup.auto: rankup.auto:
default: true default: true
rankup.maxrankup: rankup.maxrankup:
default: true default: true
rankup.playtime:
children:
rankup.playtime.get: true
rankup.playtime.set: true
default: op