mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-23 19:25:12 +01:00
Purge was not calculated player logins correctly.
https://github.com/BentoBoxWorld/BentoBox/issues/1333
This commit is contained in:
parent
3b50b01eef
commit
61fe218a16
@ -1,5 +1,6 @@
|
|||||||
package world.bentobox.bentobox.api.commands.admin.purge;
|
package world.bentobox.bentobox.api.commands.admin.purge;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,6 +12,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import world.bentobox.bentobox.BentoBox;
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandDeletedEvent;
|
import world.bentobox.bentobox.api.events.island.IslandEvent.IslandDeletedEvent;
|
||||||
import world.bentobox.bentobox.api.localization.TextVariables;
|
import world.bentobox.bentobox.api.localization.TextVariables;
|
||||||
@ -119,13 +121,26 @@ public class AdminPurgeCommand extends CompositeCommand implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> getOldIslands(int days) {
|
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()
|
return getPlugin().getIslands().getIslands().stream()
|
||||||
.filter(i -> !i.isSpawn())
|
.filter(i -> !i.isSpawn())
|
||||||
.filter(i -> !i.getPurgeProtected())
|
.filter(i -> !i.getPurgeProtected())
|
||||||
.filter(i -> i.getWorld().equals(this.getWorld()))
|
.filter(i -> i.getWorld().equals(this.getWorld()))
|
||||||
.filter(Island::isOwned)
|
.filter(Island::isOwned)
|
||||||
.filter(i -> i.getMembers().size() == 1)
|
.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)
|
.map(Island::getUniqueId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
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.CommandsManager;
|
||||||
import world.bentobox.bentobox.managers.IslandWorldManager;
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
||||||
import world.bentobox.bentobox.managers.IslandsManager;
|
import world.bentobox.bentobox.managers.IslandsManager;
|
||||||
|
import world.bentobox.bentobox.managers.PlayersManager;
|
||||||
import world.bentobox.bentobox.managers.RanksManager;
|
import world.bentobox.bentobox.managers.RanksManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,6 +67,8 @@ public class AdminPurgeCommandTest {
|
|||||||
private Island island;
|
private Island island;
|
||||||
@Mock
|
@Mock
|
||||||
private World world;
|
private World world;
|
||||||
|
@Mock
|
||||||
|
private PlayersManager pm;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws java.lang.Exception
|
* @throws java.lang.Exception
|
||||||
@ -95,6 +99,10 @@ public class AdminPurgeCommandTest {
|
|||||||
// Island
|
// Island
|
||||||
when(island.isOwned()).thenReturn(true); // Default owned
|
when(island.isOwned()).thenReturn(true); // Default owned
|
||||||
|
|
||||||
|
// Player manager
|
||||||
|
when(plugin.getPlayers()).thenReturn(pm);
|
||||||
|
when(pm.getName(any())).thenReturn("name");
|
||||||
|
|
||||||
// Command
|
// Command
|
||||||
apc = new AdminPurgeCommand(ac);
|
apc = new AdminPurgeCommand(ac);
|
||||||
}
|
}
|
||||||
@ -293,7 +301,7 @@ public class AdminPurgeCommandTest {
|
|||||||
testExecuteUserStringListOfStringIslandsFound();
|
testExecuteUserStringListOfStringIslandsFound();
|
||||||
assertTrue(apc.execute(user, "", Collections.singletonList("confirm")));
|
assertTrue(apc.execute(user, "", Collections.singletonList("confirm")));
|
||||||
verify(im).deleteIsland(eq(island), eq(true), eq(null));
|
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"));
|
verify(user).sendMessage(eq("commands.admin.purge.see-console-for-status"), eq("[label]"), eq("bsb"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user