diff --git a/src/main/java/fr/xephi/authme/listener/PlayerListener.java b/src/main/java/fr/xephi/authme/listener/PlayerListener.java index 9b3eda8e..c380fbe1 100644 --- a/src/main/java/fr/xephi/authme/listener/PlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/PlayerListener.java @@ -157,9 +157,7 @@ public class PlayerListener implements Listener { if (spawn != null && spawn.getWorld() != null) { if (!player.getWorld().equals(spawn.getWorld())) { player.teleport(spawn); - return; - } - if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) { + } else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) { player.teleport(spawn); } } @@ -313,17 +311,9 @@ public class PlayerListener implements Listener { @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerInventoryClick(InventoryClickEvent event) { - if (event.getWhoClicked() == null) { - return; + if (listenerService.shouldCancelEvent(event.getWhoClicked())) { + event.setCancelled(true); } - if (!(event.getWhoClicked() instanceof Player)) { - return; - } - Player player = (Player) event.getWhoClicked(); - if (!listenerService.shouldCancelEvent(player)) { - return; - } - event.setCancelled(true); } @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) diff --git a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java index 490bc9ba..cf70c386 100644 --- a/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java +++ b/src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java @@ -15,6 +15,7 @@ import fr.xephi.authme.permission.PlayerStatePermission; import fr.xephi.authme.process.AsynchronousProcess; import fr.xephi.authme.process.ProcessService; import fr.xephi.authme.process.login.AsynchronousLogin; +import fr.xephi.authme.settings.commandconfig.CommandManager; import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.RegistrationSettings; @@ -67,6 +68,9 @@ public class AsynchronousJoin implements AsynchronousProcess { @Inject private AsynchronousLogin asynchronousLogin; + @Inject + private CommandManager commandManager; + AsynchronousJoin() { } @@ -150,26 +154,23 @@ public class AsynchronousJoin implements AsynchronousProcess { final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; - bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(new Runnable() { - @Override - public void run() { - player.setOp(false); - if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) - && service.getProperty(RestrictionSettings.REMOVE_SPEED)) { - player.setFlySpeed(0.0f); - player.setWalkSpeed(0.0f); - } - player.setNoDamageTicks(registrationTimeout); - if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) { - player.performCommand("motd"); - } - if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { - // Allow infinite blindness effect - int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout; - player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2)); - } + bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> { + player.setOp(false); + if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT) + && service.getProperty(RestrictionSettings.REMOVE_SPEED)) { + player.setFlySpeed(0.0f); + player.setWalkSpeed(0.0f); } - + player.setNoDamageTicks(registrationTimeout); + if (pluginHookService.isEssentialsAvailable() && service.getProperty(HooksSettings.USE_ESSENTIALS_MOTD)) { + player.performCommand("motd"); + } + if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) { + // Allow infinite blindness effect + int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout; + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2)); + } + commandManager.runCommandsOnJoin(player); }); // Timeout and message task diff --git a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java index 2b476c4a..f21f7e5c 100644 --- a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java +++ b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandManager.java @@ -19,26 +19,42 @@ public class CommandManager implements Reloadable { private final File dataFolder; private final BukkitService bukkitService; - private final CommandsMigrater commandsMigrater; + private final CommandMigrationService commandMigrationService; private CommandConfig commandConfig; @Inject - CommandManager(@DataFolder File dataFolder, BukkitService bukkitService, CommandsMigrater commandsMigrater) { + CommandManager(@DataFolder File dataFolder, BukkitService bukkitService, + CommandMigrationService commandMigrationService) { this.dataFolder = dataFolder; this.bukkitService = bukkitService; - this.commandsMigrater = commandsMigrater; + this.commandMigrationService = commandMigrationService; reload(); } + /** + * Runs the configured commands for when a player has joined. + * + * @param player the joining player + */ public void runCommandsOnJoin(Player player) { executeCommands(player, commandConfig.getOnJoin()); } + /** + * Runs the configured commands for when a player has successfully registered. + * + * @param player the player who has registered + */ public void runCommandsOnRegister(Player player) { executeCommands(player, commandConfig.getOnRegister()); } + /** + * Runs the configured commands for when a player has logged in successfully. + * + * @param player the player that logged in + */ public void runCommandsOnLogin(Player player) { executeCommands(player, commandConfig.getOnLogin()); } @@ -60,7 +76,7 @@ public class CommandManager implements Reloadable { FileUtils.copyFileFromResource(file, "commands.yml"); SettingsManager settingsManager = new SettingsManager( - new YamlFileResource(file), commandsMigrater, CommandSettingsHolder.class); + new YamlFileResource(file), commandMigrationService, CommandSettingsHolder.class); commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS); } diff --git a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandsMigrater.java b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandMigrationService.java similarity index 98% rename from src/main/java/fr/xephi/authme/settings/commandconfig/CommandsMigrater.java rename to src/main/java/fr/xephi/authme/settings/commandconfig/CommandMigrationService.java index a64260e0..6b357615 100644 --- a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandsMigrater.java +++ b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandMigrationService.java @@ -17,12 +17,12 @@ import java.util.stream.Collectors; /** * Migrates the commands from their old location, in config.yml, to the dedicated commands configuration file. */ -class CommandsMigrater implements MigrationService { +class CommandMigrationService implements MigrationService { @Inject private SettingsMigrationService settingsMigrationService; - CommandsMigrater() { + CommandMigrationService() { } @Override diff --git a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java index 75906a32..99a1c6e8 100644 --- a/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java +++ b/src/main/java/fr/xephi/authme/settings/commandconfig/CommandSettingsHolder.java @@ -46,6 +46,7 @@ public final class CommandSettingsHolder implements SettingsHolder { "Supported command events: onLogin, onJoin, onRegister" }; Map commentMap = new HashMap<>(); + // TODO ConfigMe/#25 cannot set comments on the root ("") commentMap.put("onLogin", comments); return commentMap; } diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java index ec03cb19..7b9d1bfc 100644 --- a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java @@ -42,7 +42,7 @@ public class CommandManagerTest { private CommandManager manager; @InjectMocks - private CommandsMigrater commandsMigrater; + private CommandMigrationService commandMigrationService; @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -158,7 +158,7 @@ public class CommandManagerTest { } private void initManager() { - manager = new CommandManager(testFolder, bukkitService, commandsMigrater); + manager = new CommandManager(testFolder, bukkitService, commandMigrationService); } private void copyJarFileAsCommandsYml(String path) { diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandsMigraterTest.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandMigrationServiceTest.java similarity index 93% rename from src/test/java/fr/xephi/authme/settings/commandconfig/CommandsMigraterTest.java rename to src/test/java/fr/xephi/authme/settings/commandconfig/CommandMigrationServiceTest.java index 0dae65fe..d04fc89e 100644 --- a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandsMigraterTest.java +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandMigrationServiceTest.java @@ -33,13 +33,13 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verifyZeroInteractions; /** - * Test for {@link CommandsMigrater}. + * Test for {@link CommandMigrationService}. */ @RunWith(MockitoJUnitRunner.class) -public class CommandsMigraterTest { +public class CommandMigrationServiceTest { @InjectMocks - private CommandsMigrater commandsMigrater; + private CommandMigrationService commandMigrationService; @Mock private SettingsMigrationService settingsMigrationService; @@ -62,7 +62,7 @@ public class CommandsMigraterTest { CommandConfig configSpy = spy(commandConfig); // when - boolean result = commandsMigrater.transformOldCommands(configSpy); + boolean result = commandMigrationService.transformOldCommands(configSpy); // then assertThat(result, equalTo(false)); @@ -92,7 +92,7 @@ public class CommandsMigraterTest { commandConfig.setOnRegister(onRegisterCommands); // when - boolean result = commandsMigrater.transformOldCommands(commandConfig); + boolean result = commandMigrationService.transformOldCommands(commandConfig); // then assertThat(result, equalTo(true)); @@ -122,7 +122,7 @@ public class CommandsMigraterTest { PropertyResource resource = new YamlFileResource(commandFile); // when - boolean result = commandsMigrater.checkAndMigrate( + boolean result = commandMigrationService.checkAndMigrate( resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); // then diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java index ff9e51da..0cb17fbc 100644 --- a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandYmlConsistencyTest.java @@ -28,7 +28,7 @@ import static org.mockito.BDDMockito.given; public class CommandYmlConsistencyTest { @InjectMocks - private CommandsMigrater commandsMigrater; + private CommandMigrationService commandMigrationService; @Mock private SettingsMigrationService settingsMigrationService; @@ -51,7 +51,7 @@ public class CommandYmlConsistencyTest { PropertyResource resource = new YamlFileResource(commandFile); // when - boolean result = commandsMigrater.checkAndMigrate( + boolean result = commandMigrationService.checkAndMigrate( resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties()); // then