Starting simplification

This commit is contained in:
okx-code
2019-03-18 00:17:07 +00:00
parent 240b80c814
commit 7bfd407c58
23 changed files with 89 additions and 254 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
} }
group 'sh.okx' group 'sh.okx'
version '3.4.2-beta.1' version '3.4.2'
repositories { repositories {
mavenCentral() mavenCentral()
+7 -12
View File
@@ -32,7 +32,7 @@ public class RankList<T extends Rank> {
for (T rank : ranks) { for (T rank : ranks) {
// see if anything ranks up to this // see if anything ranks up to this
for (T rank0 : ranks) { for (T rank0 : ranks) {
if (!rank0.isLast() && rank0.getNext().equals(rank.getName())) { if (rank0.getNext().equals(rank.getRank())) {
continue OUTER; continue OUTER;
} }
} }
@@ -45,21 +45,20 @@ public class RankList<T extends Rank> {
public List<T> getOrderedList() { public List<T> getOrderedList() {
List<T> list = new ArrayList<>(); List<T> list = new ArrayList<>();
T t = getFirst(); T t = getFirst();
while (t != null) {
list.add(t); list.add(t);
do {
t = next(t); t = next(t);
list.add(t); }
} while (!t.isLast());
return list; return list;
} }
public T getByName(String name) { public T getByName(String name) {
for (T rank : ranks) { for (T rank : ranks) {
if (rank.getName().equalsIgnoreCase(name)) { if (rank.getRank().equalsIgnoreCase(name)) {
return rank; return rank;
} }
} }
throw new RuntimeException("Invalid rank: " + name); return null;
} }
public T getByPlayer(Player player) { public T getByPlayer(Player player) {
@@ -74,15 +73,11 @@ public class RankList<T extends Rank> {
} }
public T next(T rank) { public T next(T rank) {
if (rank.isLast()) {
return null;
}
for (T nextRank : ranks) { for (T nextRank : ranks) {
if (rank.getNext().equalsIgnoreCase(nextRank.getName())) { if (rank.getNext().equalsIgnoreCase(nextRank.getRank())) {
return nextRank; return nextRank;
} }
} }
throw new RuntimeException(rank.getName() + " has an invalid next rank"); return null;
} }
} }
+10 -17
View File
@@ -25,10 +25,8 @@ import sh.okx.rankup.prestige.Prestige;
import sh.okx.rankup.prestige.Prestiges; import sh.okx.rankup.prestige.Prestiges;
import sh.okx.rankup.ranks.Rank; import sh.okx.rankup.ranks.Rank;
import sh.okx.rankup.ranks.Rankups; import sh.okx.rankup.ranks.Rankups;
import sh.okx.rankup.requirements.OperationRegistry;
import sh.okx.rankup.requirements.Requirement; import sh.okx.rankup.requirements.Requirement;
import sh.okx.rankup.requirements.RequirementRegistry; import sh.okx.rankup.requirements.RequirementRegistry;
import sh.okx.rankup.requirements.operation.*;
import sh.okx.rankup.requirements.requirement.*; import sh.okx.rankup.requirements.requirement.*;
import sh.okx.rankup.requirements.requirement.XpLevelRequirement; import sh.okx.rankup.requirements.requirement.XpLevelRequirement;
import sh.okx.rankup.requirements.requirement.advancedachievements.*; import sh.okx.rankup.requirements.requirement.advancedachievements.*;
@@ -53,8 +51,6 @@ public class Rankup extends JavaPlugin {
@Getter @Getter
private RequirementRegistry requirementRegistry; private RequirementRegistry requirementRegistry;
@Getter @Getter
private OperationRegistry operationRegistry;
@Getter
private FileConfiguration messages; private FileConfiguration messages;
@Getter @Getter
private FileConfiguration config; private FileConfiguration config;
@@ -226,12 +222,6 @@ public class Rankup extends JavaPlugin {
requirementRegistry.addRequirement(new AdvancedAchievementsAchievementRequirement(this)); requirementRegistry.addRequirement(new AdvancedAchievementsAchievementRequirement(this));
requirementRegistry.addRequirement(new AdvancedAchievementsTotalRequirement(this)); requirementRegistry.addRequirement(new AdvancedAchievementsTotalRequirement(this));
} }
operationRegistry = new OperationRegistry();
operationRegistry.addOperation("all", new AllOperation());
operationRegistry.addOperation("none", new NoneOperation());
operationRegistry.addOperation("one", new OneOperation());
operationRegistry.addOperation("any", new AnyOperation());
} }
private void setupPermissions() { private void setupPermissions() {
@@ -266,7 +256,7 @@ public class Rankup extends JavaPlugin {
public MessageBuilder getMessage(Rank rank, Message message) { public MessageBuilder getMessage(Rank rank, Message message) {
ConfigurationSection messages = (rank instanceof Prestige ? prestiges : rankups).getConfig() ConfigurationSection messages = (rank instanceof Prestige ? prestiges : rankups).getConfig()
.getConfigurationSection(rank.getName()); .getConfigurationSection(rank.getRank());
if (messages == null || !messages.isSet(message.getName())) { if (messages == null || !messages.isSet(message.getName())) {
messages = this.messages; messages = this.messages;
} }
@@ -410,7 +400,7 @@ public class Rankup extends JavaPlugin {
public boolean checkPrestige(Player player, boolean message) { public boolean checkPrestige(Player player, boolean message) {
Prestige prestige = prestiges.getByPlayer(player); Prestige prestige = prestiges.getByPlayer(player);
if (!prestige.isEligable(player)) { // check if in ladder if (!prestige.isIn(player)) { // check if in ladder
getMessage(Message.NOT_HIGH_ENOUGH) getMessage(Message.NOT_HIGH_ENOUGH)
.failIf(!message) .failIf(!message)
.replace(Variable.PLAYER, player.getName()) .replace(Variable.PLAYER, player.getName())
@@ -486,12 +476,10 @@ public class Rankup extends JavaPlugin {
builder.replace(variable + " " + requirement.getName(), value.get()); builder.replace(variable + " " + requirement.getName(), value.get());
} }
public void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) { public MessageBuilder getMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
replaceMoneyRequirements(getMessage(oldRank, message) return replaceMoneyRequirements(getMessage(oldRank, message)
.replaceFirstPrestige(oldRank, prestiges, config.getString("placeholders.first-prestige-rank"))
.replaceRanks(player, oldRank, rank), player, oldRank) .replaceRanks(player, oldRank, rank), player, oldRank)
.replaceFromTo(oldRank) .replaceFromTo(oldRank);
.send(player);
} }
public void sendHeaderFooter(CommandSender sender, Rank rank, Message type) { public void sendHeaderFooter(CommandSender sender, Rank rank, Message type) {
@@ -508,4 +496,9 @@ public class Rankup extends JavaPlugin {
} }
builder.send(sender); builder.send(sender);
} }
public boolean isLegacy() {
String version = Bukkit.getVersion();
return !(version.startsWith("1.13") || version.startsWith("1.14"));
}
} }
@@ -4,14 +4,12 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.bukkit.event.Event; import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import sh.okx.rankup.requirements.Operation;
import sh.okx.rankup.requirements.OperationRegistry;
import sh.okx.rankup.requirements.Requirement; import sh.okx.rankup.requirements.Requirement;
import sh.okx.rankup.requirements.RequirementRegistry; import sh.okx.rankup.requirements.RequirementRegistry;
/** /**
* Called immediately before rankups and prestiges are registered, * Called immediately before rankups and prestiges are registered,
* and immediately after the built-in requirements and operations are registered. * and immediately after the built-in requirements are registered.
* This is used to register custom requirements. * This is used to register custom requirements.
* This is called when the plugin is enabled, and when it is reloaded from a command. * This is called when the plugin is enabled, and when it is reloaded from a command.
*/ */
@@ -29,18 +27,10 @@ public class RankupRegisterEvent extends Event {
return plugin.getRequirementRegistry(); return plugin.getRequirementRegistry();
} }
public OperationRegistry getOperationRegistry() {
return plugin.getOperationRegistry();
}
public void addRequirement(Requirement requirement) { public void addRequirement(Requirement requirement) {
plugin.getRequirementRegistry().addRequirement(requirement); plugin.getRequirementRegistry().addRequirement(requirement);
} }
public void addOperation(String name, Operation operation) {
plugin.getOperationRegistry().addOperation(name, operation);
}
@Override @Override
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
@@ -26,13 +26,17 @@ public class PrestigesCommand implements CommandExecutor {
Message message = playerRank == null ? Message.PRESTIGES_INCOMPLETE : Message.PRESTIGES_COMPLETE; Message message = playerRank == null ? Message.PRESTIGES_INCOMPLETE : Message.PRESTIGES_COMPLETE;
Prestige prestige = prestiges.getFirst(); Prestige prestige = prestiges.getFirst();
while (!prestige.isLast()) { Prestige next;
Prestige next = prestiges.next(prestige); while ((next = prestiges.next(prestige)) != null) {
if (prestige.equals(playerRank)) { if (prestige.equals(playerRank)) {
plugin.sendMessage(sender, Message.PRESTIGES_CURRENT, prestige, next); plugin.getMessage(sender, Message.PRESTIGES_CURRENT, prestige, next)
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
.send(sender);
message = Message.PRESTIGES_INCOMPLETE; message = Message.PRESTIGES_INCOMPLETE;
} else { } else {
plugin.sendMessage(sender, message, prestige, next); plugin.getMessage(sender, message, prestige, next)
.replaceFirstPrestige(prestige, prestiges, prestige.getFrom())
.send(sender);
} }
prestige = next; prestige = next;
} }
@@ -26,25 +26,16 @@ public class RanksCommand implements CommandExecutor {
Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE; Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
Rank rank = rankups.getFirst(); Rank rank = rankups.getFirst();
do { Rank next;
Rank next = rankups.next(rank); while ((next = rankups.next(rank)) != null) {
if (rank.equals(playerRank)) { if (rank.equals(playerRank)) {
plugin.sendMessage(sender, Message.RANKS_CURRENT, rank, next); plugin.getMessage(sender, Message.RANKS_CURRENT, rank, next).send(sender);
message = Message.RANKS_INCOMPLETE; message = Message.RANKS_INCOMPLETE;
} else { } else {
// helpful message to say there is a null rankup plugin.getMessage(sender, message, rank, next).send(sender);
if (next == null) {
plugin.getMessage(Message.INVALID_RANKUP).failIfEmpty().send(sender);
plugin.getLogger().severe("Rankup from " + rank.getName() + " to " + rank.getNext()
+ " is defined but " + rank.getNext() + " does not exist.");
return true;
}
plugin.sendMessage(sender, message, rank, next);
} }
rank = next; rank = next;
} while (!rank.isLast()); }
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER); plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
return true; return true;
} }
@@ -37,7 +37,7 @@ public class RankupCommand implements CommandExecutor {
} }
Rank next = rankups.next(rank); Rank next = rankups.next(rank);
if (next == null) { if (next == null) {
plugin.getLogger().severe("Rankup from " + rank.getName() + " to " + rank.getNext() + plugin.getLogger().severe("Rankup from " + rank.getRank() + " to " + rank.getNext() +
" is defined but " + rank.getNext() + " does not exist."); " is defined but " + rank.getNext() + " does not exist.");
plugin.getMessage(Message.INVALID_RANKUP).failIfEmpty().send(player); plugin.getMessage(Message.INVALID_RANKUP).failIfEmpty().send(player);
return true; return true;
+3 -3
View File
@@ -59,18 +59,18 @@ public class Gui implements InventoryHolder {
return gui; return gui;
} }
@SuppressWarnings("deprecation")
private static ItemStack getItem(Rankup plugin, String name, Player player, Rank oldRank, Rank rank) { private static ItemStack getItem(Rankup plugin, String name, Player player, Rank oldRank, Rank rank) {
ConfigurationSection section = plugin.getConfig().getConfigurationSection("gui").getConfigurationSection(name); ConfigurationSection section = plugin.getConfig().getConfigurationSection("gui").getConfigurationSection(name);
boolean legacy = !Bukkit.getVersion().contains("1.13");
String materialName = section.getString("material").toUpperCase(); String materialName = section.getString("material").toUpperCase();
// handle default material correctly on older versions // handle default material correctly on older versions
if (legacy && materialName.equals("BLACK_STAINED_GLASS_PANE")) { if (plugin.isLegacy() && materialName.equals("BLACK_STAINED_GLASS_PANE")) {
materialName = "STAINED_GLASS_PANE:15"; materialName = "STAINED_GLASS_PANE:15";
} }
ItemStack item; ItemStack item;
if (legacy) { if (plugin.isLegacy()) {
String[] parts = materialName.split(":"); String[] parts = materialName.split(":");
Material material = Material.valueOf(parts[0]); Material material = Material.valueOf(parts[0]);
@@ -64,14 +64,14 @@ public class MessageBuilder {
public MessageBuilder replaceRanks(Rank rank) { public MessageBuilder replaceRanks(Rank rank) {
replace(Variable.RANK, rank.getRank()); replace(Variable.RANK, rank.getRank());
replace(Variable.RANK_NAME, rank.getName()); replace(Variable.RANK_NAME, rank.getRank());
return this; return this;
} }
public MessageBuilder replaceRanks(Rank oldRank, Rank rank) { public MessageBuilder replaceRanks(Rank oldRank, Rank rank) {
replaceRanks(rank); replaceRanks(rank);
replace(Variable.OLD_RANK, oldRank.getRank()); replace(Variable.OLD_RANK, oldRank.getRank());
replace(Variable.OLD_RANK_NAME, oldRank.getName()); replace(Variable.OLD_RANK_NAME, oldRank.getRank());
return this; return this;
} }
@@ -10,6 +10,7 @@ import sh.okx.rankup.ranks.Rank;
import sh.okx.rankup.ranks.Rankups; import sh.okx.rankup.ranks.Rankups;
import sh.okx.rankup.requirements.Requirement; import sh.okx.rankup.requirements.Requirement;
import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
@RequiredArgsConstructor @RequiredArgsConstructor
@@ -47,7 +48,7 @@ public class RankupExpansion extends PlaceholderExpansion {
// return placeholders.getSimpleFormat().format(orElse(rankups.getByName(parts[2]).getRequirement(parts[3]), Requirement::getValueDouble, 0)); // return placeholders.getSimpleFormat().format(orElse(rankups.getByName(parts[2]).getRequirement(parts[3]), Requirement::getValueDouble, 0));
} else if (params.startsWith("rank_money_")) { } else if (params.startsWith("rank_money_")) {
String[] parts = params.split("_", 4); String[] parts = params.split("_", 4);
double amount = rankups.getByName(parts[2]).getRequirement("money").getValueDouble(); double amount = Objects.requireNonNull(rankups.getByName(parts[2]), "Rankup " + parts[2] + " does not exist").getRequirement("money").getValueDouble();
if (parts.length > 3 && parts[3].equalsIgnoreCase("left")) { if (parts.length > 3 && parts[3].equalsIgnoreCase("left")) {
amount = amount - plugin.getEconomy().getBalance(player); amount = amount - plugin.getEconomy().getBalance(player);
} }
@@ -56,25 +57,17 @@ public class RankupExpansion extends PlaceholderExpansion {
switch (params) { switch (params) {
case "current_prestige": case "current_prestige":
return prestige.getRank(); return Objects.requireNonNull(prestige, "Using current_prestige placeholder but prestiging is disabled").getRank();
case "current_prestige_name":
return prestige.getName();
case "next_prestige": case "next_prestige":
return orElsePlaceholder(nextPrestige, Prestige::getRank, "highest-rank"); return orElsePlaceholder(nextPrestige, Prestige::getRank, "highest-rank");
case "next_prestige_name":
return orElsePlaceholder(nextPrestige, Prestige::getName, "highest-rank");
case "prestige_money": case "prestige_money":
return String.valueOf(simplify(orElse(prestige, r -> r.isEligable(player) ? r.getRequirement("money").getValueDouble() : 0, 0))); return String.valueOf(simplify(orElse(prestige, r -> r.isIn(player) ? r.getRequirement("money").getValueDouble() : 0, 0)));
case "prestige_money_formatted": case "prestige_money_formatted":
return plugin.formatMoney(orElse(prestige, r -> r.isEligable(player) ? r.getRequirement("money").getValueDouble() : 0, 0D)); return plugin.formatMoney(orElse(prestige, r -> r.isIn(player) ? r.getRequirement("money").getValueDouble() : 0, 0D));
case "current_rank": case "current_rank":
return orElsePlaceholder(rank, Rank::getRank, "not-in-ladder"); return orElsePlaceholder(rank, Rank::getRank, "not-in-ladder");
case "current_rank_name":
return orElsePlaceholder(rank, Rank::getName, "not-in-ladder");
case "next_rank": case "next_rank":
return orElsePlaceholder(rank, r -> orElsePlaceholder(nextRank, Rank::getRank, "highest-rank"), "not-in-ladder"); return orElsePlaceholder(rank, r -> orElsePlaceholder(nextRank, Rank::getRank, "highest-rank"), "not-in-ladder");
case "next_rank_name":
return orElsePlaceholder(rank, r -> orElsePlaceholder(nextRank, Rank::getName, "highest-rank"), "not-in-ladder");
case "money": case "money":
return String.valueOf(orElse(rank, r -> simplify(r.getRequirement("money").getValueDouble()), 0)); return String.valueOf(orElse(rank, r -> simplify(r.getRequirement("money").getValueDouble()), 0));
case "money_formatted": case "money_formatted":
@@ -1,65 +1,42 @@
package sh.okx.rankup.prestige; package sh.okx.rankup.prestige;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import org.apache.commons.lang3.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import sh.okx.rankup.Rankup; import sh.okx.rankup.Rankup;
import sh.okx.rankup.ranks.Rank; import sh.okx.rankup.ranks.Rank;
import sh.okx.rankup.requirements.Operation;
import sh.okx.rankup.requirements.Requirement; import sh.okx.rankup.requirements.Requirement;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@EqualsAndHashCode(callSuper = true)
public class Prestige extends Rank { public class Prestige extends Rank {
@Getter @Getter
private final String from; private final String from;
@Getter @Getter
private final String to; private final String to;
private Prestige(Rankup plugin, String name, String next, String rank, Set<Requirement> requirements, Operation operation, List<String> commands, String from, String to) { private Prestige(Rankup plugin, String next, String rank, Set<Requirement> requirements, List<String> commands, String from, String to) {
super(plugin, name, next, rank, requirements, operation, commands); super(plugin, next, rank, requirements, commands);
this.from = from; this.from = from;
this.to = to; this.to = to;
} }
public static Prestige deserialize(Rankup plugin, ConfigurationSection section) { public static Prestige deserialize(Rankup plugin, ConfigurationSection section) {
Set<Requirement> requirements = new HashSet<>();
Operation operation = null;
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements"); ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
Validate.notNull(requirementsSection, "No requirements defined for section " + section.getName());
if (requirementsSection != null) { Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
operation = plugin.getOperationRegistry().getOperation(section.getString("operation"));
}
return new Prestige(plugin, return new Prestige(plugin,
section.getName(),
section.getString("next"), section.getString("next"),
section.getString("rank"), section.getString("rank"),
requirements, requirements,
operation,
section.getStringList("commands"), section.getStringList("commands"),
section.getString("from"), section.getString("from"),
section.getString("to")); section.getString("to"));
} }
public boolean isEligable(Player player) {
String[] groups = plugin.getPermissions().getPlayerGroups(null, player);
for (String group : groups) {
if (group.equalsIgnoreCase(from)) {
return true;
}
}
return false;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Prestige)) {
return false;
}
return ((Prestige) o).name.equals(name);
}
} }
+13 -28
View File
@@ -1,62 +1,55 @@
package sh.okx.rankup.ranks; package sh.okx.rankup.ranks;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.Validate;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import sh.okx.rankup.Rankup; import sh.okx.rankup.Rankup;
import sh.okx.rankup.messages.MessageBuilder; import sh.okx.rankup.messages.MessageBuilder;
import sh.okx.rankup.requirements.DeductibleRequirement; import sh.okx.rankup.requirements.DeductibleRequirement;
import sh.okx.rankup.requirements.Operation;
import sh.okx.rankup.requirements.Requirement; import sh.okx.rankup.requirements.Requirement;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@EqualsAndHashCode
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) @RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class Rank { public class Rank {
protected final Rankup plugin; protected final Rankup plugin;
@Getter @Getter
protected final String name;
@Getter
protected final String next; protected final String next;
@Getter @Getter
protected final String rank; protected final String rank;
@Getter @Getter
protected final Set<Requirement> requirements; protected final Set<Requirement> requirements;
protected final Operation operation;
protected final List<String> commands; protected final List<String> commands;
public static Rank deserialize(Rankup plugin, ConfigurationSection section) { public static Rank deserialize(Rankup plugin, ConfigurationSection section) {
Set<Requirement> requirements = new HashSet<>();
Operation operation = null;
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements"); ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
Validate.notNull(requirementsSection, "No requirements defined for section " + section.getName());
if (requirementsSection != null) { Set<Requirement> requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
operation = plugin.getOperationRegistry().getOperation(section.getString("operation"));
} else if (section.contains("next")) {
plugin.getLogger().severe("Rank " + section.getName() + " has no requirements.");
return null;
}
return new Rank(plugin, return new Rank(plugin,
section.getName(),
section.getString("next"), section.getString("next"),
section.getString("rank"), section.getString("rank"),
requirements, requirements,
operation,
section.getStringList("commands")); section.getStringList("commands"));
} }
public boolean hasRequirements(Player player) { public boolean hasRequirements(Player player) {
return operation.check(requirements.stream() for (Requirement requirement : requirements) {
.map(requirement -> requirement.check(player)) if (!requirement.check(player)) {
.collect(Collectors.toList())); return false;
}
}
return true;
} }
public boolean isIn(Player player) { public boolean isIn(Player player) {
@@ -70,7 +63,7 @@ public class Rank {
} }
public boolean isLast() { public boolean isLast() {
return next == null; return plugin.getRankups().getByName(next) == null;
} }
public Requirement getRequirement(String name) { public Requirement getRequirement(String name) {
@@ -96,12 +89,4 @@ public class Rank {
new MessageBuilder(command).replaceRanks(player, this, nextRank).toString()); new MessageBuilder(command).replaceRanks(player, this, nextRank).toString());
} }
} }
@Override
public boolean equals(Object o) {
if (!(o instanceof Rank)) {
return false;
}
return ((Rank) o).name.equals(name);
}
} }
@@ -1,7 +0,0 @@
package sh.okx.rankup.requirements;
import java.util.List;
public interface Operation {
boolean check(List<Boolean> booleans);
}
@@ -1,16 +0,0 @@
package sh.okx.rankup.requirements;
import java.util.HashMap;
import java.util.Map;
public class OperationRegistry {
private Map<String, Operation> operations = new HashMap<>();
public void addOperation(String name, Operation operation) {
operations.put(name.toLowerCase(), operation);
}
public Operation getOperation(String name) {
return operations.get(name == null ? "all" : name.toLowerCase());
}
}
@@ -1,12 +0,0 @@
package sh.okx.rankup.requirements;
import java.util.List;
public abstract class ReducerOperation implements Operation {
public abstract boolean check(boolean a, boolean b);
@Override
public boolean check(List<Boolean> booleans) {
return booleans.stream().reduce(this::check).orElse(true);
}
}
@@ -1,10 +0,0 @@
package sh.okx.rankup.requirements.operation;
import sh.okx.rankup.requirements.ReducerOperation;
public class AllOperation extends ReducerOperation {
@Override
public boolean check(boolean a, boolean b) {
return a && b;
}
}
@@ -1,10 +0,0 @@
package sh.okx.rankup.requirements.operation;
import sh.okx.rankup.requirements.ReducerOperation;
public class AnyOperation extends ReducerOperation {
@Override
public boolean check(boolean a, boolean b) {
return a || b;
}
}
@@ -1,10 +0,0 @@
package sh.okx.rankup.requirements.operation;
import sh.okx.rankup.requirements.ReducerOperation;
public class NoneOperation extends ReducerOperation {
@Override
public boolean check(boolean a, boolean b) {
return !a && !b;
}
}
@@ -1,10 +0,0 @@
package sh.okx.rankup.requirements.operation;
import sh.okx.rankup.requirements.ReducerOperation;
public class OneOperation extends ReducerOperation {
@Override
public boolean check(boolean a, boolean b) {
return (a && !b) || (b && !a);
}
}
+5 -7
View File
@@ -1,7 +1,7 @@
# this is used for letting you know that you need to update/change your config file # this is used for letting you know that you need to update/change your config file
version: 3 version: 3
# the ISO-639-1 locale to use for messages # the locale to use for messages
# all messages can be customised but this allows you to # all messages can be customised but this allows you to
# choose messages that are already translated # choose messages that are already translated
# locales can be found in the locale/ folder # locales can be found in the locale/ folder
@@ -29,8 +29,7 @@ prestige: true
# options are: gui, text or none # options are: gui, text or none
confirmation-type: 'gui' confirmation-type: 'gui'
# how long in seconds people have to wait between a /rankup and a /prestige # how long, in seconds, people have to wait between a successful /rankup or a /prestige
# only successful rankups and prestiges start the cooldown.
# set to 0 to disable. # set to 0 to disable.
cooldown: 1 cooldown: 1
@@ -38,8 +37,8 @@ gui:
rows: 1 rows: 1
rankup: rankup:
material: EMERALD_BLOCK material: EMERALD_BLOCK
# index can be separated by spaces to show in multiple ways # index can be separated by spaces to show in multiple groups
# ie, 0-3 9-12 18-21 # for example: 0-3 9-12 18-21
# you can also just use a single number instead of a range. # you can also just use a single number instead of a range.
index: 0-3 index: 0-3
name: '&a&lConfirm' name: '&a&lConfirm'
@@ -56,6 +55,7 @@ gui:
# this works for both the rankup and cancel blocks as well # this works for both the rankup and cancel blocks as well
material: BLACK_STAINED_GLASS_PANE material: BLACK_STAINED_GLASS_PANE
# options when using the text rankup confirmation
text: text:
# the time in seconds for a player to # the time in seconds for a player to
# confirm by typing /rankup again # confirm by typing /rankup again
@@ -72,8 +72,6 @@ placeholders:
not-in-ladder: "None" not-in-ladder: "None"
# used in next_rank placeholders when there is no rankup # used in next_rank placeholders when there is no rankup
highest-rank: "None" highest-rank: "None"
# used in /prestiges as the {OLD_RANK} placeholder for the first prestige rank
first-prestige-rank: 'D'
# what to shorten money by. # what to shorten money by.
# ie 1000 -> 1k # ie 1000 -> 1k
+1 -1
View File
@@ -1,5 +1,5 @@
name: Rankup name: Rankup
version: 3.4.2-beta.1 version: 3.4.2
main: sh.okx.rankup.Rankup main: sh.okx.rankup.Rankup
author: Okx author: Okx
depend: [Vault] depend: [Vault]
+5 -7
View File
@@ -3,21 +3,19 @@ first:
from: 'D' from: 'D'
# the rank to change it to # the rank to change it to
to: 'A' to: 'A'
next: 'P1example' next: 'P1'
# see rankups.yml for more information on requirements, operations, commands and messages # see rankups.yml for more information on requirements, operations, commands and messages
requirements: requirements:
money: 10000 - 'money 10000'
# optional, defaults to all
operation: all
P1example: P1example:
from: 'D' from: 'D'
to: 'A' to: 'A'
# the rank added to indicate this prestige # the rank added to indicate this prestige
rank: 'P1' rank: 'P1'
next: 'P2example' next: 'P2'
requirements: requirements:
money: 20000 - 'money 20000'
xp-level: 5 - 'xp-level 5'
P2example: P2example:
from: 'D' from: 'D'
to: 'A' to: 'A'
+13 -27
View File
@@ -1,54 +1,40 @@
# see https://github.com/okx-code/Rankup3/wiki/Rank-format # see https://github.com/okx-code/Rankup3/wiki/Rank-format
# this name can be equal to your rank name for simplicity, # this name doesn't matter
# eg "A" instead of "Aexample".
Aexample: Aexample:
# the name of the rank in your permissions plugin # the name of the group
# players have to be in this rank to rankup # players have to be in this rank to rankup
rank: 'A' rank: 'A'
# the next rank a player can rank up to. # the name of the rank a player can rankup to
# this must be the name of the configuration section, not the rank name. next: 'B'
# for example, the name of this configuration section is "Aexample".
# if this is the last rank, you don't need this.
next: 'Bexample'
# List of requirements to go to the next rank # List of requirements to go to the next rank
# (ie, this example will charge 1000 money to rankup from A to B) # This example will charge 1000 money to rankup from A to B.
# https://github.com/okx-code/Rankup3/wiki/Requirements # https://github.com/okx-code/Rankup3/wiki/Requirements
# custom requirements can also be added by other plugins. # custom requirements can also be added by other plugins.
requirements: requirements:
money: 1000 - 'money 1000'
# What requirements players need to match to /rankup.
# this is optional - if you don't use it, it defaults to "all"
# n.b. if there are no requirements players will always be able to /rankup.
# all: all requirements
# any: at least one requirement
# one: only one requirement
# none: no requirements
operation: all
# the console will run these commands when a player ranks up # the console will run these commands when a player ranks up
# rankup will change the group for you, commands are not needed for that # the groups are automatically changed with vault
#commands: #commands:
# this will run when a player ranks up from A to B. # this will run when a player ranks up from A to B.
#- 'say {PLAYER} well done for ranking up from {OLD_RANK} to {RANK}!' #- 'say {PLAYER} well done for ranking up from {OLD_RANK} to {RANK}!'
Bexample: Bexample:
rank: 'B' rank: 'B'
next: 'Cexample' next: 'C'
requirements: requirements:
money: 2500 - 'money 2500'
Cexample: Cexample:
rank: 'C' rank: 'C'
next: 'Dexample' next: 'D'
requirements: requirements:
money: 5000 - 'money 5000'
xp-level: 2 - 'xp-level 2'
# you can have a custom messages for each rank # you can have a custom messages for each rank
# you can use this to list the requirements needed. # you can use this to list the requirements needed.
# the paths of these messages are the exact same as in the messages for your locale
rankup: rankup:
requirements-not-met: '&cYou need 5000 money and 2 levels of XP to rankup to D.' requirements-not-met: '&cYou need 5000 money and 2 levels of XP to rankup to D.'
list: list:
complete: "&7{OLD_RANK} &8\xbb &7{RANK} &e(5000 money, 2 XP levels)" complete: "&7{OLD_RANK} &8\xbb &7{RANK} &e(5000 money, 2 XP levels)"
current: "&c{OLD_RANK} &e\xbb &c{RANK} &e(5000 money, 2 XP levels)" current: "&c{OLD_RANK} &e\xbb &c{RANK} &e(5000 money, 2 XP levels)"
incomplete: "&r{OLD_RANK} &e\xbb &r{RANK} &e(5000 money, 2 XP levels)" incomplete: "&r{OLD_RANK} &e\xbb &r{RANK} &e(5000 money, 2 XP levels)"
# for the last rank, you just need to specify the rank.
Dexample:
rank: 'D'