Purge was not calculated player logins correctly.

https://github.com/BentoBoxWorld/BentoBox/issues/1333
This commit is contained in:
tastybento 2020-05-02 16:14:03 -07:00
parent 3b50b01eef
commit 61fe218a16
2 changed files with 25 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package world.bentobox.bentobox.api.commands.admin.purge;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -11,6 +12,7 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandDeletedEvent;
import world.bentobox.bentobox.api.localization.TextVariables;
@ -119,13 +121,26 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
}
Set<String> getOldIslands(int days) {
getPlugin().getIslands().getIslands().stream()
.filter(i -> !i.isSpawn())
.filter(i -> !i.getPurgeProtected())
.filter(i -> i.getWorld().equals(this.getWorld()))
.filter(Island::isOwned)
.filter(i -> i.getMembers().size() == 1)
.filter(i -> ((double)(System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) / 1000 / 3600 / 24) > days)
.forEach(i -> {
Date date = new Date(Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed());
BentoBox.getInstance().log("Will purge " +
BentoBox.getInstance().getPlayers().getName(i.getOwner()) +
" last logged in " + (int)((double)(System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) / 1000 / 3600 / 24) + " days ago. " + date);
});
return getPlugin().getIslands().getIslands().stream()
.filter(i -> !i.isSpawn())
.filter(i -> !i.getPurgeProtected())
.filter(i -> i.getWorld().equals(this.getWorld()))
.filter(Island::isOwned)
.filter(i -> i.getMembers().size() == 1)
.filter(i -> (System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) > days * 1000 * 24 * 3600)
.filter(i -> ((double)(System.currentTimeMillis() - Bukkit.getOfflinePlayer(i.getOwner()).getLastPlayed()) / 1000 / 3600 / 24) > days)
.map(Island::getUniqueId)
.collect(Collectors.toSet());
}

View File

@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -39,6 +40,7 @@ import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.CommandsManager;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.managers.IslandsManager;
import world.bentobox.bentobox.managers.PlayersManager;
import world.bentobox.bentobox.managers.RanksManager;
/**
@ -65,6 +67,8 @@ public class AdminPurgeCommandTest {
private Island island;
@Mock
private World world;
@Mock
private PlayersManager pm;
/**
* @throws java.lang.Exception
@ -95,6 +99,10 @@ public class AdminPurgeCommandTest {
// Island
when(island.isOwned()).thenReturn(true); // Default owned
// Player manager
when(plugin.getPlayers()).thenReturn(pm);
when(pm.getName(any())).thenReturn("name");
// Command
apc = new AdminPurgeCommand(ac);
}
@ -293,7 +301,7 @@ public class AdminPurgeCommandTest {
testExecuteUserStringListOfStringIslandsFound();
assertTrue(apc.execute(user, "", Collections.singletonList("confirm")));
verify(im).deleteIsland(eq(island), eq(true), eq(null));
verify(plugin).log(any());
verify(plugin, times(2)).log(any());
verify(user).sendMessage(eq("commands.admin.purge.see-console-for-status"), eq("[label]"), eq("bsb"));
}