Advertisement
Guest User

Untitled

a guest
Apr 5th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.57 KB | None | 0 0
  1. package com.xdsmp.ranks;
  2.  
  3. import java.util.HashMap;
  4. import java.util.UUID;
  5.  
  6. import org.bukkit.Bukkit;
  7. import org.bukkit.command.Command;
  8. import org.bukkit.command.CommandSender;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.event.Listener;
  11. import org.bukkit.permissions.PermissionAttachment;
  12. import org.bukkit.plugin.java.JavaPlugin;
  13.  
  14. public class Main extends JavaPlugin implements Listener {
  15.    
  16.     public static Main plugin;
  17.     public HashMap<UUID, PermissionAttachment> playerPermissions = new HashMap<>();
  18.    
  19.     @Override
  20.     public void onEnable(){
  21.         plugin = this;
  22.         this.getConfig().options().copyDefaults(true);
  23.  
  24.         this.getServer().getPluginManager().registerEvents(this, this);
  25.         saveConfig();
  26.     }
  27.    
  28.     @Override
  29.     public void onDisable(){
  30.        
  31.     }
  32.    
  33.     public void defaultPermissions(Player player) {
  34.         PermissionAttachment attachment = player.addAttachment(this);
  35.         this.playerPermissions.put(player.getUniqueId(), attachment);
  36.         defaultpermissionSetter(player.getUniqueId());
  37.     }
  38.  
  39.     private void defaultpermissionSetter(UUID uuid) {
  40.         PermissionAttachment attachment = this.playerPermissions.get(uuid);
  41.         for (String groups : this.getConfig().getConfigurationSection("Groups").getKeys(true)) {
  42.             for (String permissions : this.getConfig().getStringList("Groups." + groups + "default.permissions")) {
  43.                 System.out.print(permissions);
  44.                 attachment.setPermission(permissions, true);
  45.             }
  46.         }
  47.     }
  48.    
  49.     public void helperPermissions(Player player) {
  50.         PermissionAttachment attachment = player.addAttachment(this);
  51.         this.playerPermissions.put(player.getUniqueId(), attachment);
  52.         helperpermissionSetter(player.getUniqueId());
  53.     }
  54.  
  55.     private void helperpermissionSetter(UUID uuid) {
  56.         PermissionAttachment attachment = this.playerPermissions.get(uuid);
  57.         for (String groups : this.getConfig().getConfigurationSection("Groups").getKeys(false)) {
  58.             for (String permissions : this.getConfig().getStringList("Groups." + groups + "helper.permissions")) {
  59.                 System.out.print(permissions);
  60.                 attachment.setPermission(permissions, true);
  61.             }
  62.         }
  63.     }
  64.    
  65.     public void moderatorPermissions(Player player) {
  66.         PermissionAttachment attachment = player.addAttachment(this);
  67.         this.playerPermissions.put(player.getUniqueId(), attachment);
  68.         moderatorpermissionSetter(player.getUniqueId());
  69.     }
  70.  
  71.     private void moderatorpermissionSetter(UUID uuid) {
  72.         PermissionAttachment attachment = this.playerPermissions.get(uuid);
  73.         for (String groups : this.getConfig().getConfigurationSection("Groups").getKeys(false)) {
  74.             for (String permissions : this.getConfig().getStringList("Groups." + groups + "moderator." + ".permissions")) {
  75.                 System.out.print(permissions);
  76.                 attachment.setPermission(permissions, true);
  77.             }
  78.         }
  79.     }
  80.    
  81.     public void adminPermissions(Player player) {
  82.         PermissionAttachment attachment = player.addAttachment(this);
  83.         this.playerPermissions.put(player.getUniqueId(), attachment);
  84.         adminpermissionSetter(player.getUniqueId());
  85.     }
  86.  
  87.     private void adminpermissionSetter(UUID uuid) {
  88.         PermissionAttachment attachment = this.playerPermissions.get(uuid);
  89.         for (String groups : this.getConfig().getConfigurationSection("Groups").getKeys(false)) {
  90.             for (String permissions : this.getConfig().getStringList("Groups." + groups + "administrator." + ".permissions")) {
  91.                 System.out.print(permissions);
  92.                 attachment.setPermission(permissions, true);
  93.             }
  94.         }
  95.     }
  96.    
  97.     public void ownerPermissions(Player player) {
  98.         PermissionAttachment attachment = player.addAttachment(this);
  99.         this.playerPermissions.put(player.getUniqueId(), attachment);
  100.         ownerpermissionSetter(player.getUniqueId());
  101.     }
  102.  
  103.     private void ownerpermissionSetter(UUID uuid) {
  104.         PermissionAttachment attachment = this.playerPermissions.get(uuid);
  105.         for (String groups : this.getConfig().getConfigurationSection("Groups").getKeys(false)) {
  106.             for (String permissions : this.getConfig().getStringList("Groups." + groups + ".permissions")) {
  107.                 System.out.print(permissions);
  108.                 attachment.setPermission(permissions, true);
  109.             }
  110.         }
  111.     }
  112.    
  113.     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  114.         if (label.equalsIgnoreCase("rank")) {
  115.             Player p = (Player) sender;
  116.             Player t = Bukkit.getPlayerExact(args[0]);
  117.             if (p.hasPermission("xdsmp.admin.rank")) {
  118.                 if (args[0].equalsIgnoreCase(t.getName())) {
  119.                     if (args[1].equalsIgnoreCase("set")) {
  120.                         if (args[2].equalsIgnoreCase("member")) {
  121.                             if (!(t.hasPermission("xdsmp.default"))) {
  122.                                 defaultPermissions(t);
  123.                                 t.sendMessage("§7Your rank has been updated to §bMember");
  124.                                 p.sendMessage("§7Successfully gave §bMember§7 to " + t.getName() + "§7!");
  125.                             } else if (t.hasPermission("xdsmp.default")) {
  126.                                 p.sendMessage("§cThis player is already a Member!");
  127.                             }
  128.                         } else if (args[2].equalsIgnoreCase("helper")) {
  129.                             if (!(t.hasPermission("xdsmp.helper"))) {
  130.                                 helperPermissions(t);
  131.                                 t.sendMessage("§7Your rank has been updated to §bHelper§7!");
  132.                                 p.sendMessage("§7Successfully gave §bHelper§7 to " + t.getName() + "§7!");
  133.                             } else if (t.hasPermission("xdsmp.helper")) {
  134.                                 p.sendMessage("§cThis player is already a Helper!");
  135.                             }
  136.                         } else if (args[2].equalsIgnoreCase("moderator")) {
  137.                             if (!(t.hasPermission("xdsmp.moderator"))) {
  138.                                 moderatorPermissions(t);
  139.                                 t.sendMessage("§7Your rank has been updated to §bModerator§7!");
  140.                                 p.sendMessage("§7Successfully gave §bModerator§7 to " + t.getName() + "§7!");
  141.                             } else if (t.hasPermission("xdsmp.moderator")) {
  142.                                 p.sendMessage("§cThis player is already a Moderator!");
  143.                             }
  144.                         } else if (args[2].equalsIgnoreCase("admin")) {
  145.                             if (!(t.hasPermission("xdsmp.administrator"))) {
  146.                                 adminPermissions(t);
  147.                                 t.sendMessage("§7Your rank has been updated to §bAdmin§7!");
  148.                                 p.sendMessage("§7Successfully gave §bAdmin§7 to " + t.getName() + "§7!");
  149.                             } else if (t.hasPermission("xdsmp.administrator")) {
  150.                                 p.sendMessage("§cThis player is already a Administrator!");
  151.                             }
  152.                         } else if (args[2].equalsIgnoreCase("owner")) {
  153.                             if (!(t.hasPermission("xdsmp.owner"))) {
  154.                                 ownerPermissions(t);
  155.                                 t.sendMessage("§7Your rank has been updated to §bOwner§7!");
  156.                                 p.sendMessage("§7Successfully gave §bOwner§7 to " + t.getName() + "§7!");
  157.                             } else if (t.hasPermission("xdsmp.owner")) {
  158.                                 p.sendMessage("§cThis player is already a Owner!");
  159.                             }
  160.                         }
  161.                     }
  162.                 }
  163.             } else {
  164.                 p.sendMessage("§cNo permission!");
  165.             }
  166.         }
  167.         return false;
  168.     }
  169.    
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement