Search in sources :

Example 41 with Player

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

the class DeathMark method apply.

@Override
public Optional<Instruction<DamagedCondition, Boss<Zombie, CatacombsBossDetail>>> apply(DamagedCondition damagedCondition, Boss<Zombie, CatacombsBossDetail> zombieCatacombsBossDetailBoss) {
    new PlayerCombatParser() {

        @Override
        public void processPlayerAttack(Player attacker, Living defender) {
            CatacombsBossDetail detail = zombieCatacombsBossDetailBoss.getDetail();
            CatacombsInstance inst = detail.getZone();
            if (detail.getMarked().isPresent()) {
                if (attacker.equals(detail.getMarked().get())) {
                    inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.YELLOW, attacker.getName() + " has been freed!"));
                } else {
                    detail.getMarked().get().offer(Keys.HEALTH, 0D);
                }
                detail.setMarked(null);
            } else if (activate(detail)) {
                detail.setMarked(attacker);
                inst.getPlayerMessageChannel(PlayerClassifier.SPECTATOR).send(Text.of(TextColors.DARK_RED, attacker.getName() + " has been marked!"));
            }
        }
    }.parse(damagedCondition.getEvent());
    return Optional.empty();
}
Also used : CatacombsBossDetail(com.skelril.skree.content.zone.group.catacombs.CatacombsBossDetail) Player(org.spongepowered.api.entity.living.player.Player) CatacombsInstance(com.skelril.skree.content.zone.group.catacombs.CatacombsInstance) Living(org.spongepowered.api.entity.living.Living) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 42 with Player

use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.

the class TEJobManager method onSignInteract.

/**
     * Called when a player clicks a sign. If the clicked sign is a "Job Changing" sign then the player's job will
     * be changed on click.
     *
     * @param event InteractBlockEvent
     */
@Listener
public void onSignInteract(InteractBlockEvent event) {
    if (event.getCause().first(Player.class).isPresent()) {
        Player player = event.getCause().first(Player.class).get();
        if (event.getTargetBlock().getLocation().isPresent()) {
            Optional<TileEntity> tileEntityOpt = event.getTargetBlock().getLocation().get().getTileEntity();
            if (tileEntityOpt.isPresent()) {
                TileEntity tileEntity = tileEntityOpt.get();
                if (tileEntity instanceof Sign) {
                    Sign sign = (Sign) tileEntity;
                    Optional<SignData> data = sign.getOrCreate(SignData.class);
                    if (data.isPresent()) {
                        SignData signData = data.get();
                        Text lineOneText = signData.lines().get(0);
                        Text lineTwoText = signData.lines().get(1);
                        String lineOne = lineOneText.toPlain();
                        String lineTwo = lineTwoText.toPlain().toLowerCase();
                        if (lineOne.equals("[TEJobs]")) {
                            if (jobExists(lineTwo)) {
                                if (setJob(player, lineTwo)) {
                                    player.sendMessage(Text.of(TextColors.GRAY, "Job changed to: ", TextColors.GOLD, lineTwo));
                                } else {
                                    player.sendMessage(Text.of(TextColors.RED, "[TE] Failed to set job. Contact your administrator."));
                                }
                            } else {
                                player.sendMessage(Text.of(TextColors.RED, "[TE] Sorry, this job does not exist"));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Player(org.spongepowered.api.entity.living.player.Player) SignData(org.spongepowered.api.data.manipulator.mutable.tileentity.SignData) Sign(org.spongepowered.api.block.tileentity.Sign) Text(org.spongepowered.api.text.Text) Listener(org.spongepowered.api.event.Listener)

Example 43 with Player

use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.

the class TEJobManager method onPlayerPlaceBlock.

/**
     * Used for the place option in jobs. Will check if the job has the place node and if it does it will check if the
     * block that was placed is present in the config of the player's job. If it is, it will grab the job exp reward as
     * well as the pay.
     *
     * @param event ChangeBlockEvent.Place
     */
@Listener
public void onPlayerPlaceBlock(ChangeBlockEvent.Place event) {
    if (event.getCause().first(Player.class).isPresent()) {
        Player player = event.getCause().first(Player.class).get();
        UUID playerUUID = player.getUniqueId();
        String playerJob = getPlayerJob(player);
        Optional<TEJob> optPlayerJob = getJob(playerJob, true);
        String blockName = event.getTransactions().get(0).getFinal().getState().getType().getName();
        if (optPlayerJob.isPresent()) {
            Optional<TEActionReward> reward = Optional.empty();
            List<String> sets = optPlayerJob.get().getSets();
            for (String s : sets) {
                Optional<TEJobSet> optSet = getJobSet(s);
                if (!optSet.isPresent()) {
                    logger.warn("[TE] Job " + getPlayerJob(player) + " has nonexistent set \"" + s + "\"");
                    continue;
                }
                reward = optSet.get().getRewardFor("place", blockName);
            }
            if (reward.isPresent()) {
                int expAmount = reward.get().getExpReward();
                BigDecimal payAmount = reward.get().getMoneyReward();
                boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
                TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
                if (notify) {
                    notifyPlayer(player, payAmount);
                }
                addExp(player, expAmount);
                playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
                checkForLevel(player);
            }
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) TEAccount(com.erigitic.config.TEAccount) BigDecimal(java.math.BigDecimal) Listener(org.spongepowered.api.event.Listener)

Example 44 with Player

use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.

the class TEJobManager method onPlayerKillEntity.

/**
     * Used for the break option in jobs. Will check if the job has the break node and if it does it will check if the
     * block that was broken is present in the config of the player's job. If it is, it will grab the job exp reward as
     * well as the pay.
     *
     * @param event DestructEntityEvent.Death
     */
@Listener
public void onPlayerKillEntity(DestructEntityEvent.Death event) {
    Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
    if (optDamageSource.isPresent()) {
        EntityDamageSource damageSource = optDamageSource.get();
        Entity killer = damageSource.getSource();
        Entity victim = event.getTargetEntity();
        if (!(killer instanceof Player)) {
            // If a projectile was shot to kill an entity, this will grab the player who shot it
            Optional<UUID> damageCreator = damageSource.getSource().getCreator();
            if (damageCreator.isPresent())
                killer = Sponge.getServer().getPlayer(damageCreator.get()).get();
        }
        if (killer instanceof Player) {
            Player player = (Player) killer;
            UUID playerUUID = player.getUniqueId();
            String victimName = victim.getType().getName();
            String playerJob = getPlayerJob(player);
            Optional<TEJob> optPlayerJob = getJob(playerJob, true);
            if (optPlayerJob.isPresent()) {
                Optional<TEActionReward> reward = Optional.empty();
                List<String> sets = optPlayerJob.get().getSets();
                for (String s : sets) {
                    Optional<TEJobSet> optSet = getJobSet(s);
                    if (!optSet.isPresent()) {
                        logger.warn("[TE] Job " + getPlayerJob(player) + " has nonexistent set \"" + s + "\"");
                        continue;
                    }
                    reward = optSet.get().getRewardFor("kill", victimName);
                }
                if (reward.isPresent()) {
                    int expAmount = reward.get().getExpReward();
                    BigDecimal payAmount = reward.get().getMoneyReward();
                    boolean notify = accountConfig.getNode(playerUUID.toString(), "jobnotifications").getBoolean();
                    TEAccount playerAccount = (TEAccount) accountManager.getOrCreateAccount(player.getUniqueId()).get();
                    if (notify) {
                        notifyPlayer(player, payAmount);
                    }
                    addExp(player, expAmount);
                    playerAccount.deposit(totalEconomy.getDefaultCurrency(), payAmount, Cause.of(NamedCause.of("TotalEconomy", totalEconomy.getPluginContainer())));
                    checkForLevel(player);
                }
            }
        }
    }
}
Also used : TileEntity(org.spongepowered.api.block.tileentity.TileEntity) Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) TEAccount(com.erigitic.config.TEAccount) BigDecimal(java.math.BigDecimal) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) Listener(org.spongepowered.api.event.Listener)

Example 45 with Player

use of org.spongepowered.api.entity.living.player.Player in project TotalEconomy by Erigitic.

the class TotalEconomy method onPlayerJoin.

@Listener
public void onPlayerJoin(ClientConnectionEvent.Join event) {
    Player player = event.getTargetEntity();
    accountManager.getOrCreateAccount(player.getUniqueId());
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener)

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