daily pastebin goal
46%
SHARE
TWEET

RankCommand - DailyaRank

Goobbuh Feb 16th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package be.goobbuh.dailyarank.bukkit.command;
  2.  
  3. import java.util.List;
  4.  
  5. import org.bukkit.Bukkit;
  6. import org.bukkit.OfflinePlayer;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandExecutor;
  9. import org.bukkit.command.CommandSender;
  10. import org.bukkit.command.TabCompleter;
  11. import org.bukkit.entity.Player;
  12.  
  13. import com.google.common.collect.Lists;
  14.  
  15. import be.goobbuh.dailyarank.DailyaRank;
  16. import be.goobbuh.dailyarank.RankList;
  17.  
  18. public final class RankCommand implements CommandExecutor, TabCompleter {
  19.    
  20.     private final DailyaRank dailyarank;
  21.    
  22.     public RankCommand(DailyaRank dailyarank) {
  23.         this.dailyarank = dailyarank;
  24.     }
  25.    
  26.     @SuppressWarnings("deprecation")
  27.     public boolean onCommand(CommandSender s, Command c, String l, String[] a) {
  28.         if(s instanceof Player) {
  29.             if(dailyarank.hasPowerInf((Player)s, 89))
  30.                 return sendMessage(s, " §cVous n'avez pas la permission ( §6» power supperieure a 89 « §c)");
  31.         }
  32.        
  33.         if(a.length < 2) return sendMessage(s, " §c/Grade <Player> <Grade>");
  34.        
  35.         OfflinePlayer target = Bukkit.getOfflinePlayer(a[0]);
  36.         if(target == null) return sendMessage(s, " §cLe joueur n'a pas été trouvé");
  37.        
  38.         String uuid = target.getUniqueId().toString();
  39.         if(!dailyarank.getConfig().contains(uuid)) return sendMessage(s, " §cLe joueur n'a pas été trouvé");
  40.        
  41.         RankList rankList = null;
  42.        
  43.         try {
  44.             rankList = dailyarank.getRankById(Integer.parseInt(a[1]));
  45.         }catch(NumberFormatException nbe) {
  46.             try {
  47.                 rankList = RankList.valueOf(a[1].toUpperCase());   
  48.             }catch(Exception e) {
  49.                 return sendMessage(s, "§cLe grade n'a pas été trouvé");
  50.             }
  51.         }
  52.  
  53.         dailyarank.changeRank(uuid, rankList);
  54.        
  55.         if(target.isOnline()) {
  56.             sendMessage(target.getPlayer(), "§9Votre grade a été modifier !");
  57.             dailyarank.deletePlayer(target.getPlayer());
  58.             dailyarank.loadPlayer(target.getPlayer());
  59.         }
  60.        
  61.         return sendMessage(s, "§6"+target.getName()+" §2a bien obtenu son grade §5"+rankList.getName().toLowerCase());
  62.     }
  63.  
  64.     public boolean sendMessage(CommandSender s, String msg) {
  65.         s.sendMessage(dailyarank.getPrefix() +msg);
  66.         return true;
  67.     }
  68.    
  69.     public List<String> onTabComplete(CommandSender s, Command c, String l, String[] a) {
  70.         List<String> tabComplete = Lists.newArrayList();
  71.        
  72.         if(a.length == 2) {
  73.             for(RankList rankList : RankList.values())
  74.                 if(rankList.getName().toLowerCase().startsWith(a[1].toLowerCase()))
  75.                     tabComplete.add(rankList.getName());
  76.             return tabComplete;
  77.         }
  78.         return null;
  79.     }
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top