예제 #1
0
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!args.hasAny("old")) {
      src.sendMessage(invalidArg());
      return CommandResult.empty();
    }

    String oldWorldName = args.<String>getOne("old").get();

    if (oldWorldName.equalsIgnoreCase("@w")) {
      if (src instanceof Player) {
        oldWorldName = ((Player) src).getWorld().getName();
      }
    }

    if (!args.hasAny("new")) {
      src.sendMessage(invalidArg());
      return CommandResult.empty();
    }

    String newWorldName = args.<String>getOne("new").get();

    for (WorldProperties world : Main.getGame().getServer().getAllWorldProperties()) {
      if (!world.getWorldName().equalsIgnoreCase(newWorldName)) {
        continue;
      }

      src.sendMessage(Text.of(TextColors.DARK_RED, newWorldName, " already exists"));
      return CommandResult.empty();
    }

    if (!Main.getGame().getServer().getWorld(oldWorldName).isPresent()) {
      src.sendMessage(Text.of(TextColors.DARK_RED, "World ", oldWorldName, " does not exists"));
      return CommandResult.empty();
    }

    Optional<WorldProperties> copy = null;
    try {
      copy =
          Main.getGame()
              .getServer()
              .copyWorld(
                  Main.getGame().getServer().getWorld(oldWorldName).get().getProperties(),
                  newWorldName)
              .get();
    } catch (InterruptedException | ExecutionException e) {
      e.printStackTrace();
    }

    if (!copy.isPresent()) {
      src.sendMessage(Text.of(TextColors.DARK_RED, "Could not copy ", oldWorldName));
      return CommandResult.empty();
    }

    src.sendMessage(Text.of(TextColors.DARK_GREEN, oldWorldName, " copied to ", newWorldName));

    return CommandResult.success();
  }
예제 #2
0
  @Override
  public WorldCreationSettings getCreationSettings() {
    WorldProperties properties = this.getProperties();

    // Create based on WorldProperties
    WorldSettings settings = new WorldSettings(this.worldInfo);
    IMixinWorldSettings mixin = (IMixinWorldSettings) (Object) settings;
    mixin.setDimensionType(properties.getDimensionType());
    mixin.setGeneratorSettings(properties.getGeneratorSettings());
    mixin.setGeneratorModifiers(properties.getGeneratorModifiers());
    mixin.setEnabled(true);
    mixin.setKeepSpawnLoaded(this.keepSpawnLoaded);
    mixin.setLoadOnStartup(properties.loadOnStartup());

    return (WorldCreationSettings) (Object) settings;
  }
예제 #3
0
  @Override
  public CommandResult execute(CommandSource src, CommandContext args) throws CommandException {
    if (!args.hasAny("name")) {
      src.sendMessage(invalidArg());
      return CommandResult.empty();
    }
    String worldName = args.<String>getOne("name").get();

    if (worldName.equalsIgnoreCase("@w") && src instanceof Player) {
      worldName = ((Player) src).getWorld().getName();
    }

    Collection<WorldProperties> worlds = new ArrayList<>();

    if (worldName.equalsIgnoreCase("@a")) {
      worlds = Main.getGame().getServer().getAllWorldProperties();
    } else {
      if (!Main.getGame().getServer().getWorldProperties(worldName).isPresent()) {
        src.sendMessage(Text.of(TextColors.DARK_RED, worldName, " does not exist"));
        return CommandResult.empty();
      }
      worlds.add(Main.getGame().getServer().getWorldProperties(worldName).get());
    }

    String value = null;

    if (args.hasAny("value")) {
      value = args.<String>getOne("value").get();

      if ((!value.equalsIgnoreCase("true")) && (!value.equalsIgnoreCase("false"))) {
        src.sendMessage(invalidArg());
        return CommandResult.empty();
      }
    }

    List<Text> list = new ArrayList<>();

    for (WorldProperties properties : worlds) {
      if (value == null) {
        list.add(
            Text.of(
                TextColors.GREEN,
                properties.getWorldName(),
                ": ",
                TextColors.WHITE,
                Boolean.toString(properties.isHardcore()).toUpperCase()));
        continue;
      }

      properties.setHardcore(Boolean.getBoolean(value));

      src.sendMessage(
          Text.of(
              TextColors.DARK_GREEN,
              "Set hardcore of ",
              worldName,
              " to ",
              TextColors.YELLOW,
              value.toUpperCase()));
    }

    if (!list.isEmpty()) {
      if (src instanceof Player) {
        PaginationList.Builder pages =
            Main.getGame().getServiceManager().provide(PaginationService.class).get().builder();

        pages.title(
            Text.builder()
                .color(TextColors.DARK_GREEN)
                .append(Text.of(TextColors.GREEN, "Hardcore"))
                .build());

        pages.contents(list);

        pages.sendTo(src);
      } else {
        for (Text text : list) {
          src.sendMessage(text);
        }
      }
    }

    return CommandResult.success();
  }