#432 Injector improvements
- Separate FieldInjection from default fallback for no-Inject public no-args constructor classes - Make CommandInitializer a normal, instantiable service - Add various injections instead of fetching through command service
This commit is contained in:
@@ -8,7 +8,6 @@ import fr.xephi.authme.cache.backup.JsonCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.command.CommandHandler;
|
||||
import fr.xephi.authme.command.CommandInitializer;
|
||||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceType;
|
||||
@@ -18,7 +17,6 @@ import fr.xephi.authme.datasource.SQLite;
|
||||
import fr.xephi.authme.hooks.BungeeCordMessage;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.initialization.AuthMeServiceInitializer;
|
||||
import fr.xephi.authme.initialization.BaseCommands;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.initialization.MetricsStarter;
|
||||
import fr.xephi.authme.listener.AuthMeBlockListener;
|
||||
@@ -261,7 +259,6 @@ public class AuthMe extends JavaPlugin {
|
||||
// Some statically injected things
|
||||
initializer.register(PlayerCache.class, PlayerCache.getInstance());
|
||||
initializer.register(LimboCache.class, LimboCache.getInstance());
|
||||
initializer.provide(BaseCommands.class, CommandInitializer.buildCommands(initializer));
|
||||
|
||||
permsMan = initializer.get(PermissionsManager.class);
|
||||
bukkitService = initializer.get(BukkitService.class);
|
||||
|
||||
@@ -2,6 +2,7 @@ package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -23,6 +24,7 @@ public class CommandHandler {
|
||||
private static final double SUGGEST_COMMAND_THRESHOLD = 0.75;
|
||||
|
||||
private final CommandService commandService;
|
||||
private final PermissionsManager permissionsManager;
|
||||
|
||||
/**
|
||||
* Create a command handler.
|
||||
@@ -30,8 +32,9 @@ public class CommandHandler {
|
||||
* @param commandService The CommandService instance
|
||||
*/
|
||||
@Inject
|
||||
public CommandHandler(CommandService commandService) {
|
||||
public CommandHandler(CommandService commandService, PermissionsManager permissionsManager) {
|
||||
this.commandService = commandService;
|
||||
this.permissionsManager = permissionsManager;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +129,7 @@ public class CommandHandler {
|
||||
|
||||
private void sendImproperArgumentsMessage(CommandSender sender, FoundCommandResult result) {
|
||||
CommandDescription command = result.getCommandDescription();
|
||||
if (!commandService.getPermissionsManager().hasPermission(sender, command)) {
|
||||
if (!permissionsManager.hasPermission(sender, command)) {
|
||||
sendPermissionDeniedError(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import fr.xephi.authme.initialization.AuthMeServiceInitializer;
|
||||
import fr.xephi.authme.permission.AdminPermission;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -48,13 +49,23 @@ import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
|
||||
/**
|
||||
* Initializes all available AuthMe commands.
|
||||
*/
|
||||
public final class CommandInitializer {
|
||||
public class CommandInitializer {
|
||||
|
||||
private CommandInitializer() {
|
||||
// Helper class
|
||||
private AuthMeServiceInitializer initializer;
|
||||
|
||||
private Set<CommandDescription> commands;
|
||||
|
||||
@Inject
|
||||
public CommandInitializer(AuthMeServiceInitializer initializer) {
|
||||
this.initializer = initializer;
|
||||
buildCommands();
|
||||
}
|
||||
|
||||
public static Set<CommandDescription> buildCommands(AuthMeServiceInitializer initializer) {
|
||||
public Set<CommandDescription> getCommands() {
|
||||
return commands;
|
||||
}
|
||||
|
||||
private void buildCommands() {
|
||||
// Register the base AuthMe Reloaded command
|
||||
final CommandDescription AUTHME_BASE = CommandDescription.builder()
|
||||
.labels("authme")
|
||||
@@ -402,18 +413,16 @@ public final class CommandInitializer {
|
||||
EMAIL_BASE,
|
||||
CAPTCHA_BASE);
|
||||
|
||||
setHelpOnAllBases(baseCommands, initializer);
|
||||
return baseCommands;
|
||||
setHelpOnAllBases(baseCommands);
|
||||
commands = baseCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the help command on all base commands, e.g. to register /authme help or /register help.
|
||||
*
|
||||
* @param commands The list of base commands to register a help child command on
|
||||
* @param initializer The service initializer
|
||||
*/
|
||||
private static void setHelpOnAllBases(Collection<CommandDescription> commands,
|
||||
AuthMeServiceInitializer initializer) {
|
||||
private void setHelpOnAllBases(Collection<CommandDescription> commands) {
|
||||
final HelpCommand helpCommandExecutable = initializer.newInstance(HelpCommand.class);
|
||||
final List<String> helpCommandLabels = Arrays.asList("help", "hlp", "h", "sos", "?");
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.command.executable.HelpCommand;
|
||||
import fr.xephi.authme.initialization.BaseCommands;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.util.CollectionUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
@@ -31,8 +30,8 @@ public class CommandMapper {
|
||||
private final PermissionsManager permissionsManager;
|
||||
|
||||
@Inject
|
||||
public CommandMapper(@BaseCommands Set<CommandDescription> baseCommands, PermissionsManager permissionsManager) {
|
||||
this.baseCommands = baseCommands;
|
||||
public CommandMapper(CommandInitializer commandInitializer, PermissionsManager permissionsManager) {
|
||||
this.baseCommands = commandInitializer.getCommands();
|
||||
this.permissionsManager = permissionsManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,16 @@
|
||||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.domain.Property;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
import fr.xephi.authme.util.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
@@ -27,7 +23,7 @@ import java.util.List;
|
||||
public class CommandService {
|
||||
|
||||
@Inject
|
||||
private AuthMe authMe;
|
||||
private BukkitScheduler scheduler;
|
||||
@Inject
|
||||
private Messages messages;
|
||||
@Inject
|
||||
@@ -36,16 +32,8 @@ public class CommandService {
|
||||
private CommandMapper commandMapper;
|
||||
@SuppressWarnings("unused")
|
||||
@Inject
|
||||
private PasswordSecurity passwordSecurity;
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
@Inject
|
||||
private NewSetting settings;
|
||||
@Inject
|
||||
private PluginHooks pluginHooks;
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
@@ -86,19 +74,12 @@ public class CommandService {
|
||||
* Run the given task asynchronously with the Bukkit scheduler.
|
||||
*
|
||||
* @param task The task to run
|
||||
* @return a BukkitTask that contains the id number
|
||||
* @throws IllegalArgumentException if plugin is null
|
||||
* @throws IllegalArgumentException if task is null
|
||||
*/
|
||||
public void runTaskAsynchronously(Runnable task) {
|
||||
authMe.getServer().getScheduler().runTaskAsynchronously(authMe, task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the AuthMe instance for further manipulation. Use only if other methods from
|
||||
* the command service cannot be used.
|
||||
*
|
||||
* @return The AuthMe instance
|
||||
*/
|
||||
public AuthMe getAuthMe() {
|
||||
return authMe;
|
||||
public BukkitTask runTaskAsynchronously(Runnable task) {
|
||||
return bukkitService.runTaskAsynchronously(task);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -115,24 +96,6 @@ public class CommandService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the management instance of the plugin.
|
||||
*
|
||||
* @return The Management instance linked to the AuthMe instance
|
||||
*/
|
||||
public Management getManagement() {
|
||||
return authMe.getManagement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the permissions manager.
|
||||
*
|
||||
* @return the permissions manager
|
||||
*/
|
||||
public PermissionsManager getPermissionsManager() {
|
||||
return permissionsManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a message by its message key.
|
||||
*
|
||||
@@ -163,13 +126,6 @@ public class CommandService {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public PluginHooks getPluginHooks() {
|
||||
return pluginHooks;
|
||||
}
|
||||
|
||||
public SpawnLoader getSpawnLoader() {
|
||||
return spawnLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies whether a password is valid according to the plugin settings.
|
||||
|
||||
@@ -13,15 +13,16 @@ import fr.xephi.authme.converter.xAuthConverter;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class ConverterCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private AuthMe authMe;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
|
||||
// Get the conversion job
|
||||
String job = arguments.get(0);
|
||||
|
||||
@@ -36,22 +37,22 @@ public class ConverterCommand implements ExecutableCommand {
|
||||
Converter converter = null;
|
||||
switch (jobType) {
|
||||
case XAUTH:
|
||||
converter = new xAuthConverter(plugin, sender);
|
||||
converter = new xAuthConverter(authMe, sender);
|
||||
break;
|
||||
case CRAZYLOGIN:
|
||||
converter = new CrazyLoginConverter(plugin, sender);
|
||||
converter = new CrazyLoginConverter(authMe, sender);
|
||||
break;
|
||||
case RAKAMAK:
|
||||
converter = new RakamakConverter(plugin, sender);
|
||||
converter = new RakamakConverter(authMe, sender);
|
||||
break;
|
||||
case ROYALAUTH:
|
||||
converter = new RoyalAuthConverter(plugin);
|
||||
converter = new RoyalAuthConverter(authMe);
|
||||
break;
|
||||
case VAUTH:
|
||||
converter = new vAuthConverter(plugin, sender);
|
||||
converter = new vAuthConverter(authMe, sender);
|
||||
break;
|
||||
case SQLITETOSQL:
|
||||
converter = new SqliteToSql(plugin, sender, commandService.getSettings());
|
||||
converter = new SqliteToSql(authMe, sender, commandService.getSettings());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -2,8 +2,10 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -11,10 +13,13 @@ import java.util.List;
|
||||
*/
|
||||
public class FirstSpawnCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
if (commandService.getSpawnLoader().getFirstSpawn() != null) {
|
||||
player.teleport(commandService.getSpawnLoader().getFirstSpawn());
|
||||
if (spawnLoader.getFirstSpawn() != null) {
|
||||
player.teleport(spawnLoader.getFirstSpawn());
|
||||
} else {
|
||||
player.sendMessage("[AuthMe] First spawn has failed, please try to define the first spawn");
|
||||
}
|
||||
|
||||
@@ -2,9 +2,12 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.permission.PlayerPermission.CAN_LOGIN_BE_FORCED;
|
||||
@@ -14,6 +17,12 @@ import static fr.xephi.authme.permission.PlayerPermission.CAN_LOGIN_BE_FORCED;
|
||||
*/
|
||||
public class ForceLoginCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// Get the player query
|
||||
@@ -22,10 +31,10 @@ public class ForceLoginCommand implements ExecutableCommand {
|
||||
Player player = commandService.getPlayer(playerName);
|
||||
if (player == null || !player.isOnline()) {
|
||||
sender.sendMessage("Player needs to be online!");
|
||||
} else if (!commandService.getPermissionsManager().hasPermission(player, CAN_LOGIN_BE_FORCED)) {
|
||||
} else if (!permissionsManager.hasPermission(player, CAN_LOGIN_BE_FORCED)) {
|
||||
sender.sendMessage("You cannot force login the player " + playerName + "!");
|
||||
} else {
|
||||
commandService.getManagement().performLogin(player, "dontneed", true);
|
||||
management.performLogin(player, "dontneed", true);
|
||||
sender.sendMessage("Force login for " + playerName + " performed!");
|
||||
}
|
||||
}
|
||||
|
||||
+8
-4
@@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -21,11 +22,14 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private PluginHooks pluginHooks;
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// AuthMe plugin instance
|
||||
final AuthMe plugin = commandService.getAuthMe();
|
||||
|
||||
// Get the list of banned players
|
||||
List<String> bannedPlayers = new ArrayList<>();
|
||||
for (OfflinePlayer offlinePlayer : commandService.getBukkitService().getBannedPlayers()) {
|
||||
@@ -35,7 +39,7 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
// Purge the banned players
|
||||
dataSource.purgeBanned(bannedPlayers);
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES)
|
||||
&& commandService.getPluginHooks().isEssentialsAvailable())
|
||||
&& pluginHooks.isEssentialsAvailable())
|
||||
plugin.dataManager.purgeEssentials(bannedPlayers);
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_PLAYER_DAT))
|
||||
plugin.dataManager.purgeDat(bannedPlayers);
|
||||
|
||||
@@ -4,6 +4,7 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.settings.properties.PurgeSettings;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@@ -23,6 +24,12 @@ public class PurgeCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private PluginHooks pluginHooks;
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// Get the days parameter
|
||||
@@ -56,9 +63,8 @@ public class PurgeCommand implements ExecutableCommand {
|
||||
sender.sendMessage(ChatColor.GOLD + "Deleted " + purged.size() + " user accounts");
|
||||
|
||||
// Purge other data
|
||||
AuthMe plugin = commandService.getAuthMe();
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES) &&
|
||||
commandService.getPluginHooks().isEssentialsAvailable())
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_ESSENTIALS_FILES)
|
||||
&& pluginHooks.isEssentialsAvailable())
|
||||
plugin.dataManager.purgeEssentials(purged);
|
||||
if (commandService.getProperty(PurgeSettings.REMOVE_PLAYER_DAT))
|
||||
plugin.dataManager.purgeDat(purged);
|
||||
|
||||
@@ -7,6 +7,7 @@ import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -14,9 +15,11 @@ import java.util.List;
|
||||
*/
|
||||
public class ReloadCommand implements ExecutableCommand {
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
AuthMe plugin = commandService.getAuthMe();
|
||||
try {
|
||||
plugin.reload();
|
||||
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
|
||||
|
||||
@@ -2,15 +2,20 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class SetFirstSpawnCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
if (commandService.getSpawnLoader().setFirstSpawn(player.getLocation())) {
|
||||
if (spawnLoader.setFirstSpawn(player.getLocation())) {
|
||||
player.sendMessage("[AuthMe] Correctly defined new first spawn point");
|
||||
} else {
|
||||
player.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry");
|
||||
|
||||
@@ -2,15 +2,20 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class SetSpawnCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
if (commandService.getSpawnLoader().setSpawn(player.getLocation())) {
|
||||
if (spawnLoader.setSpawn(player.getLocation())) {
|
||||
player.sendMessage("[AuthMe] Correctly defined new spawn point");
|
||||
} else {
|
||||
player.sendMessage("[AuthMe] SetSpawn has failed, please retry");
|
||||
|
||||
@@ -2,16 +2,21 @@ package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class SpawnCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
if (commandService.getSpawnLoader().getSpawn() != null) {
|
||||
player.teleport(commandService.getSpawnLoader().getSpawn());
|
||||
if (spawnLoader.getSpawn() != null) {
|
||||
player.teleport(spawnLoader.getSpawn());
|
||||
} else {
|
||||
player.sendMessage("[AuthMe] Spawn has failed, please try to define the spawn");
|
||||
}
|
||||
|
||||
@@ -36,6 +36,9 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private AuthMe authMe;
|
||||
|
||||
@Override
|
||||
public void executeCommand(final CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// Get the player name
|
||||
@@ -79,7 +82,6 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
* @param service the command service
|
||||
*/
|
||||
private void applyUnregisteredEffectsAndTasks(Player target, CommandService service) {
|
||||
final AuthMe plugin = service.getAuthMe();
|
||||
final BukkitService bukkitService = service.getBukkitService();
|
||||
final String playerNameLowerCase = target.getName().toLowerCase();
|
||||
|
||||
@@ -88,11 +90,11 @@ public class UnregisterAdminCommand implements ExecutableCommand {
|
||||
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
if (timeOut != 0) {
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(plugin, playerNameLowerCase, target), timeOut);
|
||||
BukkitTask id = bukkitService.runTaskLater(new TimeoutTask(authMe, playerNameLowerCase, target), timeOut);
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTask(id);
|
||||
}
|
||||
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTask(
|
||||
bukkitService.runTask(new MessageTask(service.getBukkitService(), plugin.getMessages(),
|
||||
bukkitService.runTask(new MessageTask(service.getBukkitService(), authMe.getMessages(),
|
||||
playerNameLowerCase, MessageKey.REGISTER_MESSAGE, interval)));
|
||||
|
||||
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
|
||||
|
||||
@@ -9,16 +9,21 @@ import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class CaptchaCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
final String playerNameLowerCase = player.getName().toLowerCase();
|
||||
final String captcha = arguments.get(0);
|
||||
final AuthMe plugin = commandService.getAuthMe();
|
||||
PlayerCache playerCache = PlayerCache.getInstance();
|
||||
|
||||
// Command logic
|
||||
if (playerCache.isAuthenticated(playerNameLowerCase)) {
|
||||
|
||||
@@ -3,8 +3,10 @@ package fr.xephi.authme.command.executable.email;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -12,6 +14,9 @@ import java.util.List;
|
||||
*/
|
||||
public class AddEmailCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String email = arguments.get(0);
|
||||
@@ -19,7 +24,7 @@ public class AddEmailCommand extends PlayerCommand {
|
||||
|
||||
if (email.equals(emailConfirmation)) {
|
||||
// Closer inspection of the mail address handled by the async task
|
||||
commandService.getManagement().performAddEmail(player, email);
|
||||
management.performAddEmail(player, email);
|
||||
} else {
|
||||
commandService.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -11,11 +13,14 @@ import java.util.List;
|
||||
*/
|
||||
public class ChangeEmailCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String playerMailOld = arguments.get(0);
|
||||
String playerMailNew = arguments.get(1);
|
||||
|
||||
commandService.getManagement().performChangeEmail(player, playerMailOld, playerMailNew);
|
||||
management.performChangeEmail(player, playerMailOld, playerMailNew);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,13 @@ public class RecoverEmailCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private PlayerCache playerCache;
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
final String playerMail = arguments.get(0);
|
||||
final String playerName = player.getName();
|
||||
final AuthMe plugin = commandService.getAuthMe();
|
||||
|
||||
if (plugin.mail == null) {
|
||||
ConsoleLogger.showError("Mail API is not set");
|
||||
|
||||
@@ -2,8 +2,10 @@ package fr.xephi.authme.command.executable.login;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -11,9 +13,12 @@ import java.util.List;
|
||||
*/
|
||||
public class LoginCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
final String password = arguments.get(0);
|
||||
commandService.getManagement().performLogin(player, password, false);
|
||||
management.performLogin(player, password, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,10 @@ package fr.xephi.authme.command.executable.logout;
|
||||
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -11,8 +13,11 @@ import java.util.List;
|
||||
*/
|
||||
public class LogoutCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
commandService.getManagement().performLogout(player);
|
||||
management.performLogout(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,14 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.RandomString;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH;
|
||||
@@ -19,11 +21,14 @@ import static fr.xephi.authme.settings.properties.RestrictionSettings.ENABLE_PAS
|
||||
|
||||
public class RegisterCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
if (commandService.getProperty(SecuritySettings.PASSWORD_HASH) == HashAlgorithm.TWO_FACTOR) {
|
||||
//for two factor auth we don't need to check the usage
|
||||
commandService.getManagement().performRegister(player, "", "", true);
|
||||
management.performRegister(player, "", "", true);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -50,7 +55,7 @@ public class RegisterCommand extends PlayerCommand {
|
||||
if (commandService.getProperty(ENABLE_PASSWORD_CONFIRMATION) && !arguments.get(0).equals(arguments.get(1))) {
|
||||
commandService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
} else {
|
||||
commandService.getManagement().performRegister(player, arguments.get(0), "", true);
|
||||
management.performRegister(player, arguments.get(0), "", true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +75,7 @@ public class RegisterCommand extends PlayerCommand {
|
||||
commandService.send(player, MessageKey.USAGE_REGISTER);
|
||||
} else {
|
||||
String thePass = RandomString.generate(commandService.getProperty(RECOVERY_PASSWORD_LENGTH));
|
||||
commandService.getManagement().performRegister(player, thePass, email, true);
|
||||
management.performRegister(player, thePass, email, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,17 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.PlayerCommand;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.process.Management;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
public class UnregisterCommand extends PlayerCommand {
|
||||
|
||||
@Inject
|
||||
private Management management;
|
||||
|
||||
@Override
|
||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||
String playerPass = arguments.get(0);
|
||||
@@ -22,6 +27,6 @@ public class UnregisterCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
// Unregister the player
|
||||
commandService.getManagement().performUnregister(player, playerPass, false);
|
||||
management.performUnregister(player, playerPass, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,7 +132,8 @@ public class AuthMeServiceInitializer {
|
||||
* @return the instantiated object
|
||||
*/
|
||||
private <T> T instantiate(Class<T> clazz, Set<Class<?>> traversedClasses) {
|
||||
Injection<T> injection = firstNotNull(ConstructorInjection.provide(clazz), FieldInjection.provide(clazz));
|
||||
Injection<T> injection = firstNotNull(
|
||||
ConstructorInjection.provide(clazz), FieldInjection.provide(clazz), InstantiationFallback.provide(clazz));
|
||||
if (injection == null) {
|
||||
throw new IllegalStateException("Did not find injection method for " + clazz + ". Make sure you have "
|
||||
+ "a constructor with @Inject or fields with @Inject. Fields with @Inject require "
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package fr.xephi.authme.initialization;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotation to denote the collection of AuthMe commands.
|
||||
*/
|
||||
@Target({ElementType.PARAMETER, ElementType.FIELD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface BaseCommands {
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class FieldInjection<T> implements Injection<T> {
|
||||
*
|
||||
* @param clazz the class to provide field injection for
|
||||
* @param <T> the class' type
|
||||
* @return field injection provider for the given class
|
||||
* @return field injection provider for the given class, or null if not applicable
|
||||
*/
|
||||
public static <T> Provider<FieldInjection<T>> provide(final Class<T> clazz) {
|
||||
return new Provider<FieldInjection<T>>() {
|
||||
@@ -85,7 +85,7 @@ class FieldInjection<T> implements Injection<T> {
|
||||
return null;
|
||||
}
|
||||
List<Field> fields = getInjectionFields(clazz);
|
||||
return fields == null ? null : new FieldInjection<>(constructor, fields);
|
||||
return fields.isEmpty() ? null : new FieldInjection<>(constructor, fields);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
package fr.xephi.authme.initialization;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Fallback instantiation method for classes with an accessible no-args constructor
|
||||
* and no no {@link Inject} annotations whatsoever.
|
||||
*/
|
||||
public class InstantiationFallback<T> implements Injection<T> {
|
||||
|
||||
private final Constructor<T> constructor;
|
||||
|
||||
private InstantiationFallback(Constructor<T> constructor) {
|
||||
this.constructor = constructor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?>[] getDependencies() {
|
||||
return new Class<?>[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?>[] getDependencyAnnotations() {
|
||||
return new Class<?>[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public T instantiateWith(Object... values) {
|
||||
if (values == null || values.length > 0) {
|
||||
throw new UnsupportedOperationException("Instantiation fallback cannot have parameters");
|
||||
}
|
||||
try {
|
||||
return constructor.newInstance();
|
||||
} catch (InvocationTargetException | IllegalAccessException | InstantiationException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an instantiation fallback if the class is applicable.
|
||||
*
|
||||
* @param clazz the class
|
||||
* @param <T> the class' type
|
||||
* @return instantiation fallback provider for the given class, or null if not applicable
|
||||
*/
|
||||
public static <T> Provider<InstantiationFallback<T>> provide(final Class<T> clazz) {
|
||||
return new Provider<InstantiationFallback<T>>() {
|
||||
@Override
|
||||
public InstantiationFallback<T> get() {
|
||||
Constructor<T> noArgsConstructor = getNoArgsConstructor(clazz);
|
||||
// Return fallback only if we have no args constructor and no @Inject annotation anywhere
|
||||
if (noArgsConstructor != null
|
||||
&& !isInjectAnnotationPresent(clazz.getDeclaredConstructors())
|
||||
&& !isInjectAnnotationPresent(clazz.getDeclaredFields())
|
||||
&& !isInjectAnnotationPresent(clazz.getDeclaredMethods())) {
|
||||
return new InstantiationFallback<>(noArgsConstructor);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static <T> Constructor<T> getNoArgsConstructor(Class<T> clazz) {
|
||||
try {
|
||||
// Note ljacqu 20160504: getConstructor(), unlike getDeclaredConstructor(), only considers public members
|
||||
return clazz.getConstructor();
|
||||
} catch (NoSuchMethodException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static <A extends AccessibleObject> boolean isInjectAnnotationPresent(A[] accessibles) {
|
||||
for (A accessible : accessibles) {
|
||||
if (accessible.isAnnotationPresent(Inject.class)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,11 @@
|
||||
package fr.xephi.authme.listener;
|
||||
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.spigotmc.event.player.PlayerSpawnLocationEvent;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
@@ -15,13 +14,13 @@ import javax.inject.Inject;
|
||||
public class AuthMePlayerListener19 implements Listener {
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
public AuthMePlayerListener19() { }
|
||||
private SpawnLoader spawnLoader;
|
||||
|
||||
AuthMePlayerListener19() { }
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerSpawn(PlayerSpawnLocationEvent event) {
|
||||
event.setSpawnLocation(plugin.getSpawnLocation(event.getPlayer()));
|
||||
event.setSpawnLocation(spawnLoader.getSpawnLocation(event.getPlayer()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
@@ -34,6 +35,8 @@ public class AuthMeServerListener implements Listener {
|
||||
private SpawnLoader spawnLoader;
|
||||
@Inject
|
||||
private ValidationService validationService;
|
||||
@Inject
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onServerPing(ServerListPingEvent event) {
|
||||
@@ -53,7 +56,7 @@ public class AuthMeServerListener implements Listener {
|
||||
}
|
||||
|
||||
// Call the onPluginDisable method in the permissions manager
|
||||
plugin.getPermissionsManager().onPluginDisable(event);
|
||||
permissionsManager.onPluginDisable(event);
|
||||
|
||||
final String pluginName = event.getPlugin().getName();
|
||||
if ("Essentials".equalsIgnoreCase(pluginName)) {
|
||||
@@ -86,7 +89,7 @@ public class AuthMeServerListener implements Listener {
|
||||
}
|
||||
|
||||
// Call the onPluginEnable method in the permissions manager
|
||||
plugin.getPermissionsManager().onPluginEnable(event);
|
||||
permissionsManager.onPluginEnable(event);
|
||||
|
||||
final String pluginName = event.getPlugin().getName();
|
||||
if ("Essentials".equalsIgnoreCase(pluginName)) {
|
||||
|
||||
Reference in New Issue
Block a user