use of org.spongepowered.api.service.user.UserStorageService in project Skree by Skelril.
the class PactScroll method onBlockInteract.
@Listener
public void onBlockInteract(InteractBlockEvent.Secondary.MainHand event, @Root Player player) {
Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
if (!optItemStack.isPresent()) {
return;
}
ItemStack itemStack = optItemStack.get();
if (itemStack.getItem() != this) {
return;
}
UserStorageService userService = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
List<Text> result = pactMap.getOrDefault(player.getUniqueId(), new ArrayList<>()).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, "Pact Members")).padding(Text.of(" ")).sendTo(player);
event.setUseBlockResult(Tristate.FALSE);
}
use of org.spongepowered.api.service.user.UserStorageService in project RedProtect by FabioZumbi12.
the class RPCommands method buyHandler.
@SuppressWarnings("deprecation")
private void buyHandler(Player player, long value, Region r) {
if (r.isLeader(RPUtil.PlayerToUUID(player.getName()))) {
RPLang.sendMessage(player, "economy.region.buy.own");
return;
}
UniqueAccount acc = RedProtect.get().econ.getOrCreateAccount(player.getUniqueId()).get();
Double money = acc.getBalance(RedProtect.get().econ.getDefaultCurrency()).doubleValue();
if (money >= value) {
String rname = r.getName();
ArrayList<String> sellers = new ArrayList<>(r.getLeaders());
if (RPEconomy.BuyRegion(r, RPUtil.PlayerToUUID(player.getName()))) {
acc.withdraw(RedProtect.get().econ.getDefaultCurrency(), BigDecimal.valueOf(value), RedProtect.get().getPVHelper().getCause(player));
for (String seller : sellers) {
UserStorageService uss = Sponge.getGame().getServiceManager().provide(UserStorageService.class).get();
Optional<User> offp = uss.get(RPUtil.UUIDtoPlayer(seller));
if (!seller.equals(RedProtect.get().cfgs.getString("region-settings.default-leader")) && offp.isPresent()) {
UniqueAccount offAcc = RedProtect.get().econ.getOrCreateAccount(offp.get().getUniqueId()).get();
offAcc.deposit(RedProtect.get().econ.getDefaultCurrency(), BigDecimal.valueOf(value), RedProtect.get().getPVHelper().getCause(player));
if (offp.get().isOnline()) {
RPLang.sendMessage(offp.get().getPlayer().get(), RPLang.get("economy.region.buy.bought").replace("{player}", player.getName()).replace("{region}", rname).replace("{world}", r.getWorld()));
}
}
}
RPLang.sendMessage(player, RPLang.get("economy.region.buy.success").replace("{region}", r.getName()).replace("{value}", String.valueOf(value)).replace("{ecosymbol}", RedProtect.get().cfgs.getEcoString("economy-name")));
} else {
RPLang.sendMessage(player, "economy.region.error");
}
} else {
RPLang.sendMessage(player, "economy.region.buy.nomoney");
}
}
use of org.spongepowered.api.service.user.UserStorageService in project RedProtect by FabioZumbi12.
the class RPUtil method UUIDtoPlayer.
public static String UUIDtoPlayer(String uuid) {
if (uuid == null) {
return null;
}
// check if is UUID
if (isDefaultServer(uuid) || !isUUIDs(uuid)) {
return uuid;
}
String PlayerName = "UnknowPlayer";
UUID uuids = UUID.fromString(uuid);
if (!RedProtect.get().OnlineMode) {
return uuid.toLowerCase();
}
UserStorageService uss = Sponge.getGame().getServiceManager().provide(UserStorageService.class).get();
/*
Optional<GameProfile> ogpName = uss.getAll().stream().filter(f -> f.getUniqueId().equals(uuids)).findFirst();
if (ogpName.isPresent()){
return ogpName.get().getName().get();
}
*/
if (uss.get(uuids).isPresent()) {
return uss.get(uuids).get().getName();
}
return PlayerName;
}
use of org.spongepowered.api.service.user.UserStorageService in project Nucleus by NucleusPowered.
the class NameUtil method getNameFromUUID.
public String getNameFromUUID(UUID uuid) {
if (Util.consoleFakeUUID.equals(uuid)) {
return Sponge.getServer().getConsole().getName();
}
UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
Optional<User> user = uss.get(uuid);
return user.map(User::getName).orElseGet(() -> Nucleus.getNucleus().getMessageProvider().getMessageWithFormat("standard.unknown"));
}
use of org.spongepowered.api.service.user.UserStorageService in project Nucleus by NucleusPowered.
the class BanCommand method executeCommand.
@Override
public CommandResult executeCommand(final CommandSource src, CommandContext args) throws Exception {
final String r = args.<String>getOne(reason).orElse(plugin.getMessageProvider().getMessageWithFormat("ban.defaultreason"));
Optional<GameProfile> ou = Optional.ofNullable(args.<GameProfile>getOne(uuid).orElseGet(() -> args.<GameProfile>getOne(user).orElse(null)));
if (ou.isPresent()) {
Optional<User> optionalUser = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(ou.get());
if ((!optionalUser.isPresent() || !optionalUser.get().isOnline()) && !permissions.testSuffix(src, "offline")) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
}
if (optionalUser.isPresent() && permissions.testSuffix(optionalUser.get(), "exempt.target", src, false)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.exempt", optionalUser.get().getName()));
}
return executeBan(src, ou.get(), r);
}
if (!permissions.testSuffix(src, "offline")) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.offline.noperms"));
}
final String userToFind = args.<String>getOne(name).get();
// Get the profile async.
Sponge.getScheduler().createAsyncExecutor(plugin).execute(() -> {
GameProfileManager gpm = Sponge.getServer().getGameProfileManager();
try {
GameProfile gp = gpm.get(userToFind).get();
// Ban the user sync.
Sponge.getScheduler().createSyncExecutor(plugin).execute(() -> {
// Create the user.
UserStorageService uss = Sponge.getServiceManager().provideUnchecked(UserStorageService.class);
User user = uss.getOrCreate(gp);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("gameprofile.new", user.getName()));
try {
executeBan(src, gp, r);
} catch (Exception e) {
Nucleus.getNucleus().printStackTraceIfDebugMode(e);
}
});
} catch (Exception e) {
Nucleus.getNucleus().printStackTraceIfDebugMode(e);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.ban.profileerror", userToFind));
}
});
return CommandResult.empty();
}
Aggregations