use of org.spongepowered.api.world.storage.WorldProperties in project LanternServer by LanternPowered.
the class CommandSetSpawn method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
specBuilder.arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), GenericArguments.optional(GenericArguments2.targetedVector3d(Text.of("coordinates")))).executor((src, args) -> {
WorldProperties world = CommandHelper.getWorldProperties(src, args);
Vector3d position;
if (args.hasAny("coordinates")) {
position = args.<Vector3d>getOne("coordinates").get();
} else if (src instanceof Locatable) {
position = ((Locatable) src).getLocation().getPosition();
} else {
throw new CommandException(t("Non-located sources must specify coordinates."));
}
Vector3i position0 = position.toInt();
world.setSpawnPosition(position0);
src.sendMessage(t("commands.setworldspawn.success", position0.getX(), position0.getY(), position0.getZ()));
return CommandResult.success();
});
}
use of org.spongepowered.api.world.storage.WorldProperties in project LanternServer by LanternPowered.
the class CommandTime method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
final Map<String, Integer> presets = new HashMap<>();
presets.put("day", 1000);
presets.put("night", 13000);
specBuilder.arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none())).child(CommandSpec.builder().arguments(new CommandElement(Text.of("value")) {
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
final String input = args.next().toLowerCase();
// Try to use one of the presets first
if (presets.containsKey(input)) {
return presets.get(input);
}
try {
return Integer.parseInt(input);
} catch (NumberFormatException ex) {
throw args.createError(t("Expected an integer or a valid preset, but input '%s' was not", input));
}
}
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
final String prefix = args.nextIfPresent().orElse("");
return presets.keySet().stream().filter(new StartsWithPredicate(prefix)).collect(ImmutableList.toImmutableList());
}
}).executor((src, args) -> {
WorldProperties world = CommandHelper.getWorldProperties(src, args);
int time = args.<Integer>getOne("value").get();
world.setWorldTime(time);
src.sendMessage(t("commands.time.set", time));
return CommandResult.success();
}).build(), "set").child(CommandSpec.builder().arguments(GenericArguments.integer(Text.of("value"))).executor((src, args) -> {
WorldProperties world = CommandHelper.getWorldProperties(src, args);
int time = args.<Integer>getOne("value").get();
world.setWorldTime(world.getWorldTime() + time);
src.sendMessage(t("commands.time.added", time));
return CommandResult.success();
}).build(), "add").child(CommandSpec.builder().arguments(GenericArguments2.enumValue(Text.of("value"), QueryType.class)).executor((src, args) -> {
WorldProperties world = CommandHelper.getWorldProperties(src, args);
QueryType queryType = args.<QueryType>getOne("value").get();
int result;
switch(queryType) {
case DAYTIME:
result = (int) (world.getWorldTime() % Integer.MAX_VALUE);
break;
case GAMETIME:
result = (int) (world.getTotalTime() % Integer.MAX_VALUE);
break;
case DAY:
result = (int) (world.getTotalTime() / 24000);
break;
default:
throw new IllegalStateException("Unknown query type: " + queryType);
}
src.sendMessage(t("commands.time.query", result));
return CommandResult.builder().successCount(1).queryResult(result).build();
}).build(), "query");
}
use of org.spongepowered.api.world.storage.WorldProperties in project LanternServer by LanternPowered.
the class CommandGameRule method completeSpec.
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
final Collection<String> defaultRules = Sponge.getRegistry().getDefaultGameRules();
final ThreadLocal<RuleType<?>> currentRule = new ThreadLocal<>();
specBuilder.arguments(GenericArguments.flags().valueFlag(GenericArguments.world(CommandHelper.WORLD_KEY), "-world", "w").buildWith(GenericArguments.none()), new CommandElement(Text.of("rule")) {
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
RuleType<?> ruleType = RuleType.getOrCreate(args.next(), RuleDataTypes.STRING, "");
currentRule.set(ruleType);
return ruleType;
}
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
final String prefix = args.nextIfPresent().orElse("");
return defaultRules.stream().filter(new StartsWithPredicate(prefix)).collect(ImmutableList.toImmutableList());
}
}, new CommandElement(Text.of("value")) {
private final List<String> booleanRuleSuggestions = ImmutableList.of("true", "false");
@Nullable
@Override
protected Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException {
RuleType<?> ruleType = currentRule.get();
currentRule.remove();
try {
return ruleType.getDataType().parse(args.next());
} catch (IllegalArgumentException e) {
throw args.createError(t(e.getMessage()));
}
}
@Override
public List<String> complete(CommandSource src, CommandArgs args, CommandContext context) {
RuleType<?> ruleType = context.<RuleType<?>>getOne("rule").get();
if (ruleType.getDataType() == RuleDataTypes.BOOLEAN) {
// match the first part of the string
return this.booleanRuleSuggestions;
}
return Collections.emptyList();
}
}).executor((src, args) -> {
WorldProperties world = CommandHelper.getWorldProperties(src, args);
Object value = args.getOne("value").get();
RuleType ruleType = args.<RuleType>getOne("rule").get();
((LanternWorldProperties) world).getRules().getOrCreateRule(ruleType).setValue(value);
src.sendMessage(t("commands.gamerule.success", ruleType.getName(), ruleType.getDataType().serialize(value)));
return CommandResult.success();
});
}
use of org.spongepowered.api.world.storage.WorldProperties in project LanternServer by LanternPowered.
the class AbstractUser method setLocation.
@Override
public boolean setLocation(Vector3d position, UUID worldUniqueId) {
checkNotNull(position, "position");
checkNotNull(worldUniqueId, "worldUniqueId");
final WorldProperties world = Lantern.getServer().getWorldManager().getWorldProperties(worldUniqueId).orElseThrow(() -> new IllegalStateException("Cannot find World with the given UUID: " + worldUniqueId));
this.userWorld = (LanternWorldProperties) world;
setRawPosition(position);
return true;
}
use of org.spongepowered.api.world.storage.WorldProperties in project SpongeAPI by SpongePowered.
the class VoidWorldGeneratorModifier method modifyWorldGenerator.
@Override
public void modifyWorldGenerator(WorldProperties world, DataContainer settings, WorldGenerator worldGenerator) {
worldGenerator.getGenerationPopulators().clear();
worldGenerator.getPopulators().clear();
for (BiomeType biome : Sponge.getRegistry().getAllOf(BiomeType.class)) {
BiomeGenerationSettings biomeSettings = worldGenerator.getBiomeSettings(biome);
biomeSettings.getGenerationPopulators().clear();
biomeSettings.getPopulators().clear();
biomeSettings.getGroundCoverLayers().clear();
}
worldGenerator.setBaseGenerationPopulator((world1, buffer, biomes) -> {
});
worldGenerator.setBiomeGenerator(buffer -> buffer.getBiomeWorker().fill((x, y, z) -> BiomeTypes.VOID));
}
Aggregations