本文整理汇总了Java中org.spongepowered.api.world.difficulty.Difficulty类的典型用法代码示例。如果您正苦于以下问题:Java Difficulty类的具体用法?Java Difficulty怎么用?Java Difficulty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Difficulty类属于org.spongepowered.api.world.difficulty包,在下文中一共展示了Difficulty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
}
示例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 + "!");
}
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
示例7: getDifficulty
import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public Difficulty getDifficulty() {
return this.difficulty;
}
示例8: getDifficulty
import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public Difficulty getDifficulty() {
return this.worldConfig.getDifficulty();
}
示例9: getDifficulty
import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public Difficulty getDifficulty() {
return this.properties.getDifficulty();
}
示例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;
}
}
}
示例11: setDifficulty
import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
public void setDifficulty(Difficulty difficulty) {
this.difficulty = difficulty;
}
示例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();
}
示例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
}
}
示例14: getDifficulty
import org.spongepowered.api.world.difficulty.Difficulty; //导入依赖的package包/类
@Override
public Difficulty getDifficulty() {
return null;
}
示例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();
}