Search in sources :

Example 16 with World

use of org.spongepowered.api.world.World 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 17 with World

use of org.spongepowered.api.world.World 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)

Example 18 with World

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

the class MainWorldWrapper method run.

@Override
public void run() {
    PotionEffect speedEffect = PotionEffect.builder().duration(3 * 20).amplifier(5).particles(false).potionType(PotionEffectTypes.SPEED).build();
    for (World world : getWorlds()) {
        for (Entity entity : world.getEntities(p -> p.getType().equals(EntityTypes.PLAYER))) {
            if (entity.get(Keys.GAME_MODE).orElse(GameModes.CREATIVE) != GameModes.SURVIVAL) {
                continue;
            }
            List<PotionEffect> potionEffects = entity.getOrElse(Keys.POTION_EFFECTS, new ArrayList<>(1));
            potionEffects.add(speedEffect);
            entity.offer(Keys.POTION_EFFECTS, potionEffects);
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) PotionEffect(org.spongepowered.api.effect.potion.PotionEffect) World(org.spongepowered.api.world.World)

Example 19 with World

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

the class RegionManager method cleanup.

public int cleanup() {
    Optional<World> optWorld = Sponge.getServer().getWorld(worldName);
    int total = 0;
    if (optWorld.isPresent()) {
        World world = optWorld.get();
        for (CachedRegion region : regionList) {
            List<RegionPoint> toRemove = new ArrayList<>();
            for (RegionPoint point : region.getFullPoints()) {
                BlockType type = world.getBlockType(point.toInt());
                if (type != CustomBlockTypes.REGION_MASTER && type != CustomBlockTypes.REGION_MARKER) {
                    ++total;
                    toRemove.add(point);
                }
            }
            region.remPoint(toRemove);
        }
    }
    return total;
}
Also used : BlockType(org.spongepowered.api.block.BlockType) World(org.spongepowered.api.world.World)

Example 20 with World

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

the class DropClearServiceImpl method onItemSpawn.

@Listener(order = Order.POST)
public void onItemSpawn(SpawnEntityEvent event) {
    long spawnedCount = event.getEntities().stream().filter(DropClearServiceImpl.CHECK_PREDICATE).count();
    World targetWorld = event.getTargetWorld();
    long newCount = entityCount.merge(targetWorld, spawnedCount, (a, b) -> a + b);
    if (newCount > autoAmt) {
        checkedCleanup(targetWorld);
    }
}
Also used : World(org.spongepowered.api.world.World) Listener(org.spongepowered.api.event.Listener)

Aggregations

World (org.spongepowered.api.world.World)81 Listener (org.spongepowered.api.event.Listener)24 Location (org.spongepowered.api.world.Location)23 Entity (org.spongepowered.api.entity.Entity)18 Player (org.spongepowered.api.entity.living.player.Player)18 Vector3i (com.flowpowered.math.vector.Vector3i)11 WorldService (com.skelril.skree.service.WorldService)11 BlockType (org.spongepowered.api.block.BlockType)10 ItemStack (org.spongepowered.api.item.inventory.ItemStack)10 Vector3d (com.flowpowered.math.vector.Vector3d)9 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)8 ArrayList (java.util.ArrayList)7 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)7 BlockState (org.spongepowered.api.block.BlockState)7 ItemStackFactory.newItemStack (com.skelril.nitro.item.ItemStackFactory.newItemStack)6 Living (org.spongepowered.api.entity.living.Living)5 Monster (org.spongepowered.api.entity.living.monster.Monster)5 ItemDropper (com.skelril.nitro.item.ItemDropper)4 ModifierService (com.skelril.skree.service.ModifierService)4 IOException (java.io.IOException)4