Updated GroupUsers support to use official API.

This commit is contained in:
sk89q 2011-01-17 19:45:25 -08:00
parent 65a61c9be7
commit 75c21623da

View File

@ -19,19 +19,16 @@
package com.sk89q.bukkit.migration; package com.sk89q.bukkit.migration;
import java.lang.reflect.*; import java.util.List;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import com.bukkit.authorblues.GroupUsers.GroupUsers; import com.bukkit.authorblues.GroupUsers.GroupUsers;
import com.bukkit.authorblues.GroupUsers.GroupUsersPlayerListener;
public class GroupUsersPemissionsResolver implements PermissionsResolver { public class GroupUsersPemissionsResolver implements PermissionsResolver {
private Server server; private Server server;
private GroupUsersPlayerListener listener; private GroupUsers groupUsers;
public void load() { public void load() {
@ -47,19 +44,8 @@ public class GroupUsersPemissionsResolver implements PermissionsResolver {
throw new MissingPluginException(); throw new MissingPluginException();
} }
GroupUsers groupUsers = (GroupUsers)plugin;
try { try {
Field field = groupUsers.getClass().getDeclaredField("playerListener"); groupUsers = (GroupUsers)plugin;
field.setAccessible(true);
listener = (GroupUsersPlayerListener)field.get(groupUsers);
} catch (SecurityException e) {
throw new PluginAccessException();
} catch (NoSuchFieldException e) {
throw new PluginAccessException();
} catch (IllegalArgumentException e) {
throw new PluginAccessException();
} catch (IllegalAccessException e) {
throw new PluginAccessException();
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new PluginAccessException(); throw new PluginAccessException();
} }
@ -68,24 +54,36 @@ public class GroupUsersPemissionsResolver implements PermissionsResolver {
public boolean hasPermission(String name, String permission) { public boolean hasPermission(String name, String permission) {
try { try {
Player player = server.getPlayer(name); Player player = server.getPlayer(name);
if (player == null) { if (player == null) return false;
return false; return groupUsers.playerCanUseCommand(player, permission);
}
PlayerChatEvent event = new PlayerChatEvent(Event.Type.PLAYER_CHAT, player, permission);
listener.onPlayerCommand(event);
return !event.isCancelled();
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
return false; return false;
} }
} }
public boolean inGroup(String player, String group) { public boolean inGroup(String name, String group) {
return false; try {
Player player = server.getPlayer(name);
if (player == null) return false;
return groupUsers.isInGroup(player, group);
} catch (Throwable t) {
t.printStackTrace();
return false;
}
} }
public String[] getGroups(String player) { public String[] getGroups(String name) {
return new String[0]; try {
Player player = server.getPlayer(name);
if (player == null) return new String[0];
List<String> groups = groupUsers.getGroups();
if (groups == null) return new String[0];
return groups.toArray(new String[groups.size()]);
} catch (Throwable t) {
t.printStackTrace();
return new String[0];
}
} }
public static class PluginAccessException extends Exception { public static class PluginAccessException extends Exception {