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);
}
}
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");
}
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()));
}
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));
}
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)));
}
Aggregations