Search in sources :

Example 1 with Difficulty

use of org.spongepowered.api.world.difficulty.Difficulty in project ProjectWorlds by trentech.

the class CommandCreate method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("create")) {
        throw new CommandException(getHelp().getUsageText());
    }
    String[] args = arguments.split(" ");
    if (args[args.length - 1].equalsIgnoreCase("--help")) {
        help.execute(source);
        return CommandResult.success();
    }
    String worldName;
    try {
        worldName = args[0];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    if (Sponge.getServer().getWorldProperties(worldName).isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, worldName, " already exists"), false);
    }
    WorldArchetype.Builder builder = WorldArchetype.builder();
    List<WorldGeneratorModifier> modifiers = new ArrayList<>();
    if (args.length > 2) {
        boolean skip = false;
        for (int i = 1; i < args.length - 1; i++) {
            if (skip) {
                skip = false;
                continue;
            }
            String arg = args[i];
            String value;
            try {
                value = args[i + 1];
            } catch (Exception e) {
                throw new CommandException(getHelp().getUsageText());
            }
            if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("-dimension")) {
                Optional<DimensionType> optionalDimension = Sponge.getRegistry().getType(DimensionType.class, value);
                if (!optionalDimension.isPresent()) {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid DimensionType"));
                    throw new CommandException(getHelp().getUsageText());
                }
                builder.dimension(optionalDimension.get());
            } else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("-generator")) {
                String[] split = value.split("\\{");
                Optional<GeneratorType> optionalGenerator = Sponge.getRegistry().getType(GeneratorType.class, split[0]);
                if (!optionalGenerator.isPresent()) {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid GeneratorType"));
                    throw new CommandException(getHelp().getUsageText());
                }
                builder.generator(optionalGenerator.get());
                if (split.length == 2) {
                    builder.generatorSettings(DataContainer.createNew().set(DataQuery.of("customSettings"), split[1].replace("\\}", "")));
                }
            } else if (arg.equalsIgnoreCase("-gm") || arg.equalsIgnoreCase("-gamemode")) {
                Optional<GameMode> optionalGamemode = Optional.empty();
                try {
                    optionalGamemode = Gamemode.get(Integer.parseInt(value));
                } catch (Exception e) {
                    optionalGamemode = Gamemode.get(value);
                }
                if (!optionalGamemode.isPresent()) {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid GameMode"));
                    throw new CommandException(getHelp().getUsageText());
                }
                builder.gameMode(optionalGamemode.get());
            } else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("-modifier")) {
                Optional<WorldGeneratorModifier> optionalModifier = Sponge.getRegistry().getType(WorldGeneratorModifier.class, value);
                if (!optionalModifier.isPresent()) {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid WorldGeneratorModifier"));
                    throw new CommandException(getHelp().getUsageText());
                }
                modifiers.add(optionalModifier.get());
            } else if (arg.equalsIgnoreCase("-s") || arg.equalsIgnoreCase("-seed")) {
                try {
                    Long s = Long.parseLong(value);
                    builder.seed(s);
                } catch (Exception e) {
                    builder.seed(value.hashCode());
                }
            } else if (arg.equalsIgnoreCase("-df") || arg.equalsIgnoreCase("-difficulty")) {
                Optional<Difficulty> optionalDifficulty = Sponge.getRegistry().getType(Difficulty.class, value);
                if (!optionalDifficulty.isPresent()) {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Difficulty"));
                    throw new CommandException(getHelp().getUsageText());
                }
                builder.difficulty(optionalDifficulty.get());
            } else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup")) {
                if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
                    builder.loadsOnStartup(Boolean.valueOf(value));
                } else {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
                    throw new CommandException(getHelp().getUsageText());
                }
            } else if (arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded")) {
                if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
                    builder.keepsSpawnLoaded(Boolean.valueOf(value));
                } else {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
                    throw new CommandException(getHelp().getUsageText());
                }
            } else if (arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands")) {
                if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
                    builder.commandsAllowed(Boolean.valueOf(value));
                } else {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
                    throw new CommandException(getHelp().getUsageText());
                }
            } else if (arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest")) {
                if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
                    builder.generateBonusChest(Boolean.valueOf(value));
                } else {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
                    throw new CommandException(getHelp().getUsageText());
                }
            } else if (arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
                if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("false")) {
                    builder.usesMapFeatures(Boolean.valueOf(value));
                } else {
                    source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Boolean"));
                    throw new CommandException(getHelp().getUsageText());
                }
            } else {
                source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid Flag"));
                throw new CommandException(getHelp().getUsageText());
            }
            skip = true;
        }
    }
    WorldArchetype settings = builder.enabled(true).keepsSpawnLoaded(true).loadsOnStartup(true).build(worldName, worldName);
    WorldProperties properties;
    try {
        properties = Sponge.getServer().createWorldProperties(worldName, settings);
        properties.setGeneratorModifiers(modifiers);
    } catch (IOException e) {
        e.printStackTrace();
        throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
    }
    Sponge.getServer().saveWorldProperties(properties);
    worlds.add(worldName);
    source.sendMessage(Text.of(TextColors.DARK_GREEN, worldName, " created successfully"));
    return CommandResult.success();
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType) Optional(java.util.Optional) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) ArrayList(java.util.ArrayList) CommandException(org.spongepowered.api.command.CommandException) IOException(java.io.IOException) IOException(java.io.IOException) CommandException(org.spongepowered.api.command.CommandException) GeneratorType(org.spongepowered.api.world.GeneratorType) GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) WorldArchetype(org.spongepowered.api.world.WorldArchetype) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 2 with Difficulty

use of org.spongepowered.api.world.difficulty.Difficulty in project ProjectWorlds by trentech.

the class Common method initHelp.

public static void initHelp() {
    Usage usageCopy = new Usage(Argument.of("<oldWorld>", "Specifies the name of world you want to copy")).addArgument(Argument.of("<newWorld>", "Enter the name of the new world"));
    Help worldCopy = new Help("world copy", "copy", "Allows you to make a new world from an existing world").setPermission("pjw.cmd.world.copy").setUsage(usageCopy).addExample("/world copy srcWorld newWorld");
    String dimTypes = null;
    for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
        if (dimTypes == null) {
            dimTypes = type.getId();
        } else {
            dimTypes = dimTypes + "\n" + type.getId();
        }
    }
    String genTypes = null;
    for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
        if (genTypes == null) {
            genTypes = type.getId();
        } else {
            genTypes = genTypes + "\n" + type.getId();
        }
    }
    String modTypes = null;
    for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
        if (modTypes == null) {
            modTypes = type.getId();
        } else {
            modTypes = modTypes + "\n" + type.getId();
        }
    }
    String gameModes = null;
    for (Gamemode type : Gamemode.values()) {
        if (gameModes == null) {
            gameModes = type.getGameMode().getName() + " -or- " + type.getIndex();
        } else {
            gameModes = gameModes + "\n" + type.getGameMode().getName() + " -or- " + type.getIndex();
        }
    }
    String difficulties = null;
    for (Difficulty type : Sponge.getRegistry().getAllOf(Difficulty.class)) {
        if (difficulties == null) {
            difficulties = type.getId();
        } else {
            difficulties = difficulties + "\n" + type.getId();
        }
    }
    Usage usageCreate = new Usage(Argument.of("<world>", "Specifies the name of the world")).addArgument(Argument.of("[-d <dimensionType>]", dimTypes)).addArgument(Argument.of("[-g <generatorType>]", genTypes)).addArgument(Argument.of("[-m <modifier>]", modTypes)).addArgument(Argument.of("[-df <difficulty>]", difficulties)).addArgument(Argument.of("[-gm <gameMode>]", gameModes)).addArgument(Argument.of("[-s <seed>]", "Sets the seed. If not specified this will default to using a random seed.")).addArgument(Argument.of("[-l <true|false>]", "Sets whether to load when the server starts. Default is true")).addArgument(Argument.of("[-k <true|false>]", "Sets whether the spawn chunks should remain loaded when no players are present. Default is true")).addArgument(Argument.of("[-b <true|false>]", "Set whether to generator bonus chest. Default is false")).addArgument(Argument.of("[-c <true|false>]", "Sets whether commands are allowed to be executed. Default is true")).addArgument(Argument.of("[-f <true|false>]", "Sets whether this world will generate map features such as villages and strongholds. Default is true"));
    Help worldCreate = new Help("world create", "create", "Allows you to creating new worlds with a combination of features. This does not automatically load newly created worlds.").setPermission("pjw.cmd.world.create").setUsage(usageCreate).addExample("/world create NewWorld -d minecraft:overworld -g minecraft:overworld").addExample("/world create NewWorld -g minecraft:flat{3;30*minecraft:bedrock;1}").addExample("/world create NewWorld -d sponge:nether -m sponge:skylands").addExample("/world create NewWorld -s -12309830198412353456");
    Usage usageModifier = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("<modifier>", modTypes)).addArgument(Argument.of("[-r]", "Adding this flag removes the specified modifier from the given world"));
    Help worldModifier = new Help("world modifier", "modifier", "Allows you to add or remove WorldGeneratorModifier's from the given world. This will have no effect on existing chunks only ungenerated chunks.").setPermission("pjw.cmd.world.modifier").setUsage(usageModifier).addExample("/world modifier World sponge:void").addExample("/world modifier World sponge:skylands -s");
    Usage usageRemove = new Usage(Argument.of("<world>", "Specifies the targetted world"));
    Help worldRemove = new Help("world remove", "remove", "Delete worlds you no longer need. Worlds must be unloaded before you can delete them").setPermission("pjw.cmd.world.remove").setUsage(usageRemove).addExample("/world remove OldWorld");
    Usage usageDifficulty = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[difficulty]", difficulties));
    Help worldDifficulty = new Help("world difficulty", "difficulty", "Set the difficulty level for each world").setPermission("pjw.cmd.world.difficulty").setUsage(usageDifficulty).addExample("/world difficulty MyWorld HARD").addExample("/world difficulty MyWorld");
    Usage usageEnable = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[true|false]"));
    Help worldEnable = new Help("world enable", "enable", "Enable and disable worlds from loading").setPermission("pjw.cmd.world.enable").setUsage(usageEnable).addExample("/world enable MyWorld false").addExample("/world enable MyWorld true");
    Help worldUseMapFeatures = new Help("world usemapfeatures", "usemapfeatures", "Sets whether this world will generate map features such as villages and strongholds").setPermission("pjw.cmd.world.usemapfeatures").setUsage(usageEnable).addExample("/world usemapfeatures MyWorld false").addExample("/world usemapfeatures MyWorld true");
    Usage usageFill = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("<diameter>", "Set the diameter of the world border or enter 'stop' to cancel already running process. The specified diameter applies to the x and z axis. The world border extends over the entire y-axis")).addArgument(Argument.of("[interval]", "Sets the interval between generation runs. Must be greater than 0. Default is 10."));
    Help worldFill = new Help("world fill", "fill", "Pre generate chunks in a world outwards from center spawn").setPermission("pjw.cmd.world.fill").setUsage(usageFill).addExample("/world fill MyWorld stop").addExample("/world fill MyWorld 1000");
    Usage usageGamemode = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[gamemode]", gameModes));
    Help worldGamemode = new Help("world gamemode", "gamemode", "Change gamemode of the specified world").setPermission("pjw.cmd.world.gamemode").setUsage(usageGamemode).addExample("/world gamemode MyWorld SURVIVAL").addExample("/world gamemode");
    Usage usageGamerule = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[rule]", "Specifies the game rule to set or query. May be any value, but only certain predefined game rules will affect gameplay.")).addArgument(Argument.of("[value]", "Specifies the value to set the game rule to. May be any value, though only true or false specified for predefined game rules will actually affect gameplay, except in the case of randomTickSpeed and spawnRadius, where any integer 0 or greater will affect gameplay"));
    Help worldGamerule = new Help("world gamerule", "gamerule", " Configure varies world properties").setPermission("pjw.cmd.world.gamerule").setUsage(usageGamerule).addExample("/world gamerule MyWorld mobGriefing false").addExample("/world gamerule MyWorld");
    Help worldHardcore = new Help("world hardcore", "hardcore", "Toggle on and off hardcore mode for world").setPermission("pjw.cmd.world.hardcore").setUsage(usageEnable).addExample("/world hardcore MyWorld false").addExample("/world hardcore MyWorld");
    Usage usageTime = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[time]", "Sets the time of day, in ticks. The total number of ticks in a day is 24000, however this value does not reset to zero at the start of each day but rather keeps counting passed 24000."));
    Help worldTime = new Help("world time", "time", "Set the time of world").setPermission("pjw.cmd.world.time").setUsage(usageTime).addExample("/world time MyWorld 6000").addExample("/world time MyWorld");
    Usage usageWeather = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[clear|rain|thunder]", "clear: Set the weather to clear, rain: Set the weather to rain (or snow in cold biomes), thunder: Set the weather to a thunderstorm (or a thunder snowstorm in cold biomes)")).addArgument(Argument.of("[duration]", "Specifies the duration the set weather will occur."));
    Help worldWeather = new Help("world weather", "weather", "Set the weather of world").setPermission("pjw.cmd.world.weather").setUsage(usageWeather).addExample("/world weather MyWorld clear").addExample("/world weather MyWorld");
    Usage usageImport = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("<dimensionType>", dimTypes)).addArgument(Argument.of("<generatorType>", genTypes)).addArgument(Argument.of("[modifer]", modTypes));
    Help worldImport = new Help("world import", "import", "Import worlds not native to Sponge").setPermission("pjw.cmd.world.import").setUsage(usageImport).addExample("/world import NewWorld minecraft:overworld overworld sponge:void").addExample("/world import NewWorld minecraft:overworld overworld");
    Help worldKeepSpawnLoaded = new Help("world keepspawnloaded", "keepspawnloaded", "Keeps spawn point of world loaded in memory").setPermission("pjw.cmd.world.keepspawnloaded").setUsage(usageEnable).addExample("/world keepspawnloaded MyWorld true").addExample("/world keepspawnloaded MyWorld");
    Help worldLoadOnStartup = new Help("world loadonstartup", "loadonstartup", "Set whether to load world on startup").setPermission("pjw.cmd.world.loadonstartup").setUsage(usageEnable).addExample("/world loadonstartup MyWorld true").addExample("/world loadonstartup MyWorld");
    Help worldList = new Help("world list", "list", "Lists all known worlds, loaded or unloaded").setPermission("pjw.cmd.world.list");
    Usage usageLoad = new Usage(Argument.of("<world>", "Specifies the targetted world"));
    Help worldLoad = new Help("world load", "load", "Loads sepcified world. If world is a non Sponge created world you will need  to /world import").setPermission("pjw.cmd.world.load").setUsage(usageLoad).addExample("/world load BukkitWorld overworld").addExample("/world load NewWorld");
    Help worldProperties = new Help("world properties", "properties", "View all properties associated with a world").setPermission("pjw.cmd.world.properties").setUsage(usageLoad).addExample("/world properties MyWorld").addExample("/world properties");
    Help worldPvp = new Help("world pvp", "pvp", "Toggle on and off pvp for world").setPermission("pjw.cmd.world.pvp").setUsage(usageEnable).addExample("/world pvp MyWorld true").addExample("/world pvp MyWorld");
    Usage usageRegen = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[true|false]", "Set whether or not to preserve the seed. Default value is 'true'")).addArgument(Argument.of("[seed]", "Specifies a seed. Optional. Random seed is chosen if previous argument is false and this is not set"));
    Help worldRegen = new Help("world regen", "regen", "Regenerates a world. You can preserve seed by setting true (true is default if none specified), or generate a new seed, random or specified").setPermission("pjw.cmd.world.regen").setUsage(usageRegen).addExample("/world regen MyWorld true").addExample("/world regen MyWorld false 3700507149557916849");
    Usage usageRename = new Usage(Argument.of("<srcWorld>", "Specifies the targetted world")).addArgument(Argument.of("<newWorld>", "Specifies the new world name"));
    Help worldRename = new Help("world rename", "rename", "Allows for renaming worlds. World must be unloaded before you can rename world").setPermission("pjw.cmd.world.rename").setUsage(usageRename).addExample("/world rename MyWorld NewWorldName");
    Usage usageSetSpawn = new Usage(Argument.of("[<world>", "Specifies the targetted world")).addArgument(Argument.of("[x,y,z]]", "Specifies the coordinates to set spawn to. x and z must fall within the range -30,000,000 to 30,000,000 (exclusive, without the commas), and y must be within the range -4096 to 4096 inclusive."));
    Help worldSetSpawn = new Help("world setspawn", "setspawn", "Sets the spawn point of specified world. If no arguments present sets spawn of current world to player location").setPermission("pjw.cmd.world.setspawn").setUsage(usageSetSpawn).addExample("/world setspawn MyWorld -153,75,300").addExample("/world setspawn");
    Usage usageTeleport = new Usage(Argument.of("<world>", "Specifies the targetted world")).addArgument(Argument.of("[-c <x,y,z>]", "Specifies the coordinates to teleport to. x and z must fall within the range -30,000,000 to 30,000,000 (exclusive, without the commas), and y must be within the range -4096 to 4096 inclusive. Set to 'random' to teleport to random location")).addArgument(Argument.of("[-d <direction>]", "Specifies the direction player will face upon teleporting. The following can be used: NORTH, NORTH_WEST, WEST, SOUTH_WEST, SOUTH, SOUTH_EAST, EAST, NORTH_EAST")).addArgument(Argument.of("[-f]", "Skip safe location check. This flag has no effect with '-c random'"));
    Help worldTeleport = new Help("world teleport", "teleport", "Teleport to specified world and location").setPermission("pjw.cmd.world.teleport").setUsage(usageTeleport).addExample("/world teleport MyWorld -c -153,75,300 -d WEST").addExample("/world teleport MyWorld -c -153,75,300").addExample("/world teleport MyWorld").addExample("/world teleport MyWorld -f");
    Help worldUnload = new Help("world unload", "unload", "Unloads specified world. If players are in world, they will be teleported to default spawn").setPermission("pjw.cmd.world.unload").setUsage(usageLoad).addExample("/world unload MyWorld");
    Help world = new Help("world", "world", "Base Project Worlds command").setPermission("pjw.cmd.world").addChild(worldUnload).addChild(worldTeleport).addChild(worldSetSpawn).addChild(worldRename).addChild(worldRegen).addChild(worldPvp).addChild(worldProperties).addChild(worldLoad).addChild(worldList).addChild(worldKeepSpawnLoaded).addChild(worldUseMapFeatures).addChild(worldImport).addChild(worldHardcore).addChild(worldGamerule).addChild(worldGamemode).addChild(worldFill).addChild(worldEnable).addChild(worldDifficulty).addChild(worldRemove).addChild(worldCreate).addChild(worldCopy).addChild(worldTime).addChild(worldWeather).addChild(worldLoadOnStartup).addChild(worldModifier);
    Help.register(world);
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType) Usage(com.gmail.trentech.pjc.help.Usage) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) Help(com.gmail.trentech.pjc.help.Help) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) Gamemode(com.gmail.trentech.pjw.utils.Gamemode) GeneratorType(org.spongepowered.api.world.GeneratorType)

Example 3 with Difficulty

use of org.spongepowered.api.world.difficulty.Difficulty in project LanternServer by LanternPowered.

the class LanternLiving method pulseFood.

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;
        }
    }
}
Also used : Difficulty(org.spongepowered.api.world.difficulty.Difficulty)

Example 4 with Difficulty

use of org.spongepowered.api.world.difficulty.Difficulty in project SpongeCommon by SpongePowered.

the class LevelStemMixin method bridge$populateFromLevelData.

@Override
public void bridge$populateFromLevelData(final PrimaryLevelData levelData) {
    final PrimaryLevelDataBridge levelDataBridge = (PrimaryLevelDataBridge) levelData;
    this.impl$gameMode = (ResourceLocation) (Object) RegistryTypes.GAME_MODE.get().valueKey((GameMode) (Object) levelData.getGameType());
    this.impl$difficulty = (ResourceLocation) (Object) RegistryTypes.DIFFICULTY.get().valueKey((Difficulty) (Object) levelData.getDifficulty());
    this.impl$serializationBehavior = levelDataBridge.bridge$serializationBehavior().orElse(null);
    this.impl$displayName = levelDataBridge.bridge$displayName().orElse(null);
    this.impl$viewDistance = levelDataBridge.bridge$viewDistance().orElse(null);
    this.impl$spawnPosition = new Vector3i(levelData.getXSpawn(), levelData.getYSpawn(), levelData.getZSpawn());
    this.impl$loadOnStartup = levelDataBridge.bridge$loadOnStartup();
    this.impl$performsSpawnLogic = levelDataBridge.bridge$performsSpawnLogic();
    this.impl$hardcore = levelData.isHardcore();
    this.impl$commands = levelData.getAllowCommands();
    this.impl$pvp = levelDataBridge.bridge$pvp().orElse(null);
}
Also used : GameMode(org.spongepowered.api.entity.living.player.gamemode.GameMode) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) Vector3i(org.spongepowered.math.vector.Vector3i) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge)

Example 5 with Difficulty

use of org.spongepowered.api.world.difficulty.Difficulty in project ProjectWorlds by trentech.

the class CommandCreate method getSuggestions.

@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
    List<String> list = new ArrayList<>();
    if (arguments.equalsIgnoreCase("create")) {
        return list;
    }
    String[] args = arguments.split(" ");
    if (args.length <= 1) {
        return list;
    }
    String arg = args[args.length - 1];
    if (arg.equalsIgnoreCase("-d") || arg.equalsIgnoreCase("-dimension")) {
        for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-g") || arg.equalsIgnoreCase("-generator")) {
        for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-gm") || arg.equalsIgnoreCase("-gamemode")) {
        for (Gamemode type : Gamemode.values()) {
            list.add(Integer.toString(type.getIndex()));
            list.add(type.getGameMode().getName());
        }
    } else if (arg.equalsIgnoreCase("-m") || arg.equalsIgnoreCase("-modifier")) {
        for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-df") || arg.equalsIgnoreCase("-difficulty")) {
        for (Difficulty type : Sponge.getRegistry().getAllOf(Difficulty.class)) {
            list.add(type.getId());
        }
    } else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup") || arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded") || arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands") || arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest") || arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
        list.add("true");
        list.add("false");
    } else {
        String parent = args[args.length - 2];
        if (parent.equalsIgnoreCase("-d") || parent.equalsIgnoreCase("-dimension")) {
            for (DimensionType type : Sponge.getRegistry().getAllOf(DimensionType.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (parent.equalsIgnoreCase("-g") || parent.equalsIgnoreCase("-generator")) {
            for (GeneratorType type : Sponge.getRegistry().getAllOf(GeneratorType.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (parent.equalsIgnoreCase("-gm") || parent.equalsIgnoreCase("-gamemode")) {
            for (Gamemode type : Gamemode.values()) {
                if (type.getGameMode().getName().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getGameMode().getName());
                }
            }
        } else if (parent.equalsIgnoreCase("-m") || parent.equalsIgnoreCase("-modifier")) {
            for (WorldGeneratorModifier type : Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (parent.equalsIgnoreCase("-df") || parent.equalsIgnoreCase("-difficulty")) {
            for (Difficulty type : Sponge.getRegistry().getAllOf(Difficulty.class)) {
                if (type.getId().toLowerCase().startsWith(arg.toLowerCase())) {
                    list.add(type.getId());
                }
            }
        } else if (arg.equalsIgnoreCase("-l") || arg.equalsIgnoreCase("-loadonstartup") || arg.equalsIgnoreCase("-k") || arg.equalsIgnoreCase("-keepspawnloaded") || arg.equalsIgnoreCase("-c") || arg.equalsIgnoreCase("-allowcommands") || arg.equalsIgnoreCase("-b") || arg.equalsIgnoreCase("-bonuschest") || arg.equalsIgnoreCase("-f") || arg.equalsIgnoreCase("-mapfeatures")) {
            if ("true".startsWith(arg.toLowerCase())) {
                list.add("true");
            }
            if ("false".startsWith(arg.toLowerCase())) {
                list.add("false");
            }
        }
    }
    return list;
}
Also used : DimensionType(org.spongepowered.api.world.DimensionType) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) Difficulty(org.spongepowered.api.world.difficulty.Difficulty) Gamemode(com.gmail.trentech.pjw.utils.Gamemode) ArrayList(java.util.ArrayList) GeneratorType(org.spongepowered.api.world.GeneratorType)

Aggregations

Difficulty (org.spongepowered.api.world.difficulty.Difficulty)11 WorldProperties (org.spongepowered.api.world.storage.WorldProperties)6 DimensionType (org.spongepowered.api.world.DimensionType)4 GeneratorType (org.spongepowered.api.world.GeneratorType)4 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)4 ArrayList (java.util.ArrayList)3 GameMode (org.spongepowered.api.entity.living.player.gamemode.GameMode)3 Gamemode (com.gmail.trentech.pjw.utils.Gamemode)2 CommandException (org.spongepowered.api.command.CommandException)2 WorldArchetype (org.spongepowered.api.world.WorldArchetype)2 Help (com.gmail.trentech.pjc.help.Help)1 Usage (com.gmail.trentech.pjc.help.Usage)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 TranslatedParserException (org.cubeengine.libcube.service.command.TranslatedParserException)1 LanternDifficulty (org.lanternpowered.server.world.difficulty.LanternDifficulty)1