Search in sources :

Example 31 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class CommandBorder method completeSpec.

@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder.child(CommandSpec.builder().arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), GenericArguments.doubleNum(Text.of("distance")), GenericArguments.optional(GenericArguments.integer(Text.of("time")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDiameter = border.getDiameter();
        double diameter = oldDiameter + args.<Double>getOne("distance").get();
        int time = args.<Integer>getOne("time").orElse(0);
        border.setDiameter(diameter, time);
        if (time > 0) {
            if (diameter < oldDiameter) {
                src.sendMessage(t("commands.worldborder.setSlowly.shrink.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            } else {
                src.sendMessage(t("commands.worldborder.setSlowly.grow.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            }
        } else {
            src.sendMessage(t("commands.worldborder.set.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter)));
        }
        return CommandResult.success();
    }).build(), "add").child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("distance")), GenericArguments.optional(GenericArguments.integer(Text.of("time"))), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDiameter = border.getDiameter();
        double diameter = args.<Double>getOne("distance").get();
        int time = args.<Integer>getOne("time").orElse(0);
        border.setDiameter(diameter, time);
        if (time > 0) {
            if (diameter < oldDiameter) {
                src.sendMessage(t("commands.worldborder.setSlowly.shrink.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            } else {
                src.sendMessage(t("commands.worldborder.setSlowly.grow.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter), time / 1000L));
            }
        } else {
            src.sendMessage(t("commands.worldborder.set.success", String.format("%.1f", diameter), String.format("%.1f", oldDiameter)));
        }
        return CommandResult.success();
    }).build(), "set").child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("x")), GenericArguments.doubleNum(Text.of("z")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double x = args.<Double>getOne("x").get();
        double z = args.<Double>getOne("z").get();
        border.setCenter(x, z);
        src.sendMessage(t("commands.worldborder.center.success", x, z));
        return CommandResult.success();
    }).build(), "center").child(CommandSpec.builder().child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("damagePerBlock")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDamage = border.getDamageAmount();
        double damage = args.<Double>getOne("damagePerBlock").get();
        border.setDamageAmount(damage);
        src.sendMessage(t("commands.worldborder.damage.buffer.success", String.format("%.1f", damage), String.format("%.1f", oldDamage)));
        return CommandResult.success();
    }).build(), "amount").child(CommandSpec.builder().arguments(GenericArguments.doubleNum(Text.of("distance")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double oldDistance = border.getDamageThreshold();
        double distance = args.<Double>getOne("distance").get();
        border.setDamageThreshold(args.<Double>getOne("distance").get());
        src.sendMessage(t("commands.worldborder.damage.amount.success", String.format("%.1f", distance), String.format("%.1f", oldDistance)));
        return CommandResult.success();
    }).build(), "buffer").build(), "damage").child(CommandSpec.builder().children(ImmutableMap.of(Lists.newArrayList("distance"), CommandSpec.builder().arguments(GenericArguments.integer(Text.of("distance")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        int oldDistance = border.getWarningDistance();
        int distance = args.<Integer>getOne("distance").get();
        border.setWarningDistance(distance);
        src.sendMessage(t("commands.worldborder.warning.distance.success", distance, oldDistance));
        return CommandResult.success();
    }).build(), Lists.newArrayList("time"), CommandSpec.builder().arguments(GenericArguments.integer(Text.of("time")), GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        int oldTime = border.getWarningTime();
        int time = args.<Integer>getOne("time").get();
        border.setWarningTime(time);
        src.sendMessage(t("commands.worldborder.warning.time.success", time, oldTime));
        return CommandResult.success();
    }).build())).build(), "warning").child(CommandSpec.builder().arguments(GenericArguments.optional(GenericArguments.world(Text.of("world")))).executor((src, args) -> {
        World world = CommandHelper.getWorld(src, args);
        WorldBorder border = world.getWorldBorder();
        double diameter = border.getDiameter();
        src.sendMessage(t("commands.worldborder.get.success", String.format("%.1f", diameter), String.format("%.1f", diameter)));
        return CommandResult.builder().queryResult((int) (diameter + 0.5)).build();
    }).build(), "get");
}
Also used : CommandResult(org.spongepowered.api.command.CommandResult) Lists(com.google.common.collect.Lists) Text(org.spongepowered.api.text.Text) TranslationHelper.t(org.lanternpowered.server.text.translation.TranslationHelper.t) ImmutableMap(com.google.common.collect.ImmutableMap) World(org.spongepowered.api.world.World) GenericArguments(org.spongepowered.api.command.args.GenericArguments) PluginContainer(org.spongepowered.api.plugin.PluginContainer) WorldBorder(org.spongepowered.api.world.WorldBorder) CommandSpec(org.spongepowered.api.command.spec.CommandSpec) WorldBorder(org.spongepowered.api.world.WorldBorder) World(org.spongepowered.api.world.World)

Example 32 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternSmeltingRecipeRegistryModule method registerDefaults.

@DelayedRegistration(RegistrationPhase.POST_INIT)
@Override
public void registerDefaults() {
    final PluginContainer plugin = Lantern.getMinecraftPlugin();
    register(ISmeltingRecipe.builder().ingredient(ItemTypes.COBBLESTONE).result(ItemStack.of(ItemTypes.STONE, 1)).build("stone", plugin));
    final ItemStack result = ItemStack.of(ItemTypes.IRON_INGOT, 1);
    result.offer(Keys.DISPLAY_NAME, Text.of(TextColors.RESET, "Steel Ingot"));
    register(ISmeltingRecipe.builder().ingredient(IIngredient.builder().with(ItemTypes.IRON_INGOT).withQuantity(2).build(), ItemStack.of(ItemTypes.IRON_INGOT, 1).createSnapshot()).result(result).build("steel_ingot", plugin));
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) ItemStack(org.spongepowered.api.item.inventory.ItemStack) DelayedRegistration(org.spongepowered.api.registry.util.DelayedRegistration)

Example 33 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternChannelRegistrar method create.

private LanternChannelBinding create(Object plugin, String channel, boolean rawChannel) throws ChannelRegistrationException {
    final PluginContainer container = checkPlugin(plugin, "plugin");
    checkNotNullOrEmpty(channel, "channel");
    checkArgument(channel.length() <= MAX_NAME_LENGTH, "channel length may not be longer then 20");
    if (!isChannelAvailable(channel)) {
        throw new ChannelRegistrationException("Channel with name \"" + channel + "\" is already registered!");
    }
    final LanternChannelBinding binding;
    if (rawChannel) {
        binding = new LanternRawDataChannel(this, channel, container);
    } else {
        binding = new LanternIndexedMessageChannel(this, channel, container);
    }
    binding.bound = true;
    final MessagePlayInOutRegisterChannels message = new MessagePlayInOutRegisterChannels(Sets.newHashSet(channel));
    for (Player player : this.server.getOnlinePlayers()) {
        ((NetworkSession) player.getConnection()).send(message);
    }
    return binding;
}
Also used : MessagePlayInOutRegisterChannels(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayInOutRegisterChannels) LanternPlayer(org.lanternpowered.server.entity.living.player.LanternPlayer) Player(org.spongepowered.api.entity.living.player.Player) PluginContainer(org.spongepowered.api.plugin.PluginContainer) NetworkSession(org.lanternpowered.server.network.NetworkSession) ChannelRegistrationException(org.spongepowered.api.network.ChannelRegistrationException)

Example 34 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternFuelBuilder method build.

@Override
public IFuel build(String id, Object plugin) {
    checkState(this.burnTimeProvider != null, "The burn time provider is not set.");
    checkState(this.ingredient != null, "The ingredient is not set.");
    checkNotNull(id, "id");
    checkNotNull(plugin, "plugin");
    final PluginContainer container = checkPlugin(plugin, "plugin");
    final int index = id.indexOf(':');
    if (index != -1) {
        final String pluginId = id.substring(0, index);
        checkState(pluginId.equals(container.getId()), "Plugin ids mismatch, " + "found %s in the id but got %s from the container", pluginId, container.getId());
        id = id.substring(index + 1);
    }
    return new LanternFuel(container.getId(), id, this.burnTimeProvider, this.ingredient);
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer)

Example 35 with PluginContainer

use of org.spongepowered.api.plugin.PluginContainer in project LanternServer by LanternPowered.

the class LanternFuelRegistryModule method registerDefaults.

@DelayedRegistration(RegistrationPhase.POST_INIT)
@Override
public void registerDefaults() {
    final PluginContainer plugin = Lantern.getMinecraftPlugin();
    register(IFuel.builder().ingredient(IIngredient.builder().with(ItemTypes.LAVA_BUCKET).withRemaining(ItemTypes.BUCKET).build()).burnTime(20000).build("lava_bucket", plugin));
    register(IFuel.builder().ingredient(Ingredient.of(ItemTypes.COAL)).burnTime(1600).build("coal", plugin));
}
Also used : PluginContainer(org.spongepowered.api.plugin.PluginContainer) DelayedRegistration(org.spongepowered.api.registry.util.DelayedRegistration)

Aggregations

PluginContainer (org.spongepowered.api.plugin.PluginContainer)75 Text (org.spongepowered.api.text.Text)15 CommandResult (org.spongepowered.api.command.CommandResult)13 GenericArguments (org.spongepowered.api.command.args.GenericArguments)13 CommandSpec (org.spongepowered.api.command.spec.CommandSpec)13 List (java.util.List)12 TranslationHelper.t (org.lanternpowered.server.text.translation.TranslationHelper.t)11 CommandException (org.spongepowered.api.command.CommandException)11 ArrayList (java.util.ArrayList)10 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)9 Sponge (org.spongepowered.api.Sponge)9 Player (org.spongepowered.api.entity.living.player.Player)8 Collection (java.util.Collection)7 Map (java.util.Map)7 Nullable (javax.annotation.Nullable)7 CommandSource (org.spongepowered.api.command.CommandSource)7 GenericArguments2 (org.lanternpowered.server.command.element.GenericArguments2)6 CommandMapping (org.spongepowered.api.command.CommandMapping)6 ArgumentParseException (org.spongepowered.api.command.args.ArgumentParseException)6