add /prestige
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
package sh.okx.rankup.ranks;
|
||||
|
||||
public class Prestige {
|
||||
}
|
||||
@@ -8,70 +8,55 @@ import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.entity.Player;
|
||||
import sh.okx.rankup.Rankup;
|
||||
import sh.okx.rankup.messages.MessageBuilder;
|
||||
import sh.okx.rankup.messages.Variable;
|
||||
import sh.okx.rankup.requirements.DeductibleRequirement;
|
||||
import sh.okx.rankup.requirements.Operation;
|
||||
import sh.okx.rankup.requirements.Requirement;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
|
||||
public class Rank {
|
||||
private final Rankup plugin;
|
||||
protected final Rankup plugin;
|
||||
@Getter
|
||||
private final String name;
|
||||
protected final String name;
|
||||
@Getter
|
||||
private final String next;
|
||||
protected final String next;
|
||||
@Getter
|
||||
private final String rank;
|
||||
protected final String rank;
|
||||
@Getter
|
||||
private final Set<Requirement> requirements;
|
||||
private final Operation operation;
|
||||
private final List<String> commands;
|
||||
protected final Set<Requirement> requirements;
|
||||
protected final Operation operation;
|
||||
protected final List<String> commands;
|
||||
|
||||
public static Rank deserialize(Rankup plugin, ConfigurationSection section) {
|
||||
String rank = section.getString("rank");
|
||||
|
||||
Set<Requirement> requirements = new HashSet<>();
|
||||
Operation operation = null;
|
||||
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
|
||||
if (requirementsSection != null) {
|
||||
for (Map.Entry<String, Object> entry : requirementsSection.getValues(false).entrySet()) {
|
||||
String name = entry.getKey();
|
||||
String value = String.valueOf(entry.getValue());
|
||||
Requirement requirement = plugin.getRequirementRegistry().newRequirement(name, value);
|
||||
if (requirement == null) {
|
||||
plugin.getLogger().warning("Unknown requirement " + name);
|
||||
} else {
|
||||
requirements.add(requirement);
|
||||
}
|
||||
}
|
||||
|
||||
String operationName = Optional.ofNullable(section.getString("operation")).orElse("all");
|
||||
operation = plugin.getOperationRegistry().getOperation(operationName);
|
||||
if (requirementsSection != null) {
|
||||
requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
||||
operation = plugin.getOperationRegistry().getOperation(section.getString("operation"));
|
||||
}
|
||||
|
||||
return new Rank(plugin,
|
||||
section.getName(),
|
||||
section.getString("next"),
|
||||
rank,
|
||||
section.getString("rank"),
|
||||
requirements,
|
||||
operation,
|
||||
section.getStringList("commands"));
|
||||
}
|
||||
|
||||
public boolean checkRequirements(Player player) {
|
||||
public boolean hasRequirements(Player player) {
|
||||
return operation.check(requirements.stream()
|
||||
.map(requirement -> requirement.check(player))
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public boolean isInRank(Player player) {
|
||||
public boolean isIn(Player player) {
|
||||
String[] groups = plugin.getPermissions().getPlayerGroups(player);
|
||||
for (String group : groups) {
|
||||
if (group.equalsIgnoreCase(rank)) {
|
||||
@@ -81,7 +66,7 @@ public class Rank {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isLastRank() {
|
||||
public boolean isLast() {
|
||||
return next == null;
|
||||
}
|
||||
|
||||
@@ -104,13 +89,8 @@ public class Rank {
|
||||
|
||||
public void runCommands(Player player, Rank nextRank) {
|
||||
for (String command : commands) {
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), new MessageBuilder(command)
|
||||
.replace(Variable.PLAYER, player.getName())
|
||||
.replace(Variable.OLD_RANK, rank)
|
||||
.replace(Variable.OLD_RANK_NAME, name)
|
||||
.replace(Variable.RANK, nextRank.rank)
|
||||
.replace(Variable.RANK_NAME, nextRank.name)
|
||||
.toString());
|
||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
|
||||
new MessageBuilder(command).replaceRanks(player, this, nextRank).toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,80 +1,11 @@
|
||||
package sh.okx.rankup.ranks;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import sh.okx.rankup.RankList;
|
||||
import sh.okx.rankup.Rankup;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Rankups {
|
||||
@Getter
|
||||
private final FileConfiguration config;
|
||||
private final Set<Rank> ranks = new HashSet<>();
|
||||
|
||||
public class Rankups extends RankList<Rank> {
|
||||
public Rankups(Rankup plugin, FileConfiguration config) {
|
||||
this.config = config;
|
||||
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
||||
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
|
||||
ranks.add(Rank.deserialize(plugin, rankSection));
|
||||
}
|
||||
super(plugin, config, section -> Rank.deserialize(plugin, section));
|
||||
}
|
||||
|
||||
public Rank getFirstRank() {
|
||||
OUTER:
|
||||
for (Rank rank : ranks) {
|
||||
// see if anything ranks up to this
|
||||
for (Rank rank0 : ranks) {
|
||||
if (!rank0.isLastRank() && rank0.getNext().equals(rank.getName())) {
|
||||
continue OUTER;
|
||||
}
|
||||
}
|
||||
// nothing ranks up to this
|
||||
return rank;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Rank getRank(String name) {
|
||||
for (Rank rank : ranks) {
|
||||
if (rank.getName().equalsIgnoreCase(name)) {
|
||||
return rank;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Rank getRank(Player player) {
|
||||
return ranks.stream()
|
||||
.filter(rank -> rank.isInRank(player))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public Rank nextRank(Rank rank) {
|
||||
if (rank.isLastRank()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (Rank nextRank : ranks) {
|
||||
if (rank.getNext().equalsIgnoreCase(nextRank.getName())) {
|
||||
return nextRank;
|
||||
}
|
||||
}
|
||||
// this shouldn't happen but whatever
|
||||
return null;
|
||||
}
|
||||
|
||||
// public boolean hasNext(Rank start, Rank rank) {
|
||||
// while(!start.isLastRank()) {
|
||||
// start = nextRank(rank);
|
||||
// if(start.equals(rank)) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user