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);
});
}
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;
}
}
}
}
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());
}
}
}
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();
}
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();
}
Aggregations