mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-25 13:49:12 +02:00
Fix GM line endings
This commit is contained in:
@@ -1,87 +1,87 @@
|
|||||||
package org.anjocaido.groupmanager.events;
|
package org.anjocaido.groupmanager.events;
|
||||||
|
|
||||||
import org.anjocaido.groupmanager.GroupManager;
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
import org.anjocaido.groupmanager.data.User;
|
import org.anjocaido.groupmanager.data.User;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ElgarL
|
* @author ElgarL
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GMUserEvent extends Event {
|
public class GMUserEvent extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
|
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
|
|
||||||
protected User user;
|
protected User user;
|
||||||
|
|
||||||
protected String userName;
|
protected String userName;
|
||||||
|
|
||||||
protected Action action;
|
protected Action action;
|
||||||
|
|
||||||
public GMUserEvent(User user, Action action) {
|
public GMUserEvent(User user, Action action) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
this.userName = user.getName();
|
this.userName = user.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GMUserEvent(String userName, Action action) {
|
public GMUserEvent(String userName, Action action) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.action = action;
|
this.action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action getAction() {
|
public Action getAction() {
|
||||||
|
|
||||||
return this.action;
|
return this.action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser() {
|
public User getUser() {
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserName() {
|
public String getUserName() {
|
||||||
|
|
||||||
return userName;
|
return userName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Action {
|
public enum Action {
|
||||||
USER_PERMISSIONS_CHANGED, USER_INHERITANCE_CHANGED, USER_INFO_CHANGED, USER_GROUP_CHANGED, USER_SUBGROUP_CHANGED, USER_ADDED, USER_REMOVED,
|
USER_PERMISSIONS_CHANGED, USER_INHERITANCE_CHANGED, USER_INFO_CHANGED, USER_GROUP_CHANGED, USER_SUBGROUP_CHANGED, USER_ADDED, USER_REMOVED,
|
||||||
}
|
}
|
||||||
|
|
||||||
public void schedule(final GMUserEvent event) {
|
public void schedule(final GMUserEvent event) {
|
||||||
|
|
||||||
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
|
if (Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(Bukkit.getPluginManager().getPlugin("GroupManager"), new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
Bukkit.getServer().getPluginManager().callEvent(event);
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
||||||
}
|
}
|
||||||
}, 1) == -1)
|
}, 1) == -1)
|
||||||
GroupManager.logger.warning("Could not schedule GM Event.");
|
GroupManager.logger.warning("Could not schedule GM Event.");
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,46 +1,46 @@
|
|||||||
package org.anjocaido.groupmanager.events;
|
package org.anjocaido.groupmanager.events;
|
||||||
|
|
||||||
import org.anjocaido.groupmanager.GroupManager;
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.world.WorldInitEvent;
|
import org.bukkit.event.world.WorldInitEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ElgarL
|
* @author ElgarL
|
||||||
*
|
*
|
||||||
* Handle new world creation from other plugins
|
* Handle new world creation from other plugins
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GMWorldListener implements Listener {
|
public class GMWorldListener implements Listener {
|
||||||
|
|
||||||
private final GroupManager plugin;
|
private final GroupManager plugin;
|
||||||
|
|
||||||
public GMWorldListener(GroupManager instance) {
|
public GMWorldListener(GroupManager instance) {
|
||||||
|
|
||||||
plugin = instance;
|
plugin = instance;
|
||||||
registerEvents();
|
registerEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
|
|
||||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onWorldInit(WorldInitEvent event) {
|
public void onWorldInit(WorldInitEvent event) {
|
||||||
|
|
||||||
String worldName = event.getWorld().getName();
|
String worldName = event.getWorld().getName();
|
||||||
|
|
||||||
if (GroupManager.isLoaded() && !plugin.getWorldsHolder().isInList(worldName)) {
|
if (GroupManager.isLoaded() && !plugin.getWorldsHolder().isInList(worldName)) {
|
||||||
GroupManager.logger.info("New world detected...");
|
GroupManager.logger.info("New world detected...");
|
||||||
GroupManager.logger.info("Creating data for: " + worldName);
|
GroupManager.logger.info("Creating data for: " + worldName);
|
||||||
plugin.getWorldsHolder().setupWorldFolder(worldName);
|
plugin.getWorldsHolder().setupWorldFolder(worldName);
|
||||||
plugin.getWorldsHolder().loadWorld(worldName);
|
plugin.getWorldsHolder().loadWorld(worldName);
|
||||||
if (plugin.getWorldsHolder().isInList(worldName)) {
|
if (plugin.getWorldsHolder().isInList(worldName)) {
|
||||||
GroupManager.logger.info("Don't forget to configure/mirror this world in config.yml.");
|
GroupManager.logger.info("Don't forget to configure/mirror this world in config.yml.");
|
||||||
} else
|
} else
|
||||||
GroupManager.logger.severe("Failed to configure this world.");
|
GroupManager.logger.severe("Failed to configure this world.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,53 +1,53 @@
|
|||||||
package org.anjocaido.groupmanager.events;
|
package org.anjocaido.groupmanager.events;
|
||||||
|
|
||||||
import org.anjocaido.groupmanager.data.Group;
|
import org.anjocaido.groupmanager.data.Group;
|
||||||
import org.anjocaido.groupmanager.data.User;
|
import org.anjocaido.groupmanager.data.User;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author ElgarL
|
* @author ElgarL
|
||||||
*
|
*
|
||||||
* Handles all Event generation.
|
* Handles all Event generation.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GroupManagerEventHandler {
|
public class GroupManagerEventHandler {
|
||||||
|
|
||||||
protected static void callEvent(GMGroupEvent event) {
|
protected static void callEvent(GMGroupEvent event) {
|
||||||
|
|
||||||
event.schedule(event);
|
event.schedule(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void callEvent(GMUserEvent event) {
|
protected static void callEvent(GMUserEvent event) {
|
||||||
|
|
||||||
event.schedule(event);
|
event.schedule(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static void callEvent(GMSystemEvent event) {
|
protected static void callEvent(GMSystemEvent event) {
|
||||||
|
|
||||||
event.schedule(event);
|
event.schedule(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callEvent(Group group, GMGroupEvent.Action action) {
|
public static void callEvent(Group group, GMGroupEvent.Action action) {
|
||||||
|
|
||||||
callEvent(new GMGroupEvent(group, action));
|
callEvent(new GMGroupEvent(group, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callEvent(String groupName, GMGroupEvent.Action action) {
|
public static void callEvent(String groupName, GMGroupEvent.Action action) {
|
||||||
|
|
||||||
callEvent(new GMGroupEvent(groupName, action));
|
callEvent(new GMGroupEvent(groupName, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callEvent(User user, GMUserEvent.Action action) {
|
public static void callEvent(User user, GMUserEvent.Action action) {
|
||||||
|
|
||||||
callEvent(new GMUserEvent(user, action));
|
callEvent(new GMUserEvent(user, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callEvent(String userName, GMUserEvent.Action action) {
|
public static void callEvent(String userName, GMUserEvent.Action action) {
|
||||||
|
|
||||||
callEvent(new GMUserEvent(userName, action));
|
callEvent(new GMUserEvent(userName, action));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void callEvent(GMSystemEvent.Action action) {
|
public static void callEvent(GMSystemEvent.Action action) {
|
||||||
|
|
||||||
callEvent(new GMSystemEvent(action));
|
callEvent(new GMSystemEvent(action));
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,491 +1,491 @@
|
|||||||
/*
|
/*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU General Public License
|
* modify it under the terms of the GNU General Public License
|
||||||
* as published by the Free Software Foundation; either version 2
|
* as published by the Free Software Foundation; either version 2
|
||||||
* of the License, or (at your option) any later version.
|
* of the License, or (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful,
|
* This program is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU General Public License for more details.
|
* GNU General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
||||||
* USA.
|
* USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.anjocaido.groupmanager.permissions;
|
package org.anjocaido.groupmanager.permissions;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.anjocaido.groupmanager.GroupManager;
|
import org.anjocaido.groupmanager.GroupManager;
|
||||||
import org.anjocaido.groupmanager.data.User;
|
import org.anjocaido.groupmanager.data.User;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.server.PluginDisableEvent;
|
import org.bukkit.event.server.PluginDisableEvent;
|
||||||
import org.bukkit.event.server.PluginEnableEvent;
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.permissions.Permission;
|
import org.bukkit.permissions.Permission;
|
||||||
import org.bukkit.permissions.PermissionAttachment;
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* BukkitPermissions overrides to force GM reponses to Superperms
|
* BukkitPermissions overrides to force GM reponses to Superperms
|
||||||
*
|
*
|
||||||
* @author ElgarL
|
* @author ElgarL
|
||||||
*/
|
*/
|
||||||
public class BukkitPermissions {
|
public class BukkitPermissions {
|
||||||
|
|
||||||
protected WeakHashMap<Player, PermissionAttachment> attachments = new WeakHashMap<Player, PermissionAttachment>();
|
protected WeakHashMap<Player, PermissionAttachment> attachments = new WeakHashMap<Player, PermissionAttachment>();
|
||||||
protected LinkedHashMap<String, Permission> registeredPermissions = new LinkedHashMap<String, Permission>();
|
protected LinkedHashMap<String, Permission> registeredPermissions = new LinkedHashMap<String, Permission>();
|
||||||
protected GroupManager plugin;
|
protected GroupManager plugin;
|
||||||
protected boolean dumpAllPermissions = true;
|
protected boolean dumpAllPermissions = true;
|
||||||
protected boolean dumpMatchedPermissions = true;
|
protected boolean dumpMatchedPermissions = true;
|
||||||
private boolean player_join = false;
|
private boolean player_join = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the player_join
|
* @return the player_join
|
||||||
*/
|
*/
|
||||||
public boolean isPlayer_join() {
|
public boolean isPlayer_join() {
|
||||||
|
|
||||||
return player_join;
|
return player_join;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player_join the player_join to set
|
* @param player_join the player_join to set
|
||||||
*/
|
*/
|
||||||
public void setPlayer_join(boolean player_join) {
|
public void setPlayer_join(boolean player_join) {
|
||||||
|
|
||||||
this.player_join = player_join;
|
this.player_join = player_join;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Field permissions;
|
private static Field permissions;
|
||||||
|
|
||||||
// Setup reflection (Thanks to Codename_B for the reflection source)
|
// Setup reflection (Thanks to Codename_B for the reflection source)
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
permissions = PermissionAttachment.class.getDeclaredField("permissions");
|
permissions = PermissionAttachment.class.getDeclaredField("permissions");
|
||||||
permissions.setAccessible(true);
|
permissions.setAccessible(true);
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BukkitPermissions(GroupManager plugin) {
|
public BukkitPermissions(GroupManager plugin) {
|
||||||
|
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.reset();
|
this.reset();
|
||||||
this.registerEvents();
|
this.registerEvents();
|
||||||
|
|
||||||
|
|
||||||
GroupManager.logger.info("Superperms support enabled.");
|
GroupManager.logger.info("Superperms support enabled.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.collectPermissions();
|
this.collectPermissions();
|
||||||
this.updateAllPlayers();
|
this.updateAllPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerEvents() {
|
private void registerEvents() {
|
||||||
|
|
||||||
PluginManager manager = plugin.getServer().getPluginManager();
|
PluginManager manager = plugin.getServer().getPluginManager();
|
||||||
|
|
||||||
manager.registerEvents(new PlayerEvents(), plugin);
|
manager.registerEvents(new PlayerEvents(), plugin);
|
||||||
manager.registerEvents(new BukkitEvents(), plugin);
|
manager.registerEvents(new BukkitEvents(), plugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collectPermissions() {
|
public void collectPermissions() {
|
||||||
|
|
||||||
registeredPermissions.clear();
|
registeredPermissions.clear();
|
||||||
|
|
||||||
for (Permission perm : Bukkit.getPluginManager().getPermissions()) {
|
for (Permission perm : Bukkit.getPluginManager().getPermissions()) {
|
||||||
registeredPermissions.put(perm.getName().toLowerCase(), perm);
|
registeredPermissions.put(perm.getName().toLowerCase(), perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updatePermissions(Player player) {
|
public void updatePermissions(Player player) {
|
||||||
|
|
||||||
this.updatePermissions(player, null);
|
this.updatePermissions(player, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Push all permissions which are registered with GM for this player, on
|
* Push all permissions which are registered with GM for this player, on
|
||||||
* this world to Bukkit
|
* this world to Bukkit
|
||||||
* and make it update for the child nodes.
|
* and make it update for the child nodes.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @param world
|
* @param world
|
||||||
*/
|
*/
|
||||||
public void updatePermissions(Player player, String world) {
|
public void updatePermissions(Player player, String world) {
|
||||||
|
|
||||||
if (player == null || !GroupManager.isLoaded()) {
|
if (player == null || !GroupManager.isLoaded()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the User objects player reference.
|
// Reset the User objects player reference.
|
||||||
User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName());
|
User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName());
|
||||||
if (user != null)
|
if (user != null)
|
||||||
user.updatePlayer(player);
|
user.updatePlayer(player);
|
||||||
|
|
||||||
PermissionAttachment attachment;
|
PermissionAttachment attachment;
|
||||||
|
|
||||||
// Find the players current attachment, or add a new one.
|
// Find the players current attachment, or add a new one.
|
||||||
if (this.attachments.containsKey(player)) {
|
if (this.attachments.containsKey(player)) {
|
||||||
attachment = this.attachments.get(player);
|
attachment = this.attachments.get(player);
|
||||||
} else {
|
} else {
|
||||||
attachment = player.addAttachment(plugin);
|
attachment = player.addAttachment(plugin);
|
||||||
this.attachments.put(player, attachment);
|
this.attachments.put(player, attachment);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
world = player.getWorld().getName();
|
world = player.getWorld().getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all permissions for this player (GM only)
|
// Add all permissions for this player (GM only)
|
||||||
// child nodes will be calculated by Bukkit.
|
// child nodes will be calculated by Bukkit.
|
||||||
List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(player.getName(), false));
|
List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(player.getName(), false));
|
||||||
LinkedHashMap<String, Boolean> newPerms = new LinkedHashMap<String, Boolean>();
|
LinkedHashMap<String, Boolean> newPerms = new LinkedHashMap<String, Boolean>();
|
||||||
|
|
||||||
// Sort the perm list by parent/child, so it will push to superperms correctly.
|
// Sort the perm list by parent/child, so it will push to superperms correctly.
|
||||||
playerPermArray = sort(playerPermArray);
|
playerPermArray = sort(playerPermArray);
|
||||||
|
|
||||||
Boolean value = false;
|
Boolean value = false;
|
||||||
for (String permission : playerPermArray) {
|
for (String permission : playerPermArray) {
|
||||||
value = (!permission.startsWith("-"));
|
value = (!permission.startsWith("-"));
|
||||||
newPerms.put((value ? permission : permission.substring(1)), value);
|
newPerms.put((value ? permission : permission.substring(1)), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is put in place until such a time as Bukkit pull 466 is
|
* This is put in place until such a time as Bukkit pull 466 is
|
||||||
* implemented
|
* implemented
|
||||||
* https://github.com/Bukkit/Bukkit/pull/466
|
* https://github.com/Bukkit/Bukkit/pull/466
|
||||||
*/
|
*/
|
||||||
try { // Codename_B source
|
try { // Codename_B source
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(attachment);
|
Map<String, Boolean> orig = (Map<String, Boolean>) permissions.get(attachment);
|
||||||
// Clear the map (faster than removing the attachment and recalculating)
|
// Clear the map (faster than removing the attachment and recalculating)
|
||||||
orig.clear();
|
orig.clear();
|
||||||
// Then whack our map into there
|
// Then whack our map into there
|
||||||
orig.putAll(newPerms);
|
orig.putAll(newPerms);
|
||||||
// That's all folks!
|
// That's all folks!
|
||||||
//attachment.getPermissible().recalculatePermissions();
|
//attachment.getPermissible().recalculatePermissions();
|
||||||
player.recalculatePermissions();
|
player.recalculatePermissions();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort a permission node list by parent/child
|
* Sort a permission node list by parent/child
|
||||||
*
|
*
|
||||||
* @param permList
|
* @param permList
|
||||||
* @return List sorted for priority
|
* @return List sorted for priority
|
||||||
*/
|
*/
|
||||||
private List<String> sort(List<String> permList) {
|
private List<String> sort(List<String> permList) {
|
||||||
|
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
|
|
||||||
for (String key : permList) {
|
for (String key : permList) {
|
||||||
String a = key.charAt(0) == '-' ? key.substring(1) : key;
|
String a = key.charAt(0) == '-' ? key.substring(1) : key;
|
||||||
Map<String, Boolean> allchildren = GroupManager.BukkitPermissions.getAllChildren(a, new HashSet<String>());
|
Map<String, Boolean> allchildren = GroupManager.BukkitPermissions.getAllChildren(a, new HashSet<String>());
|
||||||
if (allchildren != null) {
|
if (allchildren != null) {
|
||||||
|
|
||||||
ListIterator<String> itr = result.listIterator();
|
ListIterator<String> itr = result.listIterator();
|
||||||
|
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
String node = (String) itr.next();
|
String node = (String) itr.next();
|
||||||
String b = node.charAt(0) == '-' ? node.substring(1) : node;
|
String b = node.charAt(0) == '-' ? node.substring(1) : node;
|
||||||
|
|
||||||
// Insert the parent node before the child
|
// Insert the parent node before the child
|
||||||
if (allchildren.containsKey(b)) {
|
if (allchildren.containsKey(b)) {
|
||||||
itr.set(key);
|
itr.set(key);
|
||||||
itr.add(node);
|
itr.add(node);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!result.contains(key))
|
if (!result.contains(key))
|
||||||
result.add(key);
|
result.add(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch all permissions which are registered with superperms.
|
* Fetch all permissions which are registered with superperms.
|
||||||
* {can include child nodes)
|
* {can include child nodes)
|
||||||
*
|
*
|
||||||
* @param includeChildren
|
* @param includeChildren
|
||||||
* @return List of all permission nodes
|
* @return List of all permission nodes
|
||||||
*/
|
*/
|
||||||
public List<String> getAllRegisteredPermissions(boolean includeChildren) {
|
public List<String> getAllRegisteredPermissions(boolean includeChildren) {
|
||||||
|
|
||||||
List<String> perms = new ArrayList<String>();
|
List<String> perms = new ArrayList<String>();
|
||||||
|
|
||||||
for (String key : registeredPermissions.keySet()) {
|
for (String key : registeredPermissions.keySet()) {
|
||||||
if (!perms.contains(key)) {
|
if (!perms.contains(key)) {
|
||||||
perms.add(key);
|
perms.add(key);
|
||||||
|
|
||||||
if (includeChildren) {
|
if (includeChildren) {
|
||||||
Map<String, Boolean> children = getAllChildren(key, new HashSet<String>());
|
Map<String, Boolean> children = getAllChildren(key, new HashSet<String>());
|
||||||
if (children != null) {
|
if (children != null) {
|
||||||
for (String node : children.keySet())
|
for (String node : children.keySet())
|
||||||
if (!perms.contains(node))
|
if (!perms.contains(node))
|
||||||
perms.add(node);
|
perms.add(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return perms;
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a map of ALL child permissions registered with bukkit
|
* Returns a map of ALL child permissions registered with bukkit
|
||||||
* null is empty
|
* null is empty
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @param playerPermArray current list of perms to check against for
|
* @param playerPermArray current list of perms to check against for
|
||||||
* negations
|
* negations
|
||||||
* @return Map of child permissions
|
* @return Map of child permissions
|
||||||
*/
|
*/
|
||||||
public Map<String, Boolean> getAllChildren(String node, Set<String> playerPermArray) {
|
public Map<String, Boolean> getAllChildren(String node, Set<String> playerPermArray) {
|
||||||
|
|
||||||
LinkedList<String> stack = new LinkedList<String>();
|
LinkedList<String> stack = new LinkedList<String>();
|
||||||
Map<String, Boolean> alreadyVisited = new HashMap<String, Boolean>();
|
Map<String, Boolean> alreadyVisited = new HashMap<String, Boolean>();
|
||||||
stack.push(node);
|
stack.push(node);
|
||||||
alreadyVisited.put(node, true);
|
alreadyVisited.put(node, true);
|
||||||
|
|
||||||
while (!stack.isEmpty()) {
|
while (!stack.isEmpty()) {
|
||||||
String now = stack.pop();
|
String now = stack.pop();
|
||||||
|
|
||||||
Map<String, Boolean> children = getChildren(now);
|
Map<String, Boolean> children = getChildren(now);
|
||||||
|
|
||||||
if ((children != null) && (!playerPermArray.contains("-" + now))) {
|
if ((children != null) && (!playerPermArray.contains("-" + now))) {
|
||||||
for (String childName : children.keySet()) {
|
for (String childName : children.keySet()) {
|
||||||
if (!alreadyVisited.containsKey(childName)) {
|
if (!alreadyVisited.containsKey(childName)) {
|
||||||
stack.push(childName);
|
stack.push(childName);
|
||||||
alreadyVisited.put(childName, children.get(childName));
|
alreadyVisited.put(childName, children.get(childName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
alreadyVisited.remove(node);
|
alreadyVisited.remove(node);
|
||||||
if (!alreadyVisited.isEmpty())
|
if (!alreadyVisited.isEmpty())
|
||||||
return alreadyVisited;
|
return alreadyVisited;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a map of the child permissions (1 node deep) as registered with
|
* Returns a map of the child permissions (1 node deep) as registered with
|
||||||
* Bukkit.
|
* Bukkit.
|
||||||
* null is empty
|
* null is empty
|
||||||
*
|
*
|
||||||
* @param node
|
* @param node
|
||||||
* @return Map of child permissions
|
* @return Map of child permissions
|
||||||
*/
|
*/
|
||||||
public Map<String, Boolean> getChildren(String node) {
|
public Map<String, Boolean> getChildren(String node) {
|
||||||
|
|
||||||
Permission perm = registeredPermissions.get(node.toLowerCase());
|
Permission perm = registeredPermissions.get(node.toLowerCase());
|
||||||
if (perm == null)
|
if (perm == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return perm.getChildren();
|
return perm.getChildren();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all effective permissions for this player.
|
* List all effective permissions for this player.
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
* @return List<String> of permissions
|
* @return List<String> of permissions
|
||||||
*/
|
*/
|
||||||
public List<String> listPerms(Player player) {
|
public List<String> listPerms(Player player) {
|
||||||
|
|
||||||
List<String> perms = new ArrayList<String>();
|
List<String> perms = new ArrayList<String>();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* // All permissions registered with Bukkit for this player
|
* // All permissions registered with Bukkit for this player
|
||||||
* PermissionAttachment attachment = this.attachments.get(player);
|
* PermissionAttachment attachment = this.attachments.get(player);
|
||||||
*
|
*
|
||||||
* // List perms for this player perms.add("Attachment Permissions:");
|
* // List perms for this player perms.add("Attachment Permissions:");
|
||||||
* for(Map.Entry<String, Boolean> entry :
|
* for(Map.Entry<String, Boolean> entry :
|
||||||
* attachment.getPermissions().entrySet()){ perms.add(" " +
|
* attachment.getPermissions().entrySet()){ perms.add(" " +
|
||||||
* entry.getKey() + " = " + entry.getValue()); }
|
* entry.getKey() + " = " + entry.getValue()); }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
perms.add("Effective Permissions:");
|
perms.add("Effective Permissions:");
|
||||||
for (PermissionAttachmentInfo info : player.getEffectivePermissions()) {
|
for (PermissionAttachmentInfo info : player.getEffectivePermissions()) {
|
||||||
if (info.getValue() == true)
|
if (info.getValue() == true)
|
||||||
perms.add(" " + info.getPermission() + " = " + info.getValue());
|
perms.add(" " + info.getPermission() + " = " + info.getValue());
|
||||||
}
|
}
|
||||||
return perms;
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* force Bukkit to update every OnlinePlayers permissions.
|
* force Bukkit to update every OnlinePlayers permissions.
|
||||||
*/
|
*/
|
||||||
public void updateAllPlayers() {
|
public void updateAllPlayers() {
|
||||||
|
|
||||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||||
updatePermissions(player);
|
updatePermissions(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* force Bukkit to update this Players permissions.
|
* force Bukkit to update this Players permissions.
|
||||||
*/
|
*/
|
||||||
public void updatePlayer(Player player) {
|
public void updatePlayer(Player player) {
|
||||||
|
|
||||||
if (player != null)
|
if (player != null)
|
||||||
this.updatePermissions(player, null);
|
this.updatePermissions(player, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Force remove any attachments
|
* Force remove any attachments
|
||||||
*
|
*
|
||||||
* @param player
|
* @param player
|
||||||
*/
|
*/
|
||||||
private void removeAttachment(Player player) {
|
private void removeAttachment(Player player) {
|
||||||
|
|
||||||
if (attachments.containsKey(player)) {
|
if (attachments.containsKey(player)) {
|
||||||
try {
|
try {
|
||||||
player.removeAttachment(attachments.get(player));
|
player.removeAttachment(attachments.get(player));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
/*
|
/*
|
||||||
* Failed to remove attachment
|
* Failed to remove attachment
|
||||||
* This usually means Bukkit no longer knows of it.
|
* This usually means Bukkit no longer knows of it.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
attachments.remove(player);
|
attachments.remove(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove all attachments in case of a restart or reload.
|
* Remove all attachments in case of a restart or reload.
|
||||||
*/
|
*/
|
||||||
public void removeAllAttachments() {
|
public void removeAllAttachments() {
|
||||||
|
|
||||||
Iterator<Player> itr = attachments.keySet().iterator();
|
Iterator<Player> itr = attachments.keySet().iterator();
|
||||||
|
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
Player player = itr.next();
|
Player player = itr.next();
|
||||||
try {
|
try {
|
||||||
player.removeAttachment(attachments.get(player));
|
player.removeAttachment(attachments.get(player));
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
/*
|
/*
|
||||||
* Failed to remove attachment
|
* Failed to remove attachment
|
||||||
* This usually means Bukkit no longer knows of it.
|
* This usually means Bukkit no longer knows of it.
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
attachments.clear();
|
attachments.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Player events tracked to cause Superperms updates
|
* Player events tracked to cause Superperms updates
|
||||||
*
|
*
|
||||||
* @author ElgarL
|
* @author ElgarL
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected class PlayerEvents implements Listener {
|
protected class PlayerEvents implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
|
||||||
setPlayer_join(true);
|
setPlayer_join(true);
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Tidy up any lose ends
|
* Tidy up any lose ends
|
||||||
*/
|
*/
|
||||||
removeAttachment(player);
|
removeAttachment(player);
|
||||||
|
|
||||||
// force GM to create the player if they are not already listed.
|
// force GM to create the player if they are not already listed.
|
||||||
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
if (plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(player.getName()) != null) {
|
||||||
setPlayer_join(false);
|
setPlayer_join(false);
|
||||||
updatePermissions(event.getPlayer());
|
updatePermissions(event.getPlayer());
|
||||||
}
|
}
|
||||||
setPlayer_join(false);
|
setPlayer_join(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) { // has changed worlds
|
public void onPlayerChangeWorld(PlayerChangedWorldEvent event) { // has changed worlds
|
||||||
|
|
||||||
updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName());
|
updatePermissions(event.getPlayer(), event.getPlayer().getWorld().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerKick(PlayerKickEvent event) {
|
public void onPlayerKick(PlayerKickEvent event) {
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* force remove any attachments as bukkit may not
|
* force remove any attachments as bukkit may not
|
||||||
*/
|
*/
|
||||||
removeAttachment(player);
|
removeAttachment(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
|
||||||
if (!GroupManager.isLoaded())
|
if (!GroupManager.isLoaded())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* force remove any attachments as bukkit may not
|
* force remove any attachments as bukkit may not
|
||||||
*/
|
*/
|
||||||
removeAttachment(player);
|
removeAttachment(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class BukkitEvents implements Listener {
|
protected class BukkitEvents implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPluginEnable(PluginEnableEvent event) {
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
|
|
||||||
if (!GroupManager.isLoaded())
|
if (!GroupManager.isLoaded())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
collectPermissions();
|
collectPermissions();
|
||||||
updateAllPlayers();
|
updateAllPlayers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.NORMAL)
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
public void onPluginDisable(PluginDisableEvent event) {
|
public void onPluginDisable(PluginDisableEvent event) {
|
||||||
|
|
||||||
collectPermissions();
|
collectPermissions();
|
||||||
// updateAllPlayers();
|
// updateAllPlayers();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user