Search in sources :

Example 6 with WorldService

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

the class SummonWandererCommand method supportedWanderers.

private static Collection<String> supportedWanderers() {
    WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
    WildernessWorldWrapper wrapper = service.getEffectWrapper(WildernessWorldWrapper.class).get();
    return wrapper.getWanderingMobManager().getSupportedWanderers();
}
Also used : WorldService(com.skelril.skree.service.WorldService)

Example 7 with WorldService

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

the class WildernessMetaCommand method execute.

@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
    PaginationService pagination = Sponge.getServiceManager().provideUnchecked(PaginationService.class);
    WildernessWorldWrapper wrapper = service.getEffectWrapper(WildernessWorldWrapper.class).get();
    List<Text> result = wrapper.getMetaInformation().stream().sorted(Comparator.comparing(a -> a.getKey().getName())).map(this::createLine).collect(Collectors.toList());
    pagination.builder().contents(result).title(Text.of(TextColors.GOLD, "Meta Info List")).padding(Text.of(" ")).sendTo(src);
    return CommandResult.success();
}
Also used : WorldService(com.skelril.skree.service.WorldService) CommandResult(org.spongepowered.api.command.CommandResult) CommandSource(org.spongepowered.api.command.CommandSource) DecimalFormat(java.text.DecimalFormat) Sponge(org.spongepowered.api.Sponge) PaginationService(org.spongepowered.api.service.pagination.PaginationService) Collectors(java.util.stream.Collectors) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) CommandException(org.spongepowered.api.command.CommandException) List(java.util.List) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) CommandExecutor(org.spongepowered.api.command.spec.CommandExecutor) Map(java.util.Map) Player(org.spongepowered.api.entity.living.player.Player) Comparator(java.util.Comparator) TextColors(org.spongepowered.api.text.format.TextColors) Text(org.spongepowered.api.text.Text) PaginationService(org.spongepowered.api.service.pagination.PaginationService) WorldService(com.skelril.skree.service.WorldService)

Example 8 with WorldService

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

the class WildernessTeleportCommand 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();
    }
    if (!src.hasPermission("skree.world.wilderness.teleport")) {
        src.sendMessage(Text.of(TextColors.RED, "You do not have permission to access worlds of this type."));
        return CommandResult.empty();
    }
    WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
    WildernessWorldWrapper wrapper = service.getEffectWrapper(WildernessWorldWrapper.class).get();
    int targetLevel = args.<Integer>getOne("target level").get();
    if (targetLevel < 1) {
        src.sendMessage(Text.of("The target level must be at least 1."));
        return CommandResult.empty();
    }
    Optional<World> optWorld = Sponge.getServer().getWorld(args.<String>getOne("world type").get());
    if (!optWorld.isPresent()) {
        src.sendMessage(Text.of("That world is not currently accessible."));
        return CommandResult.empty();
    }
    World world = optWorld.get();
    int variance = (int) (Math.sqrt(targetLevel) * 2);
    int negative = Probability.getChance(3) ? -1 : 1;
    targetLevel += Probability.getRandom(variance) * negative;
    Player player = (Player) src;
    for (int i = 0; i < 2; ++i) {
        tf(player).hurtResistantTime = 0;
        player.damage(wrapper.getDamageMod(targetLevel) * 3, DamageSource.builder().type(DAMAGE_TYPE).build());
    }
    if (player.get(Keys.HEALTH).orElse(0D) > 0) {
        int unit = wrapper.getLevelUnit(world);
        Location<World> dest;
        do {
            int x = getLevelCoord(targetLevel, unit);
            int z = getLevelCoord(targetLevel, unit);
            dest = SafeTeleportHelper.getSafeDest(new Location<>(world, x, 60, z)).orElse(null);
        } while (dest == null);
        player.setLocation(dest);
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService)

Example 9 with WorldService

use of com.skelril.skree.service.WorldService 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 10 with WorldService

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

the class MarketImplUtil method canBuyOrSell.

public static boolean canBuyOrSell(Player player) {
    Optional<WorldService> optService = Sponge.getServiceManager().provide(WorldService.class);
    if (optService.isPresent()) {
        WorldService service = optService.get();
        Collection<World> okayWorlds = new HashSet<>();
        okayWorlds.addAll(service.getEffectWrapper(MainWorldWrapper.class).get().getWorlds());
        okayWorlds.addAll(service.getEffectWrapper(BuildWorldWrapper.class).get().getWorlds());
        return okayWorlds.contains(player.getWorld());
    }
    return true;
}
Also used : MainWorldWrapper(com.skelril.skree.content.world.main.MainWorldWrapper) BuildWorldWrapper(com.skelril.skree.content.world.build.BuildWorldWrapper) World(org.spongepowered.api.world.World) WorldService(com.skelril.skree.service.WorldService)

Aggregations

WorldService (com.skelril.skree.service.WorldService)16 World (org.spongepowered.api.world.World)10 WorldEffectWrapper (com.skelril.skree.service.internal.world.WorldEffectWrapper)5 Player (org.spongepowered.api.entity.living.player.Player)4 NModuleTrigger (com.skelril.nitro.module.NModuleTrigger)2 BuildWorldWrapper (com.skelril.skree.content.world.build.BuildWorldWrapper)2 InstanceWorldWrapper (com.skelril.skree.content.world.instance.InstanceWorldWrapper)2 MainWorldWrapper (com.skelril.skree.content.world.main.MainWorldWrapper)2 DecimalFormat (java.text.DecimalFormat)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Sponge (org.spongepowered.api.Sponge)2 CommandException (org.spongepowered.api.command.CommandException)2 CommandResult (org.spongepowered.api.command.CommandResult)2 CommandSource (org.spongepowered.api.command.CommandSource)2 CommandContext (org.spongepowered.api.command.args.CommandContext)2 CommandExecutor (org.spongepowered.api.command.spec.CommandExecutor)2 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)2 Listener (org.spongepowered.api.event.Listener)2 Text (org.spongepowered.api.text.Text)2