Skip to content
Snippets Groups Projects
Commit c5bd00da authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

Ajout de vérifications complémentaires à la classe PlayedTimeHandler,...

Ajout de vérifications complémentaires à la classe PlayedTimeHandler, concernants LuckPerms et la possible nullité de certains retours de méthodes.
parent e85c786d
Branches
No related tags found
1 merge request!7Donner le rôle habitué aux joueurs habitués
Pipeline #86 passed
......@@ -29,11 +29,21 @@ public class PlayedTimeHandler implements dataHandler {
public PlayedTimeHandler(Main plugin) {
this.plugin = plugin;
String playersAccountUpgradeRole = plugin.getConfig().getString("stats.players-account-upgrade-role");
if (playersAccountUpgradeRole != null) {
usersIndexes = new ArrayList<>();
userSessionJoinDateTime = new ArrayList<>();
userStoredPlayedTimeBeforeJoining = new ArrayList<>();
requiredPlayedTimeForUpgradingPlayersAccount = plugin.getConfig().getInt("stats.required-played-time-for-upgrading-players-account");
playersAccountUpgradeGroup = Main.luckPermsApi.getGroupManager().getGroup(plugin.getConfig().getString("stats.players-account-upgrade-role"));
playersAccountUpgradeGroup = Main.luckPermsApi.getGroupManager().getGroup(playersAccountUpgradeRole);
if (playersAccountUpgradeGroup == null) {
throw new RuntimeException("Le groupe " + playersAccountUpgradeRole + " n'existe pas !");
}
} else {
throw new RuntimeException("La configuration stats.required-played-time-for-upgrading-players-account n'existe pas !");
}
}
@Override
......@@ -84,12 +94,20 @@ public class PlayedTimeHandler implements dataHandler {
if (actualPlayedTime >= requiredPlayedTimeForUpgradingPlayersAccount) {
String playerGroupName = Main.luckPermsApi.getPlayerAdapter(Player.class).getMetaData(player).getPrimaryGroup();
if (!Objects.equals(playerGroupName, playersAccountUpgradeGroup.getName())) {
if (playerGroupName != null && !Objects.equals(playerGroupName, playersAccountUpgradeGroup.getName())) {
Group playerGroup = Main.luckPermsApi.getGroupManager().getGroup(playerGroupName);
if (playerGroup == null) {
throw new RuntimeException("Le groupe " + playerGroupName + " n'existe pas !");
}
if (playerGroup.getWeight().isPresent() && playersAccountUpgradeGroup.getWeight().isPresent()) {
if (playerGroup.getWeight().getAsInt() < playersAccountUpgradeGroup.getWeight().getAsInt()) {
ConsoleLog.info(ChatColor.GREEN + player.getName() + ChatColor.LIGHT_PURPLE + " a débloqué le rôle des joueurs " + ChatColor.GOLD + "habitués" + ChatColor.LIGHT_PURPLE + "!");
User playerLuckPerms = Main.luckPermsApi.getUserManager().getUser(player.getUniqueId());
if (playerLuckPerms == null) {
throw new RuntimeException("LuckPerms ne semble pas disposer de donnée sur le joueur " + player.getName() + " UUID:" + player.getUniqueId());
}
// https://www.spigotmc.org/threads/how-can-i-set-a-players-group-with-luckperms-api.489404/#post-4084060
InheritanceNode node = InheritanceNode.builder(playersAccountUpgradeGroup).value(true).build();
......@@ -115,6 +133,9 @@ public class PlayedTimeHandler implements dataHandler {
// Feux d'artifices
GeneralEvents.fireworkSoundEffect(player, plugin);
}
} else {
ConsoleLog.danger("Impossible de vérifier la priorité du ou des rôles suivants : " + playerGroupName + " & " + playersAccountUpgradeGroup.getName());
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment