Search in sources :

Example 16 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class LimboPlayerDeserializer method deserialize.

@Override
public LimboPlayer deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) {
    JsonObject jsonObject = jsonElement.getAsJsonObject();
    if (jsonObject == null) {
        return null;
    }
    Location loc = deserializeLocation(jsonObject);
    boolean operator = getBoolean(jsonObject, IS_OP);
    String group = getString(jsonObject, GROUP);
    boolean canFly = getBoolean(jsonObject, CAN_FLY);
    float walkSpeed = getFloat(jsonObject, WALK_SPEED, LimboPlayer.DEFAULT_WALK_SPEED);
    float flySpeed = getFloat(jsonObject, FLY_SPEED, LimboPlayer.DEFAULT_FLY_SPEED);
    return new LimboPlayer(loc, operator, group, canFly, walkSpeed, flySpeed);
}
Also used : JsonObject(com.google.gson.JsonObject) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location)

Example 17 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class EmailRegisterExecutorProviderTest method shouldCreatePlayerAuth.

@Test
public void shouldCreatePlayerAuth() {
    // given
    given(commonService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(12);
    given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
    Player player = mock(Player.class);
    TestHelper.mockPlayerIp(player, "123.45.67.89");
    given(player.getName()).willReturn("Veronica");
    World world = mock(World.class);
    given(world.getName()).willReturn("someWorld");
    given(player.getLocation()).willReturn(new Location(world, 48, 96, 144));
    EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com");
    // when
    PlayerAuth auth = executor.buildPlayerAuth(params);
    // then
    assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
    assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
    assertThat(auth.getPassword().getHash(), stringWithLength(12));
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) AuthMeMatchers.hasAuthLocation(fr.xephi.authme.AuthMeMatchers.hasAuthLocation) Location(org.bukkit.Location) Test(org.junit.Test)

Example 18 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class PasswordRegisterExecutorTest method shouldCreatePlayerAuth.

@Test
public void shouldCreatePlayerAuth() {
    // given
    given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
    Player player = mockPlayerWithName("S1m0N");
    TestHelper.mockPlayerIp(player, "123.45.67.89");
    World world = mock(World.class);
    given(world.getName()).willReturn("someWorld");
    given(player.getLocation()).willReturn(new Location(world, 48, 96, 144, 1.1f, 0.28f));
    PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
    // when
    PlayerAuth auth = executor.buildPlayerAuth(params);
    // then
    assertThat(auth, hasAuthBasicData("s1m0n", "S1m0N", "mail@example.org", "123.45.67.89"));
    assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 1.1f, 0.28f));
    assertThat(auth.getPassword(), equalToHash("pass"));
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) AuthMeMatchers.hasAuthLocation(fr.xephi.authme.AuthMeMatchers.hasAuthLocation) Location(org.bukkit.Location) Test(org.junit.Test)

Example 19 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class PlayerAuthBuilderHelperTest method shouldConstructPlayerAuth.

@Test
public void shouldConstructPlayerAuth() {
    // given
    Player player = mock(Player.class);
    given(player.getName()).willReturn("Noah");
    String ip = "192.168.34.47";
    TestHelper.mockPlayerIp(player, ip);
    World world = mock(World.class);
    given(world.getName()).willReturn("worldName");
    Location location = new Location(world, 123, 80, -99, 2.45f, 7.61f);
    given(player.getLocation()).willReturn(location);
    HashedPassword hashedPassword = new HashedPassword("myHash0001");
    String email = "test@example.org";
    // when
    PlayerAuth auth = PlayerAuthBuilderHelper.createPlayerAuth(player, hashedPassword, email);
    // then
    assertThat(auth, hasAuthBasicData("noah", "Noah", email, ip));
    assertThat(auth, hasAuthLocation(123, 80, -99, "worldName", 2.45f, 7.61f));
}
Also used : Player(org.bukkit.entity.Player) World(org.bukkit.World) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword) Location(org.bukkit.Location) AuthMeMatchers.hasAuthLocation(fr.xephi.authme.AuthMeMatchers.hasAuthLocation) Test(org.junit.Test)

Example 20 with Location

use of org.bukkit.Location in project AuthMeReloaded by AuthMe.

the class DistributedFilesPersistenceHandlerTest method shouldAddPlayer.

@Test
public void shouldAddPlayer() {
    // 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);
    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);
    // when
    persistenceHandler.saveLimboPlayer(uuidToAdd1, limbo1);
    persistenceHandler.saveLimboPlayer(uuidToAdd2, limbo2);
    // then
    LimboPlayer addedPlayer1 = persistenceHandler.getLimboPlayer(uuidToAdd1);
    assertThat(addedPlayer1, isLimbo(limbo1));
    assertThat(addedPlayer1, hasLocation(location1));
    LimboPlayer addedPlayer2 = persistenceHandler.getLimboPlayer(uuidToAdd2);
    assertThat(addedPlayer2, isLimbo(limbo2));
    assertThat(addedPlayer2, hasLocation(location2));
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(MIGRATED_UUID)), MIGRATED_LIMBO_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_FAB69)), FAB69_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_STAFF)), STAFF_MATCHER);
    assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_8C679)), SC679_MATCHER);
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Location(org.bukkit.Location) LimboPlayerMatchers.hasLocation(fr.xephi.authme.data.limbo.LimboPlayerMatchers.hasLocation) Test(org.junit.Test)

Aggregations

Location (org.bukkit.Location)351 Player (org.bukkit.entity.Player)90 World (org.bukkit.World)56 EventHandler (org.bukkit.event.EventHandler)43 Test (org.junit.Test)43 Vector (org.bukkit.util.Vector)38 ArrayList (java.util.ArrayList)29 Block (org.bukkit.block.Block)18 Entity (org.bukkit.entity.Entity)17 User (com.earth2me.essentials.User)16 ItemStack (org.bukkit.inventory.ItemStack)15 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)14 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)14 List (java.util.List)12 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)11 BlockState (org.bukkit.block.BlockState)11 UUID (java.util.UUID)10 LivingEntity (org.bukkit.entity.LivingEntity)10 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)9