mirror of
https://github.com/MilkBowl/Vault.git
synced 2025-01-03 23:08:08 +01:00
toLower all group/permission strings for PermBukkit implementation.
This commit is contained in:
parent
550f774d3d
commit
7fcc556774
@ -35,200 +35,214 @@ import com.platymuus.bukkit.permissions.PermissionsPlugin;
|
|||||||
|
|
||||||
public class Permission_PermissionsBukkit extends Permission {
|
public class Permission_PermissionsBukkit extends Permission {
|
||||||
|
|
||||||
private final String name = "PermissionsBukkit";
|
private final String name = "PermissionsBukkit";
|
||||||
private PermissionsPlugin perms = null;
|
private PermissionsPlugin perms = null;
|
||||||
|
|
||||||
public Permission_PermissionsBukkit(Vault plugin) {
|
public Permission_PermissionsBukkit(Vault plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
|
Bukkit.getServer().getPluginManager().registerEvents(new PermissionServerListener(this), plugin);
|
||||||
|
|
||||||
// Load Plugin in case it was loaded before
|
// Load Plugin in case it was loaded before
|
||||||
if (perms == null) {
|
if (perms == null) {
|
||||||
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
|
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
|
||||||
if (perms != null) {
|
if (perms != null) {
|
||||||
perms = (PermissionsPlugin) perms;
|
perms = (PermissionsPlugin) perms;
|
||||||
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PermissionServerListener implements Listener {
|
public class PermissionServerListener implements Listener {
|
||||||
Permission_PermissionsBukkit permission = null;
|
Permission_PermissionsBukkit permission = null;
|
||||||
|
|
||||||
public PermissionServerListener(Permission_PermissionsBukkit permission) {
|
public PermissionServerListener(Permission_PermissionsBukkit permission) {
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPluginEnable(PluginEnableEvent event) {
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
if (permission.perms == null) {
|
if (permission.perms == null) {
|
||||||
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
|
Plugin perms = plugin.getServer().getPluginManager().getPlugin("PermissionsBukkit");
|
||||||
|
|
||||||
if (perms != null) {
|
if (perms != null) {
|
||||||
if (perms.isEnabled()) {
|
if (perms.isEnabled()) {
|
||||||
permission.perms = (PermissionsPlugin) perms;
|
permission.perms = (PermissionsPlugin) perms;
|
||||||
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
|
log.info(String.format("[%s][Permission] %s hooked.", plugin.getDescription().getName(), permission.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPluginDisable(PluginDisableEvent event) {
|
public void onPluginDisable(PluginDisableEvent event) {
|
||||||
if (permission.perms != null) {
|
if (permission.perms != null) {
|
||||||
if (event.getPlugin().getDescription().getName().equals("PermissionsBukkit")) {
|
if (event.getPlugin().getDescription().getName().equals("PermissionsBukkit")) {
|
||||||
permission.perms = null;
|
permission.perms = null;
|
||||||
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
|
log.info(String.format("[%s][Permission] %s un-hooked.", plugin.getDescription().getName(), permission.name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
if (perms == null) {
|
if (perms == null) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return perms.isEnabled();
|
return perms.isEnabled();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerHas(String world, String player, String permission) {
|
public boolean playerHas(String world, String player, String permission) {
|
||||||
if (plugin.getServer().getPlayer(player) != null)
|
if (Bukkit.getPlayer(player) != null) {
|
||||||
return plugin.getServer().getPlayer(player).hasPermission(permission);
|
return Bukkit.getPlayer(player).hasPermission(permission);
|
||||||
else
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerAdd(String world, String player, String permission) {
|
public boolean playerAdd(String world, String player, String permission) {
|
||||||
if (world != null) {
|
permission = permission.toLowerCase();
|
||||||
permission = world + ":" + permission;
|
if (world != null) {
|
||||||
}
|
permission = world + ":" + permission;
|
||||||
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player setperm " + player + " " + permission + " true");
|
}
|
||||||
}
|
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player setperm " + player + " " + permission + " true");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerRemove(String world, String player, String permission) {
|
public boolean playerRemove(String world, String player, String permission) {
|
||||||
if (world != null) {
|
permission = permission.toLowerCase();
|
||||||
permission = world + ":" + permission;
|
if (world != null) {
|
||||||
}
|
permission = world + ":" + permission;
|
||||||
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player unsetperm " + player + " " + permission);
|
}
|
||||||
}
|
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player unsetperm " + player + " " + permission);
|
||||||
|
}
|
||||||
|
|
||||||
// use superclass implementation of playerAddTransient() and playerRemoveTransient()
|
// use superclass implementation of playerAddTransient() and playerRemoveTransient()
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupHas(String world, String group, String permission) {
|
public boolean groupHas(String world, String group, String permission) {
|
||||||
if (world != null && !world.isEmpty()) {
|
group = group.toLowerCase();
|
||||||
return perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission) == null ? false : perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission);
|
permission = permission.toLowerCase();
|
||||||
}
|
|
||||||
if (perms.getGroup(group) == null)
|
|
||||||
return false;
|
|
||||||
else if (perms.getGroup(group).getInfo() == null)
|
|
||||||
return false;
|
|
||||||
else if (perms.getGroup(group).getInfo().getPermissions() == null)
|
|
||||||
return false;
|
|
||||||
return perms.getGroup(group).getInfo().getPermissions().get(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (world != null && !world.isEmpty()) {
|
||||||
public boolean groupAdd(String world, String group, String permission) {
|
return perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission) == null ? false : perms.getGroup(group).getInfo().getWorldPermissions(world).get(permission);
|
||||||
if (world != null) {
|
}
|
||||||
permission = world + ":" + permission;
|
if (perms.getGroup(group) == null) {
|
||||||
}
|
return false;
|
||||||
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group setperm " + group + " " + permission + " true");
|
} else if (perms.getGroup(group).getInfo() == null) {
|
||||||
}
|
return false;
|
||||||
|
} else if (perms.getGroup(group).getInfo().getPermissions() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return perms.getGroup(group).getInfo().getPermissions().get(permission);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean groupRemove(String world, String group, String permission) {
|
public boolean groupAdd(String world, String group, String permission) {
|
||||||
if (world != null) {
|
group = group.toLowerCase();
|
||||||
permission = world + ":" + permission;
|
permission = permission.toLowerCase();
|
||||||
}
|
if (world != null) {
|
||||||
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group unsetperm " + group + " " + permission);
|
permission = world + ":" + permission;
|
||||||
}
|
}
|
||||||
|
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group setperm " + group + " " + permission + " true");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerInGroup(String world, String player, String group) {
|
public boolean groupRemove(String world, String group, String permission) {
|
||||||
if (world != null) {
|
group = group.toLowerCase();
|
||||||
for (Group g : perms.getPlayerInfo(player).getGroups()) {
|
permission = permission.toLowerCase();
|
||||||
if (g.getName().equals(group)) {
|
if (world != null) {
|
||||||
return g.getInfo().getWorlds().contains(world);
|
permission = world + ":" + permission;
|
||||||
}
|
}
|
||||||
}
|
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions group unsetperm " + group + " " + permission);
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
Group g = perms.getGroup(group);
|
|
||||||
if (g == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return g.getPlayers().contains(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerAddGroup(String world, String player, String group) {
|
public boolean playerInGroup(String world, String player, String group) {
|
||||||
if (world != null) {
|
group = group.toLowerCase();
|
||||||
return false;
|
if (world != null) {
|
||||||
}
|
for (Group g : perms.getPlayerInfo(player).getGroups()) {
|
||||||
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player addgroup " + player + " " + group);
|
if (g.getName().equals(group)) {
|
||||||
}
|
return g.getInfo().getWorlds().contains(world);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Group g = perms.getGroup(group);
|
||||||
|
if (g == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return g.getPlayers().contains(player);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean playerRemoveGroup(String world, String player, String group) {
|
public boolean playerAddGroup(String world, String player, String group) {
|
||||||
if (world != null) {
|
group = group.toLowerCase();
|
||||||
return false;
|
if (world != null) {
|
||||||
}
|
return false;
|
||||||
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player removegroup " + player + " " + group);
|
}
|
||||||
}
|
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player addgroup " + player + " " + group);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getPlayerGroups(String world, String player) {
|
public boolean playerRemoveGroup(String world, String player, String group) {
|
||||||
List<String> groupList = new ArrayList<String>();
|
group = group.toLowerCase();
|
||||||
PermissionInfo info = perms.getPlayerInfo(player);
|
if (world != null) {
|
||||||
if (world != null && info != null) {
|
return false;
|
||||||
for (Group group : perms.getPlayerInfo(player).getGroups()) {
|
}
|
||||||
if (group.getInfo().getWorlds().contains(world)) {
|
return plugin.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "permissions player removegroup " + player + " " + group);
|
||||||
groupList.add(group.getName());
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return groupList.toArray(new String[0]);
|
|
||||||
}
|
|
||||||
if (info != null) {
|
|
||||||
for (Group group : info.getGroups()) {
|
|
||||||
groupList.add(group.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return groupList.toArray(new String[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPrimaryGroup(String world, String player) {
|
public String[] getPlayerGroups(String world, String player) {
|
||||||
if (perms.getPlayerInfo(player) == null)
|
List<String> groupList = new ArrayList<String>();
|
||||||
return null;
|
PermissionInfo info = perms.getPlayerInfo(player);
|
||||||
else if (perms.getPlayerInfo(player).getGroups() != null && !perms.getPlayerInfo(player).getGroups().isEmpty() ) {
|
if (world != null && info != null) {
|
||||||
return perms.getPlayerInfo(player).getGroups().get(0).getName();
|
for (Group group : perms.getPlayerInfo(player).getGroups()) {
|
||||||
}
|
if (group.getInfo().getWorlds().contains(world)) {
|
||||||
return null;
|
groupList.add(group.getName());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return groupList.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
if (info != null) {
|
||||||
|
for (Group group : info.getGroups()) {
|
||||||
|
groupList.add(group.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groupList.toArray(new String[0]);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getGroups() {
|
public String getPrimaryGroup(String world, String player) {
|
||||||
List<String> groupNames = new ArrayList<String>();
|
if (perms.getPlayerInfo(player) == null) {
|
||||||
for (Group group : perms.getAllGroups()) {
|
return null;
|
||||||
groupNames.add(group.getName());
|
} else if (perms.getPlayerInfo(player).getGroups() != null && !perms.getPlayerInfo(player).getGroups().isEmpty() ) {
|
||||||
}
|
return perms.getPlayerInfo(player).getGroups().get(0).getName();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return groupNames.toArray(new String[0]);
|
@Override
|
||||||
}
|
public String[] getGroups() {
|
||||||
|
List<String> groupNames = new ArrayList<String>();
|
||||||
|
for (Group group : perms.getAllGroups()) {
|
||||||
|
groupNames.add(group.getName());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
return groupNames.toArray(new String[0]);
|
||||||
public boolean hasSuperPermsCompat() {
|
}
|
||||||
return true;
|
|
||||||
}
|
@Override
|
||||||
|
public boolean hasSuperPermsCompat() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user