Search in sources :

Example 51 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class MarketUntrackItemComand 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!"));
        return CommandResult.empty();
    }
    Optional<MarketService> optService = Sponge.getServiceManager().provide(MarketService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The market service is not currently running."));
        return CommandResult.empty();
    }
    MarketService service = optService.get();
    Optional<ItemStack> held = ((Player) src).getItemInHand(HandTypes.MAIN_HAND);
    if (!held.isPresent()) {
        src.sendMessage(Text.of(TextColors.RED, "You are not holding an item."));
        return CommandResult.empty();
    }
    ItemStack item = held.get();
    if (service.remItem(item)) {
        src.sendMessage(Text.of(TextColors.YELLOW, "Your held item is no longer being tracked."));
    } else {
        src.sendMessage(Text.of(TextColors.RED, "Your held item is not tracked."));
        return CommandResult.empty();
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) MarketService(com.skelril.skree.service.MarketService)

Example 52 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class HymnOfSummation method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (optHeldItem.isPresent()) {
        return;
    }
    ItemStack held = optHeldItem.get();
    if (held.getItem() != this) {
        return;
    }
    net.minecraft.item.ItemStack[] pInv = tf(player).inventory.mainInventory;
    Optional<ItemStack[]> optCompacted = new ItemCompactor(ImmutableList.of(CoalValueMap.inst(), IronValueMap.inst(), GoldValueMap.inst(), RedstoneValueMap.inst(), LapisValueMap.inst(), DiamondValueMap.inst(), EmeraldValueMap.inst(), CofferValueMap.inst())).execute((ItemStack[]) (Object[]) pInv);
    if (optCompacted.isPresent()) {
        Task.builder().execute(() -> {
            ItemStack[] nInv = optCompacted.get();
            for (int i = 0; i < pInv.length; ++i) {
                pInv[i] = tf(nInv[i]);
            }
            tf(player).inventoryContainer.detectAndSendChanges();
            player.sendMessage(Text.of(TextColors.GOLD, "The hymn glows brightly..."));
        }).delayTicks(1).submit(SkreePlugin.inst());
        event.setUseBlockResult(Tristate.FALSE);
    }
}
Also used : ItemCompactor(com.skelril.nitro.item.ItemCompactor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 53 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class PactScroll method onEntityInteract.

@Listener
public void onEntityInteract(InteractEntityEvent.Primary event, @Root Player player) {
    Entity targetEntity = event.getTargetEntity();
    if (!(targetEntity instanceof Player)) {
        return;
    }
    Player targetPlayer = (Player) targetEntity;
    Optional<ItemStack> optItemStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optItemStack.isPresent()) {
        return;
    }
    ItemStack itemStack = optItemStack.get();
    if (itemStack.getItem() != this) {
        return;
    }
    pactMap.putIfAbsent(player.getUniqueId(), new ArrayList<>());
    List<UUID> pacts = pactMap.get(player.getUniqueId());
    if (pacts.contains(targetPlayer.getUniqueId())) {
        pacts.remove(targetPlayer.getUniqueId());
        player.sendMessage(Text.of(TextColors.YELLOW, "Your pact with ", targetPlayer.getName(), " has been broken!"));
    } else {
        pacts.add(targetPlayer.getUniqueId());
        player.sendMessage(Text.of(TextColors.YELLOW, "You've formed a pact with ", targetPlayer.getName(), "."));
        player.sendMessage(Text.of(TextColors.YELLOW, "You will no longer be able to damage ", targetPlayer.getName(), ", unless attacked first."));
        player.sendMessage(Text.of(TextColors.YELLOW, "You must carry a pact scroll for the pact to remain in effect."));
        player.sendMessage(Text.of(TextColors.YELLOW, "All pacts will automatically be reset upon disconnect."));
    }
    event.setCancelled(true);
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 54 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack 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 55 with ItemStack

use of org.spongepowered.api.item.inventory.ItemStack in project Skree by Skelril.

the class MagicWand method onRightClick.

@Listener
public void onRightClick(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    boolean survival = player.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) == GameModes.SURVIVAL;
    Optional<ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optHeldItem.isPresent()) {
        return;
    }
    if (optHeldItem.get().getItem() != this) {
        return;
    }
    event.setUseBlockResult(Tristate.FALSE);
    Optional<Location<World>> optLoc = event.getTargetBlock().getLocation();
    if (!optLoc.isPresent()) {
        return;
    }
    Location<World> loc = optLoc.get();
    BlockType targetType = loc.getBlockType();
    if (targetType == CustomBlockTypes.MAGIC_LADDER) {
        MagicBlockStateHelper.startLadder(loc);
    } else if (targetType == CustomBlockTypes.MAGIC_PLATFORM) {
        MagicBlockStateHelper.startPlatform(loc);
    } else {
        return;
    }
    if (!survival) {
        MagicBlockStateHelper.resetCounts();
        return;
    }
    MagicBlockStateHelper.dropItems(loc, event.getCause());
}
Also used : BlockType(org.spongepowered.api.block.BlockType) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Aggregations

ItemStack (org.spongepowered.api.item.inventory.ItemStack)76 Player (org.spongepowered.api.entity.living.player.Player)30 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)29 Listener (org.spongepowered.api.event.Listener)17 ArrayList (java.util.ArrayList)12 Text (org.spongepowered.api.text.Text)10 ItemDropper (com.skelril.nitro.item.ItemDropper)9 MarketService (com.skelril.skree.service.MarketService)9 World (org.spongepowered.api.world.World)9 VirtualCrate (pw.codehusky.huskycrates.crate.VirtualCrate)9 BigDecimal (java.math.BigDecimal)8 Entity (org.spongepowered.api.entity.Entity)8 Vector3d (com.flowpowered.math.vector.Vector3d)5 Clause (com.skelril.nitro.Clause)5 InventoryTransactionResult (org.spongepowered.api.item.inventory.transaction.InventoryTransactionResult)5 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)4 Inventory (org.spongepowered.api.item.inventory.Inventory)4 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 EntityDamageSource (org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource)3