Merge branch 'dev'

This commit is contained in:
okx-code
2020-04-19 12:56:41 +01:00
12 changed files with 76 additions and 25 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ plugins {
}
group 'sh.okx'
version '3.7'
version '3.8-beta'
repositories {
mavenCentral()
+5 -4
View File
@@ -11,15 +11,16 @@ import lombok.Getter;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import sh.okx.rankup.hook.PermissionProvider;
import sh.okx.rankup.ranks.Rank;
public class RankList<T extends Rank> {
protected final RankupPlugin plugin;
@Getter
protected final FileConfiguration config;
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;
for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
ConfigurationSection rankSection = (ConfigurationSection) entry.getValue();
@@ -112,9 +113,9 @@ public class RankList<T extends Rank> {
return list.get(list.size() - 1).getNext();
}
public boolean isLast(PermissionProvider perms, Player player) {
public boolean isLast(Player player) {
String last = getLast();
return perms.inGroup(player.getUniqueId(), last);
return plugin.getPermissions().inGroup(player.getUniqueId(), last);
}
public T next(T rank) {
@@ -133,9 +133,9 @@ public class RankupHelper {
public boolean checkRankup(Player player, boolean message) {
Rankups rankups = plugin.getRankups();
Rank rank = rankups.getByPlayer(player);
if (rankups.isLast(permissions, player)) {
if (rankups.isLast(player)) {
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)
.replaceRanks(player, rankups.getLast())
.send(player);
@@ -186,8 +186,7 @@ public class RankupHelper {
.replace(Variable.PLAYER, player.getName())
.send(player);
return false;
} else if (prestiges
.isLast(plugin.getPermissions(), player)) { // check if they are at the highest rank
} else if (prestiges.isLast(player)) { // check if they are at the highest rank
plugin.getMessage(prestige, Message.PRESTIGE_NO_PRESTIGE)
.failIf(!message)
.replaceRanks(player, prestige.getRank())
+11 -5
View File
@@ -156,12 +156,19 @@ public class RankupPlugin extends JavaPlugin {
public void reload(boolean init) {
errorMessage = null;
config = loadConfig("config.yml");
PermissionManager permissionManager = new PermissionManager(this);
permissions = permissionManager.findPermissionProvider();
if (permissions == null) {
errorMessage = "No permission plugin found";
if (config.getBoolean("permission-rankup")) {
permissions = permissionManager.permissionOnlyProvider();
} else {
permissions = permissionManager.findPermissionProvider();
if (permissions == null) {
errorMessage = "No permission plugin found";
}
}
setupEconomy();
closeInventories();
@@ -176,7 +183,7 @@ public class RankupPlugin extends JavaPlugin {
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("This means that some things might not work!");
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) {
saveLocales();
config = loadConfig("config.yml");
String locale = config.getString("locale", "en");
File localeFile = new File(new File(getDataFolder(), "locale"), locale + ".yml");
messages = YamlConfiguration.loadConfiguration(localeFile);
@@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.PluginDescriptionFile;
import sh.okx.rankup.RankupPlugin;
import sh.okx.rankup.prestige.Prestige;
import sh.okx.rankup.prestige.Prestiges;
import sh.okx.rankup.ranks.Rank;
@@ -47,7 +46,7 @@ public class InfoCommand implements CommandExecutor {
}
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.");
return true;
}
@@ -83,7 +82,7 @@ public class InfoCommand implements CommandExecutor {
}
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.");
return true;
}
@@ -113,6 +112,8 @@ public class InfoCommand implements CommandExecutor {
ChatColor.YELLOW + " by " + ChatColor.BLUE + ChatColor.BOLD + String.join(", ", description.getAuthors()));
if (sender.hasPermission("rankup.reload")) {
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.");
if (plugin.getPrestiges() != null) {
sender.sendMessage(
@@ -28,7 +28,7 @@ public class RanksCommand implements CommandExecutor {
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;
Rank rank = rankups.getFirst();
while (rank != null) {
@@ -27,4 +27,8 @@ public class PermissionManager {
}
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) {
case "current_prestige":
requirePrestiging(prestiges, params);
if (prestiges.isLast(plugin.getPermissions(), player)) {
if (prestiges.isLast(player)) {
return prestiges.getLast();
} else if (prestige == null || prestige.getRank() == null) {
return getPlaceholder("no-prestige");
@@ -68,7 +68,7 @@ public class RankupExpansion extends PlaceholderExpansion {
}
case "next_prestige":
requirePrestiging(prestiges, params);
if (prestiges.isLast(plugin.getPermissions(), player)) {
if (prestiges.isLast(player)) {
return getPlaceholder("highest-rank");
}
return orElse(prestige, Prestige::getNext, prestiges.getFirst().getNext());
@@ -79,7 +79,7 @@ public class RankupExpansion extends PlaceholderExpansion {
requirePrestiging(prestiges, params);
return plugin.formatMoney(orElse(prestige, r -> r.isIn(player) ? r.getRequirement(player, "money").getValueDouble() : 0, 0D));
case "current_rank":
if (rankups.isLast(plugin.getPermissions(), player)) {
if (rankups.isLast(player)) {
return rankups.getLast();
} else if (rank == null) {
return getPlaceholder("not-in-ladder");
@@ -87,7 +87,7 @@ public class RankupExpansion extends PlaceholderExpansion {
return rank.getRank();
}
case "next_rank":
if (rankups.isLast(plugin.getPermissions(), player)) {
if (rankups.isLast(player)) {
return getPlaceholder("highest-rank");
}
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 Prestiges(RankupPlugin plugin, FileConfiguration config) {
super(config, section -> Prestige.deserialize(plugin, section));
super(plugin, config, section -> Prestige.deserialize(plugin, section));
}
@Override
@@ -6,6 +6,6 @@ import sh.okx.rankup.RankupPlugin;
public class Rankups extends RankList<Rank> {
public Rankups(RankupPlugin plugin, FileConfiguration config) {
super(config, section -> Rankup.deserialize(plugin, section));
super(plugin, config, section -> Rankup.deserialize(plugin, section));
}
}
+9 -1
View File
@@ -1,5 +1,5 @@
# 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
# 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.
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
# options are: gui, text or none
confirmation-type: 'gui'