net.milkbowl.vault.permission.Permission Java Examples

The following examples show how to use net.milkbowl.vault.permission.Permission. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VaultIntegrator.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void hook() {
    RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager()
            .getRegistration(net.milkbowl.vault.permission.Permission.class);
    if (permissionProvider != null) {
        permission = permissionProvider.getProvider();
    }
    RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager()
            .getRegistration(net.milkbowl.vault.economy.Economy.class);
    if (economyProvider != null) {
        economy = economyProvider.getProvider();
    }
    if (economy != null) {
        plugin.registerEvents("money", MoneyEvent.class);
        plugin.registerConditions("money", MoneyCondition.class);
        plugin.registerVariable("money", MoneyVariable.class);
    } else {
        LogUtils.getLogger().log(Level.WARNING, "There is no economy plugin on the server!");
    }
    if (permission != null) {
        plugin.registerEvents("permission", PermissionEvent.class);
    } else {
        LogUtils.getLogger().log(Level.WARNING, "Could not get permission provider!");
    }
}
 
Example #2
Source File: PermissionEvent.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void execute(String playerID) {
    // Run in Main Thread
    Permission vault = VaultIntegrator.getPermission();
    Player player = PlayerConverter.getPlayer(playerID);
    if (add) {
        if (perm) {
            // world add perm
            vault.playerAdd(world, player, permission);
        } else {
            // world add group
            vault.playerAddGroup(world, player, permission);
        }
    } else {
        if (perm) {
            // world remove perm
            vault.playerRemove(world, player, permission);
        } else {
            // world remove group
            vault.playerRemoveGroup(world, player, permission);
        }
    }
    return null;
}
 
Example #3
Source File: VaultHook.java    From FunnyGuilds with Apache License 2.0 6 votes vote down vote up
public static void initHooks() {
    RegisteredServiceProvider<Economy> economyProvider = Bukkit.getServer().getServicesManager().getRegistration(Economy.class);
    RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);

    if (economyProvider != null) {
        economyHook = economyProvider.getProvider();
    }
    else {
        FunnyGuilds.getInstance().getPluginLogger().warning("No economy provider found, some features may not be available");
    }

    if (permissionProvider != null) {
        permissionHook = permissionProvider.getProvider();
    }
    else {
        FunnyGuilds.getInstance().getPluginLogger().warning("No permission provider found, some features may not be available");
    }
}
 
Example #4
Source File: VaultHookManager.java    From LuckPerms with MIT License 6 votes vote down vote up
/**
 * Registers the LuckPerms implementation of {@link Permission} and {@link Chat} with
 * the service manager.
 */
public void hook() {
    try {
        if (this.permission == null) {
            this.permission = new LuckPermsVaultPermission(this.plugin);
        }

        if (this.chat == null) {
            this.chat = new LuckPermsVaultChat(this.plugin, this.permission);
        }

        final ServicesManager sm = this.plugin.getBootstrap().getServer().getServicesManager();
        sm.register(Permission.class, this.permission, this.plugin.getBootstrap(), ServicePriority.High);
        sm.register(Chat.class, this.chat, this.plugin.getBootstrap(), ServicePriority.High);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: BridgeImpl.java    From TabooLib with MIT License 6 votes vote down vote up
public BridgeImpl() {
    if (Bukkit.getPluginManager().getPlugin("Vault") != null) {
        economy = getRegisteredService(Economy.class);
        permission = getRegisteredService(Permission.class);
    }
    if (Bukkit.getPluginManager().getPlugin("WorldGuard") != null) {
        if (!WorldGuardPlugin.inst().getDescription().getVersion().startsWith("7")) {
            try {
                getRegionManager = WorldGuardPlugin.class.getDeclaredMethod("getRegionManager", World.class);
                getRegionManager.setAccessible(true);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
        }
        worldguard = true;
    }
    placeholder = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
}
 
Example #6
Source File: VaultHandler.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the Vault Permission interface.
 *
 * @param server the bukkit server instance
 * @return the vault permission instance
 * @throws PermissionHandlerException if the vault permission instance cannot be retrieved
 */
@VisibleForTesting
Permission getVaultPermission(Server server) throws PermissionHandlerException {
    // Get the permissions provider service
    RegisteredServiceProvider<Permission> permissionProvider = server
        .getServicesManager().getRegistration(Permission.class);
    if (permissionProvider == null) {
        throw new PermissionHandlerException("Could not load permissions provider service");
    }

    // Get the Vault provider and make sure it's valid
    Permission vaultPerms = permissionProvider.getProvider();
    if (vaultPerms == null) {
        throw new PermissionHandlerException("Could not load Vault permissions provider");
    }
    return vaultPerms;
}
 
Example #7
Source File: GroupSynchronizationManager.java    From DiscordSRV with GNU General Public License v3.0 6 votes vote down vote up
public Permission getPermissions() {
    if (permission != null) {
        return permission;
    } else {
        try {
            Class.forName("net.milkbowl.vault.permission.Permission");
            RegisteredServiceProvider<Permission> provider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
            if (provider == null) {
                DiscordSRV.debug("Can't access permissions: registration provider was null");
                return null;
            }
            return permission = provider.getProvider();
        } catch (ClassNotFoundException e) {
            if (!warnedAboutMissingVault) {
                DiscordSRV.error("Group synchronization failed: Vault classes couldn't be found (did it enable properly?). Vault is required for synchronization to work.");
                warnedAboutMissingVault = true;
            }
            return null;
        }
    }
}
 
Example #8
Source File: GuildHandler.java    From Guilds with MIT License 6 votes vote down vote up
/**
 * Remove all perms from a player for the guild
 * @param permission permission to remove
 * @param guild the guild being modified
 */
public void removePermsFromAll(Permission permission, Guild guild, boolean async) {
    GuildTier tier = getGuildTier(guild.getTier().getLevel());
    if (tier.getPermissions().isEmpty())
        return;
    if (async) {
        Guilds.newChain().async(() -> guild.getAllAsPlayers().forEach(player -> getGuildTier(guild.getTier().getLevel()).getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerRemove(null, player, perm);
            }
        }))).execute();
    } else {
        guild.getAllAsPlayers().forEach(player -> getGuildTier(guild.getTier().getLevel()).getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerRemove(null, player, perm);
            }
        }));
    }

}
 
Example #9
Source File: GuildHandler.java    From Guilds with MIT License 6 votes vote down vote up
/**
 * Add all the perms to a player for the guild
 * @param permission permission to add
 * @param guild the guild being modified
 */
public void addPermsToAll(Permission permission, Guild guild, boolean async) {
    GuildTier tier = getGuildTier(guild.getTier().getLevel());
    if (tier.getPermissions().isEmpty())
        return;
    if (async) {
        Guilds.newChain().async(() -> guild.getAllAsPlayers().forEach(player -> getGuildTier(guild.getTier().getLevel()).getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerAdd(null, player, perm);
            }
        }))).execute();
    } else {
        guild.getAllAsPlayers().forEach(player -> getGuildTier(guild.getTier().getLevel()).getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerAdd(null, player, perm);
            }
        }));
    }

}
 
Example #10
Source File: GuildHandler.java    From Guilds with MIT License 6 votes vote down vote up
/**
 * Remove perms from a single player
 * @param permission the permission to remove
 * @param player the player to remove from
 */
public void removePerms(Permission permission, OfflinePlayer player, boolean async) {
    Guild guild = getGuild(player);
    if (guild == null)
        return;
    GuildTier tier = getGuildTier(guild.getTier().getLevel());
    if (tier.getPermissions().isEmpty())
        return;
    if (async) {
        Guilds.newChain().async(() -> tier.getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerRemove(null, player, perm);
            }
        })).execute();
    } else {
        tier.getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerRemove(null, player, perm);
            }
        });
    }

}
 
Example #11
Source File: GuildHandler.java    From Guilds with MIT License 6 votes vote down vote up
/**
 * Add perms to a single player
 * @param permission the permission to add
 * @param player the player to add to
 */
public void addPerms(Permission permission, OfflinePlayer player, boolean async) {
    Guild guild = getGuild(player);
    if (guild == null)
        return;
    GuildTier tier = getGuildTier(guild.getTier().getLevel());
    if (tier.getPermissions().isEmpty())
        return;
    if (async) {
        Guilds.newChain().async(() -> tier.getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerAdd(null, player, perm);
            }
        })).execute();
    } else {
        tier.getPermissions().forEach(perm -> {
            if (!perm.equals("")) {
                permission.playerAdd(null, player, perm);
            }
        });
    }

}
 
Example #12
Source File: VaultProvider.java    From HoloAPI with GNU General Public License v3.0 5 votes vote down vote up
private boolean setupPermissions() {
    RegisteredServiceProvider<Permission> permissionProvider = this.getHandlingPlugin().getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    if (permissionProvider != null) {
        permission = permissionProvider.getProvider();
    }
    return (permission != null);
}
 
Example #13
Source File: Chat_BungeePerms.java    From BungeePerms with GNU General Public License v3.0 5 votes vote down vote up
public Chat_BungeePerms(Plugin plugin, Permission perms)
{
    super(perms);
    this.plugin = plugin;
    Bukkit.getServer().getPluginManager().registerEvents(new ChatServerListener(), BukkitPlugin.getInstance());

    // Load Plugin in case it was loaded before
    Plugin p = plugin.getServer().getPluginManager().getPlugin("BungeePerms");
    if (p != null)
    {
        this.perms = BungeePerms.getInstance();
        log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), name));
    }
}
 
Example #14
Source File: VaultHelper.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets up the permissions instance
 * 
 * @return true if successful
 */
public static boolean setupPermissions() {
    RegisteredServiceProvider<Permission> permissionProvider = ASkyBlock.getPlugin().getServer().getServicesManager()
            .getRegistration(net.milkbowl.vault.permission.Permission.class);
    if (permissionProvider != null) {
        permission = permissionProvider.getProvider();
    }
    return (permission != null);
}
 
Example #15
Source File: VaultHookManager.java    From LuckPerms with MIT License 5 votes vote down vote up
/**
 * Unregisters the LuckPerms Vault hooks, if present.
 */
public void unhook() {
    final ServicesManager sm = this.plugin.getBootstrap().getServer().getServicesManager();

    if (this.permission != null) {
        sm.unregister(Permission.class, this.permission);
        this.permission = null;
    }

    if (this.chat != null) {
        sm.unregister(Chat.class, this.chat);
        this.chat = null;
    }
}
 
Example #16
Source File: SentinelPlugin.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Fills the {@code vaultPerms} object if possible.
 */
public void tryGetPerms() {
    if (Bukkit.getServer().getPluginManager().getPlugin("Vault") == null) {
        return;
    }
    try {
        RegisteredServiceProvider<Permission> rsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
        vaultPerms = rsp.getProvider();
        getLogger().info("Vault linked! Group targets will work.");
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example #17
Source File: VaultHook.java    From SaneEconomy with GNU General Public License v3.0 5 votes vote down vote up
public boolean hasPermission(OfflinePlayer offlinePlayer, String permNode) {
    RegisteredServiceProvider<Permission> rsp = this.plugin.getServer().getServicesManager().getRegistration(Permission.class);

    if ((offlinePlayer == null) || (offlinePlayer.getUniqueId() == null) || Strings.isNullOrEmpty(offlinePlayer.getName())) {
        return false;
    }

    return (rsp != null) && rsp.getProvider().playerHas(null, offlinePlayer, permNode);
}
 
Example #18
Source File: VaultUtil.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public VaultUtil() {
    final RegisteredServiceProvider<Permission> permissionProvider = Bukkit.getServer().getServicesManager().getRegistration(net.milkbowl.vault.permission.Permission.class);
    if (permissionProvider != null) {
        this.permission = permissionProvider.getProvider();
    } else {
        this.permission = null;
    }
}
 
Example #19
Source File: VaultPermissions.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
private Optional<Permission> setupPermission() {
    RegisteredServiceProvider<Permission> rsp =
        plugin.getServer().getServicesManager().getRegistration(Permission.class);
    if (rsp != null) {
        permission = rsp.getProvider();
        return Optional.of(permission);
    }

    return Optional.empty();
}
 
Example #20
Source File: VaultPermissions.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
@SuppressWarnings("unused")
public void onPermissionRegister(ServiceRegisterEvent event) {
    if (event.getProvider().getProvider() instanceof Permission) {
        setupPermission().ifPresent((permission) -> this.permission = permission);
    }
}
 
Example #21
Source File: VaultPermissions.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
@SuppressWarnings("unused")
public void onPermissionUnregister(ServiceUnregisterEvent event) {
    if (event.getProvider().getProvider() instanceof Permission) {
        this.permission = null;
        setupPermission().ifPresent((permission) -> this.permission = permission);
    }
}
 
Example #22
Source File: VaultHook.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
@Override
protected boolean init() {
	economy = Bukkit.getServicesManager().getRegistration(Economy.class) == null ? null : Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
	chat = Bukkit.getServicesManager().getRegistration(Chat.class) == null ? null : Bukkit.getServicesManager().getRegistration(Chat.class).getProvider();
	permission = Bukkit.getServicesManager().getRegistration(Permission.class) == null ? null : Bukkit.getServicesManager().getRegistration(Permission.class).getProvider();
	return economy != null || chat != null || permission != null;
}
 
Example #23
Source File: VaultPermissions.java    From Modern-LWC with MIT License 5 votes vote down vote up
@Override
public List<String> getGroups(Player player) {
    RegisteredServiceProvider<Permission> serviceProvider = Bukkit.getServer().getServicesManager()
            .getRegistration(Permission.class);
    groupPrefix = LWC.getInstance().getConfiguration().getString("core.groupPrefix", "group.");
    if (serviceProvider == null) {
        return super.getGroups(player);
    }

    Permission perm = serviceProvider.getProvider();

    try {
        // the player's groups
        String[] groups = perm.getPlayerGroups(player);

        // fallback to superperms if it appears that they have no groups
        if (groups == null || groups.length == 0) {
            return super.getGroups(player);
        }

        List<String> groupss = Arrays.asList(groups);

        for (PermissionAttachmentInfo pai : player.getEffectivePermissions()) {
            if (pai.getPermission().startsWith(groupPrefix)) {
                groupss.add(pai.getPermission().substring(groupPrefix.length()));
            }
        }

        return groupss;
    } catch (UnsupportedOperationException e) {
        // Can be thrown by vault or asList. Thrown by Vault when using SuperPerms -
        // getPlayerGroups() will throw it :-(
        return super.getGroups(player);
    }
}
 
Example #24
Source File: VaultHandlerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void shouldReturnGroups() {
    // given
    Permission permissionMock = vaultHandlerTest.permissionMock;
    Player player = mock(Player.class);
    given(permissionMock.getPlayerGroups(null, player)).willReturn(new String[]{"abc", "test"});

    // when
    List<String> result = vaultHandlerTest.getGroups(player);

    // then
    assertThat(result, contains("abc", "test"));
    verify(permissionMock).getPlayerGroups(null, player);
}
 
Example #25
Source File: VaultHandlerTest.java    From AuthMeReloaded with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Bug #1702: VaultHandler may return null for groups list.
 */
@Test
public void shouldHandleNullAsGroups() {
    // given
    Permission permissionMock = vaultHandlerTest.permissionMock;
    Player player = mock(Player.class);
    given(permissionMock.getPlayerGroups(null, player)).willReturn(null);

    // when
    List<String> result = vaultHandlerTest.getGroups(player);

    // then
    assertThat(result, empty());
    verify(permissionMock).getPlayerGroups(null, player);
}
 
Example #26
Source File: PluginHooks.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static String Vault_getPermissionPlugin() {
	try {
		return ((Permission)Vault_permission).getName();
	} catch (Throwable e) {
		return Shared.errorManager.printError("Unknown/None", "Failed to get permission plugin name using Vault", e);
	}
}
 
Example #27
Source File: VaultInvoker.java    From CloudNet with Apache License 2.0 5 votes vote down vote up
public static void invoke() {
    ServicesManager servicesManager = BukkitBootstrap.getPlugin(BukkitBootstrap.class).getServer().getServicesManager();

    Permission permission = new VaultPermissionImpl();

    servicesManager.register(Permission.class, permission, BukkitBootstrap.getPlugin(BukkitBootstrap.class), ServicePriority.Highest);
    servicesManager.register(Chat.class,
                             new VaultChatImpl(permission),
                             BukkitBootstrap.getPlugin(BukkitBootstrap.class),
                             ServicePriority.Highest);
}
 
Example #28
Source File: VaultPermissionProvider.java    From QuickShop-Reremake with GNU General Public License v3.0 5 votes vote down vote up
@Deprecated
public VaultPermissionProvider() {
    RegisteredServiceProvider<Permission> rsp =
            Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
    if (rsp == null) {
        throw new ProviderIsEmptyException(getName());
    }
    api = rsp.getProvider();
}
 
Example #29
Source File: PluginHooks.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static void Vault_loadProviders() {
	RegisteredServiceProvider<Economy> rspEconomy = Bukkit.getServicesManager().getRegistration(Economy.class);
	if (rspEconomy != null) Vault_economy = rspEconomy.getProvider();
	RegisteredServiceProvider<Permission> rspPermission = Bukkit.getServicesManager().getRegistration(Permission.class);
	if (rspPermission != null) Vault_permission = rspPermission.getProvider();
	RegisteredServiceProvider<Chat> rspChat = Bukkit.getServicesManager().getRegistration(Chat.class);
	if (rspChat != null) Vault_chat = rspChat.getProvider();
}
 
Example #30
Source File: PluginHooks.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static String Vault_getPrimaryGroup(ITabPlayer p) {
	try {
		return ((Permission)Vault_permission).getPrimaryGroup(p.getBukkitEntity());
	} catch (Throwable e) {
		return Shared.errorManager.printError("null", "Failed to get permission group of " + p.getName() + " using Vault", e);
	}
}