Skip to content

Commit 7d5b672

Browse files
authored
Merge pull request #16 from EndlessCodeGroup/feature/paper
Paper support
2 parents 27be346 + 5e8c544 commit 7d5b672

File tree

9 files changed

+376
-111
lines changed

9 files changed

+376
-111
lines changed

README.md

Lines changed: 98 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ Gradle utilities for easier writing Bukkit plugins.
77
2. [Usage](#usage)
88
1. [First steps](#first-steps)
99
2. [Configuring plugin](#configuring-plugin)
10-
3. [Running Dev server](#running-dev-server)
10+
1. [Quotes around values](#quotes-around-values)
11+
3. [Repositories and Dependencies](#repositories-and-dependencies)
12+
4. [Running Dev server](#running-dev-server)
1113
1. [Server run configurations](#server-run-configurations)
1214

1315
#### Features:
1416
- Automatically applies plugins: java, idea, eclipse
1517
- Sets up compiler encoding to UTF-8
16-
- Adds repositories: mavenCentral, mavenLocal, spigot-repo, sk89q-repo
17-
- Provides short extension-functions to include bukkit/craftbukkit/spigot/spigot-api
18+
- Provides short extension-functions to add common repositories and dependencies
1819
- Generates plugin.yml from Gradle project information
1920
- Allows to run dev server from IDE
2021
- Automatically copies your plugin to plugins dir on server running
@@ -63,10 +64,16 @@ group "com.example"
6364
description "My first Bukkit plugin with Gradle"
6465
version "0.1"
6566
67+
// Wee need to add some repos
68+
repositories {
69+
spigot()
70+
// see section 'Repositories' for more info
71+
}
72+
6673
// Let's add needed API to project
6774
dependencies {
6875
compileOnly bukkit()
69-
// You also can use craftbukkit(), spigot() and spigotApi()
76+
// see section 'Dependencies' for more info
7077
}
7178
```
7279
`compileOnly` - it's like provided scope in Maven. It means that this dependncy will not included to your final jar.
@@ -84,7 +91,7 @@ You can configure attributes that will be placed to `plugin.yml`:
8491
```groovy
8592
// Override default configurations
8693
bukkit {
87-
// Version of API (latest by default)
94+
// Version of API (if you will not set this property, will be used latest available)
8895
version = "1.12.2"
8996
9097
// Attributes for plugin.yml
@@ -112,17 +119,83 @@ authors: [OsipXD, Contributors]
112119
Also you can add custom (unsupported by BukkitGradle) attributes like a `depend` etc.
113120
Just create `plugin.yml` file and put custom attributes into.
114121

122+
#### Quotes around values
123+
In some cases you may need put meta value in quotes. For this you can use `q` and `qq` functions.
124+
125+
For example we have meta:
126+
```groovy
127+
meta {
128+
name = qq "Double Quoted Name"
129+
description = q "Single quoted description"
130+
url = "http://without.quot.es/"
131+
}
132+
```
133+
134+
And will be generated:
135+
```yaml
136+
name: "Double Quoted Name"
137+
description: 'Single quoted description'
138+
website: http://without.quot.es/
139+
```
140+
141+
**Note:** In Groovy you can use functions in two ways: normal - `q("value")` and without braces - `q "value"`
142+
143+
### Repositories and Dependencies
144+
BukkitGradle provides short extension-functions to add common repositories and dependencies.
145+
There are list of its.
146+
147+
Usage example:
148+
```groovy
149+
repositories {
150+
spigot() // Adds spigot repo
151+
}
152+
153+
dependencies {
154+
compileOnly paperApi() // Adds paper-api dependency
155+
}
156+
```
157+
158+
##### Repositories:
159+
Name | Url
160+
----------------|----------------------------------------------------------------
161+
spigot | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
162+
sk98q | http://maven.sk89q.com/repo/
163+
destroystokyo | https://repo.destroystokyo.com/repository/maven-public/
164+
dmulloy2 | http://repo.dmulloy2.net/nexus/repository/public/
165+
md5 | http://repo.md-5.net/content/groups/public/
166+
vault | http://nexus.hc.to/content/repositories/pub_releases/
167+
placeholderapi | http://repo.extendedclip.com/content/repositories/placeholderapi/
168+
169+
##### Dependencies:
170+
Name | Signature
171+
-------------|-----------------------------------------------
172+
spigot | org.spigotmc:spigot:$apiVersion
173+
spigotApi | org.spigotmc:spigot-api:$apiVersion
174+
bukkit | org.bukkit:bukkit:$apiVersion
175+
craftbukkit | org.bukkit:craftbukkit:$apiVersion
176+
paperApi | com.destroystokyo.paper:paper-api:$apiVersion
177+
178+
**Note:** `$apiVersion` - is `${version}-R0.1-SNAPSHOT` (where `$version` is `bukkit.version`)
179+
180+
115181
### Running Dev server
116-
Before running server you should configure BuildTools and dev server location.
182+
Before running server you should configure dev server location.
117183

118-
You can define it in `local.properties` file (that was automatically created in project root on refresh):
184+
You can define it in `local.properties` file (that was automatically created in project directory on refresh):
119185
```properties
120-
# Absolute path to directory that contains BuildTools.jar
121-
buildtools.dir=/path/to/buildtools/
122186
# Absolute path to dev server
123187
server.dir=/path/to/buildtools/
124188
```
125-
Or you can define it globally (for all projects that uses BukkitGradle) with environment variables `BUKKIT_DEV_SERVER_HOME`
189+
190+
If you use Spigot (see `bukkit.run.core`) you also should specify BuildTools location. For Paper no additional actions
191+
needed.
192+
```properties
193+
# Absolute path to directory that contains BuildTools.jar
194+
buildtools.dir=/path/to/buildtools/
195+
```
196+
If there no BuildTools.jar it will be automatically downloaded.
197+
198+
**TIP:** you can define it globally (for all projects that uses BukkitGradle) with environment variables `BUKKIT_DEV_SERVER_HOME`
126199
and `BUILDTOOLS_HOME`.
127200

128201
##### On IntelliJ IDEA
@@ -132,26 +205,28 @@ server configurations.
132205
![Run Configuration](http://image.prntscr.com/image/1a12a03b8ac54fccb7d5b70a335fa996.png)
133206

134207
##### On other IDEs
135-
Run ':startServer' task.
208+
Run `:startServer` task.
136209

137210
#### Server run configurations
138211
To accept EULA and change settings use `bukkit.run` section:
139212
```groovy
140213
bukkit {
141214
// INFO: Here used default values
142215
run {
143-
// Accept EULA
144-
eula = false
145-
// Set online-mode flag
146-
onlineMode = false
147-
// Debug mode (listen 5005 port, if you use running from IDEA this option will be ignored)
148-
debug = true
149-
// Set server encoding (flag -Dfile.encoding)
150-
encoding = "UTF-8"
151-
// JVM arguments
152-
javaArgs = "-Xmx1G"
153-
// Bukkit arguments
154-
bukkitArgs = ""
216+
// Core type. It can be 'spigot' or 'paper'
217+
core = "spigot"
218+
// Accept EULA
219+
eula = false
220+
// Set online-mode flag
221+
onlineMode = false
222+
// Debug mode (listen 5005 port, if you use running from IDEA this option will be ignored)
223+
debug = true
224+
// Set server encoding (flag -Dfile.encoding)
225+
encoding = "UTF-8"
226+
// JVM arguments
227+
javaArgs = "-Xmx1G"
228+
// Bukkit arguments
229+
bukkitArgs = ""
155230
}
156231
}
157232
```

src/main/groovy/ru/endlesscode/bukkitgradle/BukkitGradlePlugin.groovy

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import org.gradle.api.Project
66
import org.gradle.api.plugins.JavaPluginConvention
77
import org.gradle.api.tasks.compile.JavaCompile
88
import ru.endlesscode.bukkitgradle.util.Dependencies
9+
import ru.endlesscode.bukkitgradle.util.Repositories
910

1011
class BukkitGradlePlugin implements Plugin<Project> {
1112
final static String GROUP = 'Bukkit'
@@ -64,21 +65,11 @@ class BukkitGradlePlugin implements Plugin<Project> {
6465
* Adds needed repositories
6566
*/
6667
void addRepositories() {
67-
project.with {
68-
repositories {
69-
mavenLocal()
70-
mavenCentral()
71-
72-
maven {
73-
name = 'sk89q'
74-
url = 'http://maven.sk89q.com/repo/'
75-
}
68+
Repositories.configureProject(project)
7669

77-
maven {
78-
name = 'spigot'
79-
url = 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/'
80-
}
81-
}
70+
project.repositories {
71+
mavenLocal()
72+
mavenCentral()
8273
}
8374
}
8475

src/main/groovy/ru/endlesscode/bukkitgradle/DevServerPlugin.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package ru.endlesscode.bukkitgradle
22

3+
import org.gradle.api.GradleException
34
import org.gradle.api.Plugin
45
import org.gradle.api.Project
5-
import org.gradle.internal.impldep.org.apache.maven.lifecycle.LifecycleExecutionException
66
import ru.endlesscode.bukkitgradle.server.ServerCore
77
import ru.endlesscode.bukkitgradle.task.PrepareServer
88
import ru.endlesscode.bukkitgradle.task.RunServer
@@ -26,20 +26,20 @@ class DevServerPlugin implements Plugin<Project> {
2626
PrepareServer prepareServer = project.task(
2727
'prepareServer',
2828
type: PrepareServer,
29-
dependsOn: ['build', 'buildServerCore', 'copyServerCore']
29+
dependsOn: ['build', 'copyServerCore']
3030
) {
3131
group = BukkitGradlePlugin.GROUP
3232
description = 'Prepare server ro run. Configure server and copy compiled plugin to plugins dir'
3333
core serverCore
3434
} as PrepareServer
3535

36-
Path runConfigurationsDir = project.projectDir.toPath().resolve(".idea/runConfigurations")
36+
Path runConfigurationsDir = project.rootProject.projectDir.toPath().resolve(".idea/runConfigurations")
3737
project.task('buildIdeaRun', dependsOn: 'prepareServer') {
3838
group = BukkitGradlePlugin.GROUP
3939
description = 'Configure IDEA server run configuration'
4040
}.doLast {
4141
if (Files.notExists(runConfigurationsDir.parent)) {
42-
throw new LifecycleExecutionException("This task only for IntelliJ IDEA.")
42+
throw new GradleException("This task only for IntelliJ IDEA.")
4343
}
4444

4545
Files.createDirectories(runConfigurationsDir)

src/main/groovy/ru/endlesscode/bukkitgradle/extension/RunConfiguration.groovy

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ru.endlesscode.bukkitgradle.extension
22

33
import groovy.xml.MarkupBuilder
44
import org.gradle.api.Project
5+
import ru.endlesscode.bukkitgradle.server.CoreType
56
import ru.endlesscode.bukkitgradle.server.ServerCore
67
import ru.endlesscode.bukkitgradle.task.PrepareServer
78

@@ -21,9 +22,13 @@ class RunConfiguration {
2122
String javaArgs
2223
String bukkitArgs
2324

25+
private CoreType coreType
26+
2427
RunConfiguration(Project project) {
2528
this.project = project
2629

30+
this.coreType = CoreType.SPIGOT
31+
2732
this.eula = false
2833
this.onlineMode = false
2934
this.debug = true
@@ -33,6 +38,20 @@ class RunConfiguration {
3338
this.bukkitArgs = ''
3439
}
3540

41+
void setCore(String core) {
42+
try {
43+
coreType = CoreType.valueOf(core.toUpperCase())
44+
} catch (IllegalArgumentException ignored) {
45+
project.logger.warn("Core type '$core' not found. May be it doesn't supported by BukkitGradle yet. " +
46+
"You may write issue on GitHub to request supporting.\n" +
47+
"Fallback core type is '${coreType.toString().toLowerCase()}'")
48+
}
49+
}
50+
51+
def getCoreType() {
52+
return coreType
53+
}
54+
3655
/**
3756
* Returns arguments for java
3857
*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package ru.endlesscode.bukkitgradle.server
2+
3+
enum CoreType {
4+
SPIGOT, PAPER
5+
}

0 commit comments

Comments
 (0)