First Lines

This commit is contained in:
Michel Roux 2012-05-11 11:13:24 +02:00
parent b664e822d5
commit 1ebfca911c
3 changed files with 119 additions and 1 deletions

View File

@ -1,4 +1,4 @@
SimplyWrap SimplyWrap
========== ==========
Wrapper for SimplyPerms to keep compatibility with old PermissionBukkit plugins Wrapper for SimplyPerms to keep compatibility with old PermissionsBukkit based plugins

View File

@ -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<String> getPlayers() {
return plugin.plugin.getAllPlayers();
}
public List<Player> getOnlinePlayers() {
ArrayList<Player> result = new ArrayList<Player>();
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();
}
}

View File

@ -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<Group> getGroups(String playerName) {
ArrayList<Group> result = new ArrayList<Group>();
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<Group> getAllGroups() {
ArrayList<Group> result = new ArrayList<Group>();
for (String key : plugin.getAllGroups()) {
result.add(new Group(this, key));
}
return result;
}
}