misc. changes (check description)
rename SECONDS to SECONDS_LEFT, and add SECONDS. add %rankup_rank_money_left_<rank>% placeholder add permission requirement
This commit is contained in:
@@ -37,6 +37,7 @@ import sh.okx.rankup.requirements.operation.NoneOperation;
|
|||||||
import sh.okx.rankup.requirements.operation.OneOperation;
|
import sh.okx.rankup.requirements.operation.OneOperation;
|
||||||
import sh.okx.rankup.requirements.requirement.GroupRequirement;
|
import sh.okx.rankup.requirements.requirement.GroupRequirement;
|
||||||
import sh.okx.rankup.requirements.requirement.MoneyRequirement;
|
import sh.okx.rankup.requirements.requirement.MoneyRequirement;
|
||||||
|
import sh.okx.rankup.requirements.requirement.PermissionRequirement;
|
||||||
import sh.okx.rankup.requirements.requirement.PlaytimeMinutesRequirement;
|
import sh.okx.rankup.requirements.requirement.PlaytimeMinutesRequirement;
|
||||||
import sh.okx.rankup.requirements.requirement.XpLevelRequirement;
|
import sh.okx.rankup.requirements.requirement.XpLevelRequirement;
|
||||||
|
|
||||||
@@ -161,10 +162,11 @@ public class Rankup extends JavaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerRequirements() {
|
private void registerRequirements() {
|
||||||
requirementRegistry.addRequirement(new MoneyRequirement(this, "money"));
|
requirementRegistry.addRequirement(new MoneyRequirement(this));
|
||||||
requirementRegistry.addRequirement(new XpLevelRequirement(this, "xp-level"));
|
requirementRegistry.addRequirement(new XpLevelRequirement(this));
|
||||||
requirementRegistry.addRequirement(new PlaytimeMinutesRequirement(this, "playtime-minutes"));
|
requirementRegistry.addRequirement(new PlaytimeMinutesRequirement(this));
|
||||||
requirementRegistry.addRequirement(new GroupRequirement(this, "group"));
|
requirementRegistry.addRequirement(new GroupRequirement(this));
|
||||||
|
requirementRegistry.addRequirement(new PermissionRequirement(this));
|
||||||
|
|
||||||
operationRegistry.addOperation("all", new AllOperation());
|
operationRegistry.addOperation("all", new AllOperation());
|
||||||
operationRegistry.addOperation("none", new NoneOperation());
|
operationRegistry.addOperation("none", new NoneOperation());
|
||||||
@@ -215,6 +217,29 @@ public class Rankup extends JavaPlugin {
|
|||||||
return MessageBuilder.of(messages, message);
|
return MessageBuilder.of(messages, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean checkCooldown(Player player, Rank rank) {
|
||||||
|
if (cooldowns.containsKey(player)) {
|
||||||
|
long time = System.currentTimeMillis() - cooldowns.get(player);
|
||||||
|
// if time passed is less than the cooldown
|
||||||
|
long cooldownSeconds = config.getInt("cooldown");
|
||||||
|
long timeLeft = (cooldownSeconds * 1000) - time;
|
||||||
|
if (timeLeft > 0) {
|
||||||
|
long secondsLeft = (long) Math.ceil(timeLeft / 1000f);
|
||||||
|
getMessage(rank, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR)
|
||||||
|
.failIfEmpty()
|
||||||
|
.replaceRanks(player, rank)
|
||||||
|
.replaceFromTo(rank)
|
||||||
|
.replace(Variable.SECONDS, cooldownSeconds)
|
||||||
|
.replace(Variable.SECONDS_LEFT, secondsLeft)
|
||||||
|
.send(player);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// cooldown has expired so remove it
|
||||||
|
cooldowns.remove(player);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void applyCooldown(Player player) {
|
private void applyCooldown(Player player) {
|
||||||
if (config.getInt("cooldown") > 0) {
|
if (config.getInt("cooldown") > 0) {
|
||||||
cooldowns.put(player, System.currentTimeMillis());
|
cooldowns.put(player, System.currentTimeMillis());
|
||||||
@@ -278,22 +303,9 @@ public class Rankup extends JavaPlugin {
|
|||||||
.replaceRanks(player, rank, rankups.next(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 (checkCooldown(player, rank)) {
|
||||||
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(rank, secondsLeft > 1 ? Message.COOLDOWN_PLURAL : Message.COOLDOWN_SINGULAR)
|
|
||||||
.failIfEmpty()
|
|
||||||
.replaceRanks(player, rank)
|
|
||||||
.replace(Variable.SECONDS, secondsLeft)
|
|
||||||
.send(player);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// cooldown has expired so remove it
|
|
||||||
cooldowns.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -349,23 +361,9 @@ public class Rankup extends JavaPlugin {
|
|||||||
.replaceFromTo(prestige)
|
.replaceFromTo(prestige)
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (cooldowns.containsKey(player)) {
|
} else if (checkCooldown(player, prestige)) {
|
||||||
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)
|
|
||||||
.send(player);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// cooldown has expired so remove it
|
|
||||||
cooldowns.remove(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,20 +40,15 @@ public class Gui implements InventoryHolder {
|
|||||||
addItem(items, config.getConfigurationSection("fill"), player, oldRank, rank);
|
addItem(items, config.getConfigurationSection("fill"), player, oldRank, rank);
|
||||||
|
|
||||||
Gui gui = new Gui();
|
Gui gui = new Gui();
|
||||||
|
gui.prestige = oldRank instanceof Prestige;
|
||||||
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);
|
||||||
|
|
||||||
MessageBuilder builder = plugin.getMessage(rank, Message.TITLE)
|
Inventory inventory = Bukkit.createInventory(gui, items.length,
|
||||||
.replaceRanks(player, oldRank, rank);
|
plugin.getMessage(rank, Message.TITLE)
|
||||||
if(oldRank instanceof Prestige) {
|
.replaceRanks(player, oldRank, rank)
|
||||||
gui.prestige = true;
|
.replaceFromTo(oldRank)
|
||||||
builder.replaceFromTo((Prestige) oldRank);
|
.toString());
|
||||||
} 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;
|
||||||
|
|||||||
@@ -58,9 +58,12 @@ public class MessageBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageBuilder replaceFromTo(Prestige prestige) {
|
public MessageBuilder replaceFromTo(Rank rank) {
|
||||||
|
if(rank instanceof Prestige) {
|
||||||
|
Prestige prestige = (Prestige) rank;
|
||||||
replace(Variable.FROM, prestige.getFrom());
|
replace(Variable.FROM, prestige.getFrom());
|
||||||
replace(Variable.TO, prestige.getTo());
|
replace(Variable.TO, prestige.getTo());
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ public enum Variable {
|
|||||||
AMOUNT_NEEDED,
|
AMOUNT_NEEDED,
|
||||||
PERCENT_DONE,
|
PERCENT_DONE,
|
||||||
PERCENT_LEFT,
|
PERCENT_LEFT,
|
||||||
SECONDS;
|
SECONDS,
|
||||||
|
SECONDS_LEFT;
|
||||||
|
|
||||||
public String replace(String message, String value, String type) {
|
public String replace(String message, String value, String type) {
|
||||||
Pattern pattern = Pattern.compile("\\{" + type + "_" + this + "}", Pattern.CASE_INSENSITIVE);
|
Pattern pattern = Pattern.compile("\\{" + type + "_" + this + "}", Pattern.CASE_INSENSITIVE);
|
||||||
|
|||||||
@@ -46,8 +46,12 @@ public class Placeholders extends PlaceholderExpansion {
|
|||||||
String[] parts = params.split("_", 4);
|
String[] parts = params.split("_", 4);
|
||||||
return simpleFormat.format(orElse(rankups.getByName(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("_", 4);
|
||||||
return plugin.formatMoney(rankups.getByName(parts[2]).getRequirement("money").getValueDouble());
|
double amount = rankups.getByName(parts[2]).getRequirement("money").getValueDouble();
|
||||||
|
if(parts.length > 3 && parts[3].equalsIgnoreCase("left")) {
|
||||||
|
amount = amount - plugin.getEconomy().getBalance(player);
|
||||||
|
}
|
||||||
|
return plugin.formatMoney(Math.max(0, amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (params) {
|
switch (params) {
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import sh.okx.rankup.Rankup;
|
|||||||
import sh.okx.rankup.requirements.Requirement;
|
import sh.okx.rankup.requirements.Requirement;
|
||||||
|
|
||||||
public class GroupRequirement extends Requirement {
|
public class GroupRequirement extends Requirement {
|
||||||
public GroupRequirement(Rankup plugin, String name) {
|
public GroupRequirement(Rankup plugin) {
|
||||||
super(plugin, name);
|
super(plugin, "group");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected GroupRequirement(Requirement clone) {
|
protected GroupRequirement(Requirement clone) {
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ import sh.okx.rankup.requirements.DeductibleRequirement;
|
|||||||
import sh.okx.rankup.requirements.Requirement;
|
import sh.okx.rankup.requirements.Requirement;
|
||||||
|
|
||||||
public class MoneyRequirement extends DeductibleRequirement {
|
public class MoneyRequirement extends DeductibleRequirement {
|
||||||
public MoneyRequirement(Rankup plugin, String name) {
|
public MoneyRequirement(Rankup plugin) {
|
||||||
super(plugin, name);
|
super(plugin, "money");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected MoneyRequirement(Requirement clone) {
|
protected MoneyRequirement(Requirement clone) {
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package sh.okx.rankup.requirements.requirement;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import sh.okx.rankup.Rankup;
|
||||||
|
import sh.okx.rankup.requirements.Requirement;
|
||||||
|
|
||||||
|
public class PermissionRequirement extends Requirement {
|
||||||
|
public PermissionRequirement(Rankup plugin) {
|
||||||
|
super(plugin, "permission");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PermissionRequirement(Requirement clone) {
|
||||||
|
super(clone);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean check(Player player) {
|
||||||
|
for(String permission : getValueString().split(" ")) {
|
||||||
|
if(!player.hasPermission(permission)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Requirement clone() {
|
||||||
|
return new PermissionRequirement(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-2
@@ -9,8 +9,8 @@ public class PlaytimeMinutesRequirement extends Requirement {
|
|||||||
private static final int TICKS_PER_MINUTE = 20 * 60;
|
private static final int TICKS_PER_MINUTE = 20 * 60;
|
||||||
private Statistic playOneTick;
|
private Statistic playOneTick;
|
||||||
|
|
||||||
public PlaytimeMinutesRequirement(Rankup plugin, String name) {
|
public PlaytimeMinutesRequirement(Rankup plugin) {
|
||||||
super(plugin, name);
|
super(plugin, "playtime-minutes");
|
||||||
try {
|
try {
|
||||||
playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE");
|
playOneTick = Statistic.valueOf("PLAY_ONE_MINUTE");
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import sh.okx.rankup.requirements.DeductibleRequirement;
|
|||||||
import sh.okx.rankup.requirements.Requirement;
|
import sh.okx.rankup.requirements.Requirement;
|
||||||
|
|
||||||
public class XpLevelRequirement extends DeductibleRequirement {
|
public class XpLevelRequirement extends DeductibleRequirement {
|
||||||
public XpLevelRequirement(Rankup plugin, String name) {
|
public XpLevelRequirement(Rankup plugin) {
|
||||||
super(plugin, name);
|
super(plugin, "xp-level");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected XpLevelRequirement(Requirement clone) {
|
protected XpLevelRequirement(Requirement clone) {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ rankup:
|
|||||||
footer: ''
|
footer: ''
|
||||||
# sent when a player tries to rankup when they are on cooldown
|
# sent when a player tries to rankup when they are on cooldown
|
||||||
cooldown:
|
cooldown:
|
||||||
singular: '&cYou must wait {SECONDS} more second to rankup again.'
|
singular: '&cYou must wait {SECONDS_LEFT} more second to rankup again.'
|
||||||
plural: '&cYou must wait {SECONDS} more seconds to rankup again.'
|
plural: '&cYou must wait {SECONDS_LEFT} more seconds to rankup again.'
|
||||||
|
|
||||||
not-in-ladder: "&cSorry, but we could not find any rankups for the group(s) you are in."
|
not-in-ladder: "&cSorry, but we could not find any rankups for the group(s) you are in."
|
||||||
@@ -2,16 +2,13 @@ Aexample:
|
|||||||
# the name of the rank in your permissions plugin
|
# the name of the rank in your permissions plugin
|
||||||
rank: 'A'
|
rank: 'A'
|
||||||
# the next rank a player can rank up to.
|
# the next rank a player can rank up to.
|
||||||
# this must be the name of the configuration section.
|
# this must be the name of the configuration section, not the rank name.
|
||||||
# for example, the name of this configuration section is "Aexample".
|
# for example, the name of this configuration section is "Aexample".
|
||||||
# if this is the last rank, you don't need this.
|
# if this is the last rank, you don't need this.
|
||||||
next: 'Bexample'
|
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)
|
# (ie, this example will charge 1000 money to rankup from A to B)
|
||||||
# money: money from the server economy
|
# https://github.com/okx-code/Rankup3/wiki/Requirements
|
||||||
# xp-level: amount of experience levels
|
|
||||||
# playtime-minutes: minutes a player has played
|
|
||||||
# group: requires a player to have a certain group - separate by spaces to require multiple. note that the group is not removed.
|
|
||||||
# custom requirements can also be added by other plugins.
|
# custom requirements can also be added by other plugins.
|
||||||
requirements:
|
requirements:
|
||||||
money: 1000
|
money: 1000
|
||||||
|
|||||||
Reference in New Issue
Block a user