add /prestige
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'sh.okx'
|
group 'sh.okx'
|
||||||
version '3.0-alpha.19'
|
version '3.0-alpha.20'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package sh.okx.rankup;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import sh.okx.rankup.ranks.Rank;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
public class RankList<T extends Rank> {
|
||||||
|
@Getter
|
||||||
|
protected final FileConfiguration config;
|
||||||
|
protected final Set<T> ranks = new HashSet<>();
|
||||||
|
|
||||||
|
public RankList(Rankup plugin, FileConfiguration config, Function<ConfigurationSection, T> deserializer) {
|
||||||
|
this.config = config;
|
||||||
|
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
||||||
|
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
|
||||||
|
ranks.add(deserializer.apply(rankSection));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getFirst() {
|
||||||
|
OUTER:
|
||||||
|
for (T rank : ranks) {
|
||||||
|
// see if anything ranks up to this
|
||||||
|
for (T rank0 : ranks) {
|
||||||
|
if (!rank0.isLast() && rank0.getNext().equals(rank.getName())) {
|
||||||
|
continue OUTER;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// nothing ranks up to this
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getByName(String name) {
|
||||||
|
for (T rank : ranks) {
|
||||||
|
if (rank.getName().equalsIgnoreCase(name)) {
|
||||||
|
return rank;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getByPlayer(Player player) {
|
||||||
|
return ranks.stream()
|
||||||
|
.filter(rank -> rank.isIn(player))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T next(T rank) {
|
||||||
|
if (rank.isLast()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (T nextRank : ranks) {
|
||||||
|
if (rank.getNext().equalsIgnoreCase(nextRank.getName())) {
|
||||||
|
return nextRank;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// this shouldn't happen but whatever
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,8 @@ import org.bukkit.inventory.InventoryView;
|
|||||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
import sh.okx.rankup.commands.InfoCommand;
|
import sh.okx.rankup.commands.InfoCommand;
|
||||||
import sh.okx.rankup.commands.RankListCommand;
|
import sh.okx.rankup.commands.PrestigeCommand;
|
||||||
|
import sh.okx.rankup.commands.RanksCommand;
|
||||||
import sh.okx.rankup.commands.RankupCommand;
|
import sh.okx.rankup.commands.RankupCommand;
|
||||||
import sh.okx.rankup.gui.Gui;
|
import sh.okx.rankup.gui.Gui;
|
||||||
import sh.okx.rankup.gui.GuiListener;
|
import sh.okx.rankup.gui.GuiListener;
|
||||||
@@ -23,6 +24,8 @@ import sh.okx.rankup.messages.Message;
|
|||||||
import sh.okx.rankup.messages.MessageBuilder;
|
import sh.okx.rankup.messages.MessageBuilder;
|
||||||
import sh.okx.rankup.messages.Variable;
|
import sh.okx.rankup.messages.Variable;
|
||||||
import sh.okx.rankup.placeholders.Placeholders;
|
import sh.okx.rankup.placeholders.Placeholders;
|
||||||
|
import sh.okx.rankup.prestige.Prestige;
|
||||||
|
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.OperationRegistry;
|
||||||
@@ -63,9 +66,11 @@ public class Rankup extends JavaPlugin {
|
|||||||
@Getter
|
@Getter
|
||||||
private Rankups rankups;
|
private Rankups rankups;
|
||||||
@Getter
|
@Getter
|
||||||
|
private Prestiges prestiges;
|
||||||
|
@Getter
|
||||||
private Placeholders placeholders;
|
private Placeholders placeholders;
|
||||||
/**
|
/**
|
||||||
* Players who cannot rankup for a certain amount of time.
|
* Players who cannot rankup/prestige for a certain amount of time.
|
||||||
*/
|
*/
|
||||||
private Map<Player, Long> cooldowns;
|
private Map<Player, Long> cooldowns;
|
||||||
|
|
||||||
@@ -85,8 +90,12 @@ public class Rankup extends JavaPlugin {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (config.getBoolean("ranks")) {
|
if (config.getBoolean("ranks")) {
|
||||||
getCommand("ranks").setExecutor(new RankListCommand(this));
|
getCommand("ranks").setExecutor(new RanksCommand(this));
|
||||||
}
|
}
|
||||||
|
if(prestiges != null) {
|
||||||
|
getCommand("prestige").setExecutor(new PrestigeCommand(this));
|
||||||
|
}
|
||||||
|
|
||||||
getCommand("rankup").setExecutor(new RankupCommand(this));
|
getCommand("rankup").setExecutor(new RankupCommand(this));
|
||||||
getCommand("rankup3").setExecutor(new InfoCommand(this));
|
getCommand("rankup3").setExecutor(new InfoCommand(this));
|
||||||
getServer().getPluginManager().registerEvents(new GuiListener(this), this);
|
getServer().getPluginManager().registerEvents(new GuiListener(this), this);
|
||||||
@@ -138,6 +147,9 @@ public class Rankup extends JavaPlugin {
|
|||||||
messages = loadConfig("messages.yml");
|
messages = loadConfig("messages.yml");
|
||||||
config = loadConfig("config.yml");
|
config = loadConfig("config.yml");
|
||||||
rankups = new Rankups(this, loadConfig("rankups.yml"));
|
rankups = new Rankups(this, loadConfig("rankups.yml"));
|
||||||
|
if(config.getBoolean("prestige")) {
|
||||||
|
prestiges = new Prestiges(this, loadConfig("prestiges.yml"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private FileConfiguration loadConfig(String name) {
|
private FileConfiguration loadConfig(String name) {
|
||||||
@@ -203,13 +215,19 @@ public class Rankup extends JavaPlugin {
|
|||||||
return MessageBuilder.of(messages, message);
|
return MessageBuilder.of(messages, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void applyCooldown(Player player) {
|
||||||
|
if (config.getInt("cooldown") > 0) {
|
||||||
|
cooldowns.put(player, System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void rankup(Player player) {
|
public void rankup(Player player) {
|
||||||
if (!checkRankup(player)) {
|
if (!checkRankup(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Rank oldRank = rankups.getRank(player);
|
Rank oldRank = rankups.getByPlayer(player);
|
||||||
Rank rank = rankups.nextRank(oldRank);
|
Rank rank = rankups.next(oldRank);
|
||||||
|
|
||||||
oldRank.applyRequirements(player);
|
oldRank.applyRequirements(player);
|
||||||
|
|
||||||
@@ -218,19 +236,15 @@ public class Rankup extends JavaPlugin {
|
|||||||
|
|
||||||
getMessage(oldRank, Message.SUCCESS_PUBLIC)
|
getMessage(oldRank, Message.SUCCESS_PUBLIC)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceAll(player, oldRank, rank)
|
.replaceRanks(player, oldRank, rank)
|
||||||
.broadcast();
|
.broadcast();
|
||||||
getMessage(oldRank, Message.SUCCESS_PRIVATE)
|
getMessage(oldRank, Message.SUCCESS_PRIVATE)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceAll(player, oldRank, rank)
|
.replaceRanks(player, oldRank, rank)
|
||||||
.send(player);
|
.send(player);
|
||||||
|
|
||||||
oldRank.runCommands(player, rank);
|
oldRank.runCommands(player, rank);
|
||||||
|
applyCooldown(player);
|
||||||
// apply cooldown last
|
|
||||||
if (config.getInt("cooldown") > 0) {
|
|
||||||
cooldowns.put(player, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -241,20 +255,27 @@ public class Rankup extends JavaPlugin {
|
|||||||
* @return true if the player can rankup, false otherwise
|
* @return true if the player can rankup, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean checkRankup(Player player) {
|
public boolean checkRankup(Player player) {
|
||||||
Rank rank = rankups.getRank(player);
|
Rank rank = rankups.getByPlayer(player);
|
||||||
if (rank == null) { // check if in ladder
|
if (rank == null) { // check if in ladder
|
||||||
getMessage(Message.NOT_IN_LADDER)
|
getMessage(Message.NOT_IN_LADDER)
|
||||||
.replace(Variable.PLAYER, player.getName())
|
.replace(Variable.PLAYER, player.getName())
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (rank.isLastRank()) { // check if they are at the highest rank
|
} else if (rank.isLast()) { // check if they are at the highest rank
|
||||||
getMessage(rank, Message.NO_RANKUP)
|
if(prestiges != null) {
|
||||||
.replaceAll(player, rank)
|
Prestige prestige = prestiges.getByPlayer(player);
|
||||||
|
if(prestige.isLast()) {
|
||||||
|
getMessage(rank, Message.NO_RANKUP);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getMessage(rank, prestiges == null ? Message.NO_RANKUP :
|
||||||
|
prestiges.getByPlayer(player).isLast() ? Message.NO_RANKUP : Message.MUST_PRESTIGE)
|
||||||
|
.replaceRanks(player, rank)
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (!rank.checkRequirements(player)) { // check if they can afford it
|
} else if (!rank.hasRequirements(player)) { // check if they can afford it
|
||||||
replaceMoneyRequirements(getMessage(rank, Message.REQUIREMENTS_NOT_MET)
|
replaceMoneyRequirements(getMessage(rank, Message.REQUIREMENTS_NOT_MET)
|
||||||
.replaceAll(player, rank, rankups.nextRank(rank)), player, rank)
|
.replaceRanks(player, rank, rankups.next(rank)), player, rank)
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (cooldowns.containsKey(player)) {
|
} else if (cooldowns.containsKey(player)) {
|
||||||
@@ -265,7 +286,79 @@ public class Rankup extends JavaPlugin {
|
|||||||
long secondsLeft = (long) Math.ceil(timeLeft / 1000f);
|
long secondsLeft = (long) Math.ceil(timeLeft / 1000f);
|
||||||
getMessage(rank, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR)
|
getMessage(rank, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR)
|
||||||
.failIfEmpty()
|
.failIfEmpty()
|
||||||
.replaceAll(player, rank)
|
.replaceRanks(player, rank)
|
||||||
|
.replace(Variable.SECONDS, secondsLeft)
|
||||||
|
.send(player);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// cooldown has expired so remove it
|
||||||
|
cooldowns.remove(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void prestige(Player player) {
|
||||||
|
if (!checkPrestige(player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Prestige oldPrestige = prestiges.getByPlayer(player);
|
||||||
|
Prestige prestige = prestiges.next(oldPrestige);
|
||||||
|
|
||||||
|
oldPrestige.applyRequirements(player);
|
||||||
|
|
||||||
|
permissions.playerRemoveGroup(null, player, oldPrestige.getFrom());
|
||||||
|
permissions.playerAddGroup(null, player, oldPrestige.getTo());
|
||||||
|
if(oldPrestige.getRank() != null) {
|
||||||
|
permissions.playerRemoveGroup(null, player, oldPrestige.getRank());
|
||||||
|
}
|
||||||
|
permissions.playerAddGroup(null, player, prestige.getRank());
|
||||||
|
|
||||||
|
getMessage(oldPrestige, Message.SUCCESS_PUBLIC)
|
||||||
|
.failIfEmpty()
|
||||||
|
.replaceRanks(player, oldPrestige, prestige)
|
||||||
|
.replaceFromTo(oldPrestige)
|
||||||
|
.broadcast();
|
||||||
|
getMessage(oldPrestige, Message.SUCCESS_PRIVATE)
|
||||||
|
.failIfEmpty()
|
||||||
|
.replaceRanks(player, oldPrestige, prestige)
|
||||||
|
.replaceFromTo(oldPrestige)
|
||||||
|
.send(player);
|
||||||
|
|
||||||
|
oldPrestige.runCommands(player, prestige);
|
||||||
|
applyCooldown(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkPrestige(Player player) {
|
||||||
|
Prestige prestige = prestiges.getByPlayer(player);
|
||||||
|
if (!prestige.isEligable(player)) { // check if in ladder
|
||||||
|
getMessage(Message.NOT_HIGH_ENOUGH)
|
||||||
|
.replace(Variable.PLAYER, player.getName())
|
||||||
|
.send(player);
|
||||||
|
return false;
|
||||||
|
} else if (prestige.isLast()) { // check if they are at the highest rank
|
||||||
|
getMessage(prestige, Message.NO_RANKUP)
|
||||||
|
.replaceRanks(player, prestige)
|
||||||
|
.replaceFromTo(prestige)
|
||||||
|
.send(player);
|
||||||
|
return false;
|
||||||
|
} else if (!prestige.hasRequirements(player)) { // check if they can afford it
|
||||||
|
replaceMoneyRequirements(getMessage(prestige, Message.REQUIREMENTS_NOT_MET)
|
||||||
|
.replaceRanks(player, prestige, prestiges.next(prestige)), player, prestige)
|
||||||
|
.replaceFromTo(prestige)
|
||||||
|
.send(player);
|
||||||
|
return false;
|
||||||
|
} else if (cooldowns.containsKey(player)) {
|
||||||
|
long time = System.currentTimeMillis() - cooldowns.get(player);
|
||||||
|
// if time passed is less than the cooldown
|
||||||
|
long timeLeft = (config.getInt("cooldown") * 1000) - time;
|
||||||
|
if (timeLeft > 0) {
|
||||||
|
long secondsLeft = (long) Math.ceil(timeLeft / 1000f);
|
||||||
|
getMessage(prestige, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR)
|
||||||
|
.failIfEmpty()
|
||||||
|
.replaceRanks(player, prestige)
|
||||||
|
.replaceFromTo(prestige)
|
||||||
.replace(Variable.SECONDS, secondsLeft)
|
.replace(Variable.SECONDS, secondsLeft)
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
@@ -280,7 +373,7 @@ public class Rankup extends JavaPlugin {
|
|||||||
public MessageBuilder replaceMoneyRequirements(MessageBuilder builder, CommandSender sender, Rank rank) {
|
public MessageBuilder replaceMoneyRequirements(MessageBuilder builder, CommandSender sender, Rank rank) {
|
||||||
Requirement money = rank.getRequirement("money");
|
Requirement money = rank.getRequirement("money");
|
||||||
Double amount = null;
|
Double amount = null;
|
||||||
if (sender instanceof Player && rank.isInRank((Player) sender)) {
|
if (sender instanceof Player && rank.isIn((Player) sender)) {
|
||||||
if (money != null && economy != null) {
|
if (money != null && economy != null) {
|
||||||
amount = money.getRemaining((Player) sender);
|
amount = money.getRemaining((Player) sender);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package sh.okx.rankup.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import sh.okx.rankup.Rankup;
|
||||||
|
import sh.okx.rankup.gui.Gui;
|
||||||
|
import sh.okx.rankup.messages.Message;
|
||||||
|
import sh.okx.rankup.prestige.Prestige;
|
||||||
|
import sh.okx.rankup.prestige.Prestiges;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
|
public class PrestigeCommand implements CommandExecutor {
|
||||||
|
private final Map<Player, Long> confirming = new WeakHashMap<>();
|
||||||
|
|
||||||
|
private final Rankup plugin;
|
||||||
|
|
||||||
|
public PrestigeCommand(Rankup plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
// check if player
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Player player = (Player) sender;
|
||||||
|
|
||||||
|
Prestiges prestiges = plugin.getPrestiges();
|
||||||
|
Prestige prestige = prestiges.getByPlayer(player);
|
||||||
|
if (!plugin.checkPrestige(player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
FileConfiguration config = plugin.getConfig();
|
||||||
|
String confirmationType = config.getString("confirmation-type").toLowerCase();
|
||||||
|
if (confirmationType.equals("text") && confirming.containsKey(player)) {
|
||||||
|
long time = System.currentTimeMillis() - confirming.remove(player);
|
||||||
|
if (time < config.getInt("text.timeout") * 1000) {
|
||||||
|
plugin.prestige(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (confirmationType) {
|
||||||
|
case "text":
|
||||||
|
confirming.put(player, System.currentTimeMillis());
|
||||||
|
plugin.replaceMoneyRequirements(plugin.getMessage(prestige, Message.CONFIRMATION)
|
||||||
|
.replaceRanks(player, prestige, prestiges.next(prestige)), player, prestige)
|
||||||
|
.replaceFromTo(prestige)
|
||||||
|
.send(player);
|
||||||
|
break;
|
||||||
|
case "gui":
|
||||||
|
Gui.of(player, prestige, prestiges.next(prestige), plugin).open(player);
|
||||||
|
break;
|
||||||
|
case "none":
|
||||||
|
plugin.prestige(player);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("Invalid confirmation type " + confirmationType);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-8
@@ -6,14 +6,14 @@ import org.bukkit.command.CommandExecutor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
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.Rankups;
|
||||||
import sh.okx.rankup.messages.Message;
|
import sh.okx.rankup.messages.Message;
|
||||||
import sh.okx.rankup.messages.MessageBuilder;
|
import sh.okx.rankup.messages.MessageBuilder;
|
||||||
import sh.okx.rankup.messages.Variable;
|
import sh.okx.rankup.messages.Variable;
|
||||||
import sh.okx.rankup.ranks.Rank;
|
import sh.okx.rankup.ranks.Rank;
|
||||||
import sh.okx.rankup.ranks.Rankups;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class RankListCommand implements CommandExecutor {
|
public class RanksCommand implements CommandExecutor {
|
||||||
private final Rankup plugin;
|
private final Rankup plugin;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -21,15 +21,15 @@ public class RankListCommand implements CommandExecutor {
|
|||||||
Rankups rankups = plugin.getRankups();
|
Rankups rankups = plugin.getRankups();
|
||||||
Rank playerRank = null;
|
Rank playerRank = null;
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
playerRank = rankups.getRank((Player) sender);
|
playerRank = rankups.getByPlayer((Player) sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER);
|
sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER);
|
||||||
|
|
||||||
Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
||||||
Rank rank = rankups.getFirstRank();
|
Rank rank = rankups.getFirst();
|
||||||
do {
|
do {
|
||||||
Rank next = rankups.nextRank(rank);
|
Rank next = rankups.next(rank);
|
||||||
if (rank.equals(playerRank)) {
|
if (rank.equals(playerRank)) {
|
||||||
sendMessage(sender, Message.RANKS_CURRENT, rank, next);
|
sendMessage(sender, Message.RANKS_CURRENT, rank, next);
|
||||||
message = Message.RANKS_INCOMPLETE;
|
message = Message.RANKS_INCOMPLETE;
|
||||||
@@ -37,7 +37,7 @@ public class RankListCommand implements CommandExecutor {
|
|||||||
sendMessage(sender, message, rank, next);
|
sendMessage(sender, message, rank, next);
|
||||||
}
|
}
|
||||||
rank = next;
|
rank = next;
|
||||||
} while (!rank.isLastRank());
|
} while (!rank.isLast());
|
||||||
|
|
||||||
sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
|
sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
|
||||||
return true;
|
return true;
|
||||||
@@ -49,14 +49,14 @@ public class RankListCommand implements CommandExecutor {
|
|||||||
if (rank == null) {
|
if (rank == null) {
|
||||||
builder.replace(Variable.PLAYER, sender.getName());
|
builder.replace(Variable.PLAYER, sender.getName());
|
||||||
} else {
|
} else {
|
||||||
builder.replaceAll(sender, rank);
|
builder.replaceRanks(sender, rank);
|
||||||
}
|
}
|
||||||
builder.send(sender);
|
builder.send(sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
private void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
||||||
plugin.replaceMoneyRequirements(plugin.getMessage(oldRank, message)
|
plugin.replaceMoneyRequirements(plugin.getMessage(oldRank, message)
|
||||||
.replaceAll(player, oldRank, rank), player, oldRank)
|
.replaceRanks(player, oldRank, rank), player, oldRank)
|
||||||
.send(player);
|
.send(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -34,7 +34,7 @@ public class RankupCommand implements CommandExecutor {
|
|||||||
Player player = (Player) sender;
|
Player player = (Player) sender;
|
||||||
|
|
||||||
Rankups rankups = plugin.getRankups();
|
Rankups rankups = plugin.getRankups();
|
||||||
Rank rank = rankups.getRank(player);
|
Rank rank = rankups.getByPlayer(player);
|
||||||
if (!plugin.checkRankup(player)) {
|
if (!plugin.checkRankup(player)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -55,11 +55,11 @@ public class RankupCommand implements CommandExecutor {
|
|||||||
case "text":
|
case "text":
|
||||||
confirming.put(player, System.currentTimeMillis());
|
confirming.put(player, System.currentTimeMillis());
|
||||||
plugin.replaceMoneyRequirements(plugin.getMessage(rank, Message.CONFIRMATION)
|
plugin.replaceMoneyRequirements(plugin.getMessage(rank, Message.CONFIRMATION)
|
||||||
.replaceAll(player, rank, rankups.nextRank(rank)), player, rank)
|
.replaceRanks(player, rank, rankups.next(rank)), player, rank)
|
||||||
.send(player);
|
.send(player);
|
||||||
break;
|
break;
|
||||||
case "gui":
|
case "gui":
|
||||||
Gui.of(player, rank, rankups.nextRank(rank), plugin).open(player);
|
Gui.of(player, rank, rankups.next(rank), plugin).open(player);
|
||||||
break;
|
break;
|
||||||
case "none":
|
case "none":
|
||||||
plugin.rankup(player);
|
plugin.rankup(player);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.bukkit.inventory.meta.ItemMeta;
|
|||||||
import sh.okx.rankup.Rankup;
|
import sh.okx.rankup.Rankup;
|
||||||
import sh.okx.rankup.messages.Message;
|
import sh.okx.rankup.messages.Message;
|
||||||
import sh.okx.rankup.messages.MessageBuilder;
|
import sh.okx.rankup.messages.MessageBuilder;
|
||||||
|
import sh.okx.rankup.prestige.Prestige;
|
||||||
import sh.okx.rankup.ranks.Rank;
|
import sh.okx.rankup.ranks.Rank;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -28,6 +29,8 @@ public class Gui implements InventoryHolder {
|
|||||||
private ItemStack rankup;
|
private ItemStack rankup;
|
||||||
@Getter
|
@Getter
|
||||||
private ItemStack cancel;
|
private ItemStack cancel;
|
||||||
|
@Getter
|
||||||
|
private boolean prestige;
|
||||||
|
|
||||||
public static Gui of(Player player, Rank oldRank, Rank rank, Rankup plugin) {
|
public static Gui of(Player player, Rank oldRank, Rank rank, Rankup plugin) {
|
||||||
ConfigurationSection config = plugin.getConfig().getConfigurationSection("gui");
|
ConfigurationSection config = plugin.getConfig().getConfigurationSection("gui");
|
||||||
@@ -39,11 +42,18 @@ public class Gui implements InventoryHolder {
|
|||||||
Gui gui = new Gui();
|
Gui gui = new Gui();
|
||||||
gui.rankup = getItem(config.getConfigurationSection("rankup"), player, oldRank, rank);
|
gui.rankup = getItem(config.getConfigurationSection("rankup"), player, oldRank, rank);
|
||||||
gui.cancel = getItem(config.getConfigurationSection("cancel"), player, oldRank, rank);
|
gui.cancel = getItem(config.getConfigurationSection("cancel"), player, oldRank, rank);
|
||||||
Inventory inventory = Bukkit.createInventory(gui,
|
|
||||||
items.length,
|
MessageBuilder builder = plugin.getMessage(rank, Message.TITLE)
|
||||||
plugin.getMessage(rank, Message.TITLE)
|
.replaceRanks(player, oldRank, rank);
|
||||||
.replaceAll(player, oldRank, rank)
|
if(oldRank instanceof Prestige) {
|
||||||
.toString());
|
gui.prestige = true;
|
||||||
|
builder.replaceFromTo((Prestige) oldRank);
|
||||||
|
} else {
|
||||||
|
gui.prestige = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Inventory inventory = Bukkit.createInventory(gui, items.length, builder.toString());
|
||||||
inventory.setContents(items);
|
inventory.setContents(items);
|
||||||
gui.inventory = inventory;
|
gui.inventory = inventory;
|
||||||
return gui;
|
return gui;
|
||||||
@@ -90,7 +100,7 @@ public class Gui implements InventoryHolder {
|
|||||||
|
|
||||||
private static String format(String message, Player player, Rank oldRank, Rank rank) {
|
private static String format(String message, Player player, Rank oldRank, Rank rank) {
|
||||||
return new MessageBuilder(ChatColor.translateAlternateColorCodes('&', message))
|
return new MessageBuilder(ChatColor.translateAlternateColorCodes('&', message))
|
||||||
.replaceAll(player, oldRank, rank)
|
.replaceRanks(player, oldRank, rank)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,11 @@ public class GuiListener implements Listener {
|
|||||||
|
|
||||||
if (gui.getRankup().isSimilar(e.getCurrentItem())) {
|
if (gui.getRankup().isSimilar(e.getCurrentItem())) {
|
||||||
Bukkit.getScheduler().runTask(plugin, player::closeInventory);
|
Bukkit.getScheduler().runTask(plugin, player::closeInventory);
|
||||||
plugin.rankup(player);
|
if(gui.isPrestige()) {
|
||||||
|
plugin.prestige(player);
|
||||||
|
} else {
|
||||||
|
plugin.rankup(player);
|
||||||
|
}
|
||||||
} else if (gui.getCancel().isSimilar(e.getCurrentItem())) {
|
} else if (gui.getCancel().isSimilar(e.getCurrentItem())) {
|
||||||
Bukkit.getScheduler().runTask(plugin, player::closeInventory);
|
Bukkit.getScheduler().runTask(plugin, player::closeInventory);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ public enum Message {
|
|||||||
RANKS_CURRENT("rankup.ranks.current"),
|
RANKS_CURRENT("rankup.ranks.current"),
|
||||||
RANKS_INCOMPLETE("rankup.ranks.incomplete"),
|
RANKS_INCOMPLETE("rankup.ranks.incomplete"),
|
||||||
COOLDOWN_SINGULAR("rankup.cooldown.singular"),
|
COOLDOWN_SINGULAR("rankup.cooldown.singular"),
|
||||||
COOLDOWN_PLURAL("rankup.cooldown.plural");
|
COOLDOWN_PLURAL("rankup.cooldown.plural"),
|
||||||
|
NOT_HIGH_ENOUGH("rankup.not-high-enough"),
|
||||||
|
MUST_PRESTIGE("rankup.must-prestige");
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import org.bukkit.ChatColor;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import sh.okx.rankup.prestige.Prestige;
|
||||||
import sh.okx.rankup.ranks.Rank;
|
import sh.okx.rankup.ranks.Rank;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -32,32 +33,37 @@ public class MessageBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceAll(CommandSender player, Rank rank) {
|
public MessageBuilder replaceRanks(CommandSender player, Rank rank) {
|
||||||
replace(Variable.PLAYER, player.getName());
|
replace(Variable.PLAYER, player.getName());
|
||||||
replaceAll(rank);
|
replaceRanks(rank);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceAll(CommandSender player, Rank oldRank, Rank rank) {
|
public MessageBuilder replaceRanks(CommandSender player, Rank oldRank, Rank rank) {
|
||||||
replace(Variable.PLAYER, player.getName());
|
replace(Variable.PLAYER, player.getName());
|
||||||
replaceAll(oldRank, rank);
|
replaceRanks(oldRank, rank);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceAll(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.getName());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceAll(Rank oldRank, Rank rank) {
|
public MessageBuilder replaceRanks(Rank oldRank, Rank rank) {
|
||||||
replace(Variable.RANK, rank.getRank());
|
replaceRanks(rank);
|
||||||
replace(Variable.RANK_NAME, rank.getName());
|
|
||||||
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.getName());
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MessageBuilder replaceFromTo(Prestige prestige) {
|
||||||
|
replace(Variable.FROM, prestige.getFrom());
|
||||||
|
replace(Variable.TO, prestige.getTo());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fails the MessageBuilder if the message is empty.
|
* Fails the MessageBuilder if the message is empty.
|
||||||
* if this fails, all subsequent calls to that MessageBuilder will do nothing
|
* if this fails, all subsequent calls to that MessageBuilder will do nothing
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ public enum Variable {
|
|||||||
OLD_RANK_NAME,
|
OLD_RANK_NAME,
|
||||||
RANK,
|
RANK,
|
||||||
RANK_NAME,
|
RANK_NAME,
|
||||||
|
FROM,
|
||||||
|
TO,
|
||||||
MONEY,
|
MONEY,
|
||||||
MONEY_NEEDED,
|
MONEY_NEEDED,
|
||||||
AMOUNT,
|
AMOUNT,
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
params = params.toLowerCase();
|
params = params.toLowerCase();
|
||||||
|
|
||||||
Rankups rankups = plugin.getRankups();
|
Rankups rankups = plugin.getRankups();
|
||||||
Rank rank = rankups.getRank(player);
|
Rank rank = rankups.getByPlayer(player);
|
||||||
Rank next = rank == null ? null : rankups.nextRank(rank);
|
Rank next = rank == null ? null : rankups.next(rank);
|
||||||
|
|
||||||
if (params.startsWith("requirement_")) {
|
if (params.startsWith("requirement_")) {
|
||||||
String[] parts = params.split("_", 3);
|
String[] parts = params.split("_", 3);
|
||||||
@@ -44,10 +44,10 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
parts[1], parts.length > 2 ? parts[2] : "");
|
parts[1], parts.length > 2 ? parts[2] : "");
|
||||||
} else if (params.startsWith("rank_requirement_")) {
|
} else if (params.startsWith("rank_requirement_")) {
|
||||||
String[] parts = params.split("_", 4);
|
String[] parts = params.split("_", 4);
|
||||||
return simpleFormat.format(orElse(rankups.getRank(parts[2]).getRequirement(parts[3]), Requirement::getValueDouble, 0));
|
return simpleFormat.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("_", 3);
|
String[] parts = params.split("_", 3);
|
||||||
return plugin.formatMoney(rankups.getRank(parts[2]).getRequirement("money").getValueDouble());
|
return plugin.formatMoney(rankups.getByName(parts[2]).getRequirement("money").getValueDouble());
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (params) {
|
switch (params) {
|
||||||
|
|||||||
@@ -1,4 +1,65 @@
|
|||||||
package sh.okx.rankup.prestige;
|
package sh.okx.rankup.prestige;
|
||||||
|
|
||||||
public class Prestige {
|
import lombok.Getter;
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import sh.okx.rankup.Rankup;
|
||||||
|
import sh.okx.rankup.ranks.Rank;
|
||||||
|
import sh.okx.rankup.requirements.Operation;
|
||||||
|
import sh.okx.rankup.requirements.Requirement;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Prestige extends Rank {
|
||||||
|
@Getter
|
||||||
|
private final String from;
|
||||||
|
@Getter
|
||||||
|
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) {
|
||||||
|
super(plugin, name, next, rank, requirements, operation, commands);
|
||||||
|
this.from = from;
|
||||||
|
this.to = to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Prestige deserialize(Rankup plugin, ConfigurationSection section) {
|
||||||
|
Set<Requirement> requirements = new HashSet<>();
|
||||||
|
Operation operation = null;
|
||||||
|
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
|
||||||
|
|
||||||
|
if (requirementsSection != null) {
|
||||||
|
requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
||||||
|
operation = plugin.getOperationRegistry().getOperation(section.getString("operation"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Prestige(plugin,
|
||||||
|
section.getName(),
|
||||||
|
section.getString("next"),
|
||||||
|
section.getString("rank"),
|
||||||
|
requirements,
|
||||||
|
operation,
|
||||||
|
section.getStringList("commands"),
|
||||||
|
section.getString("from"),
|
||||||
|
section.getString("to"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEligable(Player player) {
|
||||||
|
String[] groups = plugin.getPermissions().getPlayerGroups(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package sh.okx.rankup.prestige;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import sh.okx.rankup.RankList;
|
||||||
|
import sh.okx.rankup.Rankup;
|
||||||
|
|
||||||
|
public class Prestiges extends RankList<Prestige> {
|
||||||
|
public Prestiges(Rankup plugin, FileConfiguration config) {
|
||||||
|
super(plugin, config, section -> Prestige.deserialize(plugin, section));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Prestige getByPlayer(Player player) {
|
||||||
|
return ranks.stream()
|
||||||
|
.filter(rank -> rank.isIn(player))
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(this::getFirst);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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 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.messages.Variable;
|
|
||||||
import sh.okx.rankup.requirements.DeductibleRequirement;
|
import sh.okx.rankup.requirements.DeductibleRequirement;
|
||||||
import sh.okx.rankup.requirements.Operation;
|
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.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
|
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
|
||||||
public class Rank {
|
public class Rank {
|
||||||
private final Rankup plugin;
|
protected final Rankup plugin;
|
||||||
@Getter
|
@Getter
|
||||||
private final String name;
|
protected final String name;
|
||||||
@Getter
|
@Getter
|
||||||
private final String next;
|
protected final String next;
|
||||||
@Getter
|
@Getter
|
||||||
private final String rank;
|
protected final String rank;
|
||||||
@Getter
|
@Getter
|
||||||
private final Set<Requirement> requirements;
|
protected final Set<Requirement> requirements;
|
||||||
private final Operation operation;
|
protected final Operation operation;
|
||||||
private 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) {
|
||||||
String rank = section.getString("rank");
|
|
||||||
|
|
||||||
Set<Requirement> requirements = new HashSet<>();
|
Set<Requirement> requirements = new HashSet<>();
|
||||||
Operation operation = null;
|
Operation operation = null;
|
||||||
ConfigurationSection requirementsSection = section.getConfigurationSection("requirements");
|
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");
|
if (requirementsSection != null) {
|
||||||
operation = plugin.getOperationRegistry().getOperation(operationName);
|
requirements = plugin.getRequirementRegistry().getRequirements(requirementsSection);
|
||||||
|
operation = plugin.getOperationRegistry().getOperation(section.getString("operation"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Rank(plugin,
|
return new Rank(plugin,
|
||||||
section.getName(),
|
section.getName(),
|
||||||
section.getString("next"),
|
section.getString("next"),
|
||||||
rank,
|
section.getString("rank"),
|
||||||
requirements,
|
requirements,
|
||||||
operation,
|
operation,
|
||||||
section.getStringList("commands"));
|
section.getStringList("commands"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkRequirements(Player player) {
|
public boolean hasRequirements(Player player) {
|
||||||
return operation.check(requirements.stream()
|
return operation.check(requirements.stream()
|
||||||
.map(requirement -> requirement.check(player))
|
.map(requirement -> requirement.check(player))
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInRank(Player player) {
|
public boolean isIn(Player player) {
|
||||||
String[] groups = plugin.getPermissions().getPlayerGroups(player);
|
String[] groups = plugin.getPermissions().getPlayerGroups(player);
|
||||||
for (String group : groups) {
|
for (String group : groups) {
|
||||||
if (group.equalsIgnoreCase(rank)) {
|
if (group.equalsIgnoreCase(rank)) {
|
||||||
@@ -81,7 +66,7 @@ public class Rank {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLastRank() {
|
public boolean isLast() {
|
||||||
return next == null;
|
return next == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,13 +89,8 @@ public class Rank {
|
|||||||
|
|
||||||
public void runCommands(Player player, Rank nextRank) {
|
public void runCommands(Player player, Rank nextRank) {
|
||||||
for (String command : commands) {
|
for (String command : commands) {
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), new MessageBuilder(command)
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(),
|
||||||
.replace(Variable.PLAYER, player.getName())
|
new MessageBuilder(command).replaceRanks(player, this, nextRank).toString());
|
||||||
.replace(Variable.OLD_RANK, rank)
|
|
||||||
.replace(Variable.OLD_RANK_NAME, name)
|
|
||||||
.replace(Variable.RANK, nextRank.rank)
|
|
||||||
.replace(Variable.RANK_NAME, nextRank.name)
|
|
||||||
.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,80 +1,11 @@
|
|||||||
package sh.okx.rankup.ranks;
|
package sh.okx.rankup.ranks;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import sh.okx.rankup.RankList;
|
||||||
import sh.okx.rankup.Rankup;
|
import sh.okx.rankup.Rankup;
|
||||||
|
|
||||||
import java.util.HashSet;
|
public class Rankups extends RankList<Rank> {
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class Rankups {
|
|
||||||
@Getter
|
|
||||||
private final FileConfiguration config;
|
|
||||||
private final Set<Rank> ranks = new HashSet<>();
|
|
||||||
|
|
||||||
public Rankups(Rankup plugin, FileConfiguration config) {
|
public Rankups(Rankup plugin, FileConfiguration config) {
|
||||||
this.config = config;
|
super(plugin, config, section -> Rank.deserialize(plugin, section));
|
||||||
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
|
||||||
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
|
|
||||||
ranks.add(Rank.deserialize(plugin, rankSection));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
package sh.okx.rankup.requirements;
|
package sh.okx.rankup.requirements;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class OperationRegistry {
|
public class OperationRegistry {
|
||||||
private Map<String, Operation> operations;
|
private Map<String, Operation> operations = new HashMap<>();
|
||||||
|
|
||||||
public void addOperation(String name, Operation operation) {
|
public void addOperation(String name, Operation operation) {
|
||||||
operations.put(name.toLowerCase(), operation);
|
operations.put(name.toLowerCase(), operation);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Operation getOperation(String name) {
|
public Operation getOperation(String name) {
|
||||||
return operations.get(name.toLowerCase());
|
return operations.get(name == null ? "all" : name.toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
package sh.okx.rankup.requirements;
|
package sh.okx.rankup.requirements;
|
||||||
|
|
||||||
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class RequirementRegistry {
|
public class RequirementRegistry {
|
||||||
@@ -20,4 +24,28 @@ public class RequirementRegistry {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Requirement> getRequirements(ConfigurationSection section) {
|
||||||
|
Set<Requirement> requirements = new HashSet<>();
|
||||||
|
|
||||||
|
for (Map.Entry<String, Object> entry : section.getValues(false).entrySet()) {
|
||||||
|
String name = entry.getKey();
|
||||||
|
String value = String.valueOf(entry.getValue());
|
||||||
|
Requirement requirement = newRequirement(name, value);
|
||||||
|
if (requirement == null) {
|
||||||
|
System.err.println("Unknown requirement: " + name);
|
||||||
|
} else {
|
||||||
|
requirements.add(requirement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return requirements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void apply(Player player, Set<Requirement> requirements) {
|
||||||
|
for (Requirement requirement : requirements) {
|
||||||
|
if (requirement instanceof DeductibleRequirement) {
|
||||||
|
((DeductibleRequirement) requirement).apply(player);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ version: 0
|
|||||||
# you will have to restart your server.
|
# you will have to restart your server.
|
||||||
ranks: true
|
ranks: true
|
||||||
|
|
||||||
|
# whether or not prestiging should be enabled.
|
||||||
|
prestige: true
|
||||||
|
|
||||||
# how people should confirm ranking up
|
# how people should confirm ranking up
|
||||||
# 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
|
# how long in seconds people have to wait between a /rankup and a /prestige
|
||||||
# only successful rankups start the cooldown.
|
# only successful rankups and prestiges start the cooldown.
|
||||||
# set to 0 to disable.
|
# set to 0 to disable.
|
||||||
cooldown: 1
|
cooldown: 1
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# the messages in this section can be customised for each rankup in rankups.yml.
|
# the messages in this section can be customised for each rankup in rankups.yml.
|
||||||
rankup:
|
rankup:
|
||||||
# NOTE: if you are using requirements for your ranks that are NOT money,
|
|
||||||
# you will want to change this for each rank!
|
|
||||||
requirements-not-met: "&cYou need {MONEY} money to rankup."
|
requirements-not-met: "&cYou need {MONEY} money to rankup."
|
||||||
no-rankup: "&eYou are at the highest rank."
|
no-rankup: "&eYou are at the highest rank."
|
||||||
# set to an empty string, ie: success-public: ""
|
# set to an empty string, ie: success-public: ""
|
||||||
@@ -15,6 +13,9 @@ rankup:
|
|||||||
# used for the GUI confirmation
|
# used for the GUI confirmation
|
||||||
title: "Rankup to {RANK}"
|
title: "Rankup to {RANK}"
|
||||||
|
|
||||||
|
not-high-enough: "&cYou cannot prestige at your rank!"
|
||||||
|
must-prestige: "&cYou must prestige to /rankup further!"
|
||||||
|
|
||||||
# you can (and probably should) you override these in rankups.yml
|
# you can (and probably should) you override these in rankups.yml
|
||||||
# to show the specific requirements for each rank.
|
# to show the specific requirements for each rank.
|
||||||
# however if you are just using money or don't need to change the message per rank, you can use any combination of:
|
# however if you are just using money or don't need to change the message per rank, you can use any combination of:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: Rankup
|
name: Rankup
|
||||||
version: 3.0-alpha.19
|
version: 3.0-alpha.20
|
||||||
main: sh.okx.rankup.Rankup
|
main: sh.okx.rankup.Rankup
|
||||||
author: Okx
|
author: Okx
|
||||||
depend: [Vault]
|
depend: [Vault]
|
||||||
@@ -18,6 +18,9 @@ commands:
|
|||||||
ranks:
|
ranks:
|
||||||
permission: rankup.ranks
|
permission: rankup.ranks
|
||||||
description: List all the ranks.
|
description: List all the ranks.
|
||||||
|
prestige:
|
||||||
|
permission: rankup.prestige
|
||||||
|
description: Prestige.
|
||||||
permissions:
|
permissions:
|
||||||
rankup.*:
|
rankup.*:
|
||||||
children:
|
children:
|
||||||
@@ -27,6 +30,7 @@ permissions:
|
|||||||
rankup.ranks: true
|
rankup.ranks: true
|
||||||
rankup.reload: true
|
rankup.reload: true
|
||||||
rankup.ranks: true
|
rankup.ranks: true
|
||||||
|
rankup.prestige: true
|
||||||
rankup.info:
|
rankup.info:
|
||||||
default: true
|
default: true
|
||||||
rankup.rankup:
|
rankup.rankup:
|
||||||
@@ -38,4 +42,6 @@ permissions:
|
|||||||
rankup.reload:
|
rankup.reload:
|
||||||
default: op
|
default: op
|
||||||
rankup.ranks:
|
rankup.ranks:
|
||||||
|
default: true
|
||||||
|
rankup.prestige:
|
||||||
default: true
|
default: true
|
||||||
@@ -1,20 +1,24 @@
|
|||||||
P1example:
|
first:
|
||||||
# the rank people must be to use this prestige
|
# the rank people must be to use this prestige
|
||||||
from: 'D'
|
from: 'D'
|
||||||
# the rank to change it to
|
# the rank to change it to
|
||||||
to: 'A'
|
to: 'A'
|
||||||
# the rank to also add
|
next: 'P2example'
|
||||||
rank: 'P1'
|
# see rankups.yml for more information on requirements, operations, commands and messages
|
||||||
# requirements are the same as in rankups.yml
|
|
||||||
requirements:
|
requirements:
|
||||||
money: 10000
|
money: 10000
|
||||||
# optional
|
# optional, defaults to all
|
||||||
operation: all
|
operation: all
|
||||||
# commands & prestige messages can be added as per rankups.yml too.
|
|
||||||
P1example:
|
P1example:
|
||||||
from: 'D'
|
from: 'D'
|
||||||
to: 'A'
|
to: 'A'
|
||||||
rank: 'P2'
|
# the rank add to indicate this prestige
|
||||||
|
rank: 'P1'
|
||||||
|
next: 'P2example'
|
||||||
requirements:
|
requirements:
|
||||||
money: 20000
|
money: 20000
|
||||||
xp-level: 5
|
xp-level: 5
|
||||||
|
P2example:
|
||||||
|
from: 'D'
|
||||||
|
to: 'A'
|
||||||
|
rank: 'P2'
|
||||||
Reference in New Issue
Block a user