Search in sources :

Example 1 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class RespawnServiceImpl method getDefault.

@Override
public Location<World> getDefault(Player target) {
    WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
    Optional<Map<UUID, RespawnLocation>> optRespawnLocations = target.get(Keys.RESPAWN_LOCATIONS);
    if (optRespawnLocations.isPresent()) {
        BuildWorldWrapper buildWrapper = service.getEffectWrapper(BuildWorldWrapper.class).get();
        UUID buildWorldId = buildWrapper.getPrimaryWorld().getUniqueId();
        RespawnLocation targetLocation = optRespawnLocations.get().get(buildWorldId);
        if (targetLocation != null) {
            Optional<Location<World>> optLocation = targetLocation.asLocation();
            if (optLocation.isPresent()) {
                return optLocation.get();
            }
        }
    }
    return service.getEffectWrapper(MainWorldWrapper.class).get().getPrimaryWorld().getSpawnLocation();
}
Also used : MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) RespawnLocation(org.spongepowered.api.util.RespawnLocation) BuildWorldWrapper(com.skelril.skree.content.world.build.BuildWorldWrapper) WorldService(com.skelril.skree.service.WorldService) Location(org.spongepowered.api.world.Location) RespawnLocation(org.spongepowered.api.util.RespawnLocation)

Example 2 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class RegionMarker method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        return;
    }
    RegionService service = optService.get();
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        if (!block.isValid()) {
            continue;
        }
        if (block.getOriginal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (optLoc.isPresent()) {
            Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
            if (optRef.isPresent()) {
                Region ref = optRef.get();
                if (ref.isMember(player)) {
                    ref.remPoint(new RegionPoint(optLoc.get().getPosition()));
                    player.sendMessage(Text.of(TextColors.YELLOW, "Region marker deleted!"));
                }
            }
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Location(org.spongepowered.api.world.Location) RegionPoint(com.skelril.skree.service.internal.region.RegionPoint) Listener(org.spongepowered.api.event.Listener)

Example 3 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class RegionMaster method onBlockBreak.

@Listener
public void onBlockBreak(ChangeBlockEvent.Break event, @First Player player) {
    Optional<RegionService> optService = Sponge.getServiceManager().provide(RegionService.class);
    if (!optService.isPresent()) {
        return;
    }
    RegionService service = optService.get();
    for (Transaction<BlockSnapshot> block : event.getTransactions()) {
        if (!block.isValid()) {
            continue;
        }
        if (block.getOriginal().getState().getType() != this) {
            continue;
        }
        Optional<Location<World>> optLoc = block.getOriginal().getLocation();
        if (!optLoc.isPresent()) {
            continue;
        }
        Optional<Region> optRef = service.getMarkedRegion(optLoc.get());
        if (!optRef.isPresent()) {
            continue;
        }
        Region ref = optRef.get();
        if (!ref.getFullPoints().isEmpty()) {
            block.setValid(false);
            player.sendMessage(Text.of(TextColors.RED, "You must first delete all markers!"));
        } else {
            service.rem(optLoc.get());
            player.sendMessage(Text.of(TextColors.YELLOW, "Region deleted!"));
        }
    }
}
Also used : BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Region(com.skelril.skree.service.internal.region.Region) RegionService(com.skelril.skree.service.RegionService) Location(org.spongepowered.api.world.Location) Listener(org.spongepowered.api.event.Listener)

Example 4 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class PatientXInstance method spawnCreatures.

public void spawnCreatures() {
    Zombie boss = getBoss().get();
    Collection<Living> entities = getContained(Living.class);
    if (entities.size() > 500) {
        sendAttackBroadcast("Ring-a-round the rosie, a pocket full of posies...", AttackSeverity.NORMAL);
        EntityHealthUtil.toFullHealth(boss);
        for (Entity entity : entities) {
            if (entity instanceof Player) {
                entity.offer(Keys.HEALTH, 0D);
            } else if (!entity.equals(boss)) {
                entity.remove();
            }
        }
        return;
    }
    double amt = getPlayers(PARTICIPANT).size() * difficulty;
    Location l = getCenter();
    for (int i = 0; i < amt; i++) {
        Entity zombie = getRegion().getExtent().createEntity(EntityTypes.ZOMBIE, l.getPosition());
        // TODO convert to Sponge Data API
        ((EntityZombie) zombie).setCanPickUpLoot(false);
        ((EntityZombie) zombie).setChild(true);
        getRegion().getExtent().spawnEntity(zombie, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build());
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Player(org.spongepowered.api.entity.living.player.Player) EntityZombie(net.minecraft.entity.monster.EntityZombie) Zombie(org.spongepowered.api.entity.living.monster.Zombie) EntityZombie(net.minecraft.entity.monster.EntityZombie) Living(org.spongepowered.api.entity.living.Living) Location(org.spongepowered.api.world.Location)

Example 5 with Location

use of org.spongepowered.api.world.Location in project Skree by Skelril.

the class GoldRushInstance method findLeversAndFloodBlocks.

private void findLeversAndFloodBlocks() {
    Vector3i min = flashMemoryRoom.getMinimumPoint();
    Vector3i max = flashMemoryRoom.getMaximumPoint();
    int minX = min.getX();
    int minZ = min.getZ();
    int minY = min.getY();
    int maxX = max.getX();
    int maxZ = max.getZ();
    int maxY = max.getY();
    for (int x = minX; x <= maxX; x++) {
        for (int z = minZ; z <= maxZ; z++) {
            for (int y = maxY; y >= minY; --y) {
                BlockState state = getRegion().getExtent().getBlock(x, y, z);
                if (state.getType() == BlockTypes.LEVER) {
                    Location<World> loc = new Location<>(getRegion().getExtent(), x, y, z);
                    loc.getExtent().setBlock(loc.getBlockPosition(), state.withTrait(BooleanTraits.LEVER_POWERED, false).orElse(state), Cause.source(SkreePlugin.container()).build());
                    leverBlocks.put(loc, !Probability.getChance(3));
                    for (int i = y; i < maxY; i++) {
                        BlockType type = getRegion().getExtent().getBlockType(x, i, z);
                        if (type == BlockTypes.AIR) {
                            floodBlocks.add(new Location<>(getRegion().getExtent(), x, i, z));
                            break;
                        }
                    }
                    // One lever a column only
                    break;
                }
            }
        }
    }
}
Also used : BlockState(org.spongepowered.api.block.BlockState) BlockType(org.spongepowered.api.block.BlockType) Vector3i(com.flowpowered.math.vector.Vector3i) World(org.spongepowered.api.world.World) Location(org.spongepowered.api.world.Location)

Aggregations

Location (org.spongepowered.api.world.Location)166 World (org.spongepowered.api.world.World)96 Listener (org.spongepowered.api.event.Listener)44 Player (org.spongepowered.api.entity.living.player.Player)40 Vector3d (com.flowpowered.math.vector.Vector3d)38 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)32 Vector3i (com.flowpowered.math.vector.Vector3i)31 Optional (java.util.Optional)28 Entity (org.spongepowered.api.entity.Entity)27 BlockType (org.spongepowered.api.block.BlockType)24 BlockState (org.spongepowered.api.block.BlockState)23 ItemStack (org.spongepowered.api.item.inventory.ItemStack)23 Direction (org.spongepowered.api.util.Direction)21 ArrayList (java.util.ArrayList)20 Keys (org.spongepowered.api.data.key.Keys)20 List (java.util.List)19 Text (org.spongepowered.api.text.Text)19 BlockPos (net.minecraft.util.math.BlockPos)18 Sponge (org.spongepowered.api.Sponge)15 Map (java.util.Map)14