@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)); }
/** * Registers a {@link TimeoutTask} for the given player according to the configuration. * * @param player the player to register a timeout task for */ public void registerTimeoutTask(Player player) { final int timeout = settings.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND; if (timeout > 0) { final LimboPlayer limboPlayer = limboCache.getPlayerData(player.getName()); if (limboPlayer == null) { ConsoleLogger.info("PlayerData for '" + player.getName() + "' is not available"); } else { cancelTask(limboPlayer.getTimeoutTask()); String message = messages.retrieveSingle(MessageKey.LOGIN_TIMEOUT_ERROR); BukkitTask task = bukkitService.runTaskLater(new TimeoutTask(player, message, playerCache), timeout); limboPlayer.setTimeoutTask(task); } } }
/** * Registers a {@link MessageTask} for the given player name. * * @param name the name of the player to schedule a repeating message task for * @param isRegistered whether the name is registered or not (false shows "please register", true * shows "please log in") */ public void registerMessageTask(String name, boolean isRegistered) { final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL); final MessageKey key = getMessageKey(isRegistered); if (interval > 0) { final LimboPlayer limboPlayer = limboCache.getPlayerData(name); if (limboPlayer == null) { ConsoleLogger.info("PlayerData for '" + name + "' is not available"); } else { cancelTask(limboPlayer.getMessageTask()); MessageTask messageTask = new MessageTask(name, messages.retrieve(key), bukkitService, playerCache); bukkitService.runTaskTimer(messageTask, 2 * TICKS_PER_SECOND, interval * TICKS_PER_SECOND); limboPlayer.setMessageTask(messageTask); } } }