Search in sources :

Example 1 with PvPService

use of com.skelril.skree.service.PvPService in project Skree by Skelril.

the class BuildWorldWrapper method createFor.

private PlayerCombatParser createFor(Cancellable event) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender) {
            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 build worlds!"));
            event.setCancelled(true);
        }
    };
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PvPService(com.skelril.skree.service.PvPService) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 2 with PvPService

use of com.skelril.skree.service.PvPService in project Skree by Skelril.

the class ZonePvPListener method createFor.

private PlayerCombatParser createFor(Cancellable event) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender) {
            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 area!"));
            event.setCancelled(true);
        }
    };
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PvPService(com.skelril.skree.service.PvPService) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser)

Example 3 with PvPService

use of com.skelril.skree.service.PvPService in project Skree by Skelril.

the class PvPCommand 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<PvPService> optService = Sponge.getServiceManager().provide(PvPService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The PvP service is not currently running."));
        return CommandResult.empty();
    }
    PvPService service = optService.get();
    Player player = (Player) src;
    Optional<PvPState> stateArg = args.getOne("status");
    PvPState state = stateArg.orElse(service.getPvPState(player));
    service.setPvPState(player, state);
    player.sendMessage(Text.of(TextColors.BLUE, "Your Opt-in PvP Settings", (stateArg.isPresent() ? " Changed!" : "")));
    player.sendMessage(Text.of(TextColors.YELLOW, "  Currently: ", getColor(state), state.toString()));
    PvPState defaultState = service.getDefaultState(player);
    player.sendMessage(Text.of(TextColors.YELLOW, "  Upon disconnect: ", getColor(defaultState), defaultState.toString()));
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) PvPService(com.skelril.skree.service.PvPService) PvPState(com.skelril.skree.service.internal.pvp.PvPState)

Example 4 with PvPService

use of com.skelril.skree.service.PvPService 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)

Example 5 with PvPService

use of com.skelril.skree.service.PvPService in project Skree by Skelril.

the class MainWorldWrapper method createFor.

private PlayerCombatParser createFor(Cancellable event) {
    return new PlayerCombatParser() {

        @Override
        public void processPvP(Player attacker, Player defender, @Nullable Entity indirectSource) {
            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;
                }
            }
            if (!(indirectSource instanceof Snowball) || !lobby.contains(attacker)) {
                attacker.sendMessage(Text.of(TextColors.RED, "PvP is opt-in only in the main world!"));
                event.setCancelled(true);
            }
        }

        @Override
        public void processNonLivingAttack(DamageSource attacker, Player defender) {
            if (attacker.getType() == DamageTypes.VOID) {
                defender.setLocation(defender.getWorld().getSpawnLocation());
                defender.offer(Keys.FALL_DISTANCE, 0F);
                event.setCancelled(true);
            }
        }
    };
}
Also used : Entity(org.spongepowered.api.entity.Entity) Snowball(org.spongepowered.api.entity.projectile.Snowball) Player(org.spongepowered.api.entity.living.player.Player) PvPService(com.skelril.skree.service.PvPService) DamageSource(org.spongepowered.api.event.cause.entity.damage.source.DamageSource) PlayerCombatParser(com.skelril.nitro.combat.PlayerCombatParser) Nullable(javax.annotation.Nullable)

Aggregations

PvPService (com.skelril.skree.service.PvPService)5 Player (org.spongepowered.api.entity.living.player.Player)5 PlayerCombatParser (com.skelril.nitro.combat.PlayerCombatParser)4 IntegratedRunnable (com.skelril.nitro.time.IntegratedRunnable)1 TimedRunnable (com.skelril.nitro.time.TimedRunnable)1 PvPState (com.skelril.skree.service.internal.pvp.PvPState)1 Function (java.util.function.Function)1 Nullable (javax.annotation.Nullable)1 Entity (org.spongepowered.api.entity.Entity)1 Living (org.spongepowered.api.entity.living.Living)1 Creeper (org.spongepowered.api.entity.living.monster.Creeper)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Snowball (org.spongepowered.api.entity.projectile.Snowball)1 DamageModifier (org.spongepowered.api.event.cause.entity.damage.DamageModifier)1 DamageSource (org.spongepowered.api.event.cause.entity.damage.source.DamageSource)1 DamageEntityEvent (org.spongepowered.api.event.entity.DamageEntityEvent)1