add placeholders for confirmation message
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'sh.okx'
|
||||
version '3.0-alpha.16'
|
||||
version '3.0-alpha.17'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
@@ -24,9 +25,9 @@ import sh.okx.rankup.messages.Variable;
|
||||
import sh.okx.rankup.placeholders.Placeholders;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.ranks.Rankups;
|
||||
import sh.okx.rankup.ranks.requirements.GroupRequirement;
|
||||
import sh.okx.rankup.ranks.requirements.MoneyRequirement;
|
||||
import sh.okx.rankup.ranks.requirements.PlaytimeMinutesRequirement;
|
||||
import sh.okx.rankup.ranks.requirements.GroupRequirement;
|
||||
import sh.okx.rankup.ranks.requirements.Requirement;
|
||||
import sh.okx.rankup.ranks.requirements.RequirementRegistry;
|
||||
import sh.okx.rankup.ranks.requirements.XpLevelRequirement;
|
||||
@@ -241,18 +242,9 @@ public class Rankup extends JavaPlugin {
|
||||
.send(player);
|
||||
return false;
|
||||
} else if (!rank.checkRequirements(player)) { // check if they can afford it
|
||||
MessageBuilder builder =
|
||||
getMessage(rank, Message.REQUIREMENTS_NOT_MET)
|
||||
.replaceAll(player, rank, rankups.nextRank(rank));
|
||||
if (economy != null) {
|
||||
double balance = economy.getBalance(player);
|
||||
double amount = rank.getRequirement("money").getValueDouble();
|
||||
builder = builder
|
||||
.replace(Variable.MONEY, formatMoney(amount))
|
||||
.replace(Variable.MONEY_NEEDED, formatMoney(Math.max(0, amount - balance)));
|
||||
}
|
||||
replaceRequirements(player, builder, rank);
|
||||
builder.send(player);
|
||||
replaceMoneyRequirements(getMessage(rank, Message.REQUIREMENTS_NOT_MET)
|
||||
.replaceAll(player, rank, rankups.nextRank(rank)), player, rank)
|
||||
.send(player);
|
||||
return false;
|
||||
} else if (cooldowns.containsKey(player)) {
|
||||
long time = System.currentTimeMillis() - cooldowns.get(player);
|
||||
@@ -274,7 +266,25 @@ public class Rankup extends JavaPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void replaceRequirements(Player player, MessageBuilder builder, Rank rank) {
|
||||
public MessageBuilder replaceMoneyRequirements(MessageBuilder builder, CommandSender sender, Rank rank) {
|
||||
Requirement money = rank.getRequirement("money");
|
||||
Double amount = null;
|
||||
if (sender instanceof Player && rank.isInRank((Player) sender)) {
|
||||
if (money != null && economy != null) {
|
||||
amount = money.getRemaining((Player) sender);
|
||||
}
|
||||
replaceRequirements(builder, (Player) sender, rank);
|
||||
} else {
|
||||
amount = money.getValueDouble();
|
||||
}
|
||||
if (amount != null && economy != null) {
|
||||
builder.replace(Variable.MONEY_NEEDED, formatMoney(amount));
|
||||
builder.replace(Variable.MONEY, formatMoney(money.getValueDouble()));
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
public MessageBuilder replaceRequirements(MessageBuilder builder, Player player, Rank rank) {
|
||||
DecimalFormat simpleFormat = placeholders.getSimpleFormat();
|
||||
DecimalFormat percentFormat = placeholders.getPercentFormat();
|
||||
for (Requirement requirement : rank.getRequirements()) {
|
||||
@@ -286,6 +296,7 @@ public class Rankup extends JavaPlugin {
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
private void replaceRequirements(MessageBuilder builder, Variable variable, Requirement requirement, Supplier<Object> value) {
|
||||
|
||||
@@ -17,8 +17,8 @@ import java.net.URL;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class InfoCommand implements CommandExecutor {
|
||||
private String versionMessage;
|
||||
private final Rankup plugin;
|
||||
private String versionMessage;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import sh.okx.rankup.messages.MessageBuilder;
|
||||
import sh.okx.rankup.messages.Variable;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.ranks.Rankups;
|
||||
import sh.okx.rankup.ranks.requirements.Requirement;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class RankListCommand implements CommandExecutor {
|
||||
@@ -56,27 +55,8 @@ public class RankListCommand implements CommandExecutor {
|
||||
}
|
||||
|
||||
private void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
||||
replaceRequirements(plugin.getMessage(oldRank, message)
|
||||
plugin.replaceMoneyRequirements(plugin.getMessage(oldRank, message)
|
||||
.replaceAll(player, oldRank, rank), player, oldRank)
|
||||
.send(player);
|
||||
}
|
||||
|
||||
private MessageBuilder replaceRequirements(MessageBuilder builder, CommandSender sender, Rank rank) {
|
||||
Requirement money = rank.getRequirement("money");
|
||||
Double amount = null;
|
||||
if(sender instanceof Player && rank.isInRank((Player) sender)) {
|
||||
if(money != null && plugin.getEconomy() != null) {
|
||||
amount = money.getRemaining((Player) sender);
|
||||
}
|
||||
plugin.replaceRequirements((Player) sender, builder, rank);
|
||||
} else {
|
||||
amount = money.getValueDouble();
|
||||
}
|
||||
if(amount != null && plugin.getEconomy() != null) {
|
||||
builder.replace(Variable.MONEY_NEEDED, plugin.formatMoney(amount));
|
||||
builder.replace(Variable.MONEY, plugin.formatMoney(money.getValueDouble()));
|
||||
}
|
||||
return builder;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ public class RankupCommand implements CommandExecutor {
|
||||
switch (confirmationType) {
|
||||
case "text":
|
||||
confirming.put(player, System.currentTimeMillis());
|
||||
plugin.getMessage(rank, Message.CONFIRMATION)
|
||||
.replaceAll(player, rank, rankups.nextRank(rank))
|
||||
plugin.replaceMoneyRequirements(plugin.getMessage(rank, Message.CONFIRMATION)
|
||||
.replaceAll(player, rank, rankups.nextRank(rank)), player, rank)
|
||||
.send(player);
|
||||
break;
|
||||
case "gui":
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import sh.okx.rankup.Rankup;
|
||||
import sh.okx.rankup.messages.Message;
|
||||
import sh.okx.rankup.messages.MessageBuilder;
|
||||
import sh.okx.rankup.messages.Variable;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -30,10 +29,6 @@ public class Gui implements InventoryHolder {
|
||||
@Getter
|
||||
private ItemStack cancel;
|
||||
|
||||
public void open(Player player) {
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
public static Gui of(Player player, Rank oldRank, Rank rank, Rankup plugin) {
|
||||
ConfigurationSection config = plugin.getConfig().getConfigurationSection("gui");
|
||||
ItemStack[] items = new ItemStack[config.getInt("rows") * 9];
|
||||
@@ -118,4 +113,8 @@ public class Gui implements InventoryHolder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void open(Player player) {
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public abstract class DeductibleRequirement extends Requirement {
|
||||
* For money, this could be taking money away from the player.
|
||||
* You can assume that <code>Requirement#check(Player)</code> has been called,
|
||||
* and has returned true immediately prior to this.
|
||||
*
|
||||
* @param player the player to take from
|
||||
*/
|
||||
public abstract void apply(Player player);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package sh.okx.rankup.ranks.requirements;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.Player;
|
||||
import sh.okx.rankup.Rankup;
|
||||
|
||||
@@ -43,6 +42,7 @@ public abstract class Requirement implements Cloneable {
|
||||
|
||||
/**
|
||||
* Check if a player meets this requirement
|
||||
*
|
||||
* @param player the player to check
|
||||
* @return true if they meet the requirement, false otherwise
|
||||
*/
|
||||
@@ -51,11 +51,13 @@ public abstract class Requirement implements Cloneable {
|
||||
/**
|
||||
* Get the remaining amount needed for <code>Requirement#check(Player)</code> to yield true.
|
||||
* This is not required and is only used in placeholders.
|
||||
*
|
||||
* @param player the player to find the remaining amount of
|
||||
* @return the remaining amount needed. Should be non-negative.
|
||||
*/
|
||||
public double getRemaining(Player player) {
|
||||
return getValueDouble();
|
||||
}
|
||||
|
||||
public abstract Requirement clone();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: Rankup
|
||||
version: 3.0-alpha.16
|
||||
version: 3.0-alpha.17
|
||||
main: sh.okx.rankup.Rankup
|
||||
author: Okx
|
||||
depend: [Vault]
|
||||
|
||||
Reference in New Issue
Block a user