mirror of https://github.com/MilkBowl/Vault.git
added bPermissions chat support
This commit is contained in:
parent
4ab1b579a2
commit
a4a2580c53
|
@ -26,6 +26,7 @@ import net.milkbowl.vault.chat.Chat;
|
|||
import net.milkbowl.vault.chat.plugins.Chat_GroupManager;
|
||||
import net.milkbowl.vault.chat.plugins.Chat_Permissions3;
|
||||
import net.milkbowl.vault.chat.plugins.Chat_PermissionsEx;
|
||||
import net.milkbowl.vault.chat.plugins.Chat_bPermissions;
|
||||
import net.milkbowl.vault.chat.plugins.Chat_mChat;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.economy.plugins.Economy_3co;
|
||||
|
@ -100,6 +101,15 @@ public class Vault extends JavaPlugin {
|
|||
log.info(String.format("[%s][Chat] mChat not found.", getDescription().getName()));
|
||||
}
|
||||
|
||||
//try loading bPermissions
|
||||
if (packageExists(new String[] {"de.bananaco.permissions.worlds.WorldPermissionsManager"})) {
|
||||
Chat bPerms = new Chat_bPermissions(this);
|
||||
getServer().getServicesManager().register(net.milkbowl.vault.chat.Chat.class, bPerms, this, ServicePriority.High);
|
||||
log.info(String.format("[%s][Chat] bPermissions found: %s", getDescription().getName(), bPerms.isEnabled() ? "Loaded" : "Waiting"));
|
||||
} else {
|
||||
log.info(String.format("[%s][Chat] bPermissions not found.", getDescription().getName()));
|
||||
}
|
||||
|
||||
// Try to load GroupManager
|
||||
if (packageExists(new String[] { "org.anjocaido.groupmanager.GroupManager" })) {
|
||||
Chat gPerms = new Chat_GroupManager(this);
|
||||
|
|
|
@ -1,13 +1,18 @@
|
|||
package net.milkbowl.vault.chat.plugins;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.event.Event.Priority;
|
||||
import org.bukkit.event.Event.Type;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.event.server.PluginEnableEvent;
|
||||
import org.bukkit.event.server.ServerListener;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import net.D3GN.MiracleM4n.mChat.mChatAPI;
|
||||
import de.bananaco.permissions.Permissions;
|
||||
import de.bananaco.permissions.info.InfoReader;
|
||||
|
||||
import net.milkbowl.vault.Vault;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
|
||||
|
@ -15,13 +20,81 @@ public class Chat_bPermissions extends Chat {
|
|||
private static final Logger log = Logger.getLogger("Minecraft");
|
||||
private final String name = "bInfo";
|
||||
private Vault plugin = null;
|
||||
private PluginManager pluginManager = null;
|
||||
|
||||
InfoReader chat;
|
||||
private PermissionServerListener permissionServerListener = null;
|
||||
|
||||
public Chat_bPermissions(Vault plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
|
||||
permissionServerListener = new PermissionServerListener(this);
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvent(Type.PLUGIN_ENABLE, permissionServerListener, Priority.Monitor, plugin);
|
||||
plugin.getServer().getPluginManager().registerEvent(Type.PLUGIN_DISABLE, permissionServerListener, Priority.Monitor, plugin);
|
||||
|
||||
// Load Plugin in case it was loaded before
|
||||
if (chat == null) {
|
||||
Plugin p = plugin.getServer().getPluginManager().getPlugin("bPermissions");
|
||||
if (p != null) {
|
||||
Permissions perms = (Permissions) p;
|
||||
Field f;
|
||||
try {
|
||||
f = perms.getClass().getField(name);
|
||||
f.setAccessible(true);
|
||||
chat = (InfoReader) f.get(perms);
|
||||
} catch (SecurityException e) {
|
||||
return;
|
||||
} catch (NoSuchFieldException e) {
|
||||
return;
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class PermissionServerListener extends ServerListener {
|
||||
Chat_bPermissions chat = null;
|
||||
|
||||
public PermissionServerListener(Chat_bPermissions chat) {
|
||||
this.chat = chat;
|
||||
}
|
||||
|
||||
public void onPluginEnable(PluginEnableEvent event) {
|
||||
if (this.chat.chat == null) {
|
||||
Plugin chat = plugin.getServer().getPluginManager().getPlugin("bPermissions");
|
||||
if (chat != null) {
|
||||
Permissions perms = (Permissions) chat;
|
||||
Field f;
|
||||
try {
|
||||
f = perms.getClass().getField(name);
|
||||
f.setAccessible(true);
|
||||
this.chat.chat = (InfoReader) f.get(perms);
|
||||
} catch (SecurityException e) {
|
||||
return;
|
||||
} catch (NoSuchFieldException e) {
|
||||
return;
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
log.info(String.format("[%s][Chat] %s hooked.", plugin.getDescription().getName(), "bPermissions"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onPluginDisable(PluginDisableEvent event) {
|
||||
if (this.chat.chat != null) {
|
||||
if (event.getPlugin().getDescription().getName().equals("bPermissions")) {
|
||||
this.chat.chat = null;
|
||||
log.info(String.format("[%s][Chat] %s un-hooked.", plugin.getDescription().getName(), "bPermissions"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -29,168 +102,176 @@ public class Chat_bPermissions extends Chat {
|
|||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return chat != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerPrefix(String world, String player) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return chat.getPrefix(player, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerPrefix(String world, String player, String prefix) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerSuffix(String world, String player) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return chat.getSuffix(player, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerSuffix(String world, String player, String suffix) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupPrefix(String world, String group) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return chat.getGroupPrefix(group, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupPrefix(String world, String group, String prefix) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupSuffix(String world, String group) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return chat.getGroupSuffix(group, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupSuffix(String world, String group, String suffix) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPlayerInfoInteger(String world, String player, String node,
|
||||
int defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
public int getPlayerInfoInteger(String world, String player, String node, int defaultValue) {
|
||||
String s = getPlayerInfoString(world, player, node, null);
|
||||
if (s == null)
|
||||
return defaultValue;
|
||||
try {
|
||||
int i = Integer.valueOf(s);
|
||||
return i;
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerInfoInteger(String world, String player, String node,
|
||||
int value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setPlayerInfoInteger(String world, String player, String node, int value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupInfoInteger(String world, String group, String node,
|
||||
int defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
public int getGroupInfoInteger(String world, String group, String node, int defaultValue) {
|
||||
String s = getGroupInfoString(world, group, node, null);
|
||||
if (s == null)
|
||||
return defaultValue;
|
||||
try {
|
||||
int i = Integer.valueOf(s);
|
||||
return i;
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupInfoInteger(String world, String group, String node,
|
||||
int value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setGroupInfoInteger(String world, String group, String node, int value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPlayerInfoDouble(String world, String player, String node,
|
||||
double defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
public double getPlayerInfoDouble(String world, String player, String node, double defaultValue) {
|
||||
String s = getPlayerInfoString(world, player, node, null);
|
||||
if (s == null)
|
||||
return defaultValue;
|
||||
try {
|
||||
double d = Double.valueOf(s);
|
||||
return d;
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerInfoDouble(String world, String player, String node,
|
||||
double value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setPlayerInfoDouble(String world, String player, String node, double value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getGroupInfoDouble(String world, String group, String node,
|
||||
double defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
public double getGroupInfoDouble(String world, String group, String node, double defaultValue) {
|
||||
String s = getGroupInfoString(world, group, node, null);
|
||||
if (s == null)
|
||||
return defaultValue;
|
||||
try {
|
||||
double d = Double.valueOf(s);
|
||||
return d;
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupInfoDouble(String world, String group, String node,
|
||||
double value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setGroupInfoDouble(String world, String group, String node, double value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getPlayerInfoBoolean(String world, String player,
|
||||
String node, boolean defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean getPlayerInfoBoolean(String world, String player, String node, boolean defaultValue) {
|
||||
String s = getPlayerInfoString(world, player, node, null);
|
||||
if (s == null)
|
||||
return defaultValue;
|
||||
try {
|
||||
boolean b = Boolean.valueOf(s);
|
||||
return b;
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerInfoBoolean(String world, String player, String node,
|
||||
boolean value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setPlayerInfoBoolean(String world, String player, String node, boolean value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getGroupInfoBoolean(String world, String group, String node,
|
||||
boolean defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean getGroupInfoBoolean(String world, String group, String node, boolean defaultValue) {
|
||||
String s = getGroupInfoString(world, group, node, null);
|
||||
if (s == null)
|
||||
return defaultValue;
|
||||
try {
|
||||
boolean b = Boolean.valueOf(s);
|
||||
return b;
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupInfoBoolean(String world, String group, String node,
|
||||
boolean value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setGroupInfoBoolean(String world, String group, String node, boolean value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerInfoString(String world, String player, String node,
|
||||
String defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public String getPlayerInfoString(String world, String player, String node, String defaultValue) {
|
||||
String val = chat.getValue(player, world, node);
|
||||
return val == null ? defaultValue : val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerInfoString(String world, String player, String node,
|
||||
String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setPlayerInfoString(String world, String player, String node, String value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroupInfoString(String world, String group, String node,
|
||||
String defaultValue) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public String getGroupInfoString(String world, String group, String node, String defaultValue) {
|
||||
String val = chat.getGroupValue(group, world, node);
|
||||
return val == null ? defaultValue : val;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGroupInfoString(String world, String group, String node,
|
||||
String value) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
public void setGroupInfoString(String world, String group, String node, String value) {
|
||||
throw new UnsupportedOperationException("bPermissions does not support altering info nodes");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue