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

Merge branch 'feature/10_donner_le_role_habitue_aux_joueurs_habitues' into 'main'

Donner le rôle habitué aux joueurs habitués

See merge request SofianeLasri/sl-craft-plugin!7
parents 6a615721 c5bd00da
Branches
No related tags found
1 merge request!7Donner le rôle habitué aux joueurs habitués
Pipeline #87 passed
...@@ -29,11 +29,21 @@ public class PlayedTimeHandler implements dataHandler { ...@@ -29,11 +29,21 @@ public class PlayedTimeHandler implements dataHandler {
public PlayedTimeHandler(Main plugin) { public PlayedTimeHandler(Main plugin) {
this.plugin = plugin; this.plugin = plugin;
String playersAccountUpgradeRole = plugin.getConfig().getString("stats.players-account-upgrade-role");
if (playersAccountUpgradeRole != null) {
usersIndexes = new ArrayList<>(); usersIndexes = new ArrayList<>();
userSessionJoinDateTime = new ArrayList<>(); userSessionJoinDateTime = new ArrayList<>();
userStoredPlayedTimeBeforeJoining = new ArrayList<>(); userStoredPlayedTimeBeforeJoining = new ArrayList<>();
requiredPlayedTimeForUpgradingPlayersAccount = plugin.getConfig().getInt("stats.required-played-time-for-upgrading-players-account"); 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 @Override
...@@ -84,12 +94,20 @@ public class PlayedTimeHandler implements dataHandler { ...@@ -84,12 +94,20 @@ public class PlayedTimeHandler implements dataHandler {
if (actualPlayedTime >= requiredPlayedTimeForUpgradingPlayersAccount) { if (actualPlayedTime >= requiredPlayedTimeForUpgradingPlayersAccount) {
String playerGroupName = Main.luckPermsApi.getPlayerAdapter(Player.class).getMetaData(player).getPrimaryGroup(); 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); 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()) { 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 + "!"); 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()); 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 // 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(); InheritanceNode node = InheritanceNode.builder(playersAccountUpgradeGroup).value(true).build();
...@@ -115,6 +133,9 @@ public class PlayedTimeHandler implements dataHandler { ...@@ -115,6 +133,9 @@ public class PlayedTimeHandler implements dataHandler {
// Feux d'artifices // Feux d'artifices
GeneralEvents.fireworkSoundEffect(player, plugin); 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