improve prestige customisation

add prestiges section of messages.yml
add prestige gui title
add first rank for prestiges
This commit is contained in:
okx-code
2018-09-06 21:30:21 +01:00
parent f78bc81d0f
commit 4c7c4ef7f5
10 changed files with 72 additions and 50 deletions
+7 -5
View File
@@ -210,7 +210,7 @@ public class Rankup extends JavaPlugin {
}
public MessageBuilder getMessage(Rank rank, Message message) {
ConfigurationSection messages = rankups.getConfig()
ConfigurationSection messages = (rank instanceof Prestige ? prestiges : rankups).getConfig()
.getConfigurationSection(rank.getName());
if (messages == null || !messages.isSet(message.getName())) {
messages = this.messages;
@@ -298,8 +298,7 @@ public class Rankup extends JavaPlugin {
getMessage(rank, Message.NO_RANKUP);
}
}
getMessage(rank, prestiges == null ? Message.NO_RANKUP :
prestiges.getByPlayer(player).isLast() ? Message.NO_RANKUP : Message.MUST_PRESTIGE)
getMessage(rank, prestiges == null ? Message.NO_RANKUP : prestiges.getByPlayer(player).isLast() ? Message.NO_RANKUP : Message.MUST_PRESTIGE)
.replaceRanks(player, rank)
.send(player);
return false;
@@ -398,8 +397,10 @@ public class Rankup extends JavaPlugin {
try {
replaceRequirements(builder, Variable.AMOUNT, requirement, () -> simpleFormat.format(requirement.getValueDouble()));
replaceRequirements(builder, Variable.AMOUNT_NEEDED, requirement, () -> simpleFormat.format(requirement.getRemaining(player)));
replaceRequirements(builder, Variable.PERCENT_LEFT, requirement, () -> percentFormat.format(Math.max(0, (requirement.getRemaining(player) / requirement.getValueDouble()) * 100)));
replaceRequirements(builder, Variable.PERCENT_DONE, requirement, () -> percentFormat.format(Math.min(100, (1 - (requirement.getRemaining(player) / requirement.getValueDouble())) * 100)));
replaceRequirements(builder, Variable.PERCENT_LEFT, requirement,
() -> percentFormat.format(Math.max(0, (requirement.getRemaining(player) / requirement.getValueDouble()) * 100)));
replaceRequirements(builder, Variable.PERCENT_DONE, requirement,
() -> percentFormat.format(Math.min(100, (1 - (requirement.getRemaining(player) / requirement.getValueDouble())) * 100)));
} catch (NumberFormatException ignored) {
}
}
@@ -412,6 +413,7 @@ public class Rankup extends JavaPlugin {
public void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
replaceMoneyRequirements(getMessage(oldRank, message)
.replaceFirstPrestige(oldRank, prestiges, config.getString("placeholders.first-prestige-rank"))
.replaceRanks(player, oldRank, rank), player, oldRank)
.replaceFromTo(oldRank)
.send(player);
@@ -9,7 +9,6 @@ import sh.okx.rankup.Rankup;
import sh.okx.rankup.messages.Message;
import sh.okx.rankup.prestige.Prestige;
import sh.okx.rankup.prestige.Prestiges;
import sh.okx.rankup.ranks.Rank;
@RequiredArgsConstructor
public class PrestigesCommand implements CommandExecutor {
@@ -27,18 +26,15 @@ public class PrestigesCommand implements CommandExecutor {
Message message = playerRank == null ? Message.PRESTIGES_INCOMPLETE : Message.PRESTIGES_COMPLETE;
Prestige prestige = prestiges.getFirst();
if(!prestige.isLast()) {
prestige = prestiges.next(prestige);
while (!prestige.isLast()) {
Prestige next = prestiges.next(prestige);
if (prestige.equals(playerRank)) {
plugin.sendMessage(sender, Message.PRESTIGES_CURRENT, prestige, next);
message = Message.PRESTIGES_INCOMPLETE;
} else {
plugin.sendMessage(sender, message, prestige, next);
}
prestige = next;
while (!prestige.isLast()) {
Prestige next = prestiges.next(prestige);
if (prestige.equals(playerRank)) {
plugin.sendMessage(sender, Message.PRESTIGES_CURRENT, prestige, next);
message = Message.PRESTIGES_INCOMPLETE;
} else {
plugin.sendMessage(sender, message, prestige, next);
}
prestige = next;
}
plugin.sendHeaderFooter(sender, playerRank, Message.PRESTIGES_FOOTER);
+1 -1
View File
@@ -45,7 +45,7 @@ public class Gui implements InventoryHolder {
gui.cancel = getItem(config.getConfigurationSection("cancel"), player, oldRank, rank);
Inventory inventory = Bukkit.createInventory(gui, items.length,
plugin.getMessage(rank, Message.TITLE)
plugin.getMessage(oldRank, gui.prestige ? Message.PRESTIGE_TITLE : Message.TITLE)
.replaceRanks(player, oldRank, rank)
.replaceFromTo(oldRank)
.toString());
@@ -10,20 +10,21 @@ public enum Message {
SUCCESS_PRIVATE("rankup.success-private"),
CONFIRMATION("rankup.confirmation"),
TITLE("rankup.title"),
RANKS_HEADER("rankup.ranks.header"),
RANKS_FOOTER("rankup.ranks.footer"),
RANKS_COMPLETE("rankup.ranks.complete"),
RANKS_CURRENT("rankup.ranks.current"),
RANKS_INCOMPLETE("rankup.ranks.incomplete"),
PRESTIGES_HEADER("rankup.prestiges.header"),
PRESTIGES_FOOTER("rankup.prestiges.footer"),
PRESTIGES_COMPLETE("rankup.prestiges.complete"),
PRESTIGES_CURRENT("rankup.prestiges.current"),
PRESTIGES_INCOMPLETE("rankup.prestiges.incomplete"),
RANKS_HEADER("rankup.list.header"),
RANKS_FOOTER("rankup.list.footer"),
RANKS_COMPLETE("rankup.list.complete"),
RANKS_CURRENT("rankup.list.current"),
RANKS_INCOMPLETE("rankup.list.incomplete"),
PRESTIGES_HEADER("prestige.list.header"),
PRESTIGES_FOOTER("prestige.list.footer"),
PRESTIGES_COMPLETE("prestige.list.complete"),
PRESTIGES_CURRENT("prestige.list.current"),
PRESTIGES_INCOMPLETE("prestige.list.incomplete"),
PRESTIGE_TITLE("prestige.title"),
COOLDOWN_SINGULAR("rankup.cooldown.singular"),
COOLDOWN_PLURAL("rankup.cooldown.plural"),
NOT_HIGH_ENOUGH("rankup.not-high-enough"),
MUST_PRESTIGE("rankup.must-prestige");
MUST_PRESTIGE("rankup.must-prestige"),
NOT_HIGH_ENOUGH("prestige.not-high-enough");
@Getter
private final String name;
@@ -31,4 +32,4 @@ public enum Message {
Message(String name) {
this.name = name;
}
}
}
@@ -6,6 +6,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import sh.okx.rankup.prestige.Prestige;
import sh.okx.rankup.prestige.Prestiges;
import sh.okx.rankup.ranks.Rank;
import java.util.regex.Matcher;
@@ -19,7 +20,11 @@ public class MessageBuilder {
}
public static MessageBuilder of(ConfigurationSection config, Message message) {
return new MessageBuilder(ChatColor.translateAlternateColorCodes('&', config.getString(message.getName())));
return MessageBuilder.of(config, message.getName());
}
private static MessageBuilder of(ConfigurationSection config, String message) {
return new MessageBuilder(ChatColor.translateAlternateColorCodes('&', config.getString(message)));
}
public MessageBuilder replace(Variable variable, Object value) {
@@ -33,6 +38,14 @@ public class MessageBuilder {
return this;
}
public MessageBuilder replaceFirstPrestige(Rank rank, Prestiges prestiges, String with) {
if(prestiges.getFirst().equals(rank)) {
replace(Variable.OLD_RANK, with);
replace(Variable.OLD_RANK_NAME, with);
}
return this;
}
public MessageBuilder replaceRanks(CommandSender player, Rank rank) {
replace(Variable.PLAYER, player.getName());
replaceRanks(rank);
@@ -12,9 +12,11 @@ public class Prestiges extends RankList<Prestige> {
@Override
public Prestige getByPlayer(Player player) {
return ranks.stream()
.filter(rank -> rank.isIn(player))
.findFirst()
.orElseGet(this::getFirst);
Prestige prestige = super.getByPlayer(player);
if(prestige == null) {
return getFirst();
} else {
return prestige;
}
}
}