aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/xyz/brysonsteck/ServerCraft/dialogs/EulaDialog.kt
blob: 4084b083fe8b161870478129c04496f3702261ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package xyz.brysonsteck.ServerCraft.dialogs

import xyz.brysonsteck.ServerCraft.dialogs.Dialog
import javafx.scene.control.Button
import javafx.event.EventHandler
import javafx.event.ActionEvent
import java.awt.Desktop
import java.net.URI

class EulaDialog: Dialog {
  override val type: String
  override val title: String
  override val msg: String
  override val neutralButton: Button?
  override val yesButton: Button?
  override val noButton: Button?

  constructor() {
    type = "warning"
    title = "Minecraft End User License Agreement (EULA)"
    msg = "Do you agree to the terms of the Minecraft End User License Agreement?"

    noButton = Button("I Disagree")
    noButton.onAction = EventHandler<ActionEvent>() {
      result = false
      dialog.hide()
    }
    noButton.isDefaultButton = true
    yesButton = Button("I Agree")
    yesButton.onAction = EventHandler<ActionEvent>() {
      result = true
      dialog.hide()
    }
    neutralButton = Button("View EULA")
    neutralButton.onAction = EventHandler<ActionEvent>() {
      val desktop = Desktop.getDesktop()
      if (desktop.isSupported(Desktop.Action.BROWSE)) {
        // most likely running on Windows or macOS
        try {
          desktop.browse(URI("https://account.mojang.com/documents/minecraft_eula"))
        } catch (e: Exception) {
          println(e)
        }
      } else {
        // assume running on linux
        try {
          Runtime.getRuntime().exec("xdg-open https://account.mojang.com/documents/minecraft_eula");
        } catch (e: Exception) {
          println(e)
        }
      }
    }
  }

}