Search in sources :

Example 1 with LimboService

use of fr.xephi.authme.data.limbo.LimboService in project AuthMeReloaded by AuthMe.

the class DebugSectionUtilsTest method shouldHandleErrorGracefully.

@Test
public void shouldHandleErrorGracefully() {
    // given
    LimboService limboService = mock(LimboService.class);
    Map<String, LimboPlayer> limboMap = new HashMap<>();
    ReflectionTestUtils.setField(LimboService.class, limboService, "entries", limboMap);
    // when
    Object result = DebugSectionUtils.applyToLimboPlayersMap(limboService, map -> {
        throw new IllegalStateException();
    });
    // then
    assertThat(result, nullValue());
}
Also used : HashMap(java.util.HashMap) LimboService(fr.xephi.authme.data.limbo.LimboService) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Test(org.junit.Test)

Example 2 with LimboService

use of fr.xephi.authme.data.limbo.LimboService in project AuthMeReloaded by AuthMe.

the class LimboPlayerViewer method execute.

@Override
public void execute(CommandSender sender, List<String> arguments) {
    if (arguments.isEmpty()) {
        sender.sendMessage(ChatColor.BLUE + "AuthMe limbo viewer");
        sender.sendMessage("/authme debug limbo <player>: show a player's limbo info");
        sender.sendMessage("Available limbo records: " + applyToLimboPlayersMap(limboService, Map::keySet));
        return;
    }
    LimboPlayer memoryLimbo = limboService.getLimboPlayer(arguments.get(0));
    Player player = bukkitService.getPlayerExact(arguments.get(0));
    LimboPlayer diskLimbo = player != null ? limboPersistence.getLimboPlayer(player) : null;
    if (memoryLimbo == null && player == null) {
        sender.sendMessage(ChatColor.BLUE + "No AuthMe limbo data");
        sender.sendMessage("No limbo data and no player online with name '" + arguments.get(0) + "'");
        return;
    }
    sender.sendMessage(ChatColor.BLUE + "Player / limbo / disk limbo info for '" + arguments.get(0) + "'");
    new InfoDisplayer(sender, player, memoryLimbo, diskLimbo).sendEntry("Is op", Player::isOp, LimboPlayer::isOperator).sendEntry("Walk speed", Player::getWalkSpeed, LimboPlayer::getWalkSpeed).sendEntry("Can fly", Player::getAllowFlight, LimboPlayer::isCanFly).sendEntry("Fly speed", Player::getFlySpeed, LimboPlayer::getFlySpeed).sendEntry("Location", p -> formatLocation(p.getLocation()), l -> formatLocation(l.getLocation())).sendEntry("Prim. group", p -> permissionsManager.hasGroupSupport() ? permissionsManager.getPrimaryGroup(p) : "N/A", LimboPlayer::getGroups);
}
Also used : PermissionNode(fr.xephi.authme.permission.PermissionNode) LimboService(fr.xephi.authme.data.limbo.LimboService) CommandSender(org.bukkit.command.CommandSender) BukkitService(fr.xephi.authme.service.BukkitService) Player(org.bukkit.entity.Player) LimboPersistence(fr.xephi.authme.data.limbo.persistence.LimboPersistence) Function(java.util.function.Function) Inject(javax.inject.Inject) List(java.util.List) DebugSectionUtils.formatLocation(fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) PermissionsManager(fr.xephi.authme.permission.PermissionsManager) Map(java.util.Map) Optional(java.util.Optional) DebugSectionPermissions(fr.xephi.authme.permission.DebugSectionPermissions) ChatColor(org.bukkit.ChatColor) DebugSectionUtils.applyToLimboPlayersMap(fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap) Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Map(java.util.Map) DebugSectionUtils.applyToLimboPlayersMap(fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap)

Example 3 with LimboService

use of fr.xephi.authme.data.limbo.LimboService in project AuthMeReloaded by AuthMe.

the class DebugSectionUtilsTest method shouldFetchMapInLimboService.

@Test
public void shouldFetchMapInLimboService() {
    // given
    LimboService limboService = mock(LimboService.class);
    Map<String, LimboPlayer> limboMap = new HashMap<>();
    ReflectionTestUtils.setField(LimboService.class, limboService, "entries", limboMap);
    // when
    Map map = DebugSectionUtils.applyToLimboPlayersMap(limboService, Function.identity());
    // then
    assertThat(map, sameInstance(limboMap));
}
Also used : HashMap(java.util.HashMap) LimboService(fr.xephi.authme.data.limbo.LimboService) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)3 LimboService (fr.xephi.authme.data.limbo.LimboService)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Test (org.junit.Test)2 DebugSectionUtils.applyToLimboPlayersMap (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.applyToLimboPlayersMap)1 DebugSectionUtils.formatLocation (fr.xephi.authme.command.executable.authme.debug.DebugSectionUtils.formatLocation)1 LimboPersistence (fr.xephi.authme.data.limbo.persistence.LimboPersistence)1 DebugSectionPermissions (fr.xephi.authme.permission.DebugSectionPermissions)1 PermissionNode (fr.xephi.authme.permission.PermissionNode)1 PermissionsManager (fr.xephi.authme.permission.PermissionsManager)1 BukkitService (fr.xephi.authme.service.BukkitService)1 List (java.util.List)1 Optional (java.util.Optional)1 Function (java.util.function.Function)1 Inject (javax.inject.Inject)1 ChatColor (org.bukkit.ChatColor)1 CommandSender (org.bukkit.command.CommandSender)1 Player (org.bukkit.entity.Player)1