Search in sources :

Example 81 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandUseMapFeatures method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("usemapfeatures")) {
        throw new CommandException(help.getUsageText());
    }
    String[] args = arguments.split(" ");
    if (args[args.length - 1].equalsIgnoreCase("--help")) {
        help.execute(source);
        return CommandResult.success();
    }
    String worldName;
    String bool;
    try {
        worldName = args[0];
    } catch (Exception e) {
        throw new CommandException(help.getUsageText());
    }
    try {
        bool = args[1];
    } catch (Exception e) {
        throw new CommandException(help.getUsageText());
    }
    Optional<WorldProperties> optionalWorld = Sponge.getServer().getWorldProperties(worldName);
    if (!optionalWorld.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, worldName, " does not exist"), false);
    }
    WorldProperties world = optionalWorld.get();
    if (bool.equalsIgnoreCase("true") || bool.equalsIgnoreCase("false")) {
        world.setMapFeaturesEnabled(Boolean.valueOf(bool));
    }
    Sponge.getServer().saveWorldProperties(world);
    source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set use map features of ", world.getWorldName(), " to ", TextColors.YELLOW, bool));
    return CommandResult.success();
}
Also used : CommandException(org.spongepowered.api.command.CommandException) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 82 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandWeather method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    if (arguments.equalsIgnoreCase("weather")) {
        throw new CommandException(getHelp().getUsageText());
    }
    String[] args = arguments.split(" ");
    if (args[args.length - 1].equalsIgnoreCase("--help")) {
        getHelp().execute(source);
        return CommandResult.success();
    }
    String worldName;
    String value;
    int duration = 0;
    try {
        worldName = args[0];
    } catch (Exception e) {
        throw new CommandException(getHelp().getUsageText());
    }
    Optional<WorldProperties> optionalProperties = Sponge.getServer().getWorldProperties(worldName);
    if (!optionalProperties.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, worldName, " does not exist"), false);
    }
    WorldProperties properties = optionalProperties.get();
    Optional<World> optionalWorld = Sponge.getServer().getWorld(properties.getUniqueId());
    if (!optionalWorld.isPresent()) {
        throw new CommandException(Text.of(TextColors.RED, properties.getWorldName(), " must be loaded"), false);
    }
    World world = optionalWorld.get();
    try {
        value = args[1];
    } catch (Exception e) {
        if (properties.isRaining()) {
            source.sendMessage(Text.of(TextColors.GREEN, "Weather: ", TextColors.WHITE, "rain"));
        } else if (properties.isThundering()) {
            source.sendMessage(Text.of(TextColors.GREEN, "Weather: ", TextColors.WHITE, "thunder"));
        } else {
            source.sendMessage(Text.of(TextColors.GREEN, "Weather: ", TextColors.WHITE, "clear"));
        }
        return CommandResult.success();
    }
    if (args.length == 3) {
        try {
            duration = Integer.parseInt(args[2]);
        } catch (Exception e) {
            throw new CommandException(getHelp().getUsageText());
        }
    }
    if (duration == 0) {
        if (value.equalsIgnoreCase("clear")) {
            world.setWeather(Weathers.CLEAR);
        } else if (value.equalsIgnoreCase("rain")) {
            world.setWeather(Weathers.RAIN);
        } else if (value.equalsIgnoreCase("thunder")) {
            world.setWeather(Weathers.THUNDER_STORM);
        } else {
            source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid weather type"));
            throw new CommandException(getHelp().getUsageText());
        }
    } else {
        if (value.equalsIgnoreCase("clear")) {
            world.setWeather(Weathers.CLEAR, duration);
        } else if (value.equalsIgnoreCase("rain")) {
            world.setWeather(Weathers.RAIN, duration);
        } else if (value.equalsIgnoreCase("thunder")) {
            world.setWeather(Weathers.THUNDER_STORM, duration);
        } else {
            source.sendMessage(Text.of(TextColors.YELLOW, value, " is not a valid weather type"));
            throw new CommandException(getHelp().getUsageText());
        }
    }
    source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set weather of ", properties.getWorldName(), " to ", TextColors.YELLOW, value, TextColors.DARK_GREEN, " for ", TextColors.YELLOW, world.getRemainingDuration()));
    return CommandResult.success();
}
Also used : CommandException(org.spongepowered.api.command.CommandException) World(org.spongepowered.api.world.World) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 83 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class CommandWeather method getSuggestions.

@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
    List<String> list = new ArrayList<>();
    if (arguments.equalsIgnoreCase("weather")) {
        return list;
    }
    String[] args = arguments.split(" ");
    if (args.length == 1) {
        for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
            if (world.getWorldName().equalsIgnoreCase(args[0])) {
                list.add("clear");
                list.add("thunder");
                list.add("rain");
                return list;
            }
            if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
                list.add(world.getWorldName());
            }
        }
    }
    if (args.length == 2) {
        if ("clear".equalsIgnoreCase(args[1]) || "rain".equalsIgnoreCase(args[1]) || "thunder".equalsIgnoreCase(args[1])) {
            return list;
        }
        if ("clear".toLowerCase().startsWith(args[1].toLowerCase())) {
            list.add("clear");
        }
        if ("rain".toLowerCase().startsWith(args[1].toLowerCase())) {
            list.add("rain");
        }
        if ("thunder".toLowerCase().startsWith(args[1].toLowerCase())) {
            list.add("thunder");
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) WorldProperties(org.spongepowered.api.world.storage.WorldProperties)

Example 84 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class EventManager method onMoveEntityEventEventTeleport.

@Listener
public void onMoveEntityEventEventTeleport(MoveEntityEvent.Teleport event, @Getter("getTargetEntity") Player player) {
    if (player.hasPermission("pjw.override.gamemode")) {
        return;
    }
    World from = event.getFromTransform().getExtent();
    World to = event.getToTransform().getExtent();
    WorldProperties properties = to.getProperties();
    if (!from.equals(to)) {
        if (!player.hasPermission("pjw.worlds." + properties.getWorldName())) {
            player.sendMessage(Text.of(TextColors.RED, "You do not have permission to travel to ", properties.getWorldName()));
            event.setCancelled(true);
            return;
        }
        if (properties.getGameRule("forceGamemode").get().equalsIgnoreCase("true")) {
            if (!properties.getGameMode().equals(player.gameMode().get())) {
                player.offer(Keys.GAME_MODE, properties.getGameMode());
            }
        }
    }
}
Also used : World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 85 with WorldProperties

use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.

the class EventManager method onLoadWorldEvent.

@Listener
public void onLoadWorldEvent(LoadWorldEvent event) {
    World world = event.getTargetWorld();
    WorldProperties properties = world.getProperties();
    List<WorldGeneratorModifier> modifiers = new ArrayList<>();
    boolean b = false;
    if (!properties.getGeneratorModifiers().isEmpty()) {
        for (WorldGeneratorModifier modifier : properties.getGeneratorModifiers()) {
            if (modifier.getId().equals("pjw:void")) {
                modifiers.add(Sponge.getRegistry().getType(WorldGeneratorModifier.class, "sponge:void").get());
                b = true;
            } else {
                modifiers.add(modifier);
            }
        }
    }
    if (b) {
        properties.setGeneratorModifiers(modifiers);
    }
    if (!properties.getGameRule("spawnOnDeath").isPresent()) {
        properties.setGameRule("spawnOnDeath", "default");
    }
    if (!properties.getGameRule("doWeatherCycle").isPresent()) {
        properties.setGameRule("doWeatherCycle", "true");
    }
    if (!properties.getGameRule("netherPortal").isPresent()) {
        properties.setGameRule("netherPortal", "default");
    }
    if (!properties.getGameRule("endPortal").isPresent()) {
        properties.setGameRule("endPortal", "default");
    }
    if (!properties.getGameRule("forceGamemode").isPresent()) {
        properties.setGameRule("forceGamemode", "false");
    }
}
Also used : WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) ArrayList(java.util.ArrayList) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Aggregations

WorldProperties (org.spongepowered.api.world.storage.WorldProperties)109 World (org.spongepowered.api.world.World)37 CommandException (org.spongepowered.api.command.CommandException)27 ArrayList (java.util.ArrayList)26 Player (org.spongepowered.api.entity.living.player.Player)19 Text (org.spongepowered.api.text.Text)16 Vector3d (com.flowpowered.math.vector.Vector3d)9 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)9 Listener (org.spongepowered.api.event.Listener)9 WorldGeneratorModifier (org.spongepowered.api.world.gen.WorldGeneratorModifier)9 List (java.util.List)8 Optional (java.util.Optional)8 CommandResult (org.spongepowered.api.command.CommandResult)8 Vector3i (com.flowpowered.math.vector.Vector3i)7 IOException (java.io.IOException)7 Sponge (org.spongepowered.api.Sponge)7 CommandSource (org.spongepowered.api.command.CommandSource)7 IMixinWorldInfo (org.spongepowered.common.interfaces.world.IMixinWorldInfo)7 GenericArguments (org.spongepowered.api.command.args.GenericArguments)6 Location (org.spongepowered.api.world.Location)6