#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 (spawn != null && spawn.getWorld() != null) {
|
||||||
if (!player.getWorld().equals(spawn.getWorld())) {
|
if (!player.getWorld().equals(spawn.getWorld())) {
|
||||||
player.teleport(spawn);
|
player.teleport(spawn);
|
||||||
return;
|
} else if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
|
||||||
}
|
|
||||||
if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
|
|
||||||
player.teleport(spawn);
|
player.teleport(spawn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,17 +311,9 @@ public class PlayerListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||||
public void onPlayerInventoryClick(InventoryClickEvent event) {
|
public void onPlayerInventoryClick(InventoryClickEvent event) {
|
||||||
if (event.getWhoClicked() == null) {
|
if (listenerService.shouldCancelEvent(event.getWhoClicked())) {
|
||||||
return;
|
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)
|
@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.AsynchronousProcess;
|
||||||
import fr.xephi.authme.process.ProcessService;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.process.login.AsynchronousLogin;
|
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.HooksSettings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
@ -67,6 +68,9 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private AsynchronousLogin asynchronousLogin;
|
private AsynchronousLogin asynchronousLogin;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private CommandManager commandManager;
|
||||||
|
|
||||||
AsynchronousJoin() {
|
AsynchronousJoin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,26 +154,23 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
|
|
||||||
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
|
|
||||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(new Runnable() {
|
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> {
|
||||||
@Override
|
player.setOp(false);
|
||||||
public void run() {
|
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)
|
||||||
player.setOp(false);
|
&& service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
|
||||||
if (!service.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)
|
player.setFlySpeed(0.0f);
|
||||||
&& service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
|
player.setWalkSpeed(0.0f);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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
|
// Timeout and message task
|
||||||
|
|||||||
@ -19,26 +19,42 @@ public class CommandManager implements Reloadable {
|
|||||||
|
|
||||||
private final File dataFolder;
|
private final File dataFolder;
|
||||||
private final BukkitService bukkitService;
|
private final BukkitService bukkitService;
|
||||||
private final CommandsMigrater commandsMigrater;
|
private final CommandMigrationService commandMigrationService;
|
||||||
|
|
||||||
private CommandConfig commandConfig;
|
private CommandConfig commandConfig;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
CommandManager(@DataFolder File dataFolder, BukkitService bukkitService, CommandsMigrater commandsMigrater) {
|
CommandManager(@DataFolder File dataFolder, BukkitService bukkitService,
|
||||||
|
CommandMigrationService commandMigrationService) {
|
||||||
this.dataFolder = dataFolder;
|
this.dataFolder = dataFolder;
|
||||||
this.bukkitService = bukkitService;
|
this.bukkitService = bukkitService;
|
||||||
this.commandsMigrater = commandsMigrater;
|
this.commandMigrationService = commandMigrationService;
|
||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs the configured commands for when a player has joined.
|
||||||
|
*
|
||||||
|
* @param player the joining player
|
||||||
|
*/
|
||||||
public void runCommandsOnJoin(Player player) {
|
public void runCommandsOnJoin(Player player) {
|
||||||
executeCommands(player, commandConfig.getOnJoin());
|
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) {
|
public void runCommandsOnRegister(Player player) {
|
||||||
executeCommands(player, commandConfig.getOnRegister());
|
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) {
|
public void runCommandsOnLogin(Player player) {
|
||||||
executeCommands(player, commandConfig.getOnLogin());
|
executeCommands(player, commandConfig.getOnLogin());
|
||||||
}
|
}
|
||||||
@ -60,7 +76,7 @@ public class CommandManager implements Reloadable {
|
|||||||
FileUtils.copyFileFromResource(file, "commands.yml");
|
FileUtils.copyFileFromResource(file, "commands.yml");
|
||||||
|
|
||||||
SettingsManager settingsManager = new SettingsManager(
|
SettingsManager settingsManager = new SettingsManager(
|
||||||
new YamlFileResource(file), commandsMigrater, CommandSettingsHolder.class);
|
new YamlFileResource(file), commandMigrationService, CommandSettingsHolder.class);
|
||||||
commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
|
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.
|
* 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
|
@Inject
|
||||||
private SettingsMigrationService settingsMigrationService;
|
private SettingsMigrationService settingsMigrationService;
|
||||||
|
|
||||||
CommandsMigrater() {
|
CommandMigrationService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -46,6 +46,7 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
|||||||
"Supported command events: onLogin, onJoin, onRegister"
|
"Supported command events: onLogin, onJoin, onRegister"
|
||||||
};
|
};
|
||||||
Map<String, String[]> commentMap = new HashMap<>();
|
Map<String, String[]> commentMap = new HashMap<>();
|
||||||
|
// TODO ConfigMe/#25 cannot set comments on the root ("")
|
||||||
commentMap.put("onLogin", comments);
|
commentMap.put("onLogin", comments);
|
||||||
return commentMap;
|
return commentMap;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ public class CommandManagerTest {
|
|||||||
|
|
||||||
private CommandManager manager;
|
private CommandManager manager;
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private CommandsMigrater commandsMigrater;
|
private CommandMigrationService commandMigrationService;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||||
@ -158,7 +158,7 @@ public class CommandManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void initManager() {
|
private void initManager() {
|
||||||
manager = new CommandManager(testFolder, bukkitService, commandsMigrater);
|
manager = new CommandManager(testFolder, bukkitService, commandMigrationService);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyJarFileAsCommandsYml(String path) {
|
private void copyJarFileAsCommandsYml(String path) {
|
||||||
|
|||||||
@ -33,13 +33,13 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link CommandsMigrater}.
|
* Test for {@link CommandMigrationService}.
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class CommandsMigraterTest {
|
public class CommandMigrationServiceTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private CommandsMigrater commandsMigrater;
|
private CommandMigrationService commandMigrationService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SettingsMigrationService settingsMigrationService;
|
private SettingsMigrationService settingsMigrationService;
|
||||||
@ -62,7 +62,7 @@ public class CommandsMigraterTest {
|
|||||||
CommandConfig configSpy = spy(commandConfig);
|
CommandConfig configSpy = spy(commandConfig);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = commandsMigrater.transformOldCommands(configSpy);
|
boolean result = commandMigrationService.transformOldCommands(configSpy);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(false));
|
assertThat(result, equalTo(false));
|
||||||
@ -92,7 +92,7 @@ public class CommandsMigraterTest {
|
|||||||
commandConfig.setOnRegister(onRegisterCommands);
|
commandConfig.setOnRegister(onRegisterCommands);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = commandsMigrater.transformOldCommands(commandConfig);
|
boolean result = commandMigrationService.transformOldCommands(commandConfig);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
assertThat(result, equalTo(true));
|
assertThat(result, equalTo(true));
|
||||||
@ -122,7 +122,7 @@ public class CommandsMigraterTest {
|
|||||||
PropertyResource resource = new YamlFileResource(commandFile);
|
PropertyResource resource = new YamlFileResource(commandFile);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = commandsMigrater.checkAndMigrate(
|
boolean result = commandMigrationService.checkAndMigrate(
|
||||||
resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
|
resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
@ -28,7 +28,7 @@ import static org.mockito.BDDMockito.given;
|
|||||||
public class CommandYmlConsistencyTest {
|
public class CommandYmlConsistencyTest {
|
||||||
|
|
||||||
@InjectMocks
|
@InjectMocks
|
||||||
private CommandsMigrater commandsMigrater;
|
private CommandMigrationService commandMigrationService;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private SettingsMigrationService settingsMigrationService;
|
private SettingsMigrationService settingsMigrationService;
|
||||||
@ -51,7 +51,7 @@ public class CommandYmlConsistencyTest {
|
|||||||
PropertyResource resource = new YamlFileResource(commandFile);
|
PropertyResource resource = new YamlFileResource(commandFile);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
boolean result = commandsMigrater.checkAndMigrate(
|
boolean result = commandMigrationService.checkAndMigrate(
|
||||||
resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
|
resource, ConfigurationDataBuilder.collectData(CommandSettingsHolder.class).getProperties());
|
||||||
|
|
||||||
// then
|
// then
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user