From f06475d62b83ee0de0b3fbc1a74a40e8be1df116 Mon Sep 17 00:00:00 2001 From: NK Date: Mon, 28 Nov 2022 22:52:00 +0000 Subject: [PATCH] permissions for adding role --- .../nullvalkyrie/commands/RankCommand.java | 61 +++++++------------ .../nullvalkyrie/ui/AnimatedSideBar.java | 1 - src/main/resources/plugin.yml | 2 + 3 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java index 2fc0bd8..1920075 100644 --- a/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java +++ b/src/main/java/me/night/nullvalkyrie/commands/RankCommand.java @@ -1,8 +1,6 @@ package me.night.nullvalkyrie.commands; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; -import me.night.nullvalkyrie.database.ranks.RankManager; +import me.night.nullvalkyrie.database.RankDataManager; import me.night.nullvalkyrie.ui.Rank; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -13,8 +11,6 @@ import org.bukkit.util.StringUtil; import java.util.ArrayList; import java.util.List; -import java.util.UUID; -import java.util.concurrent.TimeUnit; public class RankCommand extends Command { @@ -23,48 +19,33 @@ public class RankCommand extends Command { "rank", new String[]{}, "Set rank of players", - "" + "nv.rank.add" ); } - private final Cache cooldown = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build(); - @Override public void onCommand(CommandSender sender, String[] args) { - if (sender instanceof Player) { - Player player = (Player) sender; - if (!cooldown.asMap().containsKey(player.getUniqueId())) { - if (!player.isOp()) { - player.sendMessage(ChatColor.RED + "You must be server operator to use this command"); - return; - } - if (args.length == 2) { - if (Bukkit.getOfflinePlayer(args[0]).hasPlayedBefore()) { - OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); - for (Rank rank : Rank.values()) { - if (rank.name().equalsIgnoreCase(args[1])) { - RankManager.setRank(target.getUniqueId(), rank); - player.sendMessage(ChatColor.GREEN + "You changed " + target.getName() + "'s rank to " + rank.getDisplay()); - if (target.isOnline()) { - target.getPlayer().sendMessage(ChatColor.GREEN + player.getName() + " set your rank to " + rank.getDisplay()); - } - return; - } - - } - player.sendMessage(ChatColor.RED + "Invalid Rank, please specify a valid rank, ROOKIE, SPECIAL, ADMIN, OWNER"); - } else { - player.sendMessage("This player has never played in this server before!"); - } - } else { - player.sendMessage(ChatColor.RED + "Invalid parameter, use /rank "); - } - cooldown.put(player.getUniqueId(), System.currentTimeMillis() + 5000); - } else { - long distance = cooldown.asMap().get(player.getUniqueId()) - System.currentTimeMillis(); - player.sendMessage(ChatColor.RED + "You are on a " + TimeUnit.MILLISECONDS.toSeconds(distance) + " seconds cooldown to use the command again"); + if (sender instanceof Player player) { + if (!player.isOp()) { + player.sendMessage(ChatColor.RED + "You must be server operator to use this command"); + return; } + if (args.length == 2) { + if (Bukkit.getOfflinePlayer(args[0]).hasPlayedBefore()) { + OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); + for (Rank rank : Rank.values()) { + if (rank.name().equalsIgnoreCase(args[1])) { + RankDataManager.setRank(target.getUniqueId(), rank); + player.sendMessage(ChatColor.GREEN + "You changed " + target.getName() + "'s rank to " + rank.getDisplay()); + if (target.isOnline()) + target.getPlayer().sendMessage(ChatColor.GREEN + player.getName() + " set your rank to " + rank.getDisplay()); + return; + } + } + player.sendMessage(ChatColor.RED + "Invalid Rank, please specify a valid rank, ROOKIE, SPECIAL, ADMIN, OWNER"); + } else player.sendMessage("This player has never played in this server before!"); + } else player.sendMessage(ChatColor.RED + "Invalid parameter, use /rank "); } } diff --git a/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java b/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java index dcb4d07..0e99fca 100644 --- a/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java +++ b/src/main/java/me/night/nullvalkyrie/ui/AnimatedSideBar.java @@ -9,7 +9,6 @@ import java.util.UUID; public class AnimatedSideBar { private static final Map Tasks = new HashMap<>(); private final UUID uuid; - public AnimatedSideBar(UUID uuid) { this.uuid = uuid; } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8f88048..0c91cbd 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -9,5 +9,7 @@ depend: [ProtocolLib] permissions: nv.command.use: default: true + nv.rank.add: + default: op libraries: - "io.github.cdimascio:dotenv-java:2.3.1"