Store the entire player's list of groups instead of primary group
This commit is contained in:
@@ -6,6 +6,8 @@ import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static java.lang.String.format;
|
||||
|
||||
/**
|
||||
@@ -17,29 +19,29 @@ public final class LimboPlayerMatchers {
|
||||
}
|
||||
|
||||
public static Matcher<LimboPlayer> isLimbo(LimboPlayer limbo) {
|
||||
return isLimbo(limbo.isOperator(), limbo.getGroup(), limbo.isCanFly(),
|
||||
return isLimbo(limbo.isOperator(), limbo.getGroups(), limbo.isCanFly(),
|
||||
limbo.getWalkSpeed(), limbo.getFlySpeed());
|
||||
}
|
||||
|
||||
public static Matcher<LimboPlayer> isLimbo(boolean isOp, String group, boolean canFly,
|
||||
public static Matcher<LimboPlayer> isLimbo(boolean isOp, Collection<String> groups, boolean canFly,
|
||||
float walkSpeed, float flySpeed) {
|
||||
return new TypeSafeMatcher<LimboPlayer>() {
|
||||
@Override
|
||||
protected boolean matchesSafely(LimboPlayer item) {
|
||||
return item.isOperator() == isOp && item.getGroup().equals(group) && item.isCanFly() == canFly
|
||||
return item.isOperator() == isOp && item.getGroups().equals(groups) && item.isCanFly() == canFly
|
||||
&& walkSpeed == item.getWalkSpeed() && flySpeed == item.getFlySpeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(format("Limbo with isOp=%s, group=%s, canFly=%s, walkSpeed=%f, flySpeed=%f",
|
||||
isOp, group, canFly, walkSpeed, flySpeed));
|
||||
description.appendText(format("Limbo with isOp=%s, groups={%s}, canFly=%s, walkSpeed=%f, flySpeed=%f",
|
||||
isOp, String.join(" ,", groups), canFly, walkSpeed, flySpeed));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeMismatchSafely(LimboPlayer item, Description description) {
|
||||
description.appendText(format("Limbo with isOp=%s, group=%s, canFly=%s, walkSpeed=%f, flySpeed=%f",
|
||||
item.isOperator(), item.getGroup(), item.isCanFly(), item.getWalkSpeed(), item.getFlySpeed()));
|
||||
description.appendText(format("Limbo with isOp=%s, groups={%s}, canFly=%s, walkSpeed=%f, flySpeed=%f",
|
||||
item.isOperator(), String.join(" ,", item.getGroups()), item.isCanFly(), item.getWalkSpeed(), item.getFlySpeed()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
@@ -98,7 +101,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
public void shouldCancelExistingMessageTask() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, true, "grp", false, 0.1f, 0.0f);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, true, Collections.singletonList("grp"), false, 0.1f, 0.0f);
|
||||
MessageTask existingMessageTask = mock(MessageTask.class);
|
||||
limboPlayer.setMessageTask(existingMessageTask);
|
||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||
@@ -149,7 +152,7 @@ public class LimboPlayerTaskManagerTest {
|
||||
public void shouldCancelExistingTimeoutTask() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, false, "", true, 0.3f, 0.1f);
|
||||
LimboPlayer limboPlayer = new LimboPlayer(null, false, Collections.emptyList(), true, 0.3f, 0.1f);
|
||||
BukkitTask existingTask = mock(BukkitTask.class);
|
||||
limboPlayer.setTimeoutTask(existingTask);
|
||||
given(settings.getProperty(RestrictionSettings.TIMEOUT)).willReturn(18);
|
||||
|
||||
@@ -6,6 +6,8 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -27,9 +29,9 @@ public class LimboServiceHelperTest {
|
||||
public void shouldMergeLimboPlayers() {
|
||||
// given
|
||||
Location newLocation = mock(Location.class);
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, "grp-new", false, 0.0f, 0.0f);
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList("grp-new"), false, 0.0f, 0.0f);
|
||||
Location oldLocation = mock(Location.class);
|
||||
LimboPlayer oldLimbo = new LimboPlayer(oldLocation, true, "grp-old", true, 0.1f, 0.8f);
|
||||
LimboPlayer oldLimbo = new LimboPlayer(oldLocation, true, Collections.singletonList("grp-old"), true, 0.1f, 0.8f);
|
||||
|
||||
// when
|
||||
LimboPlayer result = limboServiceHelper.merge(newLimbo, oldLimbo);
|
||||
@@ -37,7 +39,7 @@ public class LimboServiceHelperTest {
|
||||
// then
|
||||
assertThat(result.getLocation(), equalTo(oldLocation));
|
||||
assertThat(result.isOperator(), equalTo(true));
|
||||
assertThat(result.getGroup(), equalTo("grp-old"));
|
||||
assertThat(result.getGroups(), equalTo(Collections.singletonList("grp-new")));
|
||||
assertThat(result.isCanFly(), equalTo(true));
|
||||
assertThat(result.getWalkSpeed(), equalTo(0.1f));
|
||||
assertThat(result.getFlySpeed(), equalTo(0.8f));
|
||||
@@ -47,8 +49,8 @@ public class LimboServiceHelperTest {
|
||||
public void shouldFallBackToNewLimboForMissingData() {
|
||||
// given
|
||||
Location newLocation = mock(Location.class);
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, "grp-new", true, 0.3f, 0.0f);
|
||||
LimboPlayer oldLimbo = new LimboPlayer(null, false, "", false, 0.1f, 0.1f);
|
||||
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList("grp-new"), true, 0.3f, 0.0f);
|
||||
LimboPlayer oldLimbo = new LimboPlayer(null, false, Collections.emptyList(), false, 0.1f, 0.1f);
|
||||
|
||||
// when
|
||||
LimboPlayer result = limboServiceHelper.merge(newLimbo, oldLimbo);
|
||||
@@ -56,7 +58,7 @@ public class LimboServiceHelperTest {
|
||||
// then
|
||||
assertThat(result.getLocation(), equalTo(newLocation));
|
||||
assertThat(result.isOperator(), equalTo(false));
|
||||
assertThat(result.getGroup(), equalTo("grp-new"));
|
||||
assertThat(result.getGroups(), equalTo(Collections.singletonList("grp-new")));
|
||||
assertThat(result.isCanFly(), equalTo(true));
|
||||
assertThat(result.getWalkSpeed(), equalTo(0.3f));
|
||||
assertThat(result.getFlySpeed(), equalTo(0.1f));
|
||||
|
||||
@@ -19,6 +19,9 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -81,7 +84,7 @@ public class LimboServiceTest {
|
||||
Location playerLoc = mock(Location.class);
|
||||
given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(playerLoc);
|
||||
given(permissionsManager.hasGroupSupport()).willReturn(true);
|
||||
given(permissionsManager.getPrimaryGroup(player)).willReturn("permgrwp");
|
||||
given(permissionsManager.getGroups(player)).willReturn(Collections.singletonList("permgrwp"));
|
||||
|
||||
// when
|
||||
limboService.createLimboPlayer(player, true);
|
||||
@@ -102,7 +105,7 @@ public class LimboServiceTest {
|
||||
assertThat(limbo.isCanFly(), equalTo(false));
|
||||
assertThat(limbo.getFlySpeed(), equalTo(0.2f));
|
||||
assertThat(limbo.getLocation(), equalTo(playerLoc));
|
||||
assertThat(limbo.getGroup(), equalTo("permgrwp"));
|
||||
assertThat(limbo.getGroups(), equalTo(Collections.singletonList("permgrwp")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -132,7 +135,7 @@ public class LimboServiceTest {
|
||||
assertThat(limbo.isCanFly(), equalTo(true));
|
||||
assertThat(limbo.getFlySpeed(), equalTo(0.4f));
|
||||
assertThat(limbo.getLocation(), equalTo(playerLoc));
|
||||
assertThat(limbo.getGroup(), equalTo(""));
|
||||
assertThat(limbo.getGroups(), equalTo(Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +160,7 @@ public class LimboServiceTest {
|
||||
public void shouldRestoreData() {
|
||||
// given
|
||||
LimboPlayer limbo = Mockito.spy(convertToLimboPlayer(
|
||||
newPlayer("John", true, 0.4f, false, 0.0f), null, ""));
|
||||
newPlayer("John", true, 0.4f, false, 0.0f), null, Collections.emptyList()));
|
||||
getLimboMap().put("john", limbo);
|
||||
Player player = newPlayer("John", false, 0.2f, false, 0.7f);
|
||||
|
||||
@@ -236,8 +239,8 @@ public class LimboServiceTest {
|
||||
return player;
|
||||
}
|
||||
|
||||
private static LimboPlayer convertToLimboPlayer(Player player, Location location, String group) {
|
||||
return new LimboPlayer(location, player.isOp(), group, player.getAllowFlight(),
|
||||
private static LimboPlayer convertToLimboPlayer(Player player, Location location, Collection<String> groups) {
|
||||
return new LimboPlayer(location, player.isOp(), groups, player.getAllowFlight(),
|
||||
player.getWalkSpeed(), player.getFlySpeed());
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -23,6 +23,7 @@ import org.mockito.Mock;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation;
|
||||
@@ -45,22 +46,22 @@ public class DistributedFilesPersistenceHandlerTest {
|
||||
/** Player is in seg32-10110 and should be migrated into seg16-f. */
|
||||
private static final UUID MIGRATED_UUID = fromString("f6a97c88-7c8f-c12e-4931-6206d4ca067d");
|
||||
private static final Matcher<LimboPlayer> MIGRATED_LIMBO_MATCHER =
|
||||
isLimbo(false, "noob", true, 0.2f, 0.1f);
|
||||
isLimbo(false, Collections.singletonList("noob"), true, 0.2f, 0.1f);
|
||||
|
||||
/** Existing player in seg16-f. */
|
||||
private static final UUID UUID_FAB69 = fromString("fab69c88-2cd0-1fed-f00d-dead14ca067d");
|
||||
private static final Matcher<LimboPlayer> FAB69_MATCHER =
|
||||
isLimbo(false, "", false, 0.2f, 0.1f);
|
||||
isLimbo(false, Collections.emptyList(), false, 0.2f, 0.1f);
|
||||
|
||||
/** Player in seg16-8. */
|
||||
private static final UUID UUID_STAFF = fromString("88897c88-7c8f-c12e-4931-6206d4ca067d");
|
||||
private static final Matcher<LimboPlayer> STAFF_MATCHER =
|
||||
isLimbo(true, "staff", false, 0.3f, 0.1f);
|
||||
isLimbo(true, Collections.singletonList("staff"), false, 0.3f, 0.1f);
|
||||
|
||||
/** Player in seg16-8. */
|
||||
private static final UUID UUID_8C679 = fromString("8c679491-1234-abcd-9102-1fa6e0cc3f81");
|
||||
private static final Matcher<LimboPlayer> SC679_MATCHER =
|
||||
isLimbo(false, "primary", true, 0.1f, 0.0f);
|
||||
isLimbo(false, Collections.singletonList("primary"), true, 0.1f, 0.0f);
|
||||
|
||||
/** UUID for which no data is stored (belongs to a segment file that does not exist, seg16-4). */
|
||||
private static final UUID UNKNOWN_UUID = fromString("42d1cc0b-8f12-d04a-e7ba-a067d05cdc39");
|
||||
@@ -153,10 +154,10 @@ public class DistributedFilesPersistenceHandlerTest {
|
||||
// given
|
||||
Player uuidToAdd1 = mockPlayerWithUuid(UNKNOWN_UUID);
|
||||
Location location1 = new Location(mockWorldWithName("1world"), 120, 60, -80, 0.42345f, 120.32f);
|
||||
LimboPlayer limbo1 = new LimboPlayer(location1, false, "group-1", true, 0.1f, 0.2f);
|
||||
LimboPlayer limbo1 = new LimboPlayer(location1, false, Collections.singletonList("group-1"), true, 0.1f, 0.2f);
|
||||
Player uuidToAdd2 = mockPlayerWithUuid(UNKNOWN_UUID2);
|
||||
Location location2 = new Location(mockWorldWithName("2world"), -40, 20, 33, 4.235f, 8.32299f);
|
||||
LimboPlayer limbo2 = new LimboPlayer(location2, true, "", false, 0.0f, 0.25f);
|
||||
LimboPlayer limbo2 = new LimboPlayer(location2, true, Collections.emptyList(), false, 0.0f, 0.25f);
|
||||
|
||||
// when
|
||||
persistenceHandler.saveLimboPlayer(uuidToAdd1, limbo1);
|
||||
|
||||
+3
-3
@@ -20,6 +20,7 @@ import org.mockito.Mock;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -78,7 +79,7 @@ public class IndividualFilesPersistenceHandlerTest {
|
||||
assertThat(data.isCanFly(), equalTo(true));
|
||||
assertThat(data.getWalkSpeed(), equalTo(0.2f));
|
||||
assertThat(data.getFlySpeed(), equalTo(0.1f));
|
||||
assertThat(data.getGroup(), equalTo("players"));
|
||||
assertThat(data.getGroups(), equalTo(Collections.singletonList("players")));
|
||||
Location location = data.getLocation();
|
||||
assertThat(location.getX(), equalTo(-113.219));
|
||||
assertThat(location.getY(), equalTo(72.0));
|
||||
@@ -112,8 +113,7 @@ public class IndividualFilesPersistenceHandlerTest {
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("player-world");
|
||||
Location location = new Location(world, 0.2, 102.25, -89.28, 3.02f, 90.13f);
|
||||
String group = "primary-grp";
|
||||
LimboPlayer limbo = new LimboPlayer(location, true, group, true, 1.2f, 0.8f);
|
||||
LimboPlayer limbo = new LimboPlayer(location, true, Collections.singletonList("primary-grp"), true, 1.2f, 0.8f);
|
||||
|
||||
// when
|
||||
handler.saveLimboPlayer(player, limbo);
|
||||
|
||||
Reference in New Issue
Block a user