Search in sources :

Example 26 with World

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

the class LegacyZoneBase method remove.

@Override
public Clause<Player, ZoneStatus> remove(Player player) {
    RespawnService respawnService = Sponge.getServiceManager().provideUnchecked(RespawnService.class);
    Location<World> newLocation = respawnService.pop(player).orElse(respawnService.getDefault(player));
    player.setLocation(newLocation);
    return new Clause<>(player, ZoneStatus.REMOVED);
}
Also used : RespawnService(com.skelril.skree.service.RespawnService) Clause(com.skelril.nitro.Clause) World(org.spongepowered.api.world.World)

Example 27 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 28 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 29 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 30 with World

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

the class DropClearCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    Optional<DropClearService> optService = Sponge.getServiceManager().provide(DropClearService.class);
    if (!optService.isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, "The drop clear service is not currently running."));
        return CommandResult.empty();
    }
    DropClearService service = optService.get();
    // World resolution
    Optional<WorldProperties> optWorldProps = args.getOne("world");
    Optional<World> optWorld;
    if (!optWorldProps.isPresent()) {
        if (!(src instanceof Player)) {
            src.sendMessage(Text.of(TextColors.RED, "You are not a player and need to specify a world!"));
            return CommandResult.empty();
        }
        optWorld = Optional.of(((Player) src).getWorld());
    } else {
        optWorld = Sponge.getServer().getWorld(optWorldProps.get().getUniqueId());
    }
    // Handled by command spec, so always provided
    int seconds = args.<Integer>getOne("seconds").get();
    World world = optWorld.get();
    if (!world.isLoaded()) {
        src.sendMessage(Text.of(TextColors.RED, "The specified world was not loaded!"));
        return CommandResult.empty();
    }
    service.cleanup(world, Math.max(0, Math.min(seconds, maxDelay)));
    return CommandResult.success();
}
Also used : DropClearService(com.skelril.skree.service.DropClearService) Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

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