Fixes VisitorKeepInventory to disregard coops and trusted

#2126
Also fixes some tests.
This commit is contained in:
tastybento 2023-05-13 09:20:47 -07:00
parent f05d4dc57f
commit 8f954090e7
3 changed files with 16 additions and 2 deletions

View File

@ -11,11 +11,13 @@ import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.lists.Flags;
import world.bentobox.bentobox.managers.RanksManager;
import world.bentobox.bentobox.util.Util;
/**
* Prevents visitors from losing their items if they
* die on an island in which they are a visitor.
* Coops and above are not considered visitors.
* Handles {@link world.bentobox.bentobox.lists.Flags#VISITOR_KEEP_INVENTORY}.
* @author jstnf
* @since 1.17.0
@ -32,7 +34,7 @@ public class VisitorKeepInventoryListener extends FlagListener {
}
Optional<Island> island = getIslands().getProtectedIslandAt(e.getEntity().getLocation());
if (island.isPresent() && !island.get().getMemberSet().contains(e.getEntity().getUniqueId())) {
if (island.isPresent() && !island.get().getMemberSet(RanksManager.COOP_RANK).contains(e.getEntity().getUniqueId())) {
e.setKeepInventory(true);
e.setKeepLevel(true);
e.getDrops().clear();

View File

@ -171,6 +171,17 @@ public class PanelListenerManagerTest {
return name;
}
@Override
public String getOriginalTitle() {
// TODO Auto-generated method stub
return "";
}
@Override
public void setTitle(String title) {
// TODO Auto-generated method stub
}
}
@After

View File

@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
@ -122,7 +123,7 @@ public class VisitorKeepInventoryListenerTest {
/* Islands */
when(plugin.getIslands()).thenReturn(islandsManager);
// Visitor
when(island.getMemberSet()).thenReturn(ImmutableSet.of());
when(island.getMemberSet(anyInt())).thenReturn(ImmutableSet.of());
// By default, there should be an island.
when(islandsManager.getProtectedIslandAt(any())).thenReturn(Optional.of(island));