Search in sources :

Example 16 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class CursedMineListener method onPlayerQuit.

@Listener
public void onPlayerQuit(ClientConnectionEvent.Disconnect event) {
    Player player = event.getTargetEntity();
    Optional<CursedMineInstance> optInst = manager.getApplicableZone(player);
    if (optInst.isPresent() && optInst.get().hasRecordForPlayer(player)) {
        manager.getHitList().addPlayer(player);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Listener(org.spongepowered.api.event.Listener)

Example 17 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class WildernessWorldWrapper method onBlockPlace.

@Listener
public void onBlockPlace(ChangeBlockEvent.Place event, @Named(NamedCause.SOURCE) Player player) {
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        Optional<Location<World>> optLoc = block.getFinal().getLocation();
        if (!optLoc.isPresent() || !isApplicable(optLoc.get())) {
            continue;
        }
        Location<World> loc = optLoc.get();
        BlockState finalState = block.getFinal().getState();
        if (config.getDropAmplificationConfig().amplifies(finalState)) {
            // Allow creative mode players to still place blocks
            if (player.getGameModeData().type().get().equals(GameModes.CREATIVE)) {
                continue;
            }
            BlockType originalType = block.getOriginal().getState().getType();
            if (ore().contains(originalType)) {
                continue;
            }
            try {
                Vector3d origin = loc.getPosition();
                World world = loc.getExtent();
                for (int i = 0; i < 40; ++i) {
                    ParticleEffect effect = ParticleEffect.builder().type(ParticleTypes.MAGIC_CRITICAL_HIT).velocity(new Vector3d(Probability.getRangedRandom(-1, 1), Probability.getRangedRandom(-.7, .7), Probability.getRangedRandom(-1, 1))).quantity(1).build();
                    world.spawnParticles(effect, origin.add(.5, .5, .5));
                }
            } catch (Exception ex) {
                player.sendMessage(/* ChatTypes.SYSTEM, */
                Text.of(TextColors.RED, "You find yourself unable to place that block."));
            }
            block.setValid(false);
        }
    }
}
Also used : ParticleEffect(org.spongepowered.api.effect.particle.ParticleEffect) BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) Vector3d(com.flowpowered.math.vector.Vector3d) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 18 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class WildernessWorldWrapper method onEntityDeath.

@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
    Entity entity = event.getTargetEntity();
    Location<World> loc = entity.getLocation();
    Optional<Integer> optLevel = getLevel(loc);
    if (!optLevel.isPresent()) {
        return;
    }
    int level = optLevel.get();
    if (entity instanceof Monster) {
        DropTable dropTable;
        if (entity.getLocation().getExtent().getDimension() == DimensionTypes.NETHER || entity instanceof Wither) {
            dropTable = netherMobDropTable;
        } else {
            dropTable = commonDropTable;
        }
        Optional<EntityDamageSource> optDamageSource = event.getCause().first(EntityDamageSource.class);
        if (optDamageSource.isPresent()) {
            Entity srcEntity;
            if (optDamageSource.get() instanceof IndirectEntityDamageSource) {
                srcEntity = ((IndirectEntityDamageSource) optDamageSource.get()).getIndirectSource();
            } else {
                srcEntity = optDamageSource.get().getSource();
            }
            int dropTier = level;
            if (srcEntity instanceof Player) {
                Optional<ItemStack> optHeldItem = ((Player) srcEntity).getItemInHand(HandTypes.MAIN_HAND);
                if (optHeldItem.isPresent()) {
                    Optional<ItemEnchantment> optLooting = EnchantmentUtil.getHighestEnchantment(optHeldItem.get(), Enchantments.LOOTING);
                    if (optLooting.isPresent()) {
                        dropTier += optLooting.get().getLevel();
                    }
                }
                dropTier = getDropTier(dropTier);
                Collection<ItemStack> drops = dropTable.getDrops((entity instanceof Boss ? 5 : 1) * dropTier, getDropMod(dropTier, ((Monster) entity).getHealthData().maxHealth().get(), entity.getType()));
                int times = 1;
                Optional<ModifierService> optService = Sponge.getServiceManager().provide(ModifierService.class);
                if (optService.isPresent()) {
                    ModifierService service = optService.get();
                    if (service.isActive(Modifiers.DOUBLE_WILD_DROPS)) {
                        times *= 2;
                    }
                }
                ItemDropper dropper = new ItemDropper(loc);
                for (int i = 0; i < times; ++i) {
                    dropper.dropStacks(drops, SpawnTypes.DROPPED_ITEM);
                }
            }
        }
        if (entity.getType() == EntityTypes.ENDERMITE && Probability.getChance(20)) {
            entity.getWorld().triggerExplosion(Explosion.builder().location(entity.getLocation()).shouldBreakBlocks(true).radius(4F).build(), Cause.source(SkreePlugin.container()).build());
        }
    }
    GRAVE_STONE.createGraveFromDeath(event);
}
Also used : Wither(org.spongepowered.api.entity.living.monster.Wither) Player(org.spongepowered.api.entity.living.player.Player) ItemDropper(com.skelril.nitro.item.ItemDropper) ModifierService(com.skelril.skree.service.ModifierService) World(org.spongepowered.api.world.World) DropTable(com.skelril.nitro.droptable.DropTable) MasterDropTable(com.skelril.nitro.droptable.MasterDropTable) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) WanderingBoss(com.skelril.skree.content.world.wilderness.wanderer.WanderingBoss) Boss(org.spongepowered.api.entity.living.monster.Boss) ItemEnchantment(org.spongepowered.api.data.meta.ItemEnchantment) Monster(org.spongepowered.api.entity.living.monster.Monster) IndirectEntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.IndirectEntityDamageSource) ItemStack(org.spongepowered.api.item.inventory.ItemStack) ItemStackFactory.newItemStack(com.skelril.nitro.item.ItemStackFactory.newItemStack) Listener(org.spongepowered.api.event.Listener)

Example 19 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class ZoneRelativePositionListener method onBlockInteract.

@Listener
public void onBlockInteract(InteractBlockEvent.Secondary event, @First Player player) {
    Optional<Location<World>> optLocation = event.getTargetBlock().getLocation();
    if (!optLocation.isPresent()) {
        return;
    }
    Location<World> location = optLocation.get();
    Optional<T> optInst = getApplicable(location);
    if (!optInst.isPresent()) {
        return;
    }
    T inst = optInst.get();
    Vector3i minPoint = inst.getRegion().getMinimumPoint();
    Vector3i clickedPoint = location.getBlockPosition();
    Vector3i offset = clickedPoint.sub(minPoint);
    player.sendMessage(Text.of("Offset: ", offset));
}
Also used : Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 20 with Listener

use of org.spongepowered.api.event.Listener in project Skree by Skelril.

the class InstanceWorldWrapper method onLogin.

@Listener
public void onLogin(ClientConnectionEvent.Join event, @Getter("getTargetEntity") Player player) {
    if (!isApplicable(player)) {
        return;
    }
    Optional<WorldService> optWorldService = Sponge.getServiceManager().provide(WorldService.class);
    if (!optWorldService.isPresent()) {
        return;
    }
    WorldService worldService = optWorldService.get();
    Collection<World> worlds = worldService.getEffectWrapper(MainWorldWrapper.class).get().getWorlds();
    player.setLocation(worlds.iterator().next().getSpawnLocation());
}
Also used : World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService) Listener(org.spongepowered.api.event.Listener)

Aggregations

Listener (org.spongepowered.api.event.Listener)81 Player (org.spongepowered.api.entity.living.player.Player)36 World (org.spongepowered.api.world.World)26 Location (org.spongepowered.api.world.Location)21 ItemStack (org.spongepowered.api.item.inventory.ItemStack)18 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)17 Entity (org.spongepowered.api.entity.Entity)14 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)10 BlockType (org.spongepowered.api.block.BlockType)10 Text (org.spongepowered.api.text.Text)10 ItemStack (net.minecraft.item.ItemStack)9 Task (org.spongepowered.api.scheduler.Task)7 Vector3d (com.flowpowered.math.vector.Vector3d)6 ItemDropper (com.skelril.nitro.item.ItemDropper)5 ModifierService (com.skelril.skree.service.ModifierService)5 RegionService (com.skelril.skree.service.RegionService)5 WorldService (com.skelril.skree.service.WorldService)5 Region (com.skelril.skree.service.internal.region.Region)5 Living (org.spongepowered.api.entity.living.Living)5 MainWorldWrapper (com.skelril.skree.content.world.main.MainWorldWrapper)4