Skip to content

Commit ac6e262

Browse files
authored
Merge pull request #24 from CSSUoB/multiplatform-plugin
Convert to multiplatform plugin
2 parents 83f19ee + 99c1df5 commit ac6e262

File tree

93 files changed

+3379
-490
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3379
-490
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @Thatsmusic99 @MattyTheHacker
1+
* @Thatsmusic99 @MattyTheHacker @LMBishop

.github/workflows/build.yml

+31-28
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,42 @@ name: "Build"
33
on:
44
push:
55
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
68

79
jobs:
810
build:
9-
name: Build
10-
runs-on: ubuntu-latest
11-
permissions:
12-
actions: read
13-
contents: read
14-
security-events: write
15-
1611
strategy:
1712
fail-fast: false
1813
matrix:
19-
language: [ 'java' ]
20-
21-
steps:
22-
- name: Checkout repository
23-
uses: actions/checkout@v3
14+
target: [ bukkit, fabric, forge ]
2415

25-
- name: Initialize CodeQL
26-
uses: github/codeql-action/init@v2
27-
with:
28-
languages: ${{ matrix.language }}
29-
30-
- name: Setup Java and Maven
31-
uses: actions/setup-java@v3
32-
with:
33-
java-version: '17'
34-
distribution: 'temurin'
35-
cache: maven
36-
37-
- name: Build with Maven
38-
run: mvn -B package --file pom.xml
16+
name: Build ${{ matrix.target }}
17+
runs-on: ubuntu-latest
18+
if: "!startsWith(github.event.commits[0].message, '[ci-skip]')"
3919

40-
- name: Perform CodeQL Analysis
41-
uses: github/codeql-action/analyze@v2
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
24+
- name: Setup JDK
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: 21
28+
distribution: temurin
29+
cache: gradle
30+
cache-dependency-path: |
31+
**/*.gradle*
32+
**/gradle-wrapper.properties
33+
34+
- name: Build with Gradle
35+
run: "./gradlew :${{matrix.target}}:build"
36+
37+
- name: Upload builds
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: "cssminecraft-${{matrix.target}}.jar"
41+
path: |
42+
${{matrix.target}}/build/libs/cssminecraft-${{matrix.target}}-*.jar
43+
!**/*-no-map.jar
44+
if-no-files-found: error

.github/workflows/pullrequest.yml

-42
This file was deleted.

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
target/
22
*.iml
3+
.idea
4+
.gradle
5+
**/build/
6+
!src/**/build/
7+
gradle-app.setting
8+
!gradle-wrapper.jar
9+
!gradle-wrapper.properties
10+
.gradletasknamecache

README.md

+87-17
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,110 @@
1-
## CSS-Minecraft
2-
This is the source code for CSS' Minecraft plugin.
1+
# CSS Minecraft
2+
This is the source code for CSS' Minecraft plugin/mod.
33

44
## Building
55

6-
Ensure that you have maven installed.
7-
Then:
6+
To compile, run the `build` Gradle task.
7+
88
```
9-
maven clean package
9+
./gradlew build
1010
```
1111

12-
This will automatically execute the shadow-jar goal in the package cycle.
13-
14-
There will now be a .jar file located in /target
15-
16-
You can now put this .jar file in the /plugins folder in a Spigot/CraftBukkit 1.17.1 server and run the server.
12+
Jars will be output to `**/build/libs/cssminecraft-*.jar`.
1713

1814
## Configuration
1915

16+
The configuration file will be located in the server configuration directory, which depends on the platform.
17+
Typically, this will be at:
2018

21-
MEMBER_ROLE_ID: The ID of the role that the plugin checks against when someone runs the /makegreen command.
19+
* **bukkit**: `plugins/CSSMinecraft/config.yml`
20+
* **fabric**: `config/cssminecraft/config.yml`
21+
* **forge**: `config/cssminecraft/config.yml`
2222

23-
BRIDGE_CHANNEL_ID: The ID of the channel to send bridged messages to Minecraft.
23+
```yaml
24+
# The ID of the role that the plugin checks against when someone runs the /makegreen command.
25+
member-role-id: 0
2426

25-
DISCORD_SERVER_ID: The ID of the guild to interact with.
27+
# The ID of the channel to send bridged messages to Minecraft.
28+
bridge-channel-id: 0
2629

27-
WEBHOOK_URL: The URL of the Discord webhook to send bridged messages from Minecraft.
30+
# The ID of the guild to interact with.
31+
discord-server-id: 0
2832

29-
AVATAR_SERVICE: A link to an avatar service, with %s as a placeholder of the user's minecraft username.
33+
# The URL of the Discord webhook to send bridged messages from Minecraft.
34+
webhook-url: ""
3035

31-
BOT_TOKEN: The token of the Discord bot that will be detecting messages to send to Minecraft, as well as Member roles.
36+
# The token of the Discord bot that will be detecting messages to send to Minecraft, as well as Member roles.
37+
bot-token: ""
3238

39+
# A link to an avatar service, with %s as a placeholder of the user's minecraft username.
40+
# This is used as the profile picture URL in webhook messages.
41+
# We'd recommend the following value: https://cravatar.eu/helmhead/%s/190.png
42+
avatar-service: ""
43+
44+
# The verbosity of logging (0 = error only, 1 = +warnings, 2 = +info, 3 = +debug)
45+
logging-level: 2
46+
```
3347
3448
## Dependencies
3549
36-
This plugin depends on [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/), which needs to be placed alongside this in the /plugins folder.
50+
This plugin optionally depends on [LuckPerms](https://luckperms.net/) to grant the member role.
51+
52+
Without it, only the Discord message bridge will be functional.
3753
3854
## Development
3955
4056
PR's welcome, feel free to do whatever.
57+
58+
The project is written mostly in an abstract fashion to help re-use code across
59+
different platforms.
60+
61+
Each Gradle subproject has the following purpose:
62+
* `/common`: platform-independent interfaces and implementations which houses most logic - the
63+
following subprojects depend on this
64+
* `/bukkit`: specific implementation for Bukkit / Spigot / Paper etc.
65+
* `/fabric`: specific implementation for Fabric servers
66+
* `/forge`: specific implementation for Forge servers
67+
68+
Note that this is a server only mod, and will not work on clients.
69+
70+
## Version matrix
71+
72+
The following table documents mod compatibility for older versions of Minecraft and their platforms.
73+
Any versions prior to 1.12.1 are backports.
74+
75+
If a Minecraft version is not listed here, then no version of the mod exists for it.
76+
77+
All version branches will follow the name `minecraft/<version>`.
78+
79+
| Minecraft | Java | Bukkit | Forge | Fabric | Links |
80+
|-----------|------|--------|-------|--------|-------------------------------------------------------------------------|
81+
| 1.21.1 | 21 | ✅ | ✅ | ✅ | (master) |
82+
| 1.18.2 | 17 | ❌ | ❌ | ✅ | [Branch](https://github.com/CSSUoB/CSS-Minecraft/tree/minecraft/1.18.2) |
83+
| 1.12.2 | 8 | ❌ | ✅ | ❌ | [Branch](https://github.com/CSSUoB/CSS-Minecraft/tree/minecraft/1.12.2) |
84+
85+
**Never merge `minecraft/*` branches into master.** Build features/fixes in master and cherry-pick backwards.
86+
87+
### Upgrading to future versions
88+
89+
The `master` branch should always target the latest version.
90+
Before upgrading, create a new release branch for the current version using the naming
91+
scheme `minecraft/<version>`.
92+
93+
Then, make the necessary changes to upgrade Minecraft version. Bukkit / Spigot / Paper
94+
has a stable enough API where not many changes will be needed (if any at all), but
95+
other platforms will likely break.
96+
97+
Once changes are done, update the version matrix and open a new PR to `master`.
98+
99+
### Backporting to older versions
100+
101+
This mod was originally made for Minecraft 1.21, thus
102+
it will require backporting to work on older modpacks.
103+
104+
Create a branch from the nearest Minecraft version and name it `minecraft/<version>`.
105+
You may be required to change the Java version, or upgrade/downgrade Gradle.
106+
It should be noted that Fabric does not exist prior to Minecraft 1.14.
107+
108+
Once finished, push the branch to GitHub and update this version matrix with the platform
109+
and version you have backported.
110+

build.gradle

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
plugins {
2+
id "java"
3+
id "com.gradleup.shadow" version "8.3.0"
4+
}
5+
6+
subprojects {
7+
apply plugin: "java"
8+
apply plugin: "com.gradleup.shadow"
9+
10+
group = "com.cssbham"
11+
version = "1.0.0"
12+
13+
sourceCompatibility = 21
14+
targetCompatibility = 21
15+
16+
tasks.withType(JavaCompile) {
17+
options.encoding = "UTF-8"
18+
}
19+
20+
tasks.withType(Javadoc) {
21+
options.encoding = "UTF-8"
22+
}
23+
24+
repositories {
25+
mavenCentral()
26+
}
27+
28+
assemble.dependsOn shadowJar
29+
}

bukkit/build.gradle

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
id "java"
3+
}
4+
5+
processResources {
6+
duplicatesStrategy = duplicatesStrategy.INCLUDE
7+
from(sourceSets.main.resources.srcDirs) {
8+
include "plugin.yml"
9+
expand("version": project.version)
10+
}
11+
}
12+
13+
repositories {
14+
maven { url = "https://repo.papermc.io/repository/maven-public/" }
15+
}
16+
17+
dependencies {
18+
compileOnly "io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT"
19+
20+
implementation project(path: ":common", configuration: "shadow")
21+
}
22+
23+
shadowJar {
24+
dependencies {
25+
include(project(":common"))
26+
}
27+
28+
archiveFileName = "cssminecraft-bukkit-${project.version}.jar"
29+
30+
minimize()
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.cssbham.cssminecraft.bukkit;
2+
3+
import com.cssbham.cssminecraft.bukkit.adapter.BukkitServerChatAdapter;
4+
import com.cssbham.cssminecraft.bukkit.command.BukkitCommandService;
5+
import com.cssbham.cssminecraft.bukkit.executor.BukkitServerExecutor;
6+
import com.cssbham.cssminecraft.bukkit.listener.BukkitEventListener;
7+
import com.cssbham.cssminecraft.bukkit.logger.BukkitLogger;
8+
import com.cssbham.cssminecraft.common.AbstractCSSMinecraftPlugin;
9+
import com.cssbham.cssminecraft.common.adapter.ServerChatAdapter;
10+
import com.cssbham.cssminecraft.common.command.CommandService;
11+
import com.cssbham.cssminecraft.common.executor.ServerExecutor;
12+
import com.cssbham.cssminecraft.common.logger.Logger;
13+
import org.bukkit.plugin.java.JavaPlugin;
14+
15+
import java.nio.file.Path;
16+
import java.nio.file.Paths;
17+
18+
/**
19+
* Implementation of CSS Minecraft Plugin for Bukkit
20+
*/
21+
public class BukkitCSSMinecraftPlugin extends AbstractCSSMinecraftPlugin {
22+
23+
private final JavaPlugin plugin;
24+
private final BukkitLogger logger;
25+
private final BukkitServerChatAdapter serverChatAdapter;
26+
private final BukkitServerExecutor executor;
27+
private final BukkitCommandService commandService;
28+
29+
public BukkitCSSMinecraftPlugin(JavaPlugin plugin) {
30+
this.plugin = plugin;
31+
this.logger = new BukkitLogger(plugin);
32+
this.serverChatAdapter = new BukkitServerChatAdapter();
33+
this.executor = new BukkitServerExecutor(logger, plugin);
34+
this.commandService = new BukkitCommandService(logger, executor, serverChatAdapter);
35+
}
36+
37+
@Override
38+
public void enable() {
39+
super.enable();
40+
41+
BukkitEventListener eventListener = new BukkitEventListener(plugin, executor);
42+
eventListener.bindPlatformToEventBus(super.getEventBus());
43+
44+
plugin.getCommand("makegreen").setExecutor(commandService);
45+
}
46+
47+
@Override
48+
public Logger getLogger() {
49+
return logger;
50+
}
51+
52+
@Override
53+
public ServerChatAdapter provideServerChatAdapter() {
54+
return serverChatAdapter;
55+
}
56+
57+
@Override
58+
public Path provideConfigurationPath() {
59+
return Paths.get(plugin.getDataFolder().getPath(), "config.yml");
60+
}
61+
62+
@Override
63+
public ServerExecutor provideServerExecutor() {
64+
return executor;
65+
}
66+
67+
@Override
68+
public CommandService provideCommandService() {
69+
return commandService;
70+
}
71+
}

0 commit comments

Comments
 (0)