Use injection in and for LimboCache, migrate some legacy settings, remove setGroup from Utils
- New injector method allows to retrieve services if they've already been instantiated -> useful for onDisable() which might be run after aborted initialization - Deprecate various methods that need to be removed
This commit is contained in:
@@ -2,8 +2,6 @@ package fr.xephi.authme.util;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.events.AuthMeTeleportEvent;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
@@ -23,68 +21,6 @@ public final class Utils {
|
||||
private Utils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the group of a player, by its AuthMe group type.
|
||||
*
|
||||
* @param player The player.
|
||||
* @param group The group type.
|
||||
*
|
||||
* @return True if succeeded, false otherwise. False is also returned if groups aren't supported
|
||||
* with the current permissions system.
|
||||
*/
|
||||
public static boolean setGroup(Player player, GroupType group) {
|
||||
// Check whether the permissions check is enabled
|
||||
if (!Settings.isPermissionCheckEnabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the permissions manager, and make sure it's valid
|
||||
PermissionsManager permsMan = plugin.getPermissionsManager();
|
||||
if (permsMan == null) {
|
||||
ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure group support is available
|
||||
if (!permsMan.hasGroupSupport()) {
|
||||
ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (group) {
|
||||
case UNREGISTERED:
|
||||
// Remove the other group type groups, set the current group
|
||||
permsMan.removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return permsMan.addGroup(player, Settings.unRegisteredGroup);
|
||||
|
||||
case REGISTERED:
|
||||
// Remove the other group type groups, set the current group
|
||||
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return permsMan.addGroup(player, Settings.getRegisteredGroup);
|
||||
|
||||
case NOTLOGGEDIN:
|
||||
// Remove the other group type groups, set the current group
|
||||
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup));
|
||||
return permsMan.addGroup(player, Settings.getUnloggedinGroup);
|
||||
|
||||
case LOGGEDIN:
|
||||
// Get the limbo player data
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
||||
if (limbo == null)
|
||||
return false;
|
||||
|
||||
// Get the players group
|
||||
String realGroup = limbo.getGroup();
|
||||
|
||||
// Remove the other group types groups, set the real group
|
||||
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
|
||||
return permsMan.addGroup(player, realGroup);
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: This method requires better explanation.
|
||||
* <p>
|
||||
@@ -143,13 +79,6 @@ public final class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
public enum GroupType {
|
||||
UNREGISTERED,
|
||||
REGISTERED,
|
||||
NOTLOGGEDIN,
|
||||
LOGGEDIN
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IP of the given player.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user