- add /pru playtime add
- add dutch locale
- add quotient option for requirements
This commit is contained in:
okx-code
2021-06-22 02:59:47 +01:00
parent 240b83f43f
commit 98a0dec122
11 changed files with 219 additions and 17 deletions
@@ -335,6 +335,7 @@ public class RankupPlugin extends JavaPlugin {
saveLocale("fr");
saveLocale("it");
saveLocale("es");
saveLocale("nl");
}
private void saveLocale(String locale) {
@@ -264,6 +264,39 @@ public class InfoCommand implements TabExecutor {
player.setStatistic(playOneTick, minutes * 20 * 60);
player.sendMessage(ChatColor.LIGHT_PURPLE + "Updated playtime for " + player.getName() + " to " + minutes + " minutes");
return true;
} else if (args[1].equalsIgnoreCase("add") && sender.hasPermission("rankup.playtime.set")) {
if (args.length < 4) {
sender.sendMessage(ChatColor.GREEN + "/" + label + " " + args[0] + " add <player> <minutes>" + ChatColor.YELLOW + " Increase the playtime statistic for a player");
return true;
}
Player player = Bukkit.getPlayer(args[2]);
if (player == null) {
sender.sendMessage(ChatColor.GRAY + "Player not found");
return true;
}
int minutes;
try {
minutes = Integer.parseInt(args[3]);
} catch (NumberFormatException e) {
sender.sendMessage(ChatColor.GRAY + "Invalid number: " + args[3]);
return true;
}
int oldMinutes = player.getStatistic(playOneTick) / 20 / 60;
if (minutes > 0) {
player.incrementStatistic(playOneTick, minutes * 20 * 60);
} else if (minutes < 0) {
if (oldMinutes + minutes < 0) {
player.sendMessage(ChatColor.GRAY + "Playtime cannot be negative");
return true;
}
player.decrementStatistic(playOneTick, -minutes * 20 * 60);
}
int newMinutes = oldMinutes + minutes;
player.sendMessage(ChatColor.LIGHT_PURPLE + "Increased playtime for " + player.getName() + " to " + oldMinutes + (minutes >= 0 ? "+" : "") + minutes + "=" + newMinutes + " minutes");
return true;
}
}
if (sender.hasPermission("rankup.playtime.get")) {
@@ -275,13 +308,14 @@ public class InfoCommand implements TabExecutor {
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] + " add <player> <minutes>"
+ ChatColor.YELLOW + " Increase the playtime statistic for a player");
}
return true;
}
}
// Set playtime & get playtime for other players?
PluginDescriptionFile description = plugin.getDescription();
String version = description.getVersion();
sender.sendMessage(
@@ -322,7 +356,7 @@ public class InfoCommand implements TabExecutor {
list.add("forceprestige");
list.add("rankdown");
}
if (sender.hasPermission("rankup.playtime")) {
if (sender.hasPermission("rankup.playtime.get") || sender.hasPermission("rankup.playtime.set")) {
list.add("playtime");
}
return StringUtil.copyPartialMatches(args[0], list, new ArrayList<>());
@@ -333,6 +367,16 @@ public class InfoCommand implements TabExecutor {
return StringUtil.copyPartialMatches(args[1], players(), new ArrayList<>());
} else if (args[0].equalsIgnoreCase("rankdown") && sender.hasPermission("rankup.force")) {
return StringUtil.copyPartialMatches(args[1], players(), new ArrayList<>());
} else if (args[0].equalsIgnoreCase("playtime")) {
List<String> options = new ArrayList<>();
if (sender.hasPermission("rankup.playtime.get")) {
options.add("get");
}
if (sender.hasPermission("rankup.playtime.set")) {
options.add("set");
options.add("add");
}
return StringUtil.copyPartialMatches(args[1], options, new ArrayList<>());
}
}
return Collections.emptyList();
@@ -33,10 +33,14 @@ public class RequirementContext {
return requirement.getName();
}
public double getPercent() {
public double getQuotient() {
return getProgress() / getTotal();
}
public double getPercent() {
return getProgress() / getTotal() * 100;
}
public String toString() {
return "Requirement[" + requirement.getFullName() + "]";
}
@@ -49,7 +49,6 @@ public class RankupExpansion implements Expansion {
String[] parts = params.split("_", 5);
return getPlaceholderRequirement(player, rankups.getRankByName(parts[2]),
replacePattern(parts[3]), parts.length > 4 ? parts[4] : "");
// return placeholders.getSimpleFormat().format(orElse(rankups.getByName(parts[2]).getRequirement(parts[3]), Requirement::getValueDouble, 0));
} else if (params.startsWith("rank_money_")) {
String[] parts = params.split("_", 4);
double amount = Objects.requireNonNull(rankups.getRankByName(parts[2]), "Rankup " + parts[2] + " does not exist").getRequirement(player, "money").getValueDouble();
@@ -28,6 +28,8 @@ public class PlaceholderRequirement extends ProgressiveRequirement {
switch (parts[1]) {
case "=":
return parsed.equals(value) ? 1 : 0;
case "!=":
return parsed.equals(value) ? 0 : 1;
}
// numeric operations
@@ -35,15 +37,15 @@ public class PlaceholderRequirement extends ProgressiveRequirement {
double v = Double.parseDouble(value.replace(",", ""));
switch (parts[1]) {
case ">":
return p > v ? v : 0;
return p > v ? 1 : 0;
case ">=":
return Math.min(p, v);
case "<":
return p < v ? v : 0;
return p < v ? 1 : 0;
case "<=":
return p <= v ? 1 : 0;
case "==":
return p == v ? v : 0;
return p == v ? 1 : 0;
}
throw new IllegalArgumentException("Invalid operation: " + parts[1]);
}
@@ -52,17 +54,19 @@ public class PlaceholderRequirement extends ProgressiveRequirement {
public double getTotal(Player player) {
String[] parts = getParts(player);
if (parts[1].equalsIgnoreCase("=")) {
return 1;
} else {
return Double.parseDouble(parts[2]);
switch (parts[1]) {
case ">=":
return Double.parseDouble(parts[2]);
default:
return 1;
}
}
private String[] getParts(Player player) {
String[] parts = getValueString().split(" ");
if (parts.length < 3) {
throw new IllegalArgumentException("Placeholder requirements must be in the form %placeholder% <operation> string");
throw new IllegalArgumentException(
"Placeholder requirements must be in the form %placeholder% <operation> string");
}
String parsed = PlaceholderAPI.setPlaceholders(player, parts[0]);
if (!PlaceholderAPI.containsPlaceholders(parts[0]) || parsed.equals(parts[0])) {
@@ -82,11 +82,11 @@ public class LegacyTextProcessor implements TextProcessor {
} else if (p.toLowerCase().startsWith("percent_done ")) {
String requirement = p.substring("percent_done ".length());
return get("rank", p, o -> this.options.getPercentFormat()
.format(((RankContext) o).getReq(requirement).getPercent() * 100));
.format(((RankContext) o).getReq(requirement).getPercent()));
} else if (p.toLowerCase().startsWith("percent_left ")) {
String requirement = p.substring("percent_left ".length());
return get("rank", p, o -> this.options.getPercentFormat()
.format(100 - ((RankContext) o).getReq(requirement).getPercent() * 100));
.format(100 - ((RankContext) o).getReq(requirement).getPercent()));
}
return get(p, "{" + p + "}");