Search in sources :

Example 96 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class ModifierNotifier method onPlayerJoin.

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
    if (!optService.isPresent()) {
        return;
    }
    ModifierService service = optService.get();
    List<String> messages = new ArrayList<>();
    for (Map.Entry<String, Long> entry : service.getActiveModifiers().entrySet()) {
        String friendlyName = StringUtils.capitalize(entry.getKey().replace("_", " ").toLowerCase());
        String friendlyTime = PrettyText.date(entry.getValue());
        messages.add(" - " + friendlyName + " till " + friendlyTime);
    }
    if (messages.isEmpty())
        return;
    messages.sort(String.CASE_INSENSITIVE_ORDER);
    messages.add(0, "\n\nThe following donation perks are enabled:");
    Player player = event.getTargetEntity();
    Task.builder().execute(() -> {
        for (String message : messages) {
            player.sendMessage(Text.of(TextColors.GOLD, message));
        }
    }).delay(1, TimeUnit.SECONDS).submit(SkreePlugin.inst());
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ArrayList(java.util.ArrayList) ModifierService(com.skelril.skree.service.ModifierService) Map(java.util.Map) Listener(org.spongepowered.api.event.Listener)

Example 97 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class GameModeCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<PlayerStateService> optService = Sponge.getServiceManager().provide(PlayerStateService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The player state service is not currently running."));
        return CommandResult.empty();
    }
    PlayerStateService service = optService.get();
    GameMode mode = args.<GameMode>getOne("mode").get();
    Player target = args.<Player>getOne("target").get();
    if (service.hasInventoryStored(target) && !args.hasAny("f")) {
        src.sendMessage(Text.of(TextColors.RED, "Player has an omni-state stored, action denied."));
        src.sendMessage(Text.of(TextColors.RED, "This can be overwritten using -f."));
        return CommandResult.empty();
    }
    service.save(target, target.get(Keys.GAME_MODE).get().getId());
    target.offer(Keys.FALL_DISTANCE, 0F);
    target.offer(Keys.GAME_MODE, mode);
    service.load(target, mode.getId());
    target.sendMessage(Text.of(TextColors.YELLOW, "Changed game mode to " + mode.getName() + '.'));
    return CommandResult.success();
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Player(org.spongepowered.api.entity.living.player.Player) PlayerStateService(com.skelril.skree.service.PlayerStateService)

Example 98 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class HeartsCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Player targetPlayer = args.<Player>getOne(Text.of("player")).get();
    IntegratedRunnable runnable = new IntegratedRunnable() {

        @Override
        public boolean run(int times) {
            for (int i = 0; i < 75; ++i) {
                ParticleEffect effect = ParticleEffect.builder().type(ParticleTypes.HEART).quantity(1).build();
                targetPlayer.getWorld().spawnParticles(effect, targetPlayer.getLocation().getPosition().add(getRangedRandom(-5.0, 5.0), getRangedRandom(-2, 5.0), getRangedRandom(-5.0, 5.0)));
            }
            return true;
        }

        @Override
        public void end() {
        }
    };
    TimedRunnable timedRunnable = new TimedRunnable<>(runnable, 20);
    timedRunnable.setTask(Task.builder().execute(timedRunnable).intervalTicks(5).submit(SkreePlugin.inst()));
    return CommandResult.success();
}
Also used : ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) Player(org.spongepowered.api.entity.living.player.Player) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) TimedRunnable(com.skelril.nitro.time.TimedRunnable)

Example 99 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class MarketLookupCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    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<String> optAlias = args.getOne("alias");
    Optional<BigDecimal> optPrice = Optional.empty();
    Optional<Integer> optStock = Optional.empty();
    double percentageSale = 1;
    if (optAlias.isPresent()) {
        optAlias = service.getAlias(optAlias.get());
        if (optAlias.isPresent()) {
            optPrice = service.getPrice(optAlias.get());
            optStock = service.getStock(optAlias.get());
        }
    } else {
        Optional<ItemStack> held = src instanceof Player ? ((Player) src).getItemInHand(HandTypes.MAIN_HAND) : Optional.empty();
        if (held.isPresent()) {
            optPrice = service.getPrice(held.get());
            optAlias = service.getAlias(held.get());
            optStock = service.getStock(held.get());
            net.minecraft.item.ItemStack stack = tf(held.get());
            if (stack.isItemStackDamageable()) {
                percentageSale = 1 - ((double) stack.getItemDamage() / (double) stack.getMaxDamage());
            }
        }
    }
    if (!optPrice.isPresent()) {
        src.sendMessage(Text.of(TextColors.RED, "No valid alias specified, and you're not holding a tracked item."));
        return CommandResult.empty();
    }
    BigDecimal price = optPrice.get();
    Integer stockCount = optStock.orElse(0);
    BigDecimal sellPrice = price.multiply(service.getSellFactor(price));
    DecimalFormat df = new DecimalFormat("#,###.##");
    String buyPrice = df.format(price);
    String stock = df.format(stockCount);
    String sellUsedPrice = df.format(sellPrice.multiply(new BigDecimal(percentageSale)));
    String sellNewPrice = df.format(sellPrice);
    String alias = optAlias.get();
    Text itemDisplay = Text.of(TextColors.BLUE, TextActions.showItem(service.getItem(alias).get().createSnapshot()), alias.toUpperCase());
    Text.Builder itemSteps = Text.builder();
    for (int i : new int[] { 1, 16, 32, 64, 128, 256 }) {
        if (i != 1) {
            itemSteps.append(Text.of(TextColors.YELLOW, ", "));
        }
        BigDecimal intervalPrice = price.multiply(new BigDecimal(i));
        itemSteps.append(Text.of(TextColors.BLUE, TextActions.runCommand("/market buy -a " + i + " " + alias), TextActions.showText(Text.of("Buy ", i, " for ", df.format(intervalPrice))), i));
    }
    List<Text> information = new ArrayList<>(6);
    Collections.addAll(information, Text.of(TextColors.GOLD, "Price information for: ", itemDisplay), Text.of(TextColors.YELLOW, "There are currently ", TextColors.GRAY, stock, TextColors.YELLOW, " in stock."), Text.of(TextColors.YELLOW, "When you buy it you pay:"), Text.of(TextColors.YELLOW, " - ", TextColors.WHITE, buyPrice, TextColors.YELLOW, " each."), Text.of(TextColors.YELLOW, "When you sell it you get:"), Text.of(TextColors.YELLOW, " - ", TextColors.WHITE, sellUsedPrice, TextColors.YELLOW, " each."), Text.of(TextColors.YELLOW, "Quick buy: ", itemSteps.build()));
    if (src.hasPermission("skree.market.admin")) {
        String basePrice = df.format(service.getBasePrice(alias).get());
        Collections.addAll(information, Text.of(TextColors.YELLOW, "Base Price:"), Text.of(TextColors.YELLOW, " - ", TextColors.WHITE, basePrice, TextColors.YELLOW, " each."));
    }
    if (percentageSale != 1) {
        information.add(Text.of(TextColors.YELLOW, " - ", TextColors.WHITE, sellNewPrice, TextColors.YELLOW, " each when new."));
    }
    src.sendMessages(information);
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) Text(org.spongepowered.api.text.Text) BigDecimal(java.math.BigDecimal) ItemStack(org.spongepowered.api.item.inventory.ItemStack) MarketService(com.skelril.skree.service.MarketService)

Example 100 with Player

use of org.spongepowered.api.entity.living.player.Player in project Skree by Skelril.

the class MarketSetPriceCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    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();
    BigDecimal price;
    try {
        price = new BigDecimal(args.<String>getOne("price").get());
    } catch (NumberFormatException ex) {
        src.sendMessage(Text.of(TextColors.RED, "Invalid price specified"));
        return CommandResult.empty();
    }
    Optional<String> optAlias = args.getOne("alias");
    Optional<ItemStack> held = src instanceof Player ? ((Player) src).getItemInHand(HandTypes.MAIN_HAND) : Optional.empty();
    if (optAlias.isPresent()) {
        String alias = optAlias.get();
        if (service.setBasePrice(alias, price)) {
            src.sendMessage(Text.of(TextColors.YELLOW, alias + "'s price has been set to " + format(price)));
            return CommandResult.success();
        }
    } else if (held.isPresent()) {
        if (service.setBasePrice(held.get(), price)) {
            src.sendMessage(Text.of(TextColors.YELLOW, "Your held item's price has been set to " + format(price)));
            return CommandResult.success();
        }
    }
    src.sendMessage(Text.of(TextColors.RED, "No valid alias specified, and you're not holding a tracked item."));
    return CommandResult.empty();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ItemStack(org.spongepowered.api.item.inventory.ItemStack) BigDecimal(java.math.BigDecimal) MarketService(com.skelril.skree.service.MarketService)

Aggregations

Player (org.spongepowered.api.entity.living.player.Player)113 Listener (org.spongepowered.api.event.Listener)34 ItemStack (org.spongepowered.api.item.inventory.ItemStack)28 Entity (org.spongepowered.api.entity.Entity)25 World (org.spongepowered.api.world.World)19 BigDecimal (java.math.BigDecimal)16 Text (org.spongepowered.api.text.Text)13 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)12 Vector3d (com.flowpowered.math.vector.Vector3d)10 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)10 Living (org.spongepowered.api.entity.living.Living)10 Location (org.spongepowered.api.world.Location)10 List (java.util.List)9 MarketService (com.skelril.skree.service.MarketService)8 Optional (java.util.Optional)8 ItemStack (net.minecraft.item.ItemStack)8 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 TextColors (org.spongepowered.api.text.format.TextColors)8 TEAccount (com.erigitic.config.TEAccount)7 ArrayList (java.util.ArrayList)7