Advertisement
Guest User

TestPerms v1.0.0 Spigot 1.14.4

a guest
Jul 19th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.47 KB | None | 0 0
  1. public class Main extends JavaPlugin {
  2.    
  3.     Logger pluginLogger = Bukkit.getLogger();
  4.    
  5.     @Override
  6.     public void onEnable() {
  7.        
  8.         pluginLogger.info("[TestPerms] Loading config file...");
  9.         loadConfig();
  10.         pluginLogger.info("[TestPerms] Config file loaded!");
  11.        
  12.         pluginLogger.info("[TestPerms] TestPerms enabled.");
  13.        
  14.     }
  15.    
  16.     @Override
  17.     public void onDisable() {
  18.        
  19.         pluginLogger.info("[TestPerms] Saving config file...");
  20.         saveConfig();
  21.         pluginLogger.info("[TestPerms] Config file saved!");
  22.        
  23.         pluginLogger.info("[TestPerms] TestPerms disabled.");
  24.        
  25.     }
  26.    
  27.     public void loadConfig() {
  28.        
  29.         getConfig().options().copyDefaults(true);
  30.         saveConfig();
  31.        
  32.     }
  33.    
  34.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  35.        
  36.         if(cmd.getName().equalsIgnoreCase("testperms")) {
  37.            
  38.             if(sender instanceof Player) {
  39.                
  40.                 Player p = (Player) sender;
  41.                
  42.                 if(args.length == 0) {
  43.                    
  44.                     p.sendMessage(ChatColor.GOLD + "[TestPerms] TestPerms by X21_Eagle_X21. Try using "
  45.                             + "\"/testperms help\" for information on how to use the commands.");
  46.                    
  47.                     return true;
  48.                    
  49.                 } else if(args.length == 1) {
  50.                    
  51.                     if(args[0].equalsIgnoreCase("reset")) {
  52.                        
  53.                         if(p.hasPermission("testperms.reset")) {
  54.                            
  55.                             List<String> resetTo = getConfig().getStringList("players." + p.getUniqueId() + ".actualgroups");
  56.                            
  57.                             if(resetTo.isEmpty()) {
  58.                                
  59.                                 p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command "
  60.                                         + "testperms: groups could not be reset as no groups are listed "
  61.                                         + "in the configuration file!");
  62.                                
  63.                                 return true;
  64.                                
  65.                             }
  66.                            
  67.                             getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent set " + resetTo.get(0));
  68.                            
  69.                             if(resetTo.size() > 1) {
  70.                                
  71.                                 for(int i = 1; i < resetTo.size(); i++) {
  72.                                    
  73.                                     getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent add " + resetTo.get(i));
  74.                                    
  75.                                 }
  76.                                
  77.                             }
  78.                            
  79.                             p.sendMessage(ChatColor.GREEN + "[TestPerms] Group(s) reset successfully!");
  80.                            
  81.                             return true;
  82.                            
  83.                         } else {
  84.                            
  85.                             p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  86.                                     + "you don't have the required permission(s) to execute this command!");
  87.                            
  88.                             return true;
  89.                            
  90.                         }
  91.                        
  92.                     } else if(args[0].equalsIgnoreCase("help")) {
  93.                        
  94.                         if(p.hasPermission("testperms.help")) {
  95.                            
  96.                             p.sendMessage(ChatColor.GOLD + "[TestPerms] You can test a group\'s permissions"
  97.                                     + " using the \"/testperms test [group]\" command. To get your "
  98.                                     + "actual permissions back, use the \"/testperms reset\" command. Make sure "
  99.                                     + "to set your actual groups before using these commands with the \"/testperms "
  100.                                     + "setactual\" command! You may list as many groups as you want as arguments for "
  101.                                     + "the setactual and test commands. Note that the first group listed will be the primary "
  102.                                     + "group.");
  103.                            
  104.                             return true;
  105.                            
  106.                         } else {
  107.                            
  108.                             p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  109.                                     + "you don't have the required permission(s) to execute this command!");
  110.                            
  111.                             return true;
  112.                            
  113.                         }
  114.                        
  115.                     } else if(args[0].equalsIgnoreCase("test") || args[0].equalsIgnoreCase("setactual")) {
  116.                        
  117.                         p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  118.                                 + "you must specify a group!");
  119.                        
  120.                         return false;
  121.                        
  122.                     } else {
  123.                        
  124.                         p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  125.                                 + "invalid argument(s)!");
  126.                        
  127.                         return false;
  128.                        
  129.                     }
  130.                    
  131.                 } else {
  132.                    
  133.                     if(args[0].equalsIgnoreCase("test")) {
  134.                        
  135.                         if(p.hasPermission("testperms.test")) {
  136.                            
  137.                             ArrayList<String> testGroups = new ArrayList<String>();
  138.                            
  139.                             for(int i = 1; i < args.length; i++) {
  140.                                
  141.                                 testGroups.add(args[i]);
  142.                                
  143.                             }
  144.                            
  145.                             getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent set " + testGroups.get(0));
  146.                            
  147.                             if(testGroups.size() > 1) {
  148.                                
  149.                                 for(int i = 1; i < testGroups.size(); i++) {
  150.                                    
  151.                                     getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " parent add " + testGroups.get(i));
  152.                                    
  153.                                 }
  154.                                
  155.                             }
  156.                            
  157.                             getServer().dispatchCommand(getServer().getConsoleSender(), "lp user " + p.getUniqueId() + " permission set testperms.* true");
  158.                            
  159.                             p.sendMessage(ChatColor.GREEN + "[TestPerms] Test mode enabled successfully! "
  160.                                     + "Note that all TestPerms commands are still available in test mode "
  161.                                     + "regardless of group permissions.");
  162.                            
  163.                             return true;
  164.                            
  165.                         } else {
  166.                            
  167.                             p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  168.                                     + "you don't have the required permission(s) to execute this command!");
  169.                            
  170.                             return true;
  171.                            
  172.                         }
  173.                        
  174.                     } else if(args[0].equalsIgnoreCase("setactual")) {
  175.                        
  176.                         if(p.hasPermission("testperms.setactual")) {
  177.                            
  178.                             ArrayList<String> actualGroups = new ArrayList<String>();
  179.                            
  180.                             for(int i = 1; i < args.length; i++) {
  181.                                
  182.                                 actualGroups.add(args[i]);
  183.                                
  184.                             }
  185.                            
  186.                             getConfig().set("players." + p.getUniqueId() + ".actualgroups", actualGroups);
  187.                            
  188.                             p.sendMessage(ChatColor.GREEN + "[TestPerms] Actual groups set!");
  189.                            
  190.                             return true;
  191.                            
  192.                         } else {
  193.                            
  194.                             p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  195.                                     + "you don't have the required permission(s) to execute this command!");
  196.                            
  197.                             return true;
  198.                            
  199.                         }
  200.                        
  201.                     } else {
  202.                        
  203.                         p.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  204.                                 + "invalid argument(s)!");
  205.                        
  206.                         return false;
  207.                        
  208.                     }
  209.                    
  210.                 }
  211.                
  212.             } else {
  213.                
  214.                 sender.sendMessage(ChatColor.RED + "[TestPerms] Error executing command testperms: "
  215.                         + "command sender must be a player!");
  216.                
  217.                 return true;
  218.                
  219.             }
  220.            
  221.         }
  222.        
  223.         return true;
  224.        
  225.     }
  226.    
  227. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement