use of org.spongepowered.api.service.user.UserStorageService in project RedProtect by FabioZumbi12.
the class RPUtil method PlayerToUUID.
public static String PlayerToUUID(String PlayerName) {
if (PlayerName == null || PlayerName.equals("")) {
return null;
}
// check if is already UUID
if (isUUIDs(PlayerName) || isDefaultServer(PlayerName) || (PlayerName.startsWith("[") && PlayerName.endsWith("]"))) {
return PlayerName;
}
String uuid = PlayerName;
if (!RedProtect.get().OnlineMode) {
uuid = uuid.toLowerCase();
return uuid;
}
UserStorageService uss = Sponge.getGame().getServiceManager().provide(UserStorageService.class).get();
Optional<GameProfile> ogpName = uss.getAll().stream().filter(f -> f.getName().isPresent() && f.getName().get().equalsIgnoreCase(PlayerName)).findFirst();
if (ogpName.isPresent()) {
return ogpName.get().getUniqueId().toString();
} else {
Optional<Player> p = RedProtect.get().serv.getPlayer(PlayerName);
if (p.isPresent()) {
return p.get().getUniqueId().toString();
}
}
return uuid;
}
use of org.spongepowered.api.service.user.UserStorageService in project core by CubeEngine.
the class UserMatcher method match.
public Optional<User> match(String name, boolean searchOffline) {
Game game = Sponge.getGame();
if (name == null) {
return null;
}
// Direct Match Online Players:
Optional<Player> player = game.getServer().getPlayer(name);
if (player.isPresent()) {
return Optional.of(player.get());
}
// Find Online Players with similar name
Map<String, Player> onlinePlayerMap = new HashMap<>();
for (Player onlineUser : game.getServer().getOnlinePlayers()) {
onlinePlayerMap.put(onlineUser.getName(), onlineUser);
}
String foundUser = sm.matchString(name, onlinePlayerMap.keySet());
if (foundUser != null) {
return Optional.of(onlinePlayerMap.get(foundUser));
}
UserStorageService storage = game.getServiceManager().provideUnchecked(UserStorageService.class);
Optional<User> directMatchOffline;
try {
directMatchOffline = storage.get(name);
} catch (IllegalArgumentException ignore) {
return Optional.empty();
}
if (directMatchOffline.isPresent()) {
return directMatchOffline;
}
if (searchOffline) {
String match = sm.matchString(name, storage.getAll().stream().map(GameProfile::getName).filter(Optional::isPresent).map(Optional::get).collect(toList()));
if (match != null) {
return storage.get(match);
}
}
return Optional.empty();
}
use of org.spongepowered.api.service.user.UserStorageService in project modules-extra by CubeEngine.
the class Vote method onVote.
@Listener
public void onVote(VotifierEvent event) throws ExecutionException, InterruptedException {
final com.vexsoftware.votifier.model.Vote vote = event.getVote();
UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
Optional<User> user = uss.get(vote.getUsername());
if (!user.isPresent()) {
if (vote.getUsername() == null || vote.getUsername().trim().isEmpty()) {
logger.info("{} voted but is not known to the server!", vote.getUsername());
}
return;
}
final DSLContext dsl = db.getDSL();
db.queryOne(dsl.selectFrom(TABLE_VOTE).where(TABLE_VOTE.ID.eq(user.get().getUniqueId()))).thenAcceptAsync((voteModel) -> {
if (voteModel != null) {
if (voteModel.timePassed(config.voteBonusTime.toMillis())) {
voteModel.setVotes(1);
} else {
voteModel.addVote();
}
voteModel.update();
} else {
voteModel = dsl.newRecord(TABLE_VOTE).newVote(user.get());
voteModel.insert();
}
UniqueAccount acc = economy.getOrCreateAccount(user.get().getUniqueId()).get();
final int voteAmount = voteModel.getVotes();
double money = this.config.voteReward * pow(1 + 1.5 / voteAmount, voteAmount - 1);
acc.deposit(economy.getDefaultCurrency(), new BigDecimal(money), Cause.of(EventContext.empty(), event.getVote()));
Text moneyFormat = economy.getDefaultCurrency().format(new BigDecimal(money));
bc.broadcastMessage(NONE, ChatFormat.parseFormats(this.config.voteBroadcast).replace("{PLAYER}", vote.getUsername()).replace("{MONEY}", moneyFormat.toPlain()).replace("{AMOUNT}", String.valueOf(voteAmount)).replace("{VOTEURL}", this.config.voteUrl));
user.get().getPlayer().ifPresent(p -> p.sendMessage(Text.of(ChatFormat.parseFormats(this.config.voteMessage.replace("{PLAYER}", vote.getUsername()).replace("{MONEY}", moneyFormat.toPlain()).replace("{AMOUNT}", String.valueOf(voteAmount)).replace("{VOTEURL}", this.config.voteUrl)))));
});
}
use of org.spongepowered.api.service.user.UserStorageService in project Nucleus by NucleusPowered.
the class MailFilterArgument method player.
private Optional<UUID> player(String text) {
if (text.equalsIgnoreCase("server") || (text.equalsIgnoreCase("console"))) {
return Optional.of(Util.consoleFakeUUID);
}
UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
Optional<User> ou = uss.get(text);
return ou.map(Identifiable::getUniqueId);
}
use of org.spongepowered.api.service.user.UserStorageService in project Skree by Skelril.
the class RegionListMembersCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command (for now ;) )!"));
return CommandResult.empty();
}
Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
if (!optService.isPresent()) {
src.sendMessage(Text.of(TextColors.DARK_RED, "The region service is not currently running."));
return CommandResult.empty();
}
RegionService service = optService.get();
Player player = (Player) src;
Optional<Region> optRef = service.getSelectedRegion(player);
if (!optRef.isPresent()) {
player.sendMessage(Text.of(TextColors.RED, "You do not currently have a region selected."));
return CommandResult.empty();
}
Region ref = optRef.get();
UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Text> result = ref.getMembers().stream().map(userService::get).filter(Optional::isPresent).map(Optional::get).sorted((a, b) -> a.getName().compareToIgnoreCase(b.getName())).map(a -> Text.of((a.isOnline() ? TextColors.GREEN : TextColors.RED), a.getName())).collect(Collectors.toList());
pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Region Members")).padding(Text.of(" ")).sendTo(src);
return CommandResult.success();
}
Aggregations