Search in sources :

Example 26 with Text

use of org.spongepowered.api.text.Text in project Skree by Skelril.

the class ZoneWaitingLobby method remove.

public void remove(Collection<Player> players) {
    HashMap<Player, Integer> localCounts = new HashMap<>();
    for (Player player : players) {
        localCounts.put(player, playingPlayers.remove(player));
    }
    boolean hasSnowballs = false;
    for (int value : localCounts.values()) {
        if (value > 0) {
            hasSnowballs = true;
            break;
        }
    }
    List<Text> endMessage = new ArrayList<>();
    if (hasSnowballs) {
        List<Map.Entry<Player, Integer>> results = Lists.newArrayList(localCounts.entrySet());
        results.sort((a, b) -> b.getValue() - a.getValue());
        endMessage.add(Text.of(TextColors.GOLD, "Top Snowball Fight Scores: "));
        for (int i = 0; i < Math.min(results.size(), 3); ++i) {
            Map.Entry<Player, Integer> playerScore = results.get(i);
            endMessage.add(Text.of(TextColors.YELLOW, i + 1, ") ", playerScore.getKey().getName(), " - ", playerScore.getValue()));
        }
    }
    players.stream().forEach(p -> {
        if (!endMessage.isEmpty()) {
            p.sendMessages(endMessage);
        }
        restoreInventory(p);
    });
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Text(org.spongepowered.api.text.Text)

Example 27 with Text

use of org.spongepowered.api.text.Text in project Skree by Skelril.

the class MainWorldWrapper method onBlockChange.

@Listener
public void onBlockChange(ChangeBlockEvent event, @First Player player) {
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (optLoc.isPresent() && isApplicable(optLoc.get())) {
            boolean preventedFromBuilding = check(player, optLoc.get());
            // Block players that are allowed to build, otherwise send the no build message
            Text noEditMessage = Text.of(TextColors.RED, "You can't change blocks here!");
            if (!preventedFromBuilding) {
                if (player.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.CREATIVE) {
                    preventedFromBuilding = true;
                    noEditMessage = Text.of(TextColors.RED, "You must be in creative mode to edit!");
                }
            }
            if (preventedFromBuilding) {
                if (event.getCause().root().equals(player)) {
                    player.sendMessage(noEditMessage);
                }
                event.setCancelled(true);
                return;
            }
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 28 with Text

use of org.spongepowered.api.text.Text 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 29 with Text

use of org.spongepowered.api.text.Text in project HuskyCrates-Sponge by codeHusky.

the class VirtualCrate method getCrateKey.

/***
     * Retrieve the crate item
     * @since 0.10.2
     * @param quantity the quantity of keys you want.
     * @return the ItemStack with the keys.
     */
public ItemStack getCrateKey(int quantity) {
    ItemStack key = ItemStack.builder().itemType(keyType).quantity(quantity).add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Key")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A key for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if (keyDamage != null) {
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"), keyDamage)).build();
    }
    //
    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData", "crateID"), id)).build();
}
Also used : ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Example 30 with Text

use of org.spongepowered.api.text.Text in project HuskyCrates-Sponge by codeHusky.

the class VirtualCrate method getCrateWand.

/***
     * Retrieve the crate item
     * @since 1.2.1
     * @return the ItemStack with the keys.
     */
public ItemStack getCrateWand() {
    ItemStack key = ItemStack.builder().itemType(ItemTypes.BLAZE_ROD).add(Keys.DISPLAY_NAME, TextSerializers.FORMATTING_CODE.deserialize(displayName + " Wand")).build();
    ArrayList<Text> itemLore = new ArrayList<>();
    itemLore.add(Text.of(TextColors.WHITE, "A wand for a ", TextSerializers.FORMATTING_CODE.deserialize(displayName), TextColors.WHITE, "."));
    itemLore.add(Text.of(TextColors.DARK_GRAY, "HuskyCrates"));
    key.offer(Keys.ITEM_LORE, itemLore);
    if (keyDamage != null) {
        key = ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeDamage"), keyDamage)).build();
    }
    //
    return ItemStack.builder().fromContainer(key.toContainer().set(DataQuery.of("UnsafeData", "crateID"), id)).build();
}
Also used : ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

Text (org.spongepowered.api.text.Text)39 Player (org.spongepowered.api.entity.living.player.Player)12 Listener (org.spongepowered.api.event.Listener)10 ArrayList (java.util.ArrayList)7 UUID (java.util.UUID)7 ItemStack (org.spongepowered.api.item.inventory.ItemStack)7 BigDecimal (java.math.BigDecimal)6 Collectors (java.util.stream.Collectors)6 Sponge (org.spongepowered.api.Sponge)6 CommandException (org.spongepowered.api.command.CommandException)6 PaginationService (org.spongepowered.api.service.pagination.PaginationService)6 TextColors (org.spongepowered.api.text.format.TextColors)6 Optional (java.util.Optional)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 ClientConnectionEvent (org.spongepowered.api.event.network.ClientConnectionEvent)4 ClientboundNucleusNameMappingsPacket (com.almuradev.almura.feature.nick.network.ClientboundNucleusNameMappingsPacket)3