add /prestiges
also fix inconsistency with checking groups
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'sh.okx'
|
||||
version '3.0-alpha.20'
|
||||
version '3.0-alpha.21'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
|
||||
@@ -39,6 +39,14 @@ public class RankList<T extends Rank> {
|
||||
return null;
|
||||
}
|
||||
|
||||
public T getLast() {
|
||||
T t = getFirst();
|
||||
do {
|
||||
t = next(t);
|
||||
} while(!t.isLast());
|
||||
return t;
|
||||
}
|
||||
|
||||
public T getByName(String name) {
|
||||
for (T rank : ranks) {
|
||||
if (rank.getName().equalsIgnoreCase(name)) {
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import sh.okx.rankup.commands.InfoCommand;
|
||||
import sh.okx.rankup.commands.PrestigeCommand;
|
||||
import sh.okx.rankup.commands.PrestigesCommand;
|
||||
import sh.okx.rankup.commands.RanksCommand;
|
||||
import sh.okx.rankup.commands.RankupCommand;
|
||||
import sh.okx.rankup.gui.Gui;
|
||||
@@ -95,6 +96,9 @@ public class Rankup extends JavaPlugin {
|
||||
}
|
||||
if(prestiges != null) {
|
||||
getCommand("prestige").setExecutor(new PrestigeCommand(this));
|
||||
if(config.getBoolean("prestiges")) {
|
||||
getCommand("prestiges").setExecutor(new PrestigesCommand(this));
|
||||
}
|
||||
}
|
||||
|
||||
getCommand("rankup").setExecutor(new RankupCommand(this));
|
||||
@@ -197,6 +201,7 @@ public class Rankup extends JavaPlugin {
|
||||
if (money >= value) {
|
||||
money /= value;
|
||||
suffix = shortened.get(i - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,4 +409,26 @@ public class Rankup extends JavaPlugin {
|
||||
private void replaceRequirements(MessageBuilder builder, Variable variable, Requirement requirement, Supplier<Object> value) {
|
||||
builder.replace(variable + " " + requirement.getName(), value.get());
|
||||
}
|
||||
|
||||
public void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
||||
replaceMoneyRequirements(getMessage(oldRank, message)
|
||||
.replaceRanks(player, oldRank, rank), player, oldRank)
|
||||
.replaceFromTo(oldRank)
|
||||
.send(player);
|
||||
}
|
||||
|
||||
public void sendHeaderFooter(CommandSender sender, Rank rank, Message type) {
|
||||
MessageBuilder builder;
|
||||
if(rank == null) {
|
||||
builder = getMessage(type)
|
||||
.failIfEmpty()
|
||||
.replace(Variable.PLAYER, sender.getName());
|
||||
} else {
|
||||
builder = getMessage(rank, type)
|
||||
.failIfEmpty()
|
||||
.replaceRanks(sender, rank)
|
||||
.replaceFromTo(rank);
|
||||
}
|
||||
builder.send(sender);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package sh.okx.rankup.commands;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -14,15 +15,11 @@ import sh.okx.rankup.prestige.Prestiges;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
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
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package sh.okx.rankup.commands;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
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 {
|
||||
private final Rankup plugin;
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
Prestiges prestiges = plugin.getPrestiges();
|
||||
Prestige playerRank = null;
|
||||
if (sender instanceof Player) {
|
||||
playerRank = prestiges.getByPlayer((Player) sender);
|
||||
}
|
||||
|
||||
plugin.sendHeaderFooter(sender, playerRank, Message.PRESTIGES_HEADER);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
plugin.sendHeaderFooter(sender, playerRank, Message.PRESTIGES_FOOTER);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,9 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import sh.okx.rankup.Rankup;
|
||||
import sh.okx.rankup.ranks.Rankups;
|
||||
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 sh.okx.rankup.ranks.Rankups;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class RanksCommand implements CommandExecutor {
|
||||
@@ -24,39 +22,22 @@ public class RanksCommand implements CommandExecutor {
|
||||
playerRank = rankups.getByPlayer((Player) sender);
|
||||
}
|
||||
|
||||
sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER);
|
||||
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER);
|
||||
|
||||
Message message = playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
||||
Rank rank = rankups.getFirst();
|
||||
do {
|
||||
Rank next = rankups.next(rank);
|
||||
if (rank.equals(playerRank)) {
|
||||
sendMessage(sender, Message.RANKS_CURRENT, rank, next);
|
||||
plugin.sendMessage(sender, Message.RANKS_CURRENT, rank, next);
|
||||
message = Message.RANKS_INCOMPLETE;
|
||||
} else {
|
||||
sendMessage(sender, message, rank, next);
|
||||
plugin.sendMessage(sender, message, rank, next);
|
||||
}
|
||||
rank = next;
|
||||
} while (!rank.isLast());
|
||||
|
||||
sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
|
||||
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_FOOTER);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendHeaderFooter(CommandSender sender, Rank rank, Message type) {
|
||||
MessageBuilder builder = plugin.getMessage(rank, type)
|
||||
.failIfEmpty();
|
||||
if (rank == null) {
|
||||
builder.replace(Variable.PLAYER, sender.getName());
|
||||
} else {
|
||||
builder.replaceRanks(sender, rank);
|
||||
}
|
||||
builder.send(sender);
|
||||
}
|
||||
|
||||
private void sendMessage(CommandSender player, Message message, Rank oldRank, Rank rank) {
|
||||
plugin.replaceMoneyRequirements(plugin.getMessage(oldRank, message)
|
||||
.replaceRanks(player, oldRank, rank), player, oldRank)
|
||||
.send(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package sh.okx.rankup.commands;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -14,17 +15,13 @@ import sh.okx.rankup.ranks.Rankups;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class RankupCommand implements CommandExecutor {
|
||||
// weak hash maps so players going offline are automatically removed.
|
||||
// otherwise there is a potential (but small) memory leak.
|
||||
private final Map<Player, Long> confirming = new WeakHashMap<>();
|
||||
|
||||
private final Rankup plugin;
|
||||
|
||||
public RankupCommand(Rankup plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
// check if player
|
||||
|
||||
@@ -15,6 +15,11 @@ public enum Message {
|
||||
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"),
|
||||
COOLDOWN_SINGULAR("rankup.cooldown.singular"),
|
||||
COOLDOWN_PLURAL("rankup.cooldown.plural"),
|
||||
NOT_HIGH_ENOUGH("rankup.not-high-enough"),
|
||||
|
||||
@@ -4,6 +4,8 @@ import lombok.Getter;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import org.bukkit.entity.Player;
|
||||
import sh.okx.rankup.Rankup;
|
||||
import sh.okx.rankup.prestige.Prestige;
|
||||
import sh.okx.rankup.prestige.Prestiges;
|
||||
import sh.okx.rankup.ranks.Rank;
|
||||
import sh.okx.rankup.ranks.Rankups;
|
||||
import sh.okx.rankup.requirements.Requirement;
|
||||
@@ -36,7 +38,11 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
|
||||
Rankups rankups = plugin.getRankups();
|
||||
Rank rank = rankups.getByPlayer(player);
|
||||
Rank next = rank == null ? null : rankups.next(rank);
|
||||
Rank nextRank = rank == null ? null : rankups.next(rank);
|
||||
|
||||
Prestiges prestiges = plugin.getPrestiges();
|
||||
Prestige prestige = prestiges.getByPlayer(player);
|
||||
Prestige nextPrestige = prestiges.next(prestige);
|
||||
|
||||
if (params.startsWith("requirement_")) {
|
||||
String[] parts = params.split("_", 3);
|
||||
@@ -55,6 +61,14 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
}
|
||||
|
||||
switch (params) {
|
||||
case "current_prestige":
|
||||
return prestige.getRank();
|
||||
case "current_prestige_name":
|
||||
return prestige.getName();
|
||||
case "next_prestige":
|
||||
return orElsePlaceholder(nextPrestige, Prestige::getRank, "highest-rank");
|
||||
case "next_prestige_name":
|
||||
return orElsePlaceholder(nextPrestige, Prestige::getName, "highest-rank");
|
||||
case "current_rank":
|
||||
return orElsePlaceholder(rank, Rank::getRank, "not-in-ladder");
|
||||
case "current_rank_name":
|
||||
@@ -64,9 +78,9 @@ public class Placeholders extends PlaceholderExpansion {
|
||||
case "current_rank_money_formatted":
|
||||
return moneyFormat.format(orElse(rank, r -> r.getRequirement("money").getValueDouble(), 0));
|
||||
case "next_rank":
|
||||
return orElsePlaceholder(rank, r -> orElsePlaceholder(next, Rank::getRank, "highest-rank"), "not-in-ladder");
|
||||
return orElsePlaceholder(rank, r -> orElsePlaceholder(nextRank, Rank::getRank, "highest-rank"), "not-in-ladder");
|
||||
case "next_rank_name":
|
||||
return orElsePlaceholder(rank, r -> orElsePlaceholder(next, Rank::getName, "highest-rank"), "not-in-ladder");
|
||||
return orElsePlaceholder(rank, r -> orElsePlaceholder(nextRank, Rank::getName, "highest-rank"), "not-in-ladder");
|
||||
case "money":
|
||||
return String.valueOf(orElse(rank, r -> simplify(r.getRequirement("money").getValueDouble()), 0));
|
||||
case "money_formatted":
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Prestige extends Rank {
|
||||
}
|
||||
|
||||
public boolean isEligable(Player player) {
|
||||
String[] groups = plugin.getPermissions().getPlayerGroups(player);
|
||||
String[] groups = plugin.getPermissions().getPlayerGroups(null, player);
|
||||
for (String group : groups) {
|
||||
if (group.equalsIgnoreCase(from)) {
|
||||
return true;
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Rank {
|
||||
}
|
||||
|
||||
public boolean isIn(Player player) {
|
||||
String[] groups = plugin.getPermissions().getPlayerGroups(player);
|
||||
String[] groups = plugin.getPermissions().getPlayerGroups(null, player);
|
||||
for (String group : groups) {
|
||||
if (group.equalsIgnoreCase(rank)) {
|
||||
return true;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class GroupRequirement extends Requirement {
|
||||
public boolean check(Player player) {
|
||||
OUTER:
|
||||
for (String requiredGroup : getValueString().split(" ")) {
|
||||
for (String group : plugin.getPermissions().getPlayerGroups(player)) {
|
||||
for (String group : plugin.getPermissions().getPlayerGroups(null, player)) {
|
||||
if (group.equalsIgnoreCase(requiredGroup)) {
|
||||
continue OUTER;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# this is used for letting you know that you need to update/change your config file
|
||||
version: 0
|
||||
|
||||
# whether /ranks should be enabled (true) or disabled (false)
|
||||
# whether /ranks and /prestiges 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
|
||||
prestiges: true
|
||||
|
||||
# whether or not prestiging should be enabled.
|
||||
# whether or not /prestige and /prestiges should be enabled.
|
||||
prestige: true
|
||||
|
||||
# how people should confirm ranking up
|
||||
|
||||
@@ -33,6 +33,12 @@ rankup:
|
||||
# an empty string disables the header/footer
|
||||
header: ''
|
||||
footer: ''
|
||||
prestiges:
|
||||
complete: "&7{OLD_RANK} &8\xbb &7{RANK}"
|
||||
current: "&c{OLD_RANK} &e\xbb &c{RANK}"
|
||||
incomplete: "&r{OLD_RANK} &e\xbb &r{RANK}"
|
||||
header: ''
|
||||
footer: ''
|
||||
# sent when a player tries to rankup when they are on cooldown
|
||||
cooldown:
|
||||
singular: '&cYou must wait {SECONDS_LEFT} more second to rankup again.'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name: Rankup
|
||||
version: 3.0-alpha.20
|
||||
version: 3.0-alpha.21
|
||||
main: sh.okx.rankup.Rankup
|
||||
author: Okx
|
||||
depend: [Vault]
|
||||
@@ -21,6 +21,9 @@ commands:
|
||||
prestige:
|
||||
permission: rankup.prestige
|
||||
description: Prestige.
|
||||
prestiges:
|
||||
permission: rankup.prestiges
|
||||
description: List all the prestiges.
|
||||
permissions:
|
||||
rankup.*:
|
||||
children:
|
||||
@@ -31,6 +34,7 @@ permissions:
|
||||
rankup.reload: true
|
||||
rankup.ranks: true
|
||||
rankup.prestige: true
|
||||
rankup.prestiges: true
|
||||
rankup.info:
|
||||
default: true
|
||||
rankup.rankup:
|
||||
@@ -45,3 +49,5 @@ permissions:
|
||||
default: true
|
||||
rankup.prestige:
|
||||
default: true
|
||||
rankup.prestiges:
|
||||
default: true
|
||||
@@ -3,7 +3,7 @@ first:
|
||||
from: 'D'
|
||||
# the rank to change it to
|
||||
to: 'A'
|
||||
next: 'P2example'
|
||||
next: 'P1example'
|
||||
# see rankups.yml for more information on requirements, operations, commands and messages
|
||||
requirements:
|
||||
money: 10000
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# this name can be equal to your rank name for simplicity,
|
||||
# eg "A" instead of "Aexample".
|
||||
Aexample:
|
||||
# the name of the rank in your permissions plugin
|
||||
rank: 'A'
|
||||
|
||||
Reference in New Issue
Block a user