{ config, lib, pkgs, ... }:
let
  common = import ../../common { inherit pkgs; };
in {
  services = {
    minecraft-servers.servers.roguecraft = {
      package = pkgs.paperServers.paper-1_21_1;
      jvmOpts = "-Xmx3000M";
      serverProperties = common.serverProperties // {
        difficulty = 3;
        server-port = 30014;
        motd = "\\u00A7l\\u00A7bNixFox \\u00A7cRoguecraft \\u00A7bserver.";
        require-resource-pack = true;
        resource-pack = "https://nixfox.ca/roguecraftresourcepackredir";
        resource-pack-sha1 = "b540c0562aba90c3ead2356bb9cb74fcf0db36b3";
      };
      whitelist = common.whitelist;
      symlinks = common.paperSymlinks;
      files = common.configFiles // {
        "world/datapacks/roguecraft.zip" = builtins.fetchurl {
          url = "https://nixfox.ca/roguecraftdatapackredir";
          sha256 = "04zrkvzvi1i898al45fh9j3k635sf9qhwca7phbv4ynkfl8bz3q3";
        };
      };
    };

    cloudflare-dyndns.domains = lib.mkIf config.services.minecraft-servers.servers.roguecraft.enable [ "rogue.nixfox.ca" ];

    nginx.virtualHosts."nixfox.ca".locations = lib.mkIf config.services.minecraft-servers.servers.roguecraft.enable {
      "/roguecraftdatapackredir" = {
        return = "301 https://cdn.modrinth.com/data/HtKjVijx/versions/Rme4c23R/Roguecraft%201.2.6%20-%20Data%20Pack.zip";
      };
      "/roguecraftresourcepackredir" = {
        return = "301 https://cdn.modrinth.com/data/HtKjVijx/versions/C6bITJnq/Roguecraft%201.2.5.4%20-%20Resource%20Pack.zip";
      };
    };
  };
}
