add option to disable /ranks, make config clearer

This commit is contained in:
okx-code
2018-08-28 19:38:09 +01:00
parent be5ee90036
commit 3fca80a79b
8 changed files with 34 additions and 34 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
} }
group 'sh.okx' group 'sh.okx'
version '3.0-alpha.10' version '3.0-alpha.12'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
+6 -4
View File
@@ -69,9 +69,11 @@ public class Rankup extends JavaPlugin {
} }
}); });
if(config.getBoolean("ranks")) {
getCommand("ranks").setExecutor(new RankListCommand(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));
getCommand("ranks").setExecutor(new RankListCommand(this));
getServer().getPluginManager().registerEvents(new GuiListener(this), this); getServer().getPluginManager().registerEvents(new GuiListener(this), this);
} }
@@ -226,7 +228,7 @@ public class Rankup extends JavaPlugin {
} else if (!rank.checkRequirements(player)) { // check if they can afford it } else if (!rank.checkRequirements(player)) { // check if they can afford it
MessageBuilder builder = MessageBuilder builder =
getMessage(rank, Message.REQUIREMENTS_NOT_MET) getMessage(rank, Message.REQUIREMENTS_NOT_MET)
.replaceAll(player, rank); .replaceAll(player, rank, rankups.nextRank(rank));
if (economy != null) { if (economy != null) {
double balance = economy.getBalance(player); double balance = economy.getBalance(player);
double amount = rank.getRequirement("money").getAmount(); double amount = rank.getRequirement("money").getAmount();
@@ -247,8 +249,8 @@ public class Rankup extends JavaPlugin {
for(Requirement requirement : rank.getRequirements()) { for(Requirement requirement : rank.getRequirements()) {
replaceRequirements(builder, Variable.AMOUNT, requirement, () -> simpleFormat.format(requirement.getAmount())); replaceRequirements(builder, Variable.AMOUNT, requirement, () -> simpleFormat.format(requirement.getAmount()));
replaceRequirements(builder, Variable.AMOUNT_NEEDED, requirement, () -> simpleFormat.format(requirement.getRemaining(player))); replaceRequirements(builder, Variable.AMOUNT_NEEDED, requirement, () -> simpleFormat.format(requirement.getRemaining(player)));
replaceRequirements(builder, Variable.PERCENT_LEFT, requirement, () -> percentFormat.format((requirement.getRemaining(player) / requirement.getAmount()) * 100)); replaceRequirements(builder, Variable.PERCENT_LEFT, requirement, () -> percentFormat.format(Math.max(0, (requirement.getRemaining(player) / requirement.getAmount()) * 100)));
replaceRequirements(builder, Variable.PERCENT_DONE, requirement, () -> percentFormat.format((1-(requirement.getRemaining(player) / requirement.getAmount())) * 100)); replaceRequirements(builder, Variable.PERCENT_DONE, requirement, () -> percentFormat.format(Math.min(100, (1-(requirement.getRemaining(player) / requirement.getAmount())) * 100)));
} }
} }
@@ -27,15 +27,15 @@ public class RankListCommand implements CommandExecutor {
sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER); sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER);
int state = playerRank == null ? 2 : 0; Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
Rank rank = rankups.getFirstRank(); Rank rank = rankups.getFirstRank();
do { do {
Rank next = rankups.nextRank(rank); Rank next = rankups.nextRank(rank);
if(rank.equals(playerRank)) { if(rank.equals(playerRank)) {
sendMessage(sender, 1, rank, next); sendMessage(sender, Message.RANKS_CURRENT, rank, next);
state = 2; message = Message.RANKS_COMPLETE;
} else { } else {
sendMessage(sender, state, rank, next); sendMessage(sender, message, rank, next);
} }
rank = next; rank = next;
} while(!rank.isLastRank()); } while(!rank.isLastRank());
@@ -55,20 +55,10 @@ public class RankListCommand implements CommandExecutor {
builder.send(sender); builder.send(sender);
} }
private void sendMessage(CommandSender player, int state, Rank oldRank, Rank rank) { private void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
if(state == 0) { replaceRequirements(plugin.getMessage(oldRank, message)
replaceRequirements(plugin.getMessage(oldRank, Message.RANKS_COMPLETE)
.replaceAll(player, oldRank, rank), player, oldRank) .replaceAll(player, oldRank, rank), player, oldRank)
.send(player); .send(player);
} else if(state == 1) {
replaceRequirements(plugin.getMessage(oldRank, Message.RANKS_CURRENT)
.replaceAll(player, oldRank, rank), player, oldRank)
.send(player);
} else if(state == 2) {
replaceRequirements(plugin.getMessage(oldRank, Message.RANKS_INCOMPLETE)
.replaceAll(player, oldRank, rank), player, oldRank)
.send(player);
}
} }
private MessageBuilder replaceRequirements(MessageBuilder builder, CommandSender sender, Rank rank) { private MessageBuilder replaceRequirements(MessageBuilder builder, CommandSender sender, Rank rank) {
@@ -53,9 +53,7 @@ public class RankupCommand implements CommandExecutor {
case "text": case "text":
confirming.put(player, System.currentTimeMillis()); confirming.put(player, System.currentTimeMillis());
plugin.getMessage(rank, Message.CONFIRMATION) plugin.getMessage(rank, Message.CONFIRMATION)
.replace(Variable.PLAYER, player.getName()) .replaceAll(player, rank, rankups.nextRank(rank))
.replace(Variable.RANK, rank.getRank())
.replace(Variable.RANK_NAME, rank.getName())
.send(player); .send(player);
break; break;
case "gui": case "gui":
+5
View File
@@ -1,6 +1,11 @@
# 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: 0 version: 0
# whether /ranks should be enabled (true) or disabled (false)
# /rankup3 reload will not do anything if this is changed,
# you will have to restart your server.
ranks: 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'
+6 -4
View File
@@ -15,13 +15,15 @@ rankup:
# used for the GUI confirmation # used for the GUI confirmation
title: "Rankup to {RANK}" title: "Rankup to {RANK}"
# It is HIGHLY RECOMMENDED 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, you can use {MONEY} or {MONEY_NEEDED} or {PERCENT_DONE} or {PERCENT_LEFT} # however if you are just using money or don't need to change the message per rank, you can use any combination of:
# for example: # {MONEY} {MONEY_NEEDED} {PERCENT_DONE <requirement>} {PERCENT_LEFT <requirement>} {AMOUNT <requirement>} {AMOUNT_NEEDED <requirement>}
# {MONEY} and {MONEY_NEEDED} are different from {AMOUNT money} and {AMOUNT_NEEDED money} in that they use a different format.
# here is an example of showing the requirements for just money:
#ranks: #ranks:
# complete: "&7{OLD_RANK} &8\xbb &7{RANK} &efor &7${MONEY}" # complete: "&7{OLD_RANK} &8\xbb &7{RANK} &efor &7${MONEY}"
# current: "&c{OLD_RANK} &e\xbb &c{RANK} &efor &a${MONEY} &e{PERCENT_DONE}%" # current: "&c{OLD_RANK} &e\xbb &c{RANK} &efor &a${MONEY} &e{PERCENT_DONE mon ey}%"
# incomplete: "&r{OLD_RANK} &e\xbb &r{RANK} &efor &a${MONEY}" # incomplete: "&r{OLD_RANK} &e\xbb &r{RANK} &efor &a${MONEY}"
ranks: ranks:
complete: "&7{OLD_RANK} &8\xbb &7{RANK}" complete: "&7{OLD_RANK} &8\xbb &7{RANK}"
+4 -1
View File
@@ -1,5 +1,5 @@
name: Rankup name: Rankup
version: 3.0-alpha.10 version: 3.0-alpha.12
main: sh.okx.rankup.Rankup main: sh.okx.rankup.Rankup
author: Okx author: Okx
depend: [Vault] depend: [Vault]
@@ -27,6 +27,7 @@ permissions:
rankup.ranks: true rankup.ranks: true
rankup.reload: true rankup.reload: true
rankup.ranks: true rankup.ranks: true
rankup.sign: true
rankup.info: rankup.info:
default: true default: true
rankup.rankup: rankup.rankup:
@@ -39,3 +40,5 @@ permissions:
default: op default: op
rankup.ranks: rankup.ranks:
default: true default: true
rankup.sign:
default: op
+2 -2
View File
@@ -4,7 +4,7 @@ Aexample:
# 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.
# for example, the name of this configuration section is "Aexample". # for example, the name of this configuration section is "Aexample".
# this is not required. # 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)
@@ -37,7 +37,7 @@ Cexample:
requirements: requirements:
money: 5000 money: 5000
xp-level: 2 xp-level: 2
# you can have a custom messages too. # 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.
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.'