SimplyWrap/src/com/platymuus/bukkit/permissions/PermissionsPlugin.java

98 lines
2.3 KiB
Java
Raw Normal View History

2012-05-11 09:13:24 +00:00
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.configuration.file.FileConfiguration;
2012-05-11 09:13:24 +00:00
import org.bukkit.plugin.java.JavaPlugin;
2012-05-11 09:18:16 +00:00
/**
* Main class for PermissionsBukkit.
*/
2012-05-11 09:13:24 +00:00
public class PermissionsPlugin extends JavaPlugin {
2012-05-11 09:15:54 +00:00
protected SimplyAPI api;
2012-05-11 09:13:24 +00:00
2012-05-11 09:18:16 +00:00
// -- Basic stuff
@Override
2012-05-11 09:13:24 +00:00
public void onEnable() {
2012-05-12 09:04:07 +00:00
api = ((SimplyPlugin) getServer().getPluginManager().getPlugin("SimplyPerms")).getAPI();
2012-05-11 12:21:10 +00:00
// How are you gentlemen
getLogger().info("SimplyWrapper successfully enabled !");
}
@Override
public void onDisable() {
// Good day to you! I said good day!
getLogger().info("SimplyWrapper successfully disabled !");
}
public FileConfiguration getConfig() {
2012-05-12 09:04:07 +00:00
return getServer().getPluginManager().getPlugin("SimplyPerms").getConfig();
2012-05-11 09:13:24 +00:00
}
// -- External API
/**
* Get the group with the given name.
*
2012-05-12 09:04:07 +00:00
* @param groupName The name of the group.
2012-05-11 09:13:24 +00:00
* @return A Group if it exists or null otherwise.
*/
public Group getGroup(String groupName) {
2012-05-11 09:15:54 +00:00
if (api.getAllGroups().contains(groupName)) {
2012-05-11 09:13:24 +00:00
return new Group(this, groupName);
}
return null;
}
/**
* Returns a list of groups a player is in.
*
2012-05-12 09:04:07 +00:00
* @param playerName The name of the player.
2012-05-11 09:13:24 +00:00
* @return The groups this player is in. May be empty.
*/
public List<Group> getGroups(String playerName) {
ArrayList<Group> result = new ArrayList<Group>();
2012-05-11 09:15:54 +00:00
if (api.isPlayerInDB(playerName)) {
for (String key : api.getPlayerGroups(playerName)) {
2012-05-11 09:13:24 +00:00
result.add(new Group(this, key));
}
} else {
2012-05-11 09:15:54 +00:00
result.add(new Group(this, api.getDefaultGroup()));
2012-05-11 09:13:24 +00:00
}
return result;
}
/**
* Returns permission info on the given player.
*
2012-05-12 09:04:07 +00:00
* @param playerName The name of the player.
* @return A PermissionsInfo about this player.
*/
public PermissionInfo getPlayerInfo(String playerName) {
if (!api.isPlayerInDB(playerName)) {
return null;
} else {
return new PermissionInfo(this, "users/" + playerName);
}
}
2012-05-11 09:13:24 +00:00
/**
* Returns a list of all defined groups.
*
* @return The list of groups.
*/
public List<Group> getAllGroups() {
ArrayList<Group> result = new ArrayList<Group>();
2012-05-11 09:15:54 +00:00
for (String key : api.getAllGroups()) {
2012-05-11 09:13:24 +00:00
result.add(new Group(this, key));
}
return result;
}
}