001 package org.bukkit.util.permissions; 002 003 import java.util.Map; 004 import org.bukkit.Bukkit; 005 import org.bukkit.permissions.Permission; 006 import org.bukkit.permissions.PermissionDefault; 007 008 public final class DefaultPermissions { 009 private static final String ROOT = "craftbukkit"; 010 private static final String LEGACY_PREFIX = "craft"; 011 012 private DefaultPermissions() {} 013 014 public static Permission registerPermission(Permission perm) { 015 return registerPermission(perm, true); 016 } 017 018 public static Permission registerPermission(Permission perm, boolean withLegacy) { 019 Permission result = perm; 020 021 try { 022 Bukkit.getPluginManager().addPermission(perm); 023 } catch (IllegalArgumentException ex) { 024 result = Bukkit.getPluginManager().getPermission(perm.getName()); 025 } 026 027 if (withLegacy) { 028 Permission legacy = new Permission(LEGACY_PREFIX + result.getName(), result.getDescription(), PermissionDefault.FALSE); 029 legacy.getChildren().put(result.getName(), true); 030 registerPermission(perm, false); 031 } 032 033 return result; 034 } 035 036 public static Permission registerPermission(Permission perm, Permission parent) { 037 parent.getChildren().put(perm.getName(), true); 038 return registerPermission(perm); 039 } 040 041 public static Permission registerPermission(String name, String desc) { 042 Permission perm = registerPermission(new Permission(name, desc)); 043 return perm; 044 } 045 046 public static Permission registerPermission(String name, String desc, Permission parent) { 047 Permission perm = registerPermission(name, desc); 048 parent.getChildren().put(perm.getName(), true); 049 return perm; 050 } 051 052 public static Permission registerPermission(String name, String desc, PermissionDefault def) { 053 Permission perm = registerPermission(new Permission(name, desc, def)); 054 return perm; 055 } 056 057 public static Permission registerPermission(String name, String desc, PermissionDefault def, Permission parent) { 058 Permission perm = registerPermission(name, desc, def); 059 parent.getChildren().put(perm.getName(), true); 060 return perm; 061 } 062 063 public static Permission registerPermission(String name, String desc, PermissionDefault def, Map<String, Boolean> children) { 064 Permission perm = registerPermission(new Permission(name, desc, def, children)); 065 return perm; 066 } 067 068 public static Permission registerPermission(String name, String desc, PermissionDefault def, Map<String, Boolean> children, Permission parent) { 069 Permission perm = registerPermission(name, desc, def, children); 070 parent.getChildren().put(perm.getName(), true); 071 return perm; 072 } 073 074 public static void registerCorePermissions() { 075 Permission parent = registerPermission(ROOT, "Gives the user the ability to use all CraftBukkit utilities and commands"); 076 077 CommandPermissions.registerPermissions(parent); 078 BroadcastPermissions.registerPermissions(parent); 079 080 parent.recalculatePermissibles(); 081 } 082 }