add permission-based rankups
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group 'sh.okx'
|
group 'sh.okx'
|
||||||
version '3.7'
|
version '3.8-beta'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|||||||
@@ -11,15 +11,16 @@ import lombok.Getter;
|
|||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import sh.okx.rankup.hook.PermissionProvider;
|
|
||||||
import sh.okx.rankup.ranks.Rank;
|
import sh.okx.rankup.ranks.Rank;
|
||||||
|
|
||||||
public class RankList<T extends Rank> {
|
public class RankList<T extends Rank> {
|
||||||
|
protected final RankupPlugin plugin;
|
||||||
@Getter
|
@Getter
|
||||||
protected final FileConfiguration config;
|
protected final FileConfiguration config;
|
||||||
protected final Set<T> ranks = new HashSet<>();
|
protected final Set<T> ranks = new HashSet<>();
|
||||||
|
|
||||||
public RankList(FileConfiguration config, Function<ConfigurationSection, T> deserializer) {
|
public RankList(RankupPlugin plugin, FileConfiguration config, Function<ConfigurationSection, T> deserializer) {
|
||||||
|
this.plugin = plugin;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
|
||||||
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
|
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
|
||||||
@@ -112,9 +113,9 @@ public class RankList<T extends Rank> {
|
|||||||
return list.get(list.size() - 1).getNext();
|
return list.get(list.size() - 1).getNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLast(PermissionProvider perms, Player player) {
|
public boolean isLast(Player player) {
|
||||||
String last = getLast();
|
String last = getLast();
|
||||||
return perms.inGroup(player.getUniqueId(), last);
|
return plugin.getPermissions().inGroup(player.getUniqueId(), last);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T next(T rank) {
|
public T next(T rank) {
|
||||||
|
|||||||
@@ -133,9 +133,9 @@ public class RankupHelper {
|
|||||||
public boolean checkRankup(Player player, boolean message) {
|
public boolean checkRankup(Player player, boolean message) {
|
||||||
Rankups rankups = plugin.getRankups();
|
Rankups rankups = plugin.getRankups();
|
||||||
Rank rank = rankups.getByPlayer(player);
|
Rank rank = rankups.getByPlayer(player);
|
||||||
if (rankups.isLast(permissions, player)) {
|
if (rankups.isLast(player)) {
|
||||||
Prestiges prestiges = plugin.getPrestiges();
|
Prestiges prestiges = plugin.getPrestiges();
|
||||||
plugin.getMessage(prestiges == null || prestiges.isLast(permissions, player) ? Message.NO_RANKUP : Message.MUST_PRESTIGE)
|
plugin.getMessage(prestiges == null || prestiges.isLast(player) ? Message.NO_RANKUP : Message.MUST_PRESTIGE)
|
||||||
.failIf(!message)
|
.failIf(!message)
|
||||||
.replaceRanks(player, rankups.getLast())
|
.replaceRanks(player, rankups.getLast())
|
||||||
.send(player);
|
.send(player);
|
||||||
@@ -186,8 +186,7 @@ public class RankupHelper {
|
|||||||
.replace(Variable.PLAYER, player.getName())
|
.replace(Variable.PLAYER, player.getName())
|
||||||
.send(player);
|
.send(player);
|
||||||
return false;
|
return false;
|
||||||
} else if (prestiges
|
} else if (prestiges.isLast(player)) { // check if they are at the highest rank
|
||||||
.isLast(plugin.getPermissions(), player)) { // check if they are at the highest rank
|
|
||||||
plugin.getMessage(prestige, Message.PRESTIGE_NO_PRESTIGE)
|
plugin.getMessage(prestige, Message.PRESTIGE_NO_PRESTIGE)
|
||||||
.failIf(!message)
|
.failIf(!message)
|
||||||
.replaceRanks(player, prestige.getRank())
|
.replaceRanks(player, prestige.getRank())
|
||||||
|
|||||||
@@ -156,12 +156,19 @@ public class RankupPlugin extends JavaPlugin {
|
|||||||
public void reload(boolean init) {
|
public void reload(boolean init) {
|
||||||
errorMessage = null;
|
errorMessage = null;
|
||||||
|
|
||||||
|
config = loadConfig("config.yml");
|
||||||
|
|
||||||
PermissionManager permissionManager = new PermissionManager(this);
|
PermissionManager permissionManager = new PermissionManager(this);
|
||||||
|
|
||||||
permissions = permissionManager.findPermissionProvider();
|
if (config.getBoolean("permission-rankup")) {
|
||||||
if (permissions == null) {
|
permissions = permissionManager.permissionOnlyProvider();
|
||||||
errorMessage = "No permission plugin found";
|
} else {
|
||||||
|
permissions = permissionManager.findPermissionProvider();
|
||||||
|
if (permissions == null) {
|
||||||
|
errorMessage = "No permission plugin found";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupEconomy();
|
setupEconomy();
|
||||||
|
|
||||||
closeInventories();
|
closeInventories();
|
||||||
@@ -176,7 +183,7 @@ public class RankupPlugin extends JavaPlugin {
|
|||||||
autoRankup.runTaskTimer(this, time, time);
|
autoRankup.runTaskTimer(this, time, time);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.getInt("version") < 6) {
|
if (config.getInt("version") < 7) {
|
||||||
getLogger().severe("You are using an outdated config!");
|
getLogger().severe("You are using an outdated config!");
|
||||||
getLogger().severe("This means that some things might not work!");
|
getLogger().severe("This means that some things might not work!");
|
||||||
getLogger().severe("To update, please rename ALL your config files (or the folder they are in),");
|
getLogger().severe("To update, please rename ALL your config files (or the folder they are in),");
|
||||||
@@ -243,7 +250,6 @@ public class RankupPlugin extends JavaPlugin {
|
|||||||
private void loadConfigs(boolean init) {
|
private void loadConfigs(boolean init) {
|
||||||
saveLocales();
|
saveLocales();
|
||||||
|
|
||||||
config = loadConfig("config.yml");
|
|
||||||
String locale = config.getString("locale", "en");
|
String locale = config.getString("locale", "en");
|
||||||
File localeFile = new File(new File(getDataFolder(), "locale"), locale + ".yml");
|
File localeFile = new File(new File(getDataFolder(), "locale"), locale + ".yml");
|
||||||
messages = YamlConfiguration.loadConfiguration(localeFile);
|
messages = YamlConfiguration.loadConfiguration(localeFile);
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import sh.okx.rankup.RankupPlugin;
|
import sh.okx.rankup.RankupPlugin;
|
||||||
|
|
||||||
import sh.okx.rankup.prestige.Prestige;
|
import sh.okx.rankup.prestige.Prestige;
|
||||||
import sh.okx.rankup.prestige.Prestiges;
|
import sh.okx.rankup.prestige.Prestiges;
|
||||||
import sh.okx.rankup.ranks.Rank;
|
import sh.okx.rankup.ranks.Rank;
|
||||||
@@ -47,7 +46,7 @@ public class InfoCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Rankups rankups = plugin.getRankups();
|
Rankups rankups = plugin.getRankups();
|
||||||
if (rankups.isLast(plugin.getPermissions(), player)) {
|
if (rankups.isLast(player)) {
|
||||||
sender.sendMessage(ChatColor.YELLOW + "That player is at the last rank.");
|
sender.sendMessage(ChatColor.YELLOW + "That player is at the last rank.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -83,7 +82,7 @@ public class InfoCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Prestiges prestiges = plugin.getPrestiges();
|
Prestiges prestiges = plugin.getPrestiges();
|
||||||
if (prestiges.isLast(plugin.getPermissions(), player)) {
|
if (prestiges.isLast(player)) {
|
||||||
sender.sendMessage(ChatColor.YELLOW + "That player is at the last prestige.");
|
sender.sendMessage(ChatColor.YELLOW + "That player is at the last prestige.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -113,6 +112,8 @@ public class InfoCommand implements CommandExecutor {
|
|||||||
ChatColor.YELLOW + " by " + ChatColor.BLUE + ChatColor.BOLD + String.join(", ", description.getAuthors()));
|
ChatColor.YELLOW + " by " + ChatColor.BLUE + ChatColor.BOLD + String.join(", ", description.getAuthors()));
|
||||||
if (sender.hasPermission("rankup.reload")) {
|
if (sender.hasPermission("rankup.reload")) {
|
||||||
sender.sendMessage(ChatColor.GREEN + "/" + label + " reload " + ChatColor.YELLOW + "Reloads configuration files.");
|
sender.sendMessage(ChatColor.GREEN + "/" + label + " reload " + ChatColor.YELLOW + "Reloads configuration files.");
|
||||||
|
}
|
||||||
|
if (sender.hasPermission("rankup.force")) {
|
||||||
sender.sendMessage(ChatColor.GREEN + "/" + label + " forcerankup <player> " + ChatColor.YELLOW + "Force a player to rankup, bypassing requirements.");
|
sender.sendMessage(ChatColor.GREEN + "/" + label + " forcerankup <player> " + ChatColor.YELLOW + "Force a player to rankup, bypassing requirements.");
|
||||||
if (plugin.getPrestiges() != null) {
|
if (plugin.getPrestiges() != null) {
|
||||||
sender.sendMessage(
|
sender.sendMessage(
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class RanksCommand implements CommandExecutor {
|
|||||||
|
|
||||||
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER);
|
plugin.sendHeaderFooter(sender, playerRank, Message.RANKS_HEADER);
|
||||||
|
|
||||||
Message message = !(sender instanceof Player && rankups.isLast(plugin.getPermissions(), (Player) sender))
|
Message message = !(sender instanceof Player && rankups.isLast((Player) sender))
|
||||||
&& playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
&& playerRank == null ? Message.RANKS_INCOMPLETE : Message.RANKS_COMPLETE;
|
||||||
Rank rank = rankups.getFirst();
|
Rank rank = rankups.getFirst();
|
||||||
while (rank != null) {
|
while (rank != null) {
|
||||||
|
|||||||
@@ -27,4 +27,8 @@ public class PermissionManager {
|
|||||||
}
|
}
|
||||||
return new VaultPermissionProvider(provider);
|
return new VaultPermissionProvider(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PermissionProvider permissionOnlyProvider() {
|
||||||
|
return new PermissionPermissionProvider();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package sh.okx.rankup.hook;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PermissionPermissionProvider implements PermissionProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean inGroup(UUID uuid, String group) {
|
||||||
|
Player player = getPlayer(uuid);
|
||||||
|
return player.hasPermission("rankup.rank." + group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addGroup(UUID uuid, String group) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeGroup(UUID uuid, String group) {
|
||||||
|
// no-op
|
||||||
|
}
|
||||||
|
|
||||||
|
private Player getPlayer(UUID uuid) {
|
||||||
|
Player player = Bukkit.getPlayer(uuid);
|
||||||
|
if (player == null) {
|
||||||
|
throw new IllegalArgumentException("Player not online!");
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,7 +59,7 @@ public class RankupExpansion extends PlaceholderExpansion {
|
|||||||
switch (params) {
|
switch (params) {
|
||||||
case "current_prestige":
|
case "current_prestige":
|
||||||
requirePrestiging(prestiges, params);
|
requirePrestiging(prestiges, params);
|
||||||
if (prestiges.isLast(plugin.getPermissions(), player)) {
|
if (prestiges.isLast(player)) {
|
||||||
return prestiges.getLast();
|
return prestiges.getLast();
|
||||||
} else if (prestige == null || prestige.getRank() == null) {
|
} else if (prestige == null || prestige.getRank() == null) {
|
||||||
return getPlaceholder("no-prestige");
|
return getPlaceholder("no-prestige");
|
||||||
@@ -68,7 +68,7 @@ public class RankupExpansion extends PlaceholderExpansion {
|
|||||||
}
|
}
|
||||||
case "next_prestige":
|
case "next_prestige":
|
||||||
requirePrestiging(prestiges, params);
|
requirePrestiging(prestiges, params);
|
||||||
if (prestiges.isLast(plugin.getPermissions(), player)) {
|
if (prestiges.isLast(player)) {
|
||||||
return getPlaceholder("highest-rank");
|
return getPlaceholder("highest-rank");
|
||||||
}
|
}
|
||||||
return orElse(prestige, Prestige::getNext, prestiges.getFirst().getNext());
|
return orElse(prestige, Prestige::getNext, prestiges.getFirst().getNext());
|
||||||
@@ -79,7 +79,7 @@ public class RankupExpansion extends PlaceholderExpansion {
|
|||||||
requirePrestiging(prestiges, params);
|
requirePrestiging(prestiges, params);
|
||||||
return plugin.formatMoney(orElse(prestige, r -> r.isIn(player) ? r.getRequirement(player, "money").getValueDouble() : 0, 0D));
|
return plugin.formatMoney(orElse(prestige, r -> r.isIn(player) ? r.getRequirement(player, "money").getValueDouble() : 0, 0D));
|
||||||
case "current_rank":
|
case "current_rank":
|
||||||
if (rankups.isLast(plugin.getPermissions(), player)) {
|
if (rankups.isLast(player)) {
|
||||||
return rankups.getLast();
|
return rankups.getLast();
|
||||||
} else if (rank == null) {
|
} else if (rank == null) {
|
||||||
return getPlaceholder("not-in-ladder");
|
return getPlaceholder("not-in-ladder");
|
||||||
@@ -87,7 +87,7 @@ public class RankupExpansion extends PlaceholderExpansion {
|
|||||||
return rank.getRank();
|
return rank.getRank();
|
||||||
}
|
}
|
||||||
case "next_rank":
|
case "next_rank":
|
||||||
if (rankups.isLast(plugin.getPermissions(), player)) {
|
if (rankups.isLast(player)) {
|
||||||
return getPlaceholder("highest-rank");
|
return getPlaceholder("highest-rank");
|
||||||
}
|
}
|
||||||
return orElsePlaceholder(rank, r -> orElsePlaceholder(rank, Rank::getNext, "highest-rank"), "not-in-ladder");
|
return orElsePlaceholder(rank, r -> orElsePlaceholder(rank, Rank::getNext, "highest-rank"), "not-in-ladder");
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import sh.okx.rankup.RankupPlugin;
|
|||||||
|
|
||||||
public class Prestiges extends RankList<Prestige> {
|
public class Prestiges extends RankList<Prestige> {
|
||||||
public Prestiges(RankupPlugin plugin, FileConfiguration config) {
|
public Prestiges(RankupPlugin plugin, FileConfiguration config) {
|
||||||
super(config, section -> Prestige.deserialize(plugin, section));
|
super(plugin, config, section -> Prestige.deserialize(plugin, section));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ import sh.okx.rankup.RankupPlugin;
|
|||||||
|
|
||||||
public class Rankups extends RankList<Rank> {
|
public class Rankups extends RankList<Rank> {
|
||||||
public Rankups(RankupPlugin plugin, FileConfiguration config) {
|
public Rankups(RankupPlugin plugin, FileConfiguration config) {
|
||||||
super(config, section -> Rankup.deserialize(plugin, section));
|
super(plugin, config, section -> Rankup.deserialize(plugin, section));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
# 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: 6
|
version: 7
|
||||||
|
|
||||||
# the locale to use for messages
|
# the locale to use for messages
|
||||||
# all messages can be customised but this allows you to
|
# all messages can be customised but this allows you to
|
||||||
@@ -34,6 +34,14 @@ prestige: false
|
|||||||
# to update if the server is on an older version of Rankup.
|
# to update if the server is on an older version of Rankup.
|
||||||
notify-update: true
|
notify-update: true
|
||||||
|
|
||||||
|
# if rankups and prestiges should be by permissions
|
||||||
|
# if false, players will be checked for if they have a group of the same name as in rankups.yml,
|
||||||
|
# and automatically added and taken away from those groups.
|
||||||
|
# if true, players will be checked for the permission rankup.rank.RANK, where RANK
|
||||||
|
# is the rankup in rankups.yml. Nothing will automatically happen on rankup, so you must
|
||||||
|
# use commands to change a player's group or permission.
|
||||||
|
permission-rankup: false
|
||||||
|
|
||||||
# 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'
|
||||||
|
|||||||
Reference in New Issue
Block a user