- name: Fetch Paper server
  get_url:
        url: "https://papermc.io/api/v1/paper/1.15.2/latest/download"
        dest: "/etc/paper/server.jar"
        owner: nobody
        group: nogroup
        mode: 500
  tags:
        - minecraft
- name: Copy configurations
  loop: "{{ minecraft.configs }}"
  template:
        src: "mcdir/{{ item }}"
        dest: "{{ minecraft.paths.data }}/{{ item }}"
        mode: "400"
        owner: "nobody"
        group: "nogroup"
  tags:
        - minecraft
        - configs
        - vault
  when: ( minecraft.configs|default([]) ) | length
- name: Copy local plugins
  loop: "{{ minecraft.local_plugins }}"
  copy:
        src: "{{ role_path }}/files/mcdir/{{ item }}"
        dest: "{{ minecraft.paths.data }}/{{ item }}"
        mode: "700"
        owner: "nobody"
        group: "nogroup"
  tags:
        - minecraft
  when: ( minecraft.local_plugins|default([]) ) | length
- name: Copy binary files
  loop: "{{ minecraft.files }}"
  copy:
        src: "{{ role_path }}/files/mcdir/{{ item }}"
        dest: "{{ minecraft.paths.data }}/{{ item }}"
        mode: "700"
        owner: "nobody"
        group: "nogroup"
  tags:
        - minecraft
  when: ( minecraft.files|default([]) ) | length
- name: Fetch plugins
  loop: "{{ minecraft.plugins }}"
  get_url:
        url: "{{ item.url }}"
        dest: "{{ minecraft.paths.data }}/plugins/{{ item.name }}"
        owner: nobody
        group: nogroup
        mode: 500
  tags:
        - minecraft
  when: ( minecraft.plugins|default([]) ) | length
- name: Copy systemd service file
  template:
        src: 'paper-server.service.j2'
        dest: '/etc/systemd/system/paper-server.service'
        follow: 'yes'
  notify: Restart services
  tags:
        - minecraft
        - systemd
