Skip to content

Commit 67ffd58

Browse files
committed
Make build compatible with Glowstone, add build for Spigot
1 parent 5d3782d commit 67ffd58

File tree

4 files changed

+80
-23
lines changed

4 files changed

+80
-23
lines changed

.dir-locals.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
((nil . ((cider-clojure-cli-global-options . "-A:dev:paper-api:build-plugin:licp"))))
1+
((nil . ((cider-clojure-cli-global-options . "-A:dev:mc/paper-1.17:build-plugin:licp"))))

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,40 @@
44
[![cljdoc badge](https://cljdoc.org/badge/com.lambdaisland/witchcraft-plugin)](https://cljdoc.org/d/com.lambdaisland/witchcraft-plugin) [![Clojars Project](https://img.shields.io/clojars/v/com.lambdaisland/witchcraft-plugin.svg)](https://clojars.org/com.lambdaisland/witchcraft-plugin)
55
<!-- /badges -->
66

7-
A Clojure plugin for Bukkit-based minecraft servers (Paper, Spigot, CraftBukkit, Glowstone)
7+
A Clojure plugin for Bukkit-based minecraft servers (Paper, Spigot, Glowstone)
88

9-
## Installation
9+
## Build
1010

11-
To build the plugin you need a recent version of Clojure CLI, see the [Clojure getting started](https://clojure.org/guides/getting_started) guide
11+
To build the plugin you need a recent version of Clojure CLI, see the [Clojure
12+
getting started](https://clojure.org/guides/getting_started) guide
1213

1314
```
1415
$ clojure --version
1516
Clojure CLI version 1.10.3.943
1617
```
1718

1819
Then use the build-plugin task, you need to tell it which server you will be
19-
using, and the API version. Currently only PaperMC 1.17 has been tested.
20+
using, and the API version.
2021

2122
```
23+
clojure -T:build-plugin build :server glowstone :api-version 1.12
2224
clojure -T:build-plugin build :server paper :api-version 1.17
25+
clojure -T:build-plugin build :server spigot :api-version 1.17
2326
```
2427

28+
These will create two files each
29+
30+
- `target/witchcraft-plugin-<version>-for-<server>-<api-version>.jar`
31+
- `target/witchcraft-plugin-<version>-for-<server>-<api-version>-shaded.jar`
32+
33+
It is recommended to use the shaded version. For Glowstone you must use the
34+
shaded version. (Naether pulls in an old plexus-utils, which conflicts with
35+
tools.deps.alpha).
36+
2537
Copy the plugin jar to your server's `plugins` directory
2638

2739
```
28-
$ cp target/witchcraft-plugin-0.0.3-for-paper-1.17.jar ~/PaperMC/plugins/
40+
$ cp target/witchcraft-plugin-0.0.7-for-paper-1.17-shaded.jar ~/PaperMC/plugins/
2941
```
3042

3143
The first time you run the server it will create a `deps.edn` and

build_plugin.clj

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
(ns build-plugin
22
(:require [clojure.tools.build.api :as b]
33
[clojure.string :as str]
4-
[clojure.java.io :as io]))
4+
[clojure.java.io :as io]
5+
[shade.core :as shade])
6+
(:import java.nio.file.FileSystems
7+
java.nio.file.Path
8+
java.nio.file.Paths
9+
java.nio.file.Files
10+
java.nio.file.FileVisitOption
11+
java.nio.file.StandardOpenOption
12+
java.nio.charset.StandardCharsets
13+
java.net.URI))
514

615
(def lib 'com.lambdaisland/witchcraft-plugin)
716
(def version (format "0.0.%s" (b/git-count-revs nil)))
817
(def class-dir "target/classes")
9-
(def jar-file )
18+
19+
(def shadings
20+
{"org.eclipse.aether" "com.lambdaisland.shaded.org.eclipse.aether"
21+
"org.apache.maven" "com.lambdaisland.shaded.org.apache.maven"
22+
"org.codehaus.plexus" "com.lambdaisland.shaded.org.codehaus.plexus"})
1023

1124
(defn clean [params]
1225
(b/delete {:path "target"})
@@ -29,15 +42,32 @@
2942
:description "Bootstrap Clojure/nREPL/Witchcraft"
3043
:api-version api-version})))
3144

45+
(defn shade-jar [in out]
46+
;; java
47+
(shade/shade in out shadings)
48+
49+
;; clojure
50+
(with-open [zipfs (FileSystems/newFileSystem ^Path (Paths/get out (into-array String [])))] ;; Requires JDK 12
51+
(let [paths (iterator-seq (.iterator (Files/walk (first (.getRootDirectories zipfs)) (make-array FileVisitOption 0))))]
52+
(doseq [path paths
53+
:when (re-find #"\.cljc?$" (str path))]
54+
(let [txt (slurp (.toUri path))
55+
shaded (reduce
56+
(fn [txt [from to]]
57+
(str/replace txt from to))
58+
txt
59+
shadings)]
60+
(when (not= shaded txt)
61+
(Files/write path
62+
(.getBytes shaded StandardCharsets/UTF_8)
63+
(into-array StandardOpenOption
64+
[StandardOpenOption/TRUNCATE_EXISTING]))))))))
65+
3266
(defn build [{:keys [env api-version server] :as params
3367
:or {api-version "1.17"
3468
server 'paper}}]
3569
(let [basis (b/create-basis {:project "deps.edn"
36-
:aliases [(case server
37-
paper
38-
:mc/paper-api
39-
glowstone
40-
:mc/glowstone)]})
70+
:aliases [(keyword "mc" (str server "-" api-version))]})
4171
jar-file (format "target/%s-%s-for-%s-%s.jar"
4272
(name lib)
4373
version
@@ -50,16 +80,19 @@
5080
:src-dirs ["src"]})
5181
(b/javac {:src-dirs ["java"]
5282
:class-dir class-dir
53-
:basis basis})
83+
:basis basis
84+
:javac-opts ["-source" "11" "-target" "11"]})
5485
(b/copy-dir {:src-dirs ["src"]
5586
:target-dir class-dir})
5687
(plugin-yml {:target-dir class-dir :api-version api-version})
5788
(b/uber {:class-dir class-dir
5889
:uber-file jar-file
5990
:basis (b/create-basis {:project "deps.edn"
60-
:aliases [:licp :nrepl]})}))
91+
:aliases [:licp :nrepl]})})
92+
(shade-jar jar-file (str/replace jar-file ".jar" "-shaded.jar")))
6193
params)
6294

6395
(defn build-all [& _]
6496
(build '{:server glowstone :api-version 1.12})
65-
(build '{:server paper :api-version 1.17}))
97+
(build '{:server paper :api-version 1.17})
98+
(build '{:server spigot :api-version 1.17}))

deps.edn

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
:witchcraft {:extra-deps {com.lambdaisland/witchcraft {:git/url "https://github.com/lambdaisland/witchcraft"
1212
:git/sha "fef41c2ab49b89c6b3632c546cac9c33dc7e99ea"}}}
1313

14-
:mc/glowstone {:extra-deps {net.glowstone/glowstone {:mvn/version "2021.7.0-SNAPSHOT"}}}
15-
:mc/paper {:extra-deps {io.papermc/paper {:local/root "/home/arne/Downloads/paper-1.17.1-157.jar"}}}
16-
:mc/paperclip {:extra-deps {io.papermc/paperclip {:mvn/version "2.0.1"}}}
17-
:mc/paper-api {:extra-deps {io.papermc.paper/paper-api {:mvn/version "1.17.1-R0.1-SNAPSHOT"}}}
14+
:mc/glowstone-1.12 {:extra-deps {net.glowstone/glowstone {:mvn/version "2021.7.0-SNAPSHOT"}}}
15+
:mc/paper-1.17 {:extra-deps {io.papermc.paper/paper-api {:mvn/version "1.17.1-R0.1-SNAPSHOT"}}}
16+
:mc/spigot-1.17 {:extra-deps {org.spigotmc/spigot-api {:mvn/version "1.17.1-R0.1-SNAPSHOT"}}}
17+
18+
;; :mc/paper {:extra-deps {io.papermc/paper {:local/root "/home/arne/Downloads/paper-1.17.1-157.jar"}}}
19+
;; :mc/paperclip {:extra-deps {io.papermc/paperclip {:mvn/version "2.0.1"}}}
1820

1921
:nrepl {:extra-deps {nrepl/nrepl {:mvn/version "0.8.3"}}}
2022

@@ -24,11 +26,21 @@
2426
:build-plugin
2527
{:extra-paths ["clj_yaml/src"]
2628
:extra-deps {io.github.clojure/tools.build {:git/url "https://github.com/clojure/tools.build"
27-
:sha "d3008e159eb2afbc4b0019e1d36cf20e1129c394"}}
29+
:sha "d3008e159eb2afbc4b0019e1d36cf20e1129c394"}
30+
shade/shade {:mvn/version "0.4.0"}}
31+
:ns-default build-plugin
32+
:exec-fn build}
33+
34+
:build-all
35+
{:extra-paths ["clj_yaml/src"]
36+
:extra-deps {io.github.clojure/tools.build {:git/url "https://github.com/clojure/tools.build"
37+
:sha "d3008e159eb2afbc4b0019e1d36cf20e1129c394"}
38+
shade/shade {:mvn/version "0.4.0"}}
2839
:ns-default build-plugin
29-
:exec-fn build}}
40+
:exec-fn build-all}}
3041

3142
:mvn/repos
3243
{"glowstone-repo" {:url "https://repo.glowstone.net/content/repositories/snapshots/"}
3344
"aikar" {:url "https://repo.aikar.co/nexus/content/repositories/aikar-release/"}
34-
"papermc" {:url "https://papermc.io/repo/repository/maven-public/"}}}
45+
"papermc" {:url "https://papermc.io/repo/repository/maven-public/"}
46+
"spigot" {:url "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"}}}

0 commit comments

Comments
 (0)