-
Notifications
You must be signed in to change notification settings - Fork 8
/
paper.clj
64 lines (56 loc) · 1.97 KB
/
paper.clj
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
56
57
58
59
60
61
62
63
64
(ns lambdaisland.witchcraft.paper
"Start an embedded Paper server, and paper-specific extensions.
To use this you need to download Paper yourself, and start Clojure/JVM with the right args.
deps.edn:
```
:aliases {
:cider/nrepl
{:extra-deps
{nrepl/nrepl {:mvn/version \"0.8.3\"}
refactor-nrepl/refactor-nrepl {:mvn/version \"2.5.1\"}
cider/cider-nrepl {:mvn/version \"0.26.0\"}}}
:papermc
{:extra-deps {io.papermc/paper {:local/root \"/home/arne/Downloads/paper-1.17.1-157.jar\"}}
:main-opts [\"-m\" \"paper-witch\"]}}
}
```
Command line:
```
clj -J-Dcom.mojang.eula.agree=true -J-javaagent:/home/arne/Downloads/paper-1.17.1-157.jar -A:cider/nrepl -M:papermc
```
"
(:require [lambdaisland.witchcraft :as wc]
[lambdaisland.witchcraft.util :as util])
(:import (org.bukkit Bukkit Server)
(org.bukkit.block Block BlockFace)
(org.bukkit.block.data BlockData Directional)))
(set! *warn-on-reflection* true)
(defn server
"Get the currently active server."
^Server []
(Bukkit/getServer))
(defn start! [gui?]
(if (server)
(println "Server already started...")
(do
(future
(loop []
(Thread/sleep 1000)
(if (try (server) (catch Throwable t))
(wc/init-xmaterial!)
(recur))))
(future
(try
(util/if-class-exists
io.papermc.paperclip.Paperclip
(io.papermc.paperclip.Paperclip/main (into-array String (if gui? [] ["nogui"])))
(println "Class not found: io.papermc.paperclip.Paperclip" ))
(finally
(println ::started)))))))
;; The XSeries implmenentation doesn't call `setBlockData`, which is necessary
;; on Paper, so we do it ourselves.
(defmethod wc/-set-direction :paper [_ ^Block block ^BlockFace face]
(let [data (.getBlockData block)]
(when (instance? Directional data)
(.setFacing ^Directional data face)
(.setBlockData block data))))