Search in sources :

Example 61 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 62 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)

Example 63 with ItemStack

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

the class RespawnQueueServiceImpl method onRespawn.

@Listener
public void onRespawn(RespawnPlayerEvent event) {
    EntityPlayer player = tf(event.getTargetEntity());
    net.minecraft.item.ItemStack[] mainInv = player.inventory.mainInventory;
    Task.builder().delayTicks(1).execute(() -> {
        Deque<ItemStack> queue = playerQueue.remove(player.getUniqueID());
        if (queue != null) {
            for (int i = 0; !queue.isEmpty() && i < mainInv.length; ++i) {
                if (mainInv[i] == null) {
                    mainInv[i] = tf(queue.poll());
                }
            }
            if (!queue.isEmpty()) {
                enque(tf(player), queue);
            }
        }
    }).submit(SkreePlugin.inst());
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 64 with ItemStack

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

the class SkyWarsInstance method awardPowerup.

public void awardPowerup(Player player, ItemStack held) {
    ItemStack powerup;
    Optional<String> optSuffix = SkyFeather.getSuffix(held);
    if (optSuffix.isPresent() && optSuffix.get().equals("Doom"))
        return;
    int uses = 5;
    double radius = 3;
    double flight = 2;
    double pushBack = 4;
    if (Probability.getChance(2)) {
        radius = 5;
        pushBack = 6;
    } else {
        flight = 6;
    }
    if (Probability.getChance(50)) {
        uses = -1;
        radius = 7;
        flight = 6;
        pushBack = 6;
        MutableMessageChannel targets = getPlayerMessageChannel(PlayerClassifier.SPECTATOR).asMutable();
        targets.removeMember(player);
        targets.send(Text.of(TextColors.RED, player.getName(), " has been given a Doom feather!"));
        player.getInventory().clear();
    }
    powerup = newItemStack(CustomItemTypes.SKY_FEATHER);
    SkyFeather.setFeatherProperties(powerup, uses, radius, flight, pushBack);
    player.getInventory().offer(powerup);
    tf(player).inventoryContainer.detectAndSendChanges();
    // Display name doesn't need checked as all power ups have one assigned
    player.sendMessage(Text.of(TextColors.YELLOW, "You obtain a power-up!"));
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) MutableMessageChannel(org.spongepowered.api.text.channel.MutableMessageChannel)

Example 65 with ItemStack

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

the class ItemStackFactory method newItemStack.

public static ItemStack newItemStack(ItemStack itemStack, int quantity) {
    ItemStack stack = itemStack.copy();
    stack.setQuantity(quantity);
    return stack;
}
Also used : ItemStack(org.spongepowered.api.item.inventory.ItemStack)

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