Search in sources :

Example 46 with ItemStack

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

the class GoldRushInstance method checkFloodType.

private void checkFloodType() {
    if (foundPhantomHymn) {
        return;
    }
    for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
        net.minecraft.item.ItemStack[] itemStacks = tf(player).inventory.mainInventory;
        for (net.minecraft.item.ItemStack is : itemStacks) {
            if (is == null || is.getItem() != CustomItemTypes.PRIZE_BOX) {
                continue;
            }
            Optional<ItemStack> optContained = PrizeBox.getPrizeStack(is);
            if (optContained.isPresent() && optContained.get().getItem() == CustomItemTypes.PHANTOM_HYMN) {
                // Force away all water
                drainAll();
                floodBlockType = BlockTypes.FLOWING_LAVA;
                multiplier = multiplier.multiply(new BigDecimal(1.35));
                foundPhantomHymn = true;
                break;
            }
        }
    /*for (Inventory slot : player.getInventory().query((ItemType) CustomItemTypes.PRIZE_BOX)) {
                Optional<ItemStack> optStack = slot.peek();
                if (optStack.isPresent()) {
                    Optional<ItemStack> optContained = PrizeBox.getPrizeStack(optStack.get());
                    if (optContained.isPresent() && optContained.get().getItem() == CustomItemTypes.PHANTOM_HYMN) {
                        drainAll(); // Force away all water
                        floodBlockType = BlockTypes.FLOWING_LAVA;
                        break;
                    }
                }
            }*/
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) BigDecimal(java.math.BigDecimal)

Example 47 with ItemStack

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

the class JungleRaidEffectListener method onPlayerInteract.

@Listener
public void onPlayerInteract(InteractBlockEvent.Secondary.MainHand event, @First Player player) {
    Optional<JungleRaidInstance> optInst = manager.getApplicableZone(player);
    if (!optInst.isPresent()) {
        return;
    }
    JungleRaidInstance inst = optInst.get();
    Optional<ItemStack> optStack = player.getItemInHand(HandTypes.MAIN_HAND);
    if (!optStack.isPresent()) {
        return;
    }
    ItemStack stack = optStack.get();
    if (stack.getItem() == ItemTypes.COMPASS) {
        event.setUseBlockResult(Tristate.FALSE);
        if (inst.getState() == JungleRaidState.IN_PROGRESS && inst.isFlagEnabled(JungleRaidFlag.ENHANCED_COMPASS)) {
            Set<Text> resultSet = new HashSet<>();
            for (Player aPlayer : inst.getPlayers(PlayerClassifier.PARTICIPANT)) {
                // Check validity
                if (player.equals(aPlayer))
                    continue;
                // Check team
                if (inst.isFriendlyFire(player, aPlayer))
                    continue;
                TextColor color = tf(player).canEntityBeSeen(tf(aPlayer)) ? TextColors.DARK_RED : TextColors.RED;
                resultSet.add(Text.of(color, aPlayer.getName(), " - ", player.getLocation().getPosition().distance(aPlayer.getLocation().getPosition())));
            }
            if (resultSet.isEmpty()) {
                player.sendMessage(Text.of(TextColors.RED, "No players found."));
            }
            player.sendMessage(Text.of(TextColors.YELLOW, "Player - Distance"));
            player.sendMessages(resultSet);
        } else if (inst.getState() == JungleRaidState.INITIALIZE) {
            player.setLocation(inst.getRandomLocation());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Text(org.spongepowered.api.text.Text) TextColor(org.spongepowered.api.text.format.TextColor) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) HashSet(java.util.HashSet) Listener(org.spongepowered.api.event.Listener)

Example 48 with ItemStack

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

the class PlayerStateServiceImpl method load.

@Override
public void load(Player player, String saveName) {
    Iterator<Inventory> slots = player.getInventory().slots().iterator();
    List<JsonElement> persistedInventoryContents = getInventoryContents(player, saveName);
    for (int i = 0; slots.hasNext(); ++i) {
        Inventory slot = slots.next();
        if (i < persistedInventoryContents.size()) {
            try {
                ItemStack stack = deserializeItemStack(persistedInventoryContents.get(i));
                slot.set(stack);
                continue;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        slot.set(newItemStack(ItemTypes.NONE));
    }
}
Also used : JsonElement(com.google.gson.JsonElement) IOException(java.io.IOException) ItemSerializer.serializeItemStack(com.skelril.nitro.item.ItemSerializer.serializeItemStack) ItemSerializer.deserializeItemStack(com.skelril.nitro.item.ItemSerializer.deserializeItemStack) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 49 with ItemStack

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

the class PlayerStateServiceImpl method createNewPlayerState.

private SavedPlayerState createNewPlayerState(Player player) {
    SavedPlayerState playerState = new SavedPlayerState();
    player.getInventory().slots().forEach(slot -> {
        try {
            ItemStack stackInSlot = slot.peek().orElse(newItemStack(ItemTypes.NONE));
            JsonElement serializedStack = serializeItemStack(stackInSlot);
            playerState.getInventoryContents().add(serializedStack);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
    return playerState;
}
Also used : JsonElement(com.google.gson.JsonElement) IOException(java.io.IOException) ItemSerializer.serializeItemStack(com.skelril.nitro.item.ItemSerializer.serializeItemStack) ItemSerializer.deserializeItemStack(com.skelril.nitro.item.ItemSerializer.deserializeItemStack) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

Example 50 with ItemStack

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

the class SkyWarsInstance method smartStart.

private void smartStart() {
    HashMap<Player, Color> colorMapping = new HashMap<>();
    for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
        Optional<ItemStack> optHelmet = player.getHelmet();
        if (!optHelmet.isPresent()) {
            return;
        }
        ItemStack helmet = optHelmet.get();
        Optional<Color> optColor = helmet.get(Keys.COLOR);
        if (!optColor.isPresent()) {
            return;
        }
        colorMapping.put(player, optColor.get());
    }
    // Reset the team mapping as it may have been corrupted by a bad run
    teams = createTeamsMapping();
    for (Map.Entry<Player, Color> entry : colorMapping.entrySet()) {
        Color color = entry.getValue();
        Set<Player> team = teams.get(color);
        if (team == null) {
            return;
        }
        Player player = entry.getKey();
        // Update team mapping
        team.add(player);
        SkyWarsPlayerData playerData = playerDataMapping.get(player);
        playerData.setTeam(team);
        // Give player team equipment
        giveTeamEquipment(player, color);
        // Throw player
        launchPlayer(player, 1);
        playerData.stopPushBack();
    }
    if (getWinner().isPresent()) {
        return;
    }
    getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.RED, "Fight!"));
    state = SkyWarsState.IN_PROGRESS;
    showStartingPlatform(false);
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Color(org.spongepowered.api.util.Color) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack)

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