use of org.spongepowered.api.world.storage.WorldProperties in project Skree by Skelril.
the class WorldCommand method execute.
@Override
public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
if (!(src instanceof Player)) {
src.sendMessage(Text.of("You must be a player to use this command!"));
return CommandResult.empty();
}
WorldService service = Sponge.getServiceManager().provideUnchecked(WorldService.class);
Optional<WorldProperties> optProperties = args.getOne("world");
if (!optProperties.isPresent()) {
src.sendMessage(Text.of(TextColors.YELLOW, "You are in: " + ((Player) src).getWorld().getName() + "."));
return CommandResult.empty();
}
Optional<World> optWorld = Sponge.getServer().getWorld(optProperties.get().getWorldName());
if (!optWorld.isPresent()) {
src.sendMessage(Text.of(TextColors.RED, "No loaded world by that name found."));
return CommandResult.empty();
}
World world = optWorld.get();
if (!WorldEntryPermissionCheck.checkDestination((Player) src, world)) {
src.sendMessage(Text.of(TextColors.RED, "You do not have permission to access worlds of this type."));
return CommandResult.empty();
}
Location<World> targetLocation;
if (args.hasAny("s")) {
targetLocation = world.getSpawnLocation();
} else {
targetLocation = service.getWorldEntryPoint((Player) src, world);
}
Optional<Location<World>> optLoc = SafeTeleportHelper.teleport((Player) src, targetLocation);
if (optLoc.isPresent()) {
src.sendMessage(Text.of(TextColors.YELLOW, "Entered world: " + world.getName() + " successfully!"));
} else if (args.hasAny("f")) {
((Player) src).setLocation(targetLocation);
src.sendMessage(Text.of(TextColors.YELLOW, "Force entered world: " + world.getName() + " successfully!"));
} else {
src.sendMessage(Text.of(TextColors.YELLOW, "Failed to enter " + world.getName() + " please report this!"));
}
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandCopy method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("copy")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
getHelp().execute(source);
return CommandResult.success();
}
String oldWorldName;
String newWorldName;
try {
oldWorldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
try {
newWorldName = args[1];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
Optional<WorldProperties> optionalWorld = Sponge.getServer().getWorldProperties(oldWorldName);
if (!optionalWorld.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, oldWorldName, " does not exist"), false);
}
WorldProperties world = optionalWorld.get();
if (Sponge.getServer().getWorldProperties(newWorldName).isPresent()) {
throw new CommandException(Text.of(TextColors.RED, newWorldName, " already exists"), false);
}
Optional<WorldProperties> copy = Optional.empty();
try {
CompletableFuture<Optional<WorldProperties>> copyFuture = Sponge.getServer().copyWorld(world, newWorldName);
while (!copyFuture.isDone()) {
}
copy = copyFuture.get();
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
throw new CommandException(Text.of(TextColors.RED, "Something went wrong. Check server log for details"), false);
}
if (!copy.isPresent()) {
throw new CommandException(Text.of(TextColors.RED, "Could not copy ", world.getWorldName()), false);
}
source.sendMessage(Text.of(TextColors.DARK_GREEN, world.getWorldName(), " copied to ", newWorldName));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandDifficulty method getSuggestions.
@Override
public List<String> getSuggestions(CommandSource source, String arguments, Location<World> targetPosition) throws CommandException {
List<String> list = new ArrayList<>();
if (arguments.equalsIgnoreCase("difficulty")) {
return list;
}
String[] args = arguments.split(" ");
if (args.length == 1) {
for (WorldProperties world : Sponge.getServer().getAllWorldProperties()) {
if (world.getWorldName().equalsIgnoreCase(args[0])) {
for (Difficulty difficulty : Sponge.getRegistry().getAllOf(Difficulty.class)) {
list.add(difficulty.getId());
}
return list;
}
if (world.getWorldName().toLowerCase().startsWith(args[0].toLowerCase())) {
list.add(world.getWorldName());
}
}
}
if (args.length == 2) {
for (Difficulty difficulty : Sponge.getRegistry().getAllOf(Difficulty.class)) {
if (difficulty.getId().equalsIgnoreCase(args[1])) {
return list;
}
if (difficulty.getId().toLowerCase().startsWith(args[1].toLowerCase())) {
list.add(difficulty.getId());
}
}
}
return list;
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandDifficulty method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("difficulty")) {
throw new CommandException(getHelp().getUsageText());
}
String[] args = arguments.split(" ");
if (args[args.length - 1].equalsIgnoreCase("--help")) {
help.execute(source);
return CommandResult.success();
}
String worldName;
String diff;
try {
worldName = args[0];
} catch (Exception e) {
throw new CommandException(getHelp().getUsageText());
}
try {
diff = args[1];
} catch (Exception e) {
throw new CommandException(getHelp().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();
Optional<Difficulty> optionalDifficulty = Sponge.getRegistry().getType(Difficulty.class, diff);
if (!optionalDifficulty.isPresent()) {
source.sendMessage(Text.of(TextColors.YELLOW, diff, " is not a valid Difficulty"));
throw new CommandException(getHelp().getUsageText());
}
Difficulty difficulty = optionalDifficulty.get();
world.setDifficulty(difficulty);
Sponge.getServer().saveWorldProperties(world);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set difficulty of ", world.getWorldName(), " to ", TextColors.YELLOW, difficulty.getTranslation().get().toUpperCase()));
return CommandResult.success();
}
use of org.spongepowered.api.world.storage.WorldProperties in project ProjectWorlds by trentech.
the class CommandEnable method process.
@Override
public CommandResult process(CommandSource source, String arguments) throws CommandException {
if (arguments.equalsIgnoreCase("enable")) {
throw new CommandException(getHelp().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(getHelp().getUsageText());
}
try {
bool = args[1];
} catch (Exception e) {
throw new CommandException(getHelp().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.setEnabled(Boolean.valueOf(bool));
}
Sponge.getServer().saveWorldProperties(world);
source.sendMessage(Text.of(TextColors.DARK_GREEN, "Set enabled of ", world.getWorldName(), " to ", TextColors.YELLOW, bool));
return CommandResult.success();
}
Aggregations