@Test
  public void shouldReadDataFromFile() {
    // given
    Player player = mock(Player.class);
    given(player.getUniqueId()).willReturn(SAMPLE_UUID);
    World world = mock(World.class);
    given(bukkitService.getWorld("nether")).willReturn(world);

    // when
    LimboPlayer data = limboPlayerStorage.readData(player);

    // then
    assertThat(data, not(nullValue()));
    assertThat(data.isOperator(), equalTo(true));
    assertThat(data.isCanFly(), equalTo(true));
    assertThat(data.getWalkSpeed(), equalTo(0.2f));
    assertThat(data.getFlySpeed(), equalTo(0.1f));
    assertThat(data.getGroup(), equalTo("players"));
    Location location = data.getLocation();
    assertThat(location.getX(), equalTo(-113.219));
    assertThat(location.getY(), equalTo(72.0));
    assertThat(location.getZ(), equalTo(130.637));
    assertThat(location.getWorld(), equalTo(world));
    assertThat(location.getPitch(), equalTo(24.15f));
    assertThat(location.getYaw(), equalTo(-292.484f));
  }
Ejemplo n.º 2
0
  /**
   * Set the group of a player, by its AuthMe group type.
   *
   * @param player The player.
   * @param group The group type.
   * @return True if succeeded, false otherwise. False is also returned if groups aren't supported
   *     with the current permissions system.
   */
  public boolean setGroup(Player player, AuthGroupType group) {
    // Check whether the permissions check is enabled
    if (!settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)) {
      return false;
    }

    // Make sure group support is available
    if (!permissionsManager.hasGroupSupport()) {
      ConsoleLogger.warning(
          "The current permissions system doesn't have group support, unable to set group!");
      return false;
    }

    switch (group) {
      case UNREGISTERED:
        // Remove the other group type groups, set the current group
        permissionsManager.removeGroups(player, Arrays.asList(registeredGroup, unloggedInGroup));
        return permissionsManager.addGroup(player, unregisteredGroup);

      case REGISTERED:
        // Remove the other group type groups, set the current group
        permissionsManager.removeGroups(player, Arrays.asList(unregisteredGroup, unloggedInGroup));
        return permissionsManager.addGroup(player, registeredGroup);

      case NOT_LOGGED_IN:
        // Remove the other group type groups, set the current group
        permissionsManager.removeGroups(player, Arrays.asList(unregisteredGroup, registeredGroup));
        return permissionsManager.addGroup(player, unloggedInGroup);

      case LOGGED_IN:
        // Get the player data
        LimboPlayer data = limboCache.getPlayerData(player.getName().toLowerCase());
        if (data == null) {
          return false;
        }

        // Get the players group
        String realGroup = data.getGroup();

        // Remove the other group types groups, set the real group
        permissionsManager.removeGroups(
            player, Arrays.asList(unregisteredGroup, registeredGroup, unloggedInGroup));
        return permissionsManager.addGroup(player, realGroup);
      default:
        return false;
    }
  }