Search in sources :

Example 6 with UserStorageService

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);
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) java.util(java.util) GameRegistry(net.minecraftforge.fml.common.registry.GameRegistry) UserStorageService(org.spongepowered.api.service.user.UserStorageService) Craftable(com.skelril.nitro.registry.Craftable) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Text(org.spongepowered.api.text.Text) Order(org.spongepowered.api.event.Order) DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) CollideEntityEvent(org.spongepowered.api.event.entity.CollideEntityEvent) CreativeTabs(net.minecraft.creativetab.CreativeTabs) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) TextColors(org.spongepowered.api.text.format.TextColors) InteractEntityEvent(org.spongepowered.api.event.entity.InteractEntityEvent) Items(net.minecraft.init.Items) CustomItem(com.skelril.nitro.registry.item.CustomItem) Sponge(org.spongepowered.api.Sponge) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) EventAwareContent(com.skelril.nitro.selector.EventAwareContent) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Tristate(org.spongepowered.api.util.Tristate) Root(org.spongepowered.api.event.filter.cause.Root) Cancellable(org.spongepowered.api.event.Cancellable) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) HandTypes(org.spongepowered.api.data.type.HandTypes) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener) ItemType(org.spongepowered.api.item.ItemType) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 7 with UserStorageService

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");
    }
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) User(org.spongepowered.api.entity.living.player.User) UniqueAccount(org.spongepowered.api.service.economy.account.UniqueAccount) ArrayList(java.util.ArrayList)

Example 8 with UserStorageService

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;
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) UUID(java.util.UUID)

Example 9 with UserStorageService

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"));
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) User(org.spongepowered.api.entity.living.player.User)

Example 10 with UserStorageService

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();
}
Also used : UserStorageService(org.spongepowered.api.service.user.UserStorageService) User(org.spongepowered.api.entity.living.player.User) GameProfile(org.spongepowered.api.profile.GameProfile) GameProfileManager(org.spongepowered.api.profile.GameProfileManager) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)

Aggregations

UserStorageService (org.spongepowered.api.service.user.UserStorageService)13 User (org.spongepowered.api.entity.living.player.User)10 Text (org.spongepowered.api.text.Text)5 Optional (java.util.Optional)4 Player (org.spongepowered.api.entity.living.player.Player)4 GameProfile (org.spongepowered.api.profile.GameProfile)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Sponge (org.spongepowered.api.Sponge)3 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 CommandResult (org.spongepowered.api.command.CommandResult)2 CommandSource (org.spongepowered.api.command.CommandSource)2 CommandContext (org.spongepowered.api.command.args.CommandContext)2 PaginationService (org.spongepowered.api.service.pagination.PaginationService)2 TextColors (org.spongepowered.api.text.format.TextColors)2 RPLang (br.net.fabiozumbi12.RedProtect.Sponge.config.RPLang)1 WEListener (br.net.fabiozumbi12.RedProtect.Sponge.hooks.WEListener)1