/** * Gets a copy of the {@link StatisticData} for this user. * * @return A copy of the statistic data */ default StatisticData getStatisticData() { return get(StatisticData.class).get(); }
@Override public UUID getUUID() { return user.getUniqueId(); }
public CachedPlayer(User user) { super(null); this.uuid = UUID.fromString(user.getUniqueId().toString()); this.name = user.getName(); this.isOnline = false; } public CachedPlayer(Player player) {
@Override public String getName() { return user.getName(); } }
@Override public boolean isOnline() { return user.isOnline(); }
private boolean isAllowed(User player) { if (settings.getGeneral().isBypassed(player)) { return true; } if (settings.getGeneral().isCommandOnlyProtection()) { //check if the user is already registered return plugin.getDatabase().getAccount(player).isPresent() || !player.hasPermission(PomData.ARTIFACT_ID + ".registerRequired"); } return plugin.getDatabase().isLoggedIn(player); } }
public Optional<Account> getAccount(User player) { return Optional.ofNullable(cache.get(player.getUniqueId())); }
@Override public Optional<Account> loadAccount(User player) { Optional<Account> optAcc = loadAccount(player.getName()); optAcc.ifPresent(account -> cache.put(player.getUniqueId(), account)); return optAcc; }
private MimeMessage buildMessage(User player, String email, String newPassword, MailConfig emailConfig, Session session) throws MessagingException, UnsupportedEncodingException { String serverName = Sponge.getServer().getBoundAddress() .map(sa -> sa.getAddress().getHostAddress()) .orElse("Minecraft Server"); ImmutableMap<String, String> variables = ImmutableMap.of("player", player.getName(), "server", serverName, "password", newPassword); MimeMessage message = new MimeMessage(session); String senderEmail = emailConfig.getAccount(); //sender email with an alias message.setFrom(new InternetAddress(senderEmail, emailConfig.getSenderName())); message.setRecipient(RecipientType.TO, new InternetAddress(email, player.getName())); message.setSubject(emailConfig.getSubject(serverName, player.getName()).toPlain()); //current time message.setSentDate(Calendar.getInstance().getTime()); String textContent = emailConfig.getText(serverName, player.getName(), newPassword).toPlain(); //html part BodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent(textContent, "text/html; charset=UTF-8"); //plain text BodyPart textPart = new MimeBodyPart(); textPart.setContent(textContent.replaceAll("(?s)<[^>]*>(\\s*<[^>]*>)*", " "), "text/plain; charset=UTF-8"); Multipart alternative = new MimeMultipart("alternative"); alternative.addBodyPart(htmlPart); alternative.addBodyPart(textPart); message.setContent(alternative); return message; }
public Optional<Account> remove(User player) { return Optional.ofNullable(cache.remove(player.getUniqueId())); }
@Override public CommandResult execute(CommandSource src, CommandContext args) throws CommandException { Optional<InetAddress> optIP = args.getOne("ip"); if (optIP.isPresent()) { Task.builder() //we are executing a SQL Query which is blocking .async() .execute(() -> { Set<Account> accounts = plugin.getDatabase().getAccountsByIp(optIP.get()); sendAccountNames(src, optIP.get().getHostAddress(), accounts); }) .submit(plugin); } Optional<User> optUser = args.getOne("user"); if (optUser.isPresent()) { Task.builder() //we are executing a SQL Query which is blocking .async() .execute(() -> queryAccountsByName(src, optUser.get().getName())) .submit(plugin); } return CommandResult.success(); }
/** * Gets a copy of the {@link AchievementData} for this user. * * @return A copy of the achievement data */ default AchievementData getAchievementData() { return get(AchievementData.class).get(); }
public Optional<Account> loadAccount(User player) { Optional<Account> optAcc = loadAccount(player.getUniqueId()); optAcc.ifPresent(account -> cache.put(player.getUniqueId(), account)); return optAcc; }
@Test public void testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseOnlyAnExactMatchIsReturned() throws ArgumentParseException { Set<?> list = getParser().parseValue(mockSource(), "test", ex); Assert.assertEquals(1, list.size()); Assert.assertEquals("test", ((User) list.iterator().next()).getName()); }
/** * Gets a copy of the {@link StatisticData} for this user. * * @return A copy of the statistic data */ default StatisticData getStatisticData() { return get(StatisticData.class).get(); } }
/** * Gets the user metadata for a player with the specified {@link User}. * @param user The {@link User}. * @return The {@link Result} if the user exists. */ default Optional<Result> getUserData(User user) { return getUserData(user.getUniqueId()); }
@Test public void testWhenTwoPlayersWithTheSameNameAreInTheUserDatabaseWithNoExactMatchReturnsOneReturnsIfOnlyOneMatches() throws ArgumentParseException { Set<?> list = getParser().parseValue(mockSource(), "testt", ex); Assert.assertEquals(1, list.size()); Assert.assertEquals("testtest", ((User) list.iterator().next()).getName()); }
/** * Gets the number of homes the player currently has. * * @param user The {@link User} * @return The number of homes. */ default int getHomeCount(User user) { return getHomeCount(user.getUniqueId()); }
/** * Gets the {@link Home}s for the specified user, identified by their UUID. * * @param user The {@link UUID} * @return The homes. */ default List<Home> getHomes(User user) { return getHomes(user.getUniqueId()); }