Search in sources :

Example 21 with WorldProperties

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

the class CommandRename method getSuggestions.

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

Example 22 with WorldProperties

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

the class EventManager method onRespawnPlayerEvent.

@Listener
public void onRespawnPlayerEvent(RespawnPlayerEvent event) {
    World world = event.getFromTransform().getExtent();
    WorldProperties properties = world.getProperties();
    String worldName = properties.getGameRule("spawnOnDeath").get();
    Optional<World> optionalSpawnWorld = Sponge.getServer().getWorld(worldName);
    if (!optionalSpawnWorld.isPresent()) {
        return;
    }
    World spawnWorld = optionalSpawnWorld.get();
    Transform<World> transform = event.getToTransform().setLocation(spawnWorld.getSpawnLocation());
    event.setToTransform(transform);
}
Also used : World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 23 with WorldProperties

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

the class EventManager method onDamageEntityEvent.

@Listener
public void onDamageEntityEvent(DamageEntityEvent event, @Root EntityDamageSource damageSource) {
    if (!(event.getTargetEntity() instanceof Player)) {
        return;
    }
    Player victim = (Player) event.getTargetEntity();
    if (!isValidPlayer(damageSource)) {
        return;
    }
    World world = victim.getWorld();
    WorldProperties properties = world.getProperties();
    if (!properties.isPVPEnabled() || victim.hasPermission("pjw.override.pvp")) {
        event.setCancelled(true);
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 24 with WorldProperties

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

the class EventManager method onChangeWorldWeatherEvent.

@Listener
public void onChangeWorldWeatherEvent(ChangeWorldWeatherEvent event) {
    World world = event.getTargetWorld();
    WorldProperties properties = world.getProperties();
    if (properties.getGameRule("doWeatherCycle").get().equalsIgnoreCase("false")) {
        event.setCancelled(true);
    }
}
Also used : World(org.spongepowered.api.world.World) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) Listener(org.spongepowered.api.event.Listener)

Example 25 with WorldProperties

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

the class CommandSetSpawn method process.

@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
    String worldName;
    WorldProperties properties;
    Vector3i vector3i;
    if (arguments.equalsIgnoreCase("setspawn")) {
        if (source instanceof Player) {
            properties = ((Player) source).getWorld().getProperties();
            vector3i = ((Player) source).getLocation().getBlockPosition();
        } else {
            source.sendMessage(Text.of(TextColors.YELLOW, "Console must provide <world> and <x,y,z>"));
            throw new CommandException(getHelp().getUsageText());
        }
    } else {
        String[] args = arguments.split(" ");
        if (args[args.length - 1].equalsIgnoreCase("--help")) {
            getHelp().execute(source);
            return CommandResult.success();
        }
        try {
            worldName = args[0];
            Optional<WorldProperties> optionalProperties = Sponge.getServer().getWorldProperties(worldName);
            if (!optionalProperties.isPresent()) {
                throw new CommandException(Text.of(TextColors.RED, worldName, " does not exist"), false);
            }
            properties = optionalProperties.get();
        } catch (Exception e) {
            if (source instanceof Player) {
                properties = ((Player) source).getWorld().getProperties();
            } else {
                source.sendMessage(Text.of(TextColors.YELLOW, "Console must provide <world> and <x,y,z>"));
                throw new CommandException(getHelp().getUsageText());
            }
        }
        String coords;
        try {
            coords = args[1];
            String[] coordinates = args[1].split(",");
            if (!isValidLocation(coordinates)) {
                throw new CommandException(Text.of(TextColors.RED, coords.toString(), " is not valid"), true);
            }
            vector3i = new Vector3i().add(Integer.parseInt(coordinates[0]), Integer.parseInt(coordinates[1]), Integer.parseInt(coordinates[2]));
        } catch (Exception e) {
            if (source instanceof Player) {
                vector3i = ((Player) source).getLocation().getBlockPosition();
            } else {
                source.sendMessage(Text.of(TextColors.YELLOW, "Console must provide <world> and <x,y,z>"));
                throw new CommandException(getHelp().getUsageText());
            }
        }
    }
    properties.setSpawnPosition(vector3i);
    Sponge.getServer().saveWorldProperties(properties);
    source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set spawn of world ", properties.getWorldName(), " to x: ", properties.getSpawnPosition().getX(), ", y: ", properties.getSpawnPosition().getY(), ", z: ", properties.getSpawnPosition().getZ()));
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Vector3i(com.flowpowered.math.vector.Vector3i) CommandException(org.spongepowered.api.command.CommandException) WorldProperties(org.spongepowered.api.world.storage.WorldProperties) CommandException(org.spongepowered.api.command.CommandException)

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