diff --git a/README.md b/README.md index 2d6c3af..54e29e2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ SimplyWrap ========== -Wrapper for SimplyPerms to keep compatibility with old PermissionBukkit plugins \ No newline at end of file +Wrapper for SimplyPerms to keep compatibility with old PermissionsBukkit based plugins \ No newline at end of file diff --git a/src/com/platymuus/bukkit/permissions/Group.java b/src/com/platymuus/bukkit/permissions/Group.java new file mode 100644 index 0000000..3bd7e73 --- /dev/null +++ b/src/com/platymuus/bukkit/permissions/Group.java @@ -0,0 +1,52 @@ +package com.platymuus.bukkit.permissions; + +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.entity.Player; + +public class Group { + + private PermissionsPlugin plugin; + private String name; + + protected Group(PermissionsPlugin plugin, String name) { + this.plugin = plugin; + this.name = name; + } + + public String getName() { + return name; + } + + public List getPlayers() { + return plugin.plugin.getAllPlayers(); + } + + public List getOnlinePlayers() { + ArrayList result = new ArrayList(); + for (String user : getPlayers()) { + Player player = plugin.getServer().getPlayer(user); + if (player != null && player.isOnline()) { + result.add(player); + } + } + return result; + } + + @Override + public boolean equals(Object o) { + return !(o == null || !(o instanceof Group)) && name.equalsIgnoreCase(((Group) o).getName()); + } + + @Override + public String toString() { + return "Group{name=" + name + "}"; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + +} diff --git a/src/com/platymuus/bukkit/permissions/PermissionsPlugin.java b/src/com/platymuus/bukkit/permissions/PermissionsPlugin.java new file mode 100644 index 0000000..11890ec --- /dev/null +++ b/src/com/platymuus/bukkit/permissions/PermissionsPlugin.java @@ -0,0 +1,66 @@ +package com.platymuus.bukkit.permissions; + +import java.util.ArrayList; +import java.util.List; + +import net.crystalyx.bukkit.simplyperms.SimplyAPI; +import net.crystalyx.bukkit.simplyperms.SimplyPlugin; + +import org.bukkit.plugin.java.JavaPlugin; + +public class PermissionsPlugin extends JavaPlugin { + + protected SimplyAPI plugin; + + public void onEnable() { + plugin = ((SimplyPlugin) getServer().getPluginManager().getPlugin("SimplyPerms")).getAPI(); + } + + // -- External API + /** + * Get the group with the given name. + * + * @param groupName + * The name of the group. + * @return A Group if it exists or null otherwise. + */ + public Group getGroup(String groupName) { + if (plugin.getAllGroups().contains(groupName)) { + return new Group(this, groupName); + } + return null; + } + + /** + * Returns a list of groups a player is in. + * + * @param playerName + * The name of the player. + * @return The groups this player is in. May be empty. + */ + public List getGroups(String playerName) { + ArrayList result = new ArrayList(); + if (plugin.isPlayerInDB(playerName)) { + for (String key : plugin.getPlayerGroups(playerName)) { + result.add(new Group(this, key)); + } + } else { + result.add(new Group(this, plugin.getDefaultGroup())); + } + return result; + } + + /** + * Returns a list of all defined groups. + * + * @return The list of groups. + */ + public List getAllGroups() { + ArrayList result = new ArrayList(); + for (String key : plugin.getAllGroups()) { + result.add(new Group(this, key)); + } + return result; + } + +}