mirror of
https://github.com/MilkBowl/Vault.git
synced 2025-02-05 23:11:40 +01:00
Chat interface now allows for getting groups in case a plugin only wants
to hook chat to do group related operations.
This commit is contained in:
parent
7bce4ad2fc
commit
996e8a8e6d
@ -81,38 +81,38 @@ public class Vault extends JavaPlugin {
|
||||
* Attempts to load Chat Addons
|
||||
*/
|
||||
private void loadChat() {
|
||||
|
||||
Permission perms = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
|
||||
// Try to load PermissionsEx
|
||||
if (packageExists(new String[] { "ru.tehkode.permissions.bukkit.PermissionsEx" })) {
|
||||
Chat eChat = new Chat_PermissionsEx(this);
|
||||
Chat eChat = new Chat_PermissionsEx(this, perms);
|
||||
getServer().getServicesManager().register(Chat.class, eChat, this, ServicePriority.Highest);
|
||||
log.info(String.format("[%s][Chat] PermissionsEx found: %s", getDescription().getName(), eChat.isEnabled() ? "Loaded" : "Waiting"));
|
||||
}
|
||||
|
||||
//Try loading mChat
|
||||
if (packageExists(new String[] {"net.D3GN.MiracleM4n.mChat"} )) {
|
||||
Chat mChat = new Chat_mChat(this);
|
||||
Chat mChat = new Chat_mChat(this, perms);
|
||||
getServer().getServicesManager().register(Chat.class, mChat, this, ServicePriority.Highest);
|
||||
log.info(String.format("[%s][Chat] mChat found: %s", getDescription().getName(), mChat.isEnabled() ? "Loaded" : "Waiting"));
|
||||
}
|
||||
|
||||
//try loading bPermissions
|
||||
if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"})) {
|
||||
Chat bPerms = new Chat_bPermissions(this);
|
||||
Chat bPerms = new Chat_bPermissions(this, perms);
|
||||
getServer().getServicesManager().register(Chat.class, bPerms, this, ServicePriority.High);
|
||||
log.info(String.format("[%s][Chat] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting"));
|
||||
}
|
||||
|
||||
// Try to load GroupManager
|
||||
if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) {
|
||||
Chat gPerms = new Chat_GroupManager(this);
|
||||
Chat gPerms = new Chat_GroupManager(this, perms);
|
||||
getServer().getServicesManager().register(Chat.class, gPerms, this, ServicePriority.High);
|
||||
log.info(String.format("[%s][Chat] GroupManager found: %s", getDescription().getName(), gPerms.isEnabled() ? "Loaded" : "Waiting"));
|
||||
}
|
||||
|
||||
// Try to load Permissions 3 (Yeti)
|
||||
if (packageExists(new String[] { "com.nijiko.permissions.ModularControl" })) {
|
||||
Chat nPerms = new Chat_Permissions3(this);
|
||||
Chat nPerms = new Chat_Permissions3(this, perms);
|
||||
getServer().getServicesManager().register(Chat.class, nPerms, this, ServicePriority.High);
|
||||
log.info(String.format("[%s][Chat] Permissions 3 (Yeti) found: %s", getDescription().getName(), nPerms.isEnabled() ? "Loaded" : "Waiting"));
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
package net.milkbowl.vault.chat;
|
||||
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class Chat {
|
||||
|
||||
private Permission perms;
|
||||
|
||||
public Chat(Permission perms) {
|
||||
this.perms = perms;
|
||||
}
|
||||
/**
|
||||
* Gets name of permission method
|
||||
* @return Name of Permission Method
|
||||
@ -615,4 +622,102 @@ public abstract class Chat {
|
||||
public void setGroupInfoString(World world, String group, String node, String value) {
|
||||
setGroupInfoString(world.getName(), group, node, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player is member of a group.
|
||||
* @param world World name
|
||||
* @param player Player name
|
||||
* @param group Group name
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean playerInGroup(String world, String player, String group) {
|
||||
return perms.playerInGroup(world, player, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player is member of a group.
|
||||
* @param world World Object
|
||||
* @param player Player name
|
||||
* @param group Group name
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean playerInGroup(World world, String player, String group) {
|
||||
return playerInGroup(world.getName(), player, group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if player is member of a group.
|
||||
* @param player Player Object
|
||||
* @param group Group name
|
||||
* @return Success or Failure
|
||||
*/
|
||||
public boolean playerInGroup(Player player, String group) {
|
||||
return playerInGroup(player.getWorld().getName(), player.getName(), group);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of groups that this player has
|
||||
* @param world World name
|
||||
* @param player Player name
|
||||
* @return Array of groups
|
||||
*/
|
||||
public String[] getPlayerGroups(String world, String player) {
|
||||
return perms.getPlayerGroups(world, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of groups that this player has
|
||||
* @param world World Object
|
||||
* @param player Player name
|
||||
* @return Array of groups
|
||||
*/
|
||||
public String[] getPlayerGroups(World world, String player) {
|
||||
return getPlayerGroups(world.getName(), player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of groups that this player has
|
||||
* @param player Player Object
|
||||
* @return Array of groups
|
||||
*/
|
||||
public String[] getPlayerGroups(Player player) {
|
||||
return getPlayerGroups(player.getWorld().getName(), player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets players primary group
|
||||
* @param world World name
|
||||
* @param player Player name
|
||||
* @return Players primary group
|
||||
*/
|
||||
public String getPrimaryGroup(String world, String player) {
|
||||
return perms.getPrimaryGroup(world, player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets players primary group
|
||||
* @param world World Object
|
||||
* @param player Player name
|
||||
* @return Players primary group
|
||||
*/
|
||||
public String getPrimaryGroup(World world, String player) {
|
||||
return getPrimaryGroup(world.getName(), player);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get players primary group
|
||||
* @param player Player Object
|
||||
* @return Players primary group
|
||||
*/
|
||||
public String getPrimaryGroup(Player player) {
|
||||
return getPrimaryGroup(player.getWorld().getName(), player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of all known groups
|
||||
* @return an Array of String of all groups
|
||||
*/
|
||||
public String[] getGroups() {
|
||||
return perms.getGroups();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class Chat_GroupManager extends Chat {
|
||||
@ -25,7 +26,8 @@ public class Chat_GroupManager extends Chat {
|
||||
private AnjoPermissionsHandler perms;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Chat_GroupManager(Plugin plugin) {
|
||||
public Chat_GroupManager(Plugin plugin, Permission permissions) {
|
||||
super(permissions);
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
|
@ -14,6 +14,7 @@ import com.nijiko.permissions.PermissionHandler;
|
||||
import com.nijikokun.bukkit.Permissions.Permissions;
|
||||
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class Chat_Permissions3 extends Chat {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
@ -25,7 +26,8 @@ public class Chat_Permissions3 extends Chat {
|
||||
private Permissions chat = null;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Chat_Permissions3(Plugin plugin) {
|
||||
public Chat_Permissions3(Plugin plugin, Permission permissions) {
|
||||
super(permissions);
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
|
@ -14,6 +14,7 @@ import ru.tehkode.permissions.PermissionGroup;
|
||||
import ru.tehkode.permissions.PermissionUser;
|
||||
import ru.tehkode.permissions.bukkit.PermissionsEx;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class Chat_PermissionsEx extends Chat {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
@ -24,7 +25,8 @@ public class Chat_PermissionsEx extends Chat {
|
||||
private PermissionsEx chat = null;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Chat_PermissionsEx(Plugin plugin) {
|
||||
public Chat_PermissionsEx(Plugin plugin, Permission permissions) {
|
||||
super(permissions);
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
|
@ -15,6 +15,7 @@ import de.bananaco.permissions.info.InfoReader;
|
||||
|
||||
import net.milkbowl.vault.Vault;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class Chat_bPermissions extends Chat {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
@ -23,7 +24,8 @@ public class Chat_bPermissions extends Chat {
|
||||
InfoReader chat;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Chat_bPermissions(Vault plugin) {
|
||||
public Chat_bPermissions(Vault plugin, Permission perms) {
|
||||
super(perms);
|
||||
this.plugin = plugin;
|
||||
|
||||
permissionServerListener = new PermissionServerListener(this);
|
||||
@ -35,12 +37,12 @@ public class Chat_bPermissions extends Chat {
|
||||
if (chat == null) {
|
||||
Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions");
|
||||
if (p != null) {
|
||||
Permissions perms = (Permissions) p;
|
||||
Permissions permissions = (Permissions) p;
|
||||
Field f;
|
||||
try {
|
||||
f = perms.getClass().getField(name);
|
||||
f = permissions.getClass().getField(name);
|
||||
f.setAccessible(true);
|
||||
chat = (InfoReader) f.get(perms);
|
||||
chat = (InfoReader) f.get(permissions);
|
||||
} catch (SecurityException e) {
|
||||
return;
|
||||
} catch (NoSuchFieldException e) {
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import net.D3GN.MiracleM4n.mChat.mChatAPI;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
|
||||
public class Chat_mChat extends Chat {
|
||||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
@ -23,7 +24,8 @@ public class Chat_mChat extends Chat {
|
||||
private mChatAPI mChat = null;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Chat_mChat(Plugin plugin) {
|
||||
public Chat_mChat(Plugin plugin, Permission permissions) {
|
||||
super(permissions);
|
||||
this.plugin = plugin;
|
||||
pluginManager = this.plugin.getServer().getPluginManager();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user