- AsynchronousLogin: call common permission methods through CommonService instead of PermissionsManager - CommandManager: remove superfluous replacement of %p (handled by lazy tag replacer) - Remove unused method in CommonService - Create DebugSectionConsistencyTest - SendMailSSL: Enable debug output if AuthMe log level is set to debug - Add Utils#logAndSendMessage and replace existing, separate implementations
101 lines
2.7 KiB
Java
101 lines
2.7 KiB
Java
package fr.xephi.authme.service;
|
|
|
|
import ch.jalu.configme.properties.Property;
|
|
import fr.xephi.authme.message.MessageKey;
|
|
import fr.xephi.authme.message.Messages;
|
|
import fr.xephi.authme.permission.AuthGroupHandler;
|
|
import fr.xephi.authme.permission.AuthGroupType;
|
|
import fr.xephi.authme.permission.PermissionNode;
|
|
import fr.xephi.authme.permission.PermissionsManager;
|
|
import fr.xephi.authme.settings.Settings;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
/**
|
|
* Service for the most common operations regarding settings, messages and permissions.
|
|
*/
|
|
public class CommonService {
|
|
|
|
@Inject
|
|
private Settings settings;
|
|
|
|
@Inject
|
|
private Messages messages;
|
|
|
|
@Inject
|
|
private PermissionsManager permissionsManager;
|
|
|
|
@Inject
|
|
private AuthGroupHandler authGroupHandler;
|
|
|
|
CommonService() {
|
|
}
|
|
|
|
/**
|
|
* Retrieves a property's value.
|
|
*
|
|
* @param property the property to retrieve
|
|
* @param <T> the property type
|
|
* @return the property's value
|
|
*/
|
|
public <T> T getProperty(Property<T> property) {
|
|
return settings.getProperty(property);
|
|
}
|
|
|
|
/**
|
|
* Sends a message to the command sender.
|
|
*
|
|
* @param sender the command sender
|
|
* @param key the message key
|
|
*/
|
|
public void send(CommandSender sender, MessageKey key) {
|
|
messages.send(sender, key);
|
|
}
|
|
|
|
/**
|
|
* Sends a message to the command sender with the given replacements.
|
|
*
|
|
* @param sender the command sender
|
|
* @param key the message key
|
|
* @param replacements the replacements to apply to the message
|
|
*/
|
|
public void send(CommandSender sender, MessageKey key, String... replacements) {
|
|
messages.send(sender, key, replacements);
|
|
}
|
|
|
|
/**
|
|
* Retrieves a message in one piece.
|
|
*
|
|
* @param key the key of the message
|
|
* @return the message
|
|
*/
|
|
public String retrieveSingleMessage(MessageKey key) {
|
|
return messages.retrieveSingle(key);
|
|
}
|
|
|
|
/**
|
|
* Checks whether the player has the given permission.
|
|
*
|
|
* @param player the player
|
|
* @param node the permission node to check
|
|
* @return true if player has permission, false otherwise
|
|
*/
|
|
public boolean hasPermission(Player player, PermissionNode node) {
|
|
return permissionsManager.hasPermission(player, node);
|
|
}
|
|
|
|
/**
|
|
* Sets the permission group of the given player.
|
|
*
|
|
* @param player the player to process
|
|
* @param group the group to add the player to
|
|
*/
|
|
// TODO ljacqu 20170304: Move this out of CommonService
|
|
public void setGroup(Player player, AuthGroupType group) {
|
|
authGroupHandler.setGroup(player, group);
|
|
}
|
|
|
|
}
|