Search in sources :

Example 6 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project AuthMeReloaded by AuthMe.

the class PurgeTask method run.

@Override
public void run() {
    if (toPurge.isEmpty()) {
        //everything was removed
        finish();
        return;
    }
    Set<OfflinePlayer> playerPortion = new HashSet<>(INTERVAL_CHECK);
    Set<String> namePortion = new HashSet<>(INTERVAL_CHECK);
    for (int i = 0; i < INTERVAL_CHECK; i++) {
        int nextPosition = (currentPage * INTERVAL_CHECK) + i;
        if (offlinePlayers.length <= nextPosition) {
            //no more offline players on this page
            break;
        }
        OfflinePlayer offlinePlayer = offlinePlayers[nextPosition];
        if (offlinePlayer.getName() != null && toPurge.remove(offlinePlayer.getName().toLowerCase())) {
            if (!permissionsManager.hasPermissionOffline(offlinePlayer, PlayerStatePermission.BYPASS_PURGE)) {
                playerPortion.add(offlinePlayer);
                namePortion.add(offlinePlayer.getName());
            }
        }
    }
    if (!toPurge.isEmpty() && playerPortion.isEmpty()) {
        ConsoleLogger.info("Finished lookup of offlinePlayers. Begin looking purging player names only");
        //we went through all offlineplayers but there are still names remaining
        for (String name : toPurge) {
            if (!permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_PURGE)) {
                namePortion.add(name);
            }
        }
        toPurge.clear();
    }
    currentPage++;
    purgeService.executePurge(playerPortion, namePortion);
    if (currentPage % 20 == 0) {
        int completed = totalPurgeCount - toPurge.size();
        sendMessage("[AuthMe] Purge progress " + completed + '/' + totalPurgeCount);
    }
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) HashSet(java.util.HashSet)

Example 7 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project AuthMeReloaded by AuthMe.

the class PurgeExecutor method purgeDat.

/**
     * Removes the .dat file of the given players.
     *
     * @param cleared list of players to clear
     */
synchronized void purgeDat(Collection<OfflinePlayer> cleared) {
    if (!settings.getProperty(PurgeSettings.REMOVE_PLAYER_DAT)) {
        return;
    }
    int i = 0;
    File dataFolder = new File(server.getWorldContainer(), makePath(settings.getProperty(PurgeSettings.DEFAULT_WORLD), "players"));
    for (OfflinePlayer offlinePlayer : cleared) {
        File playerFile = new File(dataFolder, PlayerUtils.getUuidOrName(offlinePlayer) + ".dat");
        if (playerFile.delete()) {
            i++;
        }
    }
    ConsoleLogger.info("AutoPurge: Removed " + i + " .dat Files");
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) File(java.io.File)

Example 8 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project AuthMeReloaded by AuthMe.

the class PurgePlayerCommandTest method shouldExecutePurgeOfRegisteredPlayer.

@Test
public void shouldExecutePurgeOfRegisteredPlayer() {
    // given
    String name = "GhiJKlmn7";
    OfflinePlayer player = mock(OfflinePlayer.class);
    given(bukkitService.getOfflinePlayer(name)).willReturn(player);
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, asList(name, "force"));
    runOptionallyAsyncTask(bukkitService);
    // then
    verify(purgeExecutor).executePurge(singletonList(player), singletonList(name.toLowerCase()));
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 9 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project AuthMeReloaded by AuthMe.

the class PurgeTaskTest method assertRanPurgeWithPlayers.

private void assertRanPurgeWithPlayers(OfflinePlayer... players) {
    List<String> names = new ArrayList<>(players.length);
    for (OfflinePlayer player : players) {
        names.add(player.getName());
    }
    verify(purgeService).executePurge(playerCaptor.capture(), namesCaptor.capture());
    assertThat(namesCaptor.getValue(), containsInAnyOrder(names.toArray()));
    assertThat(playerCaptor.getValue(), containsInAnyOrder(players));
}
Also used : ArrayList(java.util.ArrayList) OfflinePlayer(org.bukkit.OfflinePlayer) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Example 10 with OfflinePlayer

use of org.bukkit.OfflinePlayer in project AuthMeReloaded by AuthMe.

the class PurgeBannedPlayersCommandTest method shouldForwardRequestToService.

@Test
public void shouldForwardRequestToService() {
    // given
    String[] names = { "bannedPlayer", "other_banned", "evilplayer", "Someone" };
    OfflinePlayer[] players = offlinePlayersWithNames(names);
    given(bukkitService.getBannedPlayers()).willReturn(newHashSet(players));
    CommandSender sender = mock(CommandSender.class);
    // when
    command.executeCommand(sender, Collections.emptyList());
    // then
    verify(bukkitService).getBannedPlayers();
    verify(purgeService).purgePlayers(eq(sender), eq(asLowerCaseSet(names)), argThat(arrayContainingInAnyOrder(players)));
}
Also used : OfflinePlayer(org.bukkit.OfflinePlayer) CommandSender(org.bukkit.command.CommandSender) Test(org.junit.Test)

Aggregations

OfflinePlayer (org.bukkit.OfflinePlayer)52 Player (org.bukkit.entity.Player)19 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)10 Job (com.gamingmesh.jobs.container.Job)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 File (java.io.File)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 HashSet (java.util.HashSet)4 World (org.bukkit.World)4 CommandSender (org.bukkit.command.CommandSender)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 JobProgression (com.gamingmesh.jobs.container.JobProgression)2 IOException (java.io.IOException)2 UUID (java.util.UUID)2 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)2 Element (net.aufdemrand.denizencore.objects.Element)2 GlowOfflinePlayer (net.glowstone.GlowOfflinePlayer)2 User (com.earth2me.essentials.User)1 ImmutableList (com.google.common.collect.ImmutableList)1