use of org.spongepowered.api.world.Locatable in project SpongeCommon by SpongePowered.
the class SpongeContextCalculator method accumulateContexts.
@Override
public void accumulateContexts(Subject subject, Set<Context> accumulator) {
Optional<CommandSource> subjSource = subject.getCommandSource();
if (subjSource.isPresent()) {
CommandSource source = subjSource.get();
if (source instanceof Locatable) {
World currentExt = ((Locatable) source).getWorld();
accumulator.add(currentExt.getContext());
accumulator.add((currentExt.getDimension().getContext()));
}
if (source instanceof RemoteSource) {
RemoteSource rem = (RemoteSource) source;
accumulator.addAll(this.remoteIpCache.getUnchecked(rem));
accumulator.addAll(this.localIpCache.getUnchecked(rem));
accumulator.add(new Context(Context.LOCAL_PORT_KEY, String.valueOf(rem.getConnection().getVirtualHost().getPort())));
accumulator.add(new Context(Context.LOCAL_HOST_KEY, rem.getConnection().getVirtualHost().getHostName()));
}
}
}
use of org.spongepowered.api.world.Locatable in project LanternServer by LanternPowered.
the class CommandParticleEffect method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(GenericArguments.catalogedElement(Text.of("type"), ParticleType.class), GenericArguments.vector3d(Text.of("position")), GenericArguments.optional(GenericArguments.world(Text.of("world"))), // TODO: Tab complaining is currently throwing errors, but it's a small bug in SpongeAPI
GenericArguments.flags().valueFlag(GenericArguments.integer(Text.of("quantity")), "-quantity", "q").valueFlag(GenericArguments.vector3d(Text.of("offset")), "-offset", "o").valueFlag(GenericArguments.vector3d(Text.of("velocity")), "-velocity", "v").valueFlag(GenericArguments.vector3d(Text.of("color")), "-color", "c").valueFlag(GenericArguments.doubleNum(Text.of("scale")), "-scale", "s").valueFlag(GenericArguments.catalogedElement(Text.of("note"), NotePitch.class), "-note", "n").valueFlag(GenericArguments.catalogedElement(Text.of("block"), BlockState.class), "-block", "b").valueFlag(GenericArguments.catalogedElement(Text.of("item"), ItemType.class), "-item", "i").valueFlag(GenericArguments.catalogedElement(Text.of("potion"), PotionEffectType.class), "-potion", "p").buildWith(GenericArguments.none())).executor((src, args) -> {
final ParticleType particleType = args.<ParticleType>getOne("type").get();
final Vector3d position = args.<Vector3d>getOne("position").get();
final World world = args.<WorldProperties>getOne("world").map(props -> Sponge.getServer().getWorld(props.getUniqueId()).get()).orElseGet(((Locatable) src)::getWorld);
final ParticleEffect.Builder builder = ParticleEffect.builder().type(particleType);
args.<Integer>getOne("quantity").ifPresent(builder::quantity);
args.<Vector3d>getOne("offset").ifPresent(builder::offset);
args.<Vector3d>getOne("velocity").ifPresent(builder::velocity);
args.<Vector3d>getOne("color").ifPresent(color -> builder.option(ParticleOptions.COLOR, Color.of(color.toInt())));
args.<NotePitch>getOne("note").ifPresent(note -> builder.option(ParticleOptions.NOTE, note));
args.<Double>getOne("scale").ifPresent(scale -> builder.option(ParticleOptions.SCALE, scale));
args.<BlockState>getOne("block").ifPresent(blockState -> builder.option(ParticleOptions.BLOCK_STATE, blockState));
args.<ItemType>getOne("item").ifPresent(item -> builder.option(ParticleOptions.ITEM_STACK_SNAPSHOT, new LanternItemStack(item).createSnapshot()));
args.<PotionEffectType>getOne("potion").ifPresent(type -> builder.option(ParticleOptions.POTION_EFFECT_TYPE, type));
world.spawnParticles(builder.build(), position);
src.sendMessage(t("Successfully spawned the particle %s", particleType.getName()));
return CommandResult.success();
});
}
use of org.spongepowered.api.world.Locatable in project Nucleus by NucleusPowered.
the class KillEntityCommand method executeCommand.
@Override
protected CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
if (!(src instanceof Locatable) && args.hasAny(radius)) {
// We can't do that.
throw ReturnMessageException.fromKey("command.killentity.commandsourceradius");
}
if (args.hasAny(radius) && args.hasAny(world)) {
// Can't do that, either.
throw ReturnMessageException.fromKey("command.killentity.radiusworld");
}
Set<Entity> currentEntities;
if (args.hasAny(radius)) {
Locatable l = ((Locatable) src);
Vector3d locationTest = l.getLocation().getPosition();
int r = args.<Integer>getOne(radius).get();
currentEntities = Sets.newHashSet(l.getWorld().getEntities(entity -> entity.getTransform().getPosition().distance(locationTest) <= r));
} else {
WorldProperties worldProperties = this.getWorldFromUserOrArgs(src, world, args);
currentEntities = Sets.newHashSet(Sponge.getServer().getWorld(worldProperties.getUniqueId()).get().getEntities());
}
Predicate<Entity> entityPredicate = args.<Predicate<Entity>>getAll(type).stream().reduce(Predicate::or).orElseThrow(() -> ReturnMessageException.fromKey("command.killentity.noselection"));
Set<Entity> toKill = currentEntities.stream().filter(entityPredicate).collect(Collectors.toSet());
if (toKill.isEmpty()) {
throw ReturnMessageException.fromKey("command.killentity.nothing");
}
int killCount = toKill.size();
toKill.forEach(x -> {
x.offer(Keys.HEALTH, 0d);
x.remove();
});
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.killentity.success", String.valueOf(killCount)));
return CommandResult.affectedEntities(killCount);
}
use of org.spongepowered.api.world.Locatable in project Nucleus by NucleusPowered.
the class SetBorderCommand method executeCommand.
@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
WorldProperties wp = getWorldFromUserOrArgs(src, worldKey, args);
int x;
int z;
int dia = args.<Integer>getOne(diameter).get();
int delay = args.<Integer>getOne(delayKey).orElse(0);
if (src instanceof Locatable) {
Location<World> lw = ((Locatable) src).getLocation();
if (args.hasAny(zKey)) {
x = args.<Integer>getOne(xKey).get();
z = args.<Integer>getOne(zKey).get();
} else {
x = lw.getBlockX();
z = lw.getBlockZ();
}
} else {
x = args.<Integer>getOne(xKey).get();
z = args.<Integer>getOne(zKey).get();
}
// Now, if we have an x and a z key, get the centre from that.
wp.setWorldBorderCenter(x, z);
Optional<World> world = Sponge.getServer().getWorld(wp.getUniqueId());
world.ifPresent(w -> w.getWorldBorder().setCenter(x, z));
wp.setWorldBorderCenter(x, z);
if (delay == 0) {
world.ifPresent(w -> w.getWorldBorder().setDiameter(dia));
wp.setWorldBorderDiameter(dia);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setborder.set", wp.getWorldName(), String.valueOf(x), String.valueOf(z), String.valueOf(dia)));
} else {
world.ifPresent(w -> w.getWorldBorder().setDiameter(dia, delay * 1000L));
wp.setWorldBorderTimeRemaining(delay * 1000L);
wp.setWorldBorderTargetDiameter(dia);
src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.world.setborder.setdelay", wp.getWorldName(), String.valueOf(x), String.valueOf(z), String.valueOf(dia), String.valueOf(delay)));
}
return CommandResult.success();
}
Aggregations