mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-20 15:47:38 +01:00
Do not lookup twice for banned players
This commit is contained in:
parent
45ddacc88a
commit
b1957c9812
@ -4,7 +4,6 @@ import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.command.CommandService;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.hooks.PluginHooks;
|
||||
import fr.xephi.authme.task.PurgeTask;
|
||||
import fr.xephi.authme.util.BukkitService;
|
||||
|
||||
@ -27,9 +26,6 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private DataSource dataSource;
|
||||
|
||||
@Inject
|
||||
private PluginHooks pluginHooks;
|
||||
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@ -39,17 +35,18 @@ public class PurgeBannedPlayersCommand implements ExecutableCommand {
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
|
||||
// Get the list of banned players
|
||||
Set<String> bannedPlayers = new HashSet<>();
|
||||
for (OfflinePlayer offlinePlayer : bukkitService.getBannedPlayers()) {
|
||||
bannedPlayers.add(offlinePlayer.getName().toLowerCase());
|
||||
Set<String> namedBanned = new HashSet<>();
|
||||
Set<OfflinePlayer> bannedPlayers = bukkitService.getBannedPlayers();
|
||||
for (OfflinePlayer offlinePlayer : bannedPlayers) {
|
||||
namedBanned.add(offlinePlayer.getName().toLowerCase());
|
||||
}
|
||||
|
||||
//todo: note this should may run async because it may executes a SQL-Query
|
||||
// Purge the banned players
|
||||
dataSource.purgeBanned(bannedPlayers);
|
||||
dataSource.purgeBanned(namedBanned);
|
||||
|
||||
// Show a status message
|
||||
sender.sendMessage(ChatColor.GOLD + "Purging user accounts...");
|
||||
new PurgeTask(plugin, plugin.getSettings(), sender, bannedPlayers).runTaskTimer(plugin, 0, 1);
|
||||
new PurgeTask(plugin, plugin.getSettings(), sender, namedBanned, bannedPlayers).runTaskTimer(plugin, 0, 1);
|
||||
}
|
||||
}
|
||||
|
@ -27,19 +27,25 @@ public class PurgeTask extends BukkitRunnable {
|
||||
private final UUID sender;
|
||||
private final Set<String> toPurge;
|
||||
|
||||
private final OfflinePlayer[] offlinePlayers = Bukkit.getOfflinePlayers();
|
||||
private final OfflinePlayer[] offlinePlayers;
|
||||
|
||||
private final boolean autoPurging;
|
||||
private final int totalPurgeCount;
|
||||
|
||||
private int currentPage = 0;
|
||||
|
||||
public PurgeTask(AuthMe plugin, NewSetting newSetting, CommandSender sender
|
||||
, Set<String> purged, Set<OfflinePlayer> offlinePlayers) {
|
||||
this(plugin, newSetting, sender, purged, false
|
||||
, offlinePlayers.toArray(new OfflinePlayer[offlinePlayers.size()]));
|
||||
}
|
||||
|
||||
public PurgeTask(AuthMe plugin, NewSetting newSetting, CommandSender sender, Set<String> purged) {
|
||||
this(plugin, newSetting, sender, purged, false);
|
||||
this(plugin, newSetting, sender, purged, false, Bukkit.getOfflinePlayers());
|
||||
}
|
||||
|
||||
public PurgeTask(AuthMe plugin, NewSetting newSetting, CommandSender sender, Set<String> purged
|
||||
, boolean autoPurging) {
|
||||
, boolean autoPurging, OfflinePlayer[] offlinePlayers) {
|
||||
this.plugin = plugin;
|
||||
this.newSetting = newSetting;
|
||||
|
||||
@ -52,6 +58,7 @@ public class PurgeTask extends BukkitRunnable {
|
||||
this.toPurge = purged;
|
||||
this.totalPurgeCount = purged.size();
|
||||
this.autoPurging = autoPurging;
|
||||
this.offlinePlayers = offlinePlayers;
|
||||
|
||||
//this is commented out because I assume all players in the database already have an lowercase name
|
||||
// toPurge = new HashSet<>(purged.size());
|
||||
|
@ -10,6 +10,8 @@ import java.util.List;
|
||||
import static fr.xephi.authme.AuthMeMatchers.equalToHash;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthBasicData;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthLocation;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
@ -221,7 +223,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
||||
public void shouldDeletePlayers() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
List<String> playersToDelete = Arrays.asList("bobby", "doesNotExist");
|
||||
Set<String> playersToDelete = new HashSet<>(Arrays.asList("bobby", "doesNotExist"));
|
||||
assumeThat(dataSource.getAccountsRegistered(), equalTo(2));
|
||||
|
||||
// when
|
||||
|
Loading…
Reference in New Issue
Block a user