Search in sources :

Example 36 with Player

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

the class MarketQuickAddCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!(src instanceof Player)) {
        src.sendMessage(Text.of("You must be a player to use this command!"));
        return CommandResult.empty();
    }
    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<ItemStack> held = ((Player) src).getItemInHand(HandTypes.MAIN_HAND);
    if (!held.isPresent()) {
        src.sendMessage(Text.of(TextColors.RED, "You are not holding an item."));
        return CommandResult.empty();
    }
    ItemStack item = held.get();
    String alias = args.<String>getOne("alias").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();
    }
    if (service.addItem(item)) {
        if (service.addAlias(alias, item)) {
            if (service.setBasePrice(alias, price)) {
                if (service.setPrimaryAlias(alias)) {
                    src.sendMessage(Text.of(TextColors.YELLOW, alias + " added to the market with a price of " + format(price)));
                    return CommandResult.success();
                }
            // Same error, fall through
            }
            src.sendMessage(Text.of(TextColors.RED, alias + " is not a valid alias"));
            return CommandResult.empty();
        }
        src.sendMessage(Text.of(TextColors.RED, "Your held item is not currently tracked, or the alias is already in use."));
        return CommandResult.empty();
    }
    src.sendMessage(Text.of(TextColors.RED, "Your held item is already tracked."));
    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)

Example 37 with Player

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

the class PlayerCombatParser method parse.

default default void parse(DamageEntityEvent event) {
    Entity entity = event.getTargetEntity();
    if (!(entity instanceof Living)) {
        return;
    }
    Optional<DamageSource> optDamageSource = event.getCause().first(DamageSource.class);
    if (optDamageSource.isPresent()) {
        Entity srcEntity = null;
        Entity indirectSrcEntity = null;
        if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
            srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
            indirectSrcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getSource();
        } else if (optDamageSource.get() instanceof EntityDamageSource) {
            srcEntity = ((EntityDamageSource) optDamageSource.get()).getSource();
        }
        if (!(srcEntity instanceof Living)) {
            if (entity instanceof Player) {
                processNonLivingAttack(optDamageSource.get(), (Player) entity);
            }
            return;
        }
        Living living = (Living) srcEntity;
        if (verify(living)) {
            if (entity instanceof Player && living instanceof Player) {
                processPvP((Player) living, (Player) entity);
                processPvP((Player) living, (Player) entity, indirectSrcEntity);
            } else if (entity instanceof Player) {
                processMonsterAttack(living, (Player) entity);
            } else if (living instanceof Player) {
                processPlayerAttack((Player) living, (Living) entity);
            }
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) Living(org.spongepowered.api.entity.living.Living) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource)

Example 38 with Player

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

the class PlayerCombatParser method parse.

default default void parse(CollideEntityEvent.Impact event) {
    Optional<Projectile> optProjectile = event.getCause().first(Projectile.class);
    if (!optProjectile.isPresent()) {
        return;
    }
    Projectile projectile = optProjectile.get();
    ProjectileSource source = optProjectile.get().getShooter();
    if (!(source instanceof Player)) {
        return;
    }
    Player attacker = (Player) source;
    for (Entity anEntity : event.getEntities()) {
        if (anEntity instanceof Player) {
            Player defender = (Player) anEntity;
            processPvP(attacker, defender);
            processPvP(attacker, defender, projectile);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) ProjectileSource(org.spongepowered.api.entity.projectile.source.ProjectileSource) Projectile(org.spongepowered.api.entity.projectile.Projectile)

Example 39 with Player

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

the class FreakyFourInstance method runFrimus.

private void runFrimus() {
    createWall(getRegion(FreakyFourBoss.FRIMUS), type -> type == BlockTypes.AIR, type -> type == BlockTypes.LAVA || type == BlockTypes.FLOWING_LAVA, BlockTypes.AIR, BlockTypes.LAVA, config.frimusWallDensity, -1);
    for (Player player : getPlayers(PlayerClassifier.PARTICIPANT)) {
        List<PotionEffect> oldPotions = player.get(Keys.POTION_EFFECTS).orElse(new ArrayList<>());
        List<PotionEffect> newPotions = oldPotions.stream().filter(effect -> effect.getType() != PotionEffectTypes.FIRE_RESISTANCE).collect(Collectors.toList());
        if (oldPotions.size() != newPotions.size()) {
            player.offer(Keys.POTION_EFFECTS, newPotions);
        }
    }
}
Also used : LegacyZoneBase(com.skelril.skree.content.zone.LegacyZoneBase) Boss(com.skelril.openboss.Boss) Keys(org.spongepowered.api.data.key.Keys) BossManager(com.skelril.openboss.BossManager) PARTICIPANT(com.skelril.skree.service.internal.zone.PlayerClassifier.PARTICIPANT) SpawnCause(org.spongepowered.api.event.cause.entity.spawn.SpawnCause) Vector3d(com.flowpowered.math.vector.Vector3d) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) ArrayList(java.util.ArrayList) TimedRunnable(com.skelril.nitro.time.TimedRunnable) PotionEffectTypes(org.spongepowered.api.effect.potion.PotionEffectTypes) CharlotteBossManager(com.skelril.skree.content.zone.group.freakyfour.boss.CharlotteBossManager) SkreePlugin(com.skelril.skree.SkreePlugin) FrimusBossManager(com.skelril.skree.content.zone.group.freakyfour.boss.FrimusBossManager) EntityTypes(org.spongepowered.api.entity.EntityTypes) DaBombBossManager(com.skelril.skree.content.zone.group.freakyfour.boss.DaBombBossManager) ZoneRegion(com.skelril.skree.service.internal.zone.ZoneRegion) Task(org.spongepowered.api.scheduler.Task) ZoneStatus(com.skelril.skree.service.internal.zone.ZoneStatus) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) Probability(com.skelril.nitro.probability.Probability) ZoneBossDetail(com.skelril.skree.content.zone.ZoneBossDetail) Living(org.spongepowered.api.entity.living.Living) CaveSpider(org.spongepowered.api.entity.living.monster.CaveSpider) Location(org.spongepowered.api.world.Location) EnumMap(java.util.EnumMap) Predicate(java.util.function.Predicate) BlockTypes(org.spongepowered.api.block.BlockTypes) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) PlayerClassifier(com.skelril.skree.service.internal.zone.PlayerClassifier) Entity(org.spongepowered.api.entity.Entity) Collectors(java.util.stream.Collectors) Monster(org.spongepowered.api.entity.living.monster.Monster) SnipeeBossManager(com.skelril.skree.content.zone.group.freakyfour.boss.SnipeeBossManager) Cause(org.spongepowered.api.event.cause.Cause) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) List(java.util.List) Explosion(org.spongepowered.api.world.explosion.Explosion) VelocityEntitySpawner(com.skelril.nitro.entity.VelocityEntitySpawner) Vector3i(com.flowpowered.math.vector.Vector3i) BlockType(org.spongepowered.api.block.BlockType) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) ZoneBoundingBox(com.skelril.skree.service.internal.zone.ZoneBoundingBox) Clause(com.skelril.nitro.Clause) Player(org.spongepowered.api.entity.living.player.Player) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect)

Example 40 with Player

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

the class FrimusBossManager method handleDamaged.

private void handleDamaged() {
    List<Instruction<DamagedCondition, Boss<Living, ZoneBossDetail<FreakyFourInstance>>>> damagedProcessor = getDamagedProcessor();
    damagedProcessor.add((condition, boss) -> {
        DamageEntityEvent event = condition.getEvent();
        new PlayerCombatParser() {

            @Override
            public void processPlayerAttack(Player attacker, Living defender) {
                if (condition.getDamageSource().get() instanceof IndirectEntityDamageSource) {
                    attacker.sendMessage(Text.of(TextColors.RED, "Projectiles can't harm me... Mwahahaha!"));
                    event.setCancelled(true);
                }
            }
        }.parse(event);
        return Optional.empty();
    });
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) NamedBindInstruction(com.skelril.skree.content.zone.group.catacombs.instruction.bossmove.NamedBindInstruction) Instruction(com.skelril.openboss.Instruction) HealthBindInstruction(com.skelril.skree.content.zone.group.freakyfour.boss.bossmove.HealthBindInstruction) ZoneBossDetail(com.skelril.skree.content.zone.ZoneBossDetail) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Aggregations

Player (org.spongepowered.api.entity.living.player.Player)125 Listener (org.spongepowered.api.event.Listener)40 ItemStack (org.spongepowered.api.item.inventory.ItemStack)28 Entity (org.spongepowered.api.entity.Entity)25 World (org.spongepowered.api.world.World)21 Text (org.spongepowered.api.text.Text)17 BigDecimal (java.math.BigDecimal)16 EntityPlayer (net.minecraft.entity.player.EntityPlayer)13 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)12 Vector3d (com.flowpowered.math.vector.Vector3d)10 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)10 List (java.util.List)10 Optional (java.util.Optional)10 ItemStack (net.minecraft.item.ItemStack)10 Living (org.spongepowered.api.entity.living.Living)10 Task (org.spongepowered.api.scheduler.Task)10 Location (org.spongepowered.api.world.Location)10 MarketService (com.skelril.skree.service.MarketService)8 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)8 TextColors (org.spongepowered.api.text.format.TextColors)8