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;
}
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);
}
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);
}
}
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);
}
}
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();
}
Aggregations