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");
}
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));
}
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;
}
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);
}
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));
}
Aggregations