• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Difficulty类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongepowered.api.world.difficulty.Difficulty的典型用法代码示例。如果您正苦于以下问题:Java Difficulty类的具体用法?Java Difficulty怎么用?Java Difficulty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Difficulty类属于org.spongepowered.api.world.difficulty包,在下文中一共展示了Difficulty类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getCommand

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public static CommandSpec getCommand() {
    return CommandSpec.builder()
    .arguments(
        GenericArguments.string(Text.of("difficulty"))
    )
    .description(Text.of("Set difficulty for the current world."))
    .permission("bedrock.world.difficulty")
    .executor((source, args) -> {
        if (!(source instanceof Player)) {
            source.sendMessage(Format.error("Invalid player defined."));
            return CommandResult.empty();
        }

        Player player = (Player) source;
        String difficultyName = args.<String>getOne("difficulty").get();
        Optional<Difficulty> difficulty = Bedrock.getGame().getRegistry().getType(Difficulty.class, difficultyName);

        if (!difficulty.isPresent()) {
            source.sendMessage(Format.error("Invalid difficulty."));
            return CommandResult.empty();
        }

        player.getWorld().getProperties().setDifficulty(difficulty.get());

        return CommandResult.success();
    }).build();
}
 
开发者ID:prism,项目名称:Bedrock,代码行数:28,代码来源:DifficultyCommand.java


示例2: execute

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public void execute(CommandQueue queue, CommandEntry entry) {
    AbstractTagObject world = entry.getArgumentObject(queue, 0);
    WorldProperties properties;
    if (world instanceof WorldTag) {
        properties = ((WorldTag) world).getInternal().getProperties();
    }
    else {
        Optional<WorldProperties> opt = Sponge.getServer().getWorldProperties(world.toString());
        if (!opt.isPresent()) {
            queue.handleError(entry, "Invalid world specified!");
            return;
        }
        properties = opt.get();
    }
    String difficulty = entry.getArgumentObject(queue, 1).toString();
    Optional<Difficulty> type = Sponge.getRegistry().getType(Difficulty.class, difficulty);
    if (!type.isPresent()) {
        queue.handleError(entry, "Invalid difficulty level: '" + difficulty + "'!");
        return;
    }
    properties.setDifficulty(type.get());
    if (queue.shouldShowGood()) {
        queue.outGood("Set difficulty of world '" + ColorSet.emphasis + properties.getWorldName()
                + ColorSet.good + "' to: " + ColorSet.emphasis + type.get().getName() + ColorSet.good + "!");
    }
}
 
开发者ID:DenizenScript,项目名称:Denizen2Sponge,代码行数:28,代码来源:DifficultyCommand.java


示例3: LanternWorldArchetype

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
LanternWorldArchetype(String id, String name, GameMode gameMode, LanternDimensionType<?> dimensionType, @Nullable GeneratorType generatorType,
        Collection<WorldGeneratorModifier> generatorModifiers, @Nullable DataContainer generatorSettings, Difficulty difficulty,
        SerializationBehavior serializationBehavior, LanternPortalAgentType portalAgentType, boolean hardcore, boolean enabled,
        boolean loadsOnStartup, @Nullable Boolean keepsSpawnLoaded, boolean usesMapFeatures, boolean pvpEnabled, boolean generateBonusChest,
        boolean commandsAllowed, @Nullable Boolean waterEvaporates, @Nullable Boolean allowPlayerRespawns, boolean generateSpawnOnLoad,
        boolean isSeedRandomized, long seed, int buildHeight) {
    this.serializationBehavior = serializationBehavior;
    this.generateSpawnOnLoad = generateSpawnOnLoad;
    this.allowPlayerRespawns = allowPlayerRespawns;
    this.generatorModifiers = generatorModifiers;
    this.generatorSettings = generatorSettings;
    this.generateBonusChest = generateBonusChest;
    this.keepsSpawnLoaded = keepsSpawnLoaded;
    this.usesMapFeatures = usesMapFeatures;
    this.portalAgentType = portalAgentType;
    this.commandsAllowed = commandsAllowed;
    this.waterEvaporates = waterEvaporates;
    this.loadsOnStartup = loadsOnStartup;
    this.dimensionType = dimensionType;
    this.generatorType = generatorType;
    this.isSeedRandomized = isSeedRandomized;
    this.buildHeight = buildHeight;
    this.pvpEnabled = pvpEnabled;
    this.difficulty = difficulty;
    this.hardcore = hardcore;
    this.gameMode = gameMode;
    this.enabled = enabled;
    this.name = name;
    this.seed = seed;
    this.id = id;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:32,代码来源:LanternWorldArchetype.java


示例4: setDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@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);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternWorldProperties.java


示例5: execute

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    World w = args.<World>getOne("world").get();
    Difficulty dif = args.<Difficulty>getOne("difficulty").get();
    w.getProperties().setDifficulty(dif);
    Messages.send(src, "world.command.world.setdifficulty.success", "%world%", w.getName(), "%difficulty%", dif.getName());
    return CommandResult.success();
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:9,代码来源:SetdifficultyWorldCommand.java


示例6: getDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public Optional<Difficulty> getDifficulty() {
    Collection<Difficulty> types = Sponge.getRegistry().getAllOf(Difficulty.class);
    return types.stream().filter(g -> g.getId().equalsIgnoreCase(difficulty) || g.getName().equalsIgnoreCase(difficulty)).findAny();
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:5,代码来源:BaseWorldRequest.java


示例7: getDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public Difficulty getDifficulty() {
    return this.difficulty;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:LanternWorldArchetype.java


示例8: getDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public Difficulty getDifficulty() {
    return this.worldConfig.getDifficulty();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternWorldProperties.java


示例9: getDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public Difficulty getDifficulty() {
    return this.properties.getDifficulty();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternWorld.java


示例10: pulseFood

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
private void pulseFood() {
    if (!supports(FoodData.class) || get(Keys.GAME_MODE).orElse(GameModes.NOT_SET).equals(GameModes.CREATIVE)) {
        return;
    }
    final Difficulty difficulty = getWorld().getDifficulty();

    MutableBoundedValue<Double> exhaustion = getValue(Keys.EXHAUSTION).get();
    MutableBoundedValue<Double> saturation = getValue(Keys.SATURATION).get();
    MutableBoundedValue<Integer> foodLevel = getValue(Keys.FOOD_LEVEL).get();

    if (exhaustion.get() > 4.0) {
        if (saturation.get() > saturation.getMinValue()) {
            offer(Keys.SATURATION, Math.max(saturation.get() - 1.0, saturation.getMinValue()));
            // Get the updated saturation
            saturation = getValue(Keys.SATURATION).get();
        } else if (!difficulty.equals(Difficulties.PEACEFUL)) {
            offer(Keys.FOOD_LEVEL, Math.max(foodLevel.get() - 1, foodLevel.getMinValue()));
            // Get the updated food level
            foodLevel = getValue(Keys.FOOD_LEVEL).get();
        }
        offer(Keys.EXHAUSTION, Math.max(exhaustion.get() - 4.0, exhaustion.getMinValue()));
        exhaustion = getValue(Keys.EXHAUSTION).get();
    }

    final boolean naturalRegeneration = getWorld().getOrCreateRule(RuleTypes.NATURAL_REGENERATION).getValue();
    final long currentTickTime = LanternGame.currentTimeTicks();

    if (naturalRegeneration && saturation.get() > saturation.getMinValue() && foodLevel.get() >= foodLevel.getMaxValue()) {
        if ((currentTickTime - this.lastFoodTickTime) >= 10) {
            final double amount = Math.min(saturation.get(), 6.0);
            heal(amount / 6.0, HealingSources.FOOD);
            offer(Keys.EXHAUSTION, Math.min(exhaustion.get() + amount, exhaustion.getMaxValue()));
            this.lastFoodTickTime = currentTickTime;
        }
    } else if (naturalRegeneration && foodLevel.get() >= 18) {
        if ((currentTickTime - this.lastFoodTickTime) >= 80) {
            heal(1.0, HealingSources.FOOD);
            offer(Keys.EXHAUSTION, Math.min(6.0 + exhaustion.get(), exhaustion.getMaxValue()));
            this.lastFoodTickTime = currentTickTime;
        }
    } else if (foodLevel.get() <= foodLevel.getMinValue()) {
        if ((currentTickTime - this.lastFoodTickTime) >= 80) {
            final double health = get(Keys.HEALTH).orElse(20.0);
            if ((health > 10.0 && difficulty.equals(Difficulties.EASY))
                    || (health > 1.0 && difficulty.equals(Difficulties.NORMAL))
                    || difficulty.equals(Difficulties.HARD)) {
                damage(1.0, DamageSources.STARVATION);
            }
            this.lastFoodTickTime = currentTickTime;
        }
    } else {
        this.lastFoodTickTime = currentTickTime;
    }

    // Peaceful restoration
    if (naturalRegeneration && difficulty.equals(Difficulties.PEACEFUL)) {
        if (currentTickTime - this.lastPeacefulHealthTickTime >= 20) {
            heal(1.0, HealingSources.MAGIC);
            this.lastPeacefulHealthTickTime = currentTickTime;
        }

        final int oldFoodLevel = get(Keys.FOOD_LEVEL).orElse(0);
        if (currentTickTime - this.lastPeacefulFoodTickTime >= 10
                && oldFoodLevel < get(LanternKeys.MAX_FOOD_LEVEL).orElse(20)) {
            offer(Keys.FOOD_LEVEL, oldFoodLevel + 1);
            this.lastPeacefulFoodTickTime = currentTickTime;
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:70,代码来源:LanternLiving.java


示例11: setDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public void setDifficulty(Difficulty difficulty) {
    this.difficulty = difficulty;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:WorldConfig.java


示例12: execute

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	String name = ctx.<String> getOne("name").get();
	String dimensionInput = ctx.<String> getOne("dimension").get();
	String generatorInput = ctx.<String> getOne("generator").get();
	String difficultyInput = ctx.<String> getOne("difficulty").get();
	GameMode gamemode = ctx.<GameMode> getOne("gamemode").get();
	Difficulty difficulty = null;
	DimensionType dimension = null;
	GeneratorType generator = null;

	if (Sponge.getRegistry().getType(DimensionType.class, dimensionInput).isPresent())
	{
		dimension = Sponge.getRegistry().getType(DimensionType.class, dimensionInput).get();
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Dimension type specified not found."));
		return CommandResult.success();
	}

	if (Sponge.getRegistry().getType(GeneratorType.class, generatorInput).isPresent())
	{
		generator = Sponge.getRegistry().getType(GeneratorType.class, generatorInput).get();
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Generator type specified not found."));
		return CommandResult.success();
	}

	if (Sponge.getRegistry().getType(Difficulty.class, difficultyInput).isPresent())
	{
		difficulty = Sponge.getRegistry().getType(Difficulty.class, difficultyInput).get();
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Difficulty specified not found."));
		return CommandResult.success();
	}

	src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Beginning creation of world."));

	WorldArchetype worldSettings = WorldArchetype.builder()
		.enabled(true)
		.loadsOnStartup(true)
		.keepsSpawnLoaded(true)
		.dimension(dimension)
		.generator(generator)
		.gameMode(gamemode)
		.build(name.toLowerCase(), name);

	try
	{
		WorldProperties worldProperties = Sponge.getGame().getServer().createWorldProperties(name, worldSettings);
		Optional<World> world = Sponge.getGame().getServer().loadWorld(worldProperties);

		if (world.isPresent())
		{
			world.get().getProperties().setDifficulty(difficulty);
			src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.GOLD, "World ", TextColors.GRAY, name, TextColors.GOLD, " has been created."));
		}
		else
		{
			src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world could not be created."));
		}
	}
	catch (IOException e)
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "The world properties could not be created."));
	}

	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:75,代码来源:WorldsBase.java


示例13: create

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Command(desc = "Creates a new world")
public void create(CommandSource context,
                   String name,
                   @Default @Named({"dimension", "dim"}) DimensionType dimension,
                   @Named("seed") String seed,
                   @Default @Named({"type"}) GeneratorType type,
                   @Default @Label("generate") @Named({"structure", "struct"}) boolean generateStructures,
                   @Default @Named({"gamemode", "mode"}) GameMode gamemode,
                   @Default @Named({"difficulty", "diff"}) Difficulty difficulty,
                   @org.cubeengine.butler.parametric.Optional @Label("name") @Named({"generator","gen"}) WorldGeneratorModifier generator,
                   @Flag boolean recreate,
                   @Flag boolean noload,
                   @Flag boolean spawnInMemory)
{
    Optional<World> world = Sponge.getServer().getWorld(name);
    if (world.isPresent())
    {
        if (recreate)
        {
            i18n.send(context, NEGATIVE, "You have to unload a world before recreating it!");
            return;
        }
        i18n.send(context, NEGATIVE, "A world named {world} already exists and is loaded!", world.get());
        return;
    }
    Optional<WorldProperties> worldProperties = Sponge.getServer().getWorldProperties(name);
    if (worldProperties.isPresent())
    {
        if (!recreate)
        {
            i18n.send(context, NEGATIVE, "A world named {name#world} already exists but is not loaded!", name);
            return;
        }
        worldProperties.get().setEnabled(false);
        String newName = name + "_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
        Sponge.getServer().renameWorld(worldProperties.get(), newName);
        i18n.send(context, POSITIVE, "Old world moved to {name#folder}", newName);
    }

    WorldArchetype.Builder builder = WorldArchetype.builder().from(WorldArchetypes.OVERWORLD);
    builder.keepsSpawnLoaded(spawnInMemory);
    builder.loadsOnStartup(!noload);
    if (seed != null)
    {
        try
        {
            builder.seed(Long.parseLong(seed));
        }
        catch (NumberFormatException ignore)
        {
            builder.seed(seed.hashCode());
        }
    }

    builder.generator(type);
    builder.dimension(dimension);
    builder.usesMapFeatures(generateStructures);
    builder.gameMode(gamemode);
    if (generator != null)
    {
        builder.generatorModifiers(generator);
    }
    builder.difficulty(difficulty);
    try
    {
        WorldProperties properties = Sponge.getServer().createWorldProperties(name, builder.build("org.cubeengine.customworld:" + UUID.randomUUID().toString(), name));
        i18n.send(context, POSITIVE, "World {name} successfully created!", name);
        i18n.send(context, NEUTRAL, "This world is not yet loaded! Click {txt#here} to load.",
                i18n.translate(context, TextFormat.NONE, "here").toBuilder().onClick(TextActions.runCommand("/worlds load " + name)).build());
    }
    catch (IOException e)
    {
        i18n.send(context, NEGATIVE, "Could not create world!");
        throw new IllegalStateException(e); // TODO handle exception better
    }
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:77,代码来源:WorldsCommands.java


示例14: getDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public Difficulty getDifficulty() {
    return null;
}
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:5,代码来源:ServerWorldProperties.java


示例15: execute

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource sender, CommandContext args) throws CommandException {
    String name = (String) args.getOne("name").get();
    Optional<DimensionType> dimension = args.getOne("dimension");
    Optional<GeneratorType> generator = args.getOne("generator");
    Collection<WorldGeneratorModifier> wgm = args.getAll("wgm");
    Optional<Long> seed = args.getOne("seed");
    Optional<GameMode> gm = args.getOne("gamemode");
    Optional<Difficulty> diff = args.getOne("difficulty");

    boolean nostructures = args.hasAny("n");
    boolean load = args.<Boolean>getOne("l").orElse(true);
    boolean keepspawnloaded = args.<Boolean>getOne("k").orElse(true);
    boolean allowcommands = args.<Boolean>getOne("c").orElse(true);
    boolean bonuschest = args.<Boolean>getOne("b").orElse(true);

    Path path = Sponge.getGame().getSavesDirectory();
    if (Files.exists(path.resolve(name.toLowerCase())) || Files.exists(path.resolve(name)) || Sponge.getServer().getAllWorldProperties().stream().anyMatch(x -> x.getWorldName().equalsIgnoreCase(name))) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "world.exists", "%name%", name));
    }

    Messages.send(sender, "world.command.world.create.starting", "%name%", name);

    WorldArchetype.Builder archetype = WorldArchetype.builder().enabled(true);
    dimension.ifPresent(archetype::dimension);
    generator.ifPresent(archetype::generator);
    archetype.generatorModifiers(wgm.toArray(new WorldGeneratorModifier[wgm.size()]));
    seed.ifPresent(archetype::seed);
    gm.ifPresent(archetype::gameMode);
    diff.ifPresent(archetype::difficulty);
    archetype.usesMapFeatures(!nostructures);
    archetype.loadsOnStartup(load);
    archetype.keepsSpawnLoaded(keepspawnloaded);
    archetype.commandsAllowed(allowcommands);
    archetype.generateBonusChest(bonuschest);

    WorldProperties props;
    try {
        props = Sponge.getServer().createWorldProperties(name.toLowerCase(), archetype.build(name.toLowerCase(), name));
    } catch (IOException e) {
        throw new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.create.fileerror", "%error%", e.getMessage()));
    }
    Sponge.getServer().saveWorldProperties(props);
    World world = Sponge.getServer().loadWorld(props).orElseThrow(() -> new ErrorMessageException(Messages.getFormatted(sender, "world.command.world.create.loaderror")));
    Messages.send(sender, "world.command.world.create.success", "%name%", world.getName());
    return CommandResult.success();
}
 
开发者ID:Bammerbom,项目名称:UltimateCore,代码行数:48,代码来源:CreateWorldCommand.java


示例16: of

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public static Difficulty of(org.bukkit.Difficulty biome) {
    return CONVERTER.convert(biome);
}
 
开发者ID:LapisBlue,项目名称:Pore,代码行数:4,代码来源:DifficultyConverter.java


示例17: setDifficulty

import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override public void setDifficulty(Difficulty difficulty) {

    }
 
开发者ID:InspireNXE,项目名称:Pulse,代码行数:4,代码来源:ServerWorldProperties.java



注:本文中的org.spongepowered.api.world.difficulty.Difficulty类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Color类代码示例发布时间:2022-05-22
下一篇:
Java BasicCounter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap