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