Search in sources :

Example 6 with PaginationService

use of org.spongepowered.api.service.pagination.PaginationService 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)

Aggregations

Collectors (java.util.stream.Collectors)6 Sponge (org.spongepowered.api.Sponge)6 PaginationService (org.spongepowered.api.service.pagination.PaginationService)6 Text (org.spongepowered.api.text.Text)6 TextColors (org.spongepowered.api.text.format.TextColors)6 CommandException (org.spongepowered.api.command.CommandException)5 CommandResult (org.spongepowered.api.command.CommandResult)5 CommandSource (org.spongepowered.api.command.CommandSource)5 CommandContext (org.spongepowered.api.command.args.CommandContext)5 CommandExecutor (org.spongepowered.api.command.spec.CommandExecutor)5 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)5 List (java.util.List)4 Player (org.spongepowered.api.entity.living.player.Player)4 Optional (java.util.Optional)3 MarketService (com.skelril.skree.service.MarketService)2 RegionService (com.skelril.skree.service.RegionService)2 Region (com.skelril.skree.service.internal.region.Region)2 BigDecimal (java.math.BigDecimal)2 java.util (java.util)2 Comparator (java.util.Comparator)2