Search in sources :

Example 1 with LanternDifficulty

use of org.lanternpowered.server.world.difficulty.LanternDifficulty in project LanternServer by LanternPowered.

the class LanternWorldProperties method setDifficulty.

@Override
public void setDifficulty(Difficulty difficulty) {
    checkNotNull(difficulty, "difficulty");
    if (this.getDifficulty() != difficulty && this.world != null) {
        this.world.broadcast(() -> new MessagePlayOutSetDifficulty((LanternDifficulty) difficulty));
    }
    this.worldConfig.setDifficulty(difficulty);
}
Also used : LanternDifficulty(org.lanternpowered.server.world.difficulty.LanternDifficulty) MessagePlayOutSetDifficulty(org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetDifficulty)

Example 2 with LanternDifficulty

use of org.lanternpowered.server.world.difficulty.LanternDifficulty in project LanternServer by LanternPowered.

the class DifficultyRegistryModule method registerDefaults.

@Override
public void registerDefaults() {
    register(new LanternDifficulty("minecraft", "peaceful", 0));
    register(new LanternDifficulty("minecraft", "easy", 1));
    register(new LanternDifficulty("minecraft", "normal", 2));
    register(new LanternDifficulty("minecraft", "hard", 3));
}
Also used : LanternDifficulty(org.lanternpowered.server.world.difficulty.LanternDifficulty)

Example 3 with LanternDifficulty

use of org.lanternpowered.server.world.difficulty.LanternDifficulty 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();
    });
}
Also used : Difficulty(org.spongepowered.api.world.difficulty.Difficulty) LanternDifficulty(org.lanternpowered.server.world.difficulty.LanternDifficulty) LanternDifficulty(org.lanternpowered.server.world.difficulty.LanternDifficulty) ImmutableMap(com.google.common.collect.ImmutableMap) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Aggregations

LanternDifficulty (org.lanternpowered.server.world.difficulty.LanternDifficulty)3 ImmutableMap (com.google.common.collect.ImmutableMap)1 MessagePlayOutSetDifficulty (org.lanternpowered.server.network.vanilla.message.type.play.MessagePlayOutSetDifficulty)1 Difficulty (org.spongepowered.api.world.difficulty.Difficulty)1 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)1