use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class EventManager method onRespawnPlayerEvent2.
@Listener(order = Order.LAST)
public void onRespawnPlayerEvent2(RespawnPlayerEvent event) {
Player player = event.getTargetEntity();
if (player.hasPermission("pjw.override.gamemode")) {
return;
}
World from = event.getFromTransform().getExtent();
World to = event.getToTransform().getExtent();
WorldProperties properties = to.getProperties();
if (!from.equals(to)) {
if (properties.getGameRule("forceGamemode").get().equalsIgnoreCase("true")) {
if (!properties.getGameMode().equals(player.gameMode().get())) {
player.offer(Keys.GAME_MODE, properties.getGameMode());
}
}
}
}
use of org.spongepowered.api.world.storage.WorldProperties 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.storage.WorldProperties in project LanternServer by LanternPowered.
the class CommandDifficulty method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
final ImmutableMap.Builder<String, Object> baseBuilder = ImmutableMap.builder();
final ImmutableMap.Builder<String, Object> aliasesBuilder = ImmutableMap.builder();
for (Difficulty difficulty : Sponge.getRegistry().getAllOf(Difficulty.class)) {
baseBuilder.put(difficulty.getName(), difficulty);
aliasesBuilder.put(difficulty.getName().substring(0, 1), difficulty);
aliasesBuilder.put(((LanternDifficulty) difficulty).getInternalId() + "", difficulty);
}
specBuilder.arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), ChoicesElement.of(Text.of("difficulty"), baseBuilder.build(), aliasesBuilder.build(), false, true)).executor((src, args) -> {
WorldProperties world = CommandHelper.getWorldProperties(src, args);
Difficulty difficulty = args.<Difficulty>getOne("difficulty").get();
world.setDifficulty(difficulty);
src.sendMessage(t("commands.difficulty.success", difficulty.getName()));
return CommandResult.success();
});
}
use of org.spongepowered.api.world.storage.WorldProperties in project LanternServer by LanternPowered.
the class CommandTp method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(GenericArguments.optional(GenericArguments.player(Text.of("target"))), GenericArguments.firstParsing(GenericArguments.player(Text.of("destination")), GenericArguments.seq(/*
GenericArguments.flags()
.valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY),
"-world", "w")
.buildWith(GenericArguments.none()),
*/
GenericArguments.optional(GenericArguments.world(CommandHelper.WORLD_KEY)), GenericArguments2.targetedRelativeVector3d(Text.of("coordinates")), GenericArguments.optional(GenericArguments.seq(GenericArguments2.relativeDoubleNum(Text.of("y-rot")), GenericArguments2.relativeDoubleNum(Text.of("x-rot"))))))).executor((src, args) -> {
Player target = args.<Player>getOne("target").orElse(null);
if (target == null) {
if (!(src instanceof Player)) {
throw new CommandException(t("The target parameter is only optional for players."));
}
target = (Player) src;
}
final Optional<Player> optDestination = args.getOne("destination");
if (optDestination.isPresent()) {
final Player destination = optDestination.get();
target.setTransform(destination.getTransform());
src.sendMessage(t("commands.tp.success", target.getName(), destination.getName()));
} else {
final RelativeVector3d coords = args.<RelativeVector3d>getOne("coordinates").get();
final Transform<World> transform = target.getTransform();
World world = args.<WorldProperties>getOne(CommandHelper.WORLD_KEY).flatMap(p -> Lantern.getServer().getWorld(p.getUniqueId())).orElse(transform.getExtent());
Vector3d position = coords.applyToValue(transform.getPosition());
final Optional<RelativeDouble> optYRot = args.getOne("y-rot");
if (optYRot.isPresent()) {
final Vector3d rot = transform.getRotation();
double xRot = args.<RelativeDouble>getOne("x-rot").get().applyToValue(rot.getX());
double yRot = args.<RelativeDouble>getOne("y-rot").get().applyToValue(rot.getY());
double zRot = rot.getZ();
target.setLocationAndRotation(new Location<>(world, position), new Vector3d(xRot, yRot, zRot));
} else {
target.setLocation(new Location<>(world, position));
}
src.sendMessage(t("commands.tp.success.position", target.getName(), formatDouble(position.getX()), formatDouble(position.getY()), formatDouble(position.getZ()), world.getName()));
}
return CommandResult.success();
});
}
use of org.spongepowered.api.world.storage.WorldProperties 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);
}
Aggregations