mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-09 04:02:10 +01:00
#411 Finalize forced commands implementation
This commit is contained in:
parent
f6ed39b118
commit
808ed84269
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
@ -46,6 +46,7 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
||||
"Supported command events: onLogin, onJoin, onRegister"
|
||||
};
|
||||
Map<String, String[]> commentMap = new HashMap<>();
|
||||
// TODO ConfigMe/#25 cannot set comments on the root ("")
|
||||
commentMap.put("onLogin", comments);
|
||||
return commentMap;
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user