mirror of
https://github.com/MilkBowl/Vault.git
synced 2024-11-27 04:55:33 +01:00
Merge pull request #309 from krinsdeath/master
Updated Privileges' implementation in Vault
This commit is contained in:
commit
7b5da490e3
Binary file not shown.
2
pom.xml
2
pom.xml
@ -23,7 +23,7 @@
|
||||
<dependency>
|
||||
<groupId>net.krinsoft.privileges</groupId>
|
||||
<artifactId>Privileges</artifactId>
|
||||
<version>1.4.0b45</version>
|
||||
<version>1.7b127</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/lib/Privileges.jar</systemPath>
|
||||
</dependency>
|
||||
|
@ -2,12 +2,9 @@ package net.milkbowl.vault.permission.plugins;
|
||||
|
||||
import net.krinsoft.privileges.Privileges;
|
||||
import net.krinsoft.privileges.groups.Group;
|
||||
import net.krinsoft.privileges.groups.GroupManager;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -16,21 +13,22 @@ import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Permission_Privileges extends Permission {
|
||||
|
||||
private final String name = "";
|
||||
private GroupManager perms;
|
||||
private Privileges privs;
|
||||
|
||||
public Permission_Privileges(Plugin plugin) {
|
||||
this.plugin = plugin;
|
||||
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
|
||||
// Load service in case it was loaded before
|
||||
if (perms == null) {
|
||||
if (privs == null) {
|
||||
Plugin perms = plugin.getServer().getPluginManager().getPlugin("Privileges");
|
||||
if (perms != null && perms.isEnabled()) {
|
||||
this.privs = (Privileges) perms;
|
||||
this.perms = privs.getGroupManager();
|
||||
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
||||
}
|
||||
}
|
||||
@ -45,13 +43,12 @@ public class Permission_Privileges extends Permission {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (permission.perms == null) {
|
||||
if (permission.privs == null) {
|
||||
Plugin perms = plugin.getServer().getPluginManager().getPlugin("SimplyPerms");
|
||||
|
||||
if (perms != null) {
|
||||
if (perms.isEnabled()) {
|
||||
permission.privs = (Privileges) perms;
|
||||
permission.perms = permission.privs.getGroupManager();
|
||||
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
|
||||
}
|
||||
}
|
||||
@ -60,9 +57,8 @@ public class Permission_Privileges extends Permission {
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (permission.perms != null) {
|
||||
if (permission.privs != null) {
|
||||
if (event.getPlugin().getDescription().getName().equals("SimplyPerms")) {
|
||||
permission.perms = null;
|
||||
permission.privs = null;
|
||||
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
|
||||
}
|
||||
@ -83,7 +79,7 @@ public class Permission_Privileges extends Permission {
|
||||
@Override
|
||||
public boolean playerHas(String world, String player, String permission) {
|
||||
Player p = plugin.getServer().getPlayer(player);
|
||||
return p != null ? p.hasPermission(permission) : false;
|
||||
return p != null && p.hasPermission(permission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,77 +96,65 @@ public class Permission_Privileges extends Permission {
|
||||
|
||||
@Override
|
||||
public boolean groupHas(String world, String group, String permission) {
|
||||
ConfigurationSection priv = privs.getGroupNode(group);
|
||||
if (priv == null) {
|
||||
return false;
|
||||
} else {
|
||||
return priv.getBoolean(permission);
|
||||
}
|
||||
Group g = privs.getGroupManager().getGroup(group);
|
||||
return g != null && g.hasPermission(permission, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupAdd(String world, String group, String permission) {
|
||||
throw new UnsupportedOperationException("Privileges does not support modifying permissions.");
|
||||
Group g = privs.getGroupManager().getGroup(group);
|
||||
return g != null && g.addPermission(permission, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean groupRemove(String world, String group, String permission) {
|
||||
throw new UnsupportedOperationException("Privileges does not support modifying permissions.");
|
||||
Group g = privs.getGroupManager().getGroup(group);
|
||||
return g != null && g.removePermission(permission, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerInGroup(String world, String player, String group) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if (p == null) {
|
||||
throw new UnsupportedOperationException("Privileges does not support offline players.");
|
||||
}
|
||||
Group g = perms.getGroup(p);
|
||||
return g != null && g.getName().equalsIgnoreCase(group);
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
||||
Group g = privs.getGroupManager().getGroup(p);
|
||||
return g != null && g.getGroupTree().contains(group);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerAddGroup(String world, String player, String group) {
|
||||
if (world != null) {
|
||||
return false;
|
||||
}
|
||||
perms.setGroup(player, group);
|
||||
privs.getGroupManager().setGroup(player, group);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean playerRemoveGroup(String world, String player, String group) {
|
||||
Group g = perms.getDefaultGroup();
|
||||
if (g == null) {
|
||||
return false;
|
||||
}
|
||||
return playerAddGroup(world, player, g.getName());
|
||||
Group g = privs.getGroupManager().getDefaultGroup();
|
||||
return g != null && playerAddGroup(world, player, g.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPlayerGroups(String world, String player) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
||||
if (p == null) {
|
||||
throw new UnsupportedOperationException("Privileges does not support offline players.");
|
||||
}
|
||||
Group g = perms.getGroup(p);
|
||||
return g != null ? new String[] { g.getName() } : null;
|
||||
Group g = privs.getGroupManager().getGroup(p);
|
||||
return g != null ? g.getGroupTree().toArray(new String[g.getGroupTree().size()]) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryGroup(String world, String player) {
|
||||
Player p = Bukkit.getPlayer(player);
|
||||
if (p == null) {
|
||||
throw new UnsupportedOperationException("Privileges does not support offline players.");
|
||||
}
|
||||
Group g = perms.getGroup(p);
|
||||
OfflinePlayer p = Bukkit.getOfflinePlayer(player);
|
||||
Group g = privs.getGroupManager().getGroup(p);
|
||||
return g != null ? g.getName() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getGroups() {
|
||||
FileConfiguration file = privs.getGroups();
|
||||
ConfigurationSection groups = file.getConfigurationSection("groups");
|
||||
return groups != null ? groups.getKeys(false).toArray(new String[0]) : null;
|
||||
Set<String> groups = new HashSet<String>();
|
||||
for (Group g : privs.getGroupManager().getGroups()) {
|
||||
groups.add(g.getName());
|
||||
}
|
||||
return groups.toArray(new String[groups.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user