Search in sources :

Example 86 with Player

use of org.spongepowered.api.entity.living.player.Player 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 87 with Player

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

the class EvilFocus method run.

@Override
public void run(Living owner, Living target, DamageEntityEvent event) {
    Optional<PotionEffectData> optPotionEffectData = target.getOrCreate(PotionEffectData.class);
    if (!optPotionEffectData.isPresent()) {
        return;
    }
    PotionEffectData potionEffectData = optPotionEffectData.get();
    int duration = (int) (EntityHealthUtil.getHealth(target) * 10);
    potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.SLOWNESS, 9, duration));
    if (target instanceof Player) {
        potionEffectData.addElement(PotionEffect.of(PotionEffectTypes.BLINDNESS, 0, 20 * 4));
    }
    target.offer(potionEffectData);
    target.getWorld().playSound(SoundTypes.ENTITY_GHAST_SCREAM, target.getLocation().getPosition(), 1, .02F);
    notify(owner, Text.of(TextColors.YELLOW, "Your weapon traps your foe in their own sins."));
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PotionEffectData(org.spongepowered.api.data.manipulator.mutable.PotionEffectData)

Example 88 with Player

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

the class CustomTerragu method process.

public void process(InteractBlockEvent.Secondary.MainHand event) {
    Optional<Player> optPlayer = event.getCause().first(Player.class);
    if (!optPlayer.isPresent())
        return;
    Player player = optPlayer.get();
    Optional<org.spongepowered.api.item.inventory.ItemStack> optHeldItem = player.getItemInHand(HandTypes.MAIN_HAND);
    if (optHeldItem.isPresent()) {
        org.spongepowered.api.item.inventory.ItemStack held = optHeldItem.get();
        if (held.getItem() == this) {
            int newDist = getMaxEditDist(held) % 9 + 1;
            setMaxEditDist(held, newDist);
            player.setItemInHand(HandTypes.MAIN_HAND, held);
            player.sendMessage(Text.of(TextColors.YELLOW, "Distance set to: " + newDist));
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) Player(org.spongepowered.api.entity.living.player.Player) ItemStack(net.minecraft.item.ItemStack)

Example 89 with Player

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

the class WildernessWorldWrapper method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @Named(NamedCause.SOURCE) Entity srcEnt) {
    List<Transaction<BlockSnapshot>> transactions = event.getTransactions();
    for (Transaction<BlockSnapshot> block : transactions) {
        BlockSnapshot original = block.getOriginal();
        Optional<Location<World>> optLoc = original.getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Integer> optLevel = getLevel(optLoc.get());
        if (!optLevel.isPresent()) {
            continue;
        }
        int level = optLevel.get();
        Location<World> loc = optLoc.get();
        BlockState state = original.getState();
        BlockType type = state.getType();
        // Prevent item dupe glitch by removing the position before subsequent breaks
        markedOrePoints.remove(loc);
        if (config.getDropAmplificationConfig().amplifies(state)) {
            markedOrePoints.add(loc);
        }
        if (srcEnt instanceof Player && type.equals(BlockTypes.STONE) && Probability.getChance(Math.max(12, 250 - level))) {
            Vector3d max = loc.getPosition().add(1, 1, 1);
            Vector3d min = loc.getPosition().sub(1, 1, 1);
            Extent world = loc.getExtent();
            if (Probability.getChance(3)) {
                Entity entity = world.createEntity(EntityTypes.SILVERFISH, loc.getPosition().add(.5, 0, .5));
                world.spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.BLOCK_SPAWNING).build()).build());
            }
            // Do this one tick later to guarantee no collision with transaction data
            Task.builder().delayTicks(1).execute(() -> {
                for (int x = min.getFloorX(); x <= max.getFloorX(); ++x) {
                    for (int z = min.getFloorZ(); z <= max.getFloorZ(); ++z) {
                        for (int y = min.getFloorY(); y <= max.getFloorY(); ++y) {
                            if (!world.containsBlock(x, y, z)) {
                                continue;
                            }
                            if (world.getBlockType(x, y, z) == BlockTypes.STONE) {
                                world.setBlockType(x, y, z, BlockTypes.MONSTER_EGG, BlockChangeFlag.NONE, Cause.source(SkreePlugin.container()).build());
                            }
                        }
                    }
                }
            }).submit(SkreePlugin.inst());
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Extent(org.spongepowered.api.world.extent.Extent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) BlockState(org.spongepowered.api.block.BlockState) Transaction(org.spongepowered.api.data.Transaction) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 90 with Player

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

the class WildernessWorldWrapper method createFor.

private PlayerCombatParser createFor(Cancellable event, int level) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender) {
            if (allowsPvP(level)) {
                return;
            }
            Optional<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
            if (optService.isPresent()) {
                PvPService service = optService.get();
                if (service.getPvPState(attacker).allowByDefault() && service.getPvPState(defender).allowByDefault()) {
                    return;
                }
            }
            attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in this part of the Wilderness!"));
            attacker.sendMessage(Text.of(TextColors.RED, "Mandatory PvP is from level ", getFirstPvPLevel(), " and on."));
            event.setCancelled(true);
        }

        @Override
        public void processMonsterAttack(Living attacker, Player defender) {
            if (!(event instanceof DamageEntityEvent)) {
                return;
            }
            DamageEntityEvent dEvent = (DamageEntityEvent) event;
            // If they're endermites they hit through armor, otherwise they get a damage boost
            if (attacker.getType() == EntityTypes.ENDERMITE) {
                for (Tuple<DamageModifier, Function<? super Double, Double>> modifier : dEvent.getModifiers()) {
                    dEvent.setDamage(modifier.getFirst(), (a) -> 0D);
                }
                dEvent.setBaseDamage(1);
            } else {
                dEvent.setBaseDamage(dEvent.getBaseDamage() + getDamageMod(level));
            }
            // Only apply scoring while in survival mode
            if (defender.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
                return;
            }
            WildernessPlayerMeta meta = playerMetaMap.get(defender.getUniqueId());
            if (meta != null) {
                meta.hit();
            }
        }

        @Override
        public void processPlayerAttack(Player attacker, Living defender) {
            Task.builder().delayTicks(1).execute(() -> healthPrinter.print(MessageChannel.fixed(attacker), defender)).submit(SkreePlugin.inst());
            if (!(defender instanceof Monster) || defender instanceof Creeper) {
                return;
            }
            // Only apply scoring while in survival mode
            if (attacker.get(Keys.GAME_MODE).orElse(GameModes.SURVIVAL) != GameModes.SURVIVAL) {
                return;
            }
            WildernessPlayerMeta meta = playerMetaMap.get(attacker.getUniqueId());
            if (meta != null) {
                meta.attack();
                if (meta.getRatio() > 30 && meta.getFactors() > 35) {
                    Deque<Entity> spawned = new ArrayDeque<>();
                    for (int i = Probability.getRandom(5); i > 0; --i) {
                        Entity entity = attacker.getWorld().createEntity(EntityTypes.ENDERMITE, defender.getLocation().getPosition());
                        entity.getWorld().spawnEntity(entity, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
                        spawned.add(entity);
                    }
                    IntegratedRunnable runnable = new IntegratedRunnable() {

                        @Override
                        public boolean run(int times) {
                            Entity mob = spawned.poll();
                            if (mob.isLoaded() && mob.getWorld().equals(attacker.getWorld())) {
                                mob.setLocation(attacker.getLocation());
                            }
                            return true;
                        }

                        @Override
                        public void end() {
                        }
                    };
                    TimedRunnable timedRunnable = new TimedRunnable<>(runnable, spawned.size());
                    timedRunnable.setTask(Task.builder().execute(timedRunnable).delayTicks(40).intervalTicks(20).submit(SkreePlugin.inst()));
                }
                if (System.currentTimeMillis() - meta.getLastReset() >= TimeUnit.MINUTES.toMillis(5)) {
                    meta.reset();
                }
            }
        }
    };
}
Also used : DamageEntityEvent(org.spongepowered.api.event.entity.DamageEntityEvent) Player(org.spongepowered.api.entity.living.player.Player) Living(org.spongepowered.api.entity.living.Living) Creeper(org.spongepowered.api.entity.living.monster.Creeper) TimedRunnable(com.skelril.nitro.time.TimedRunnable) Function(java.util.function.Function) PvPService(com.skelril.skree.service.PvPService) IntegratedRunnable(com.skelril.nitro.time.IntegratedRunnable) DamageModifier(org.spongepowered.api.event.cause.entity.damage.DamageModifier) Monster(org.spongepowered.api.entity.living.monster.Monster) 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