Skip to content

Commit

Permalink
Merge pull request #24 from CSSUoB/multiplatform-plugin
Browse files Browse the repository at this point in the history
Convert to multiplatform plugin
  • Loading branch information
LMBishop authored Sep 9, 2024
2 parents 83f19ee + 99c1df5 commit ac6e262
Show file tree
Hide file tree
Showing 93 changed files with 3,379 additions and 490 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @Thatsmusic99 @MattyTheHacker
* @Thatsmusic99 @MattyTheHacker @LMBishop
59 changes: 31 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,42 @@ name: "Build"
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
name: Build
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'java' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3
target: [ bukkit, fabric, forge ]

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}

- name: Setup Java and Maven
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: mvn -B package --file pom.xml
name: Build ${{ matrix.target }}
runs-on: ubuntu-latest
if: "!startsWith(github.event.commits[0].message, '[ci-skip]')"

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
cache: gradle
cache-dependency-path: |
**/*.gradle*
**/gradle-wrapper.properties
- name: Build with Gradle
run: "./gradlew :${{matrix.target}}:build"

- name: Upload builds
uses: actions/upload-artifact@v4
with:
name: "cssminecraft-${{matrix.target}}.jar"
path: |
${{matrix.target}}/build/libs/cssminecraft-${{matrix.target}}-*.jar
!**/*-no-map.jar
if-no-files-found: error
42 changes: 0 additions & 42 deletions .github/workflows/pullrequest.yml

This file was deleted.

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
target/
*.iml
.idea
.gradle
**/build/
!src/**/build/
gradle-app.setting
!gradle-wrapper.jar
!gradle-wrapper.properties
.gradletasknamecache
104 changes: 87 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,110 @@
## CSS-Minecraft
This is the source code for CSS' Minecraft plugin.
# CSS Minecraft
This is the source code for CSS' Minecraft plugin/mod.

## Building

Ensure that you have maven installed.
Then:
To compile, run the `build` Gradle task.

```
maven clean package
./gradlew build
```

This will automatically execute the shadow-jar goal in the package cycle.

There will now be a .jar file located in /target

You can now put this .jar file in the /plugins folder in a Spigot/CraftBukkit 1.17.1 server and run the server.
Jars will be output to `**/build/libs/cssminecraft-*.jar`.

## Configuration

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

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

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

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

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

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

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

# A link to an avatar service, with %s as a placeholder of the user's minecraft username.
# This is used as the profile picture URL in webhook messages.
# We'd recommend the following value: https://cravatar.eu/helmhead/%s/190.png
avatar-service: ""

# The verbosity of logging (0 = error only, 1 = +warnings, 2 = +info, 3 = +debug)
logging-level: 2
```
## Dependencies
This plugin depends on [LuckPerms](https://www.spigotmc.org/resources/luckperms.28140/), which needs to be placed alongside this in the /plugins folder.
This plugin optionally depends on [LuckPerms](https://luckperms.net/) to grant the member role.
Without it, only the Discord message bridge will be functional.
## Development
PR's welcome, feel free to do whatever.
The project is written mostly in an abstract fashion to help re-use code across
different platforms.
Each Gradle subproject has the following purpose:
* `/common`: platform-independent interfaces and implementations which houses most logic - the
following subprojects depend on this
* `/bukkit`: specific implementation for Bukkit / Spigot / Paper etc.
* `/fabric`: specific implementation for Fabric servers
* `/forge`: specific implementation for Forge servers

Note that this is a server only mod, and will not work on clients.

## Version matrix

The following table documents mod compatibility for older versions of Minecraft and their platforms.
Any versions prior to 1.12.1 are backports.

If a Minecraft version is not listed here, then no version of the mod exists for it.

All version branches will follow the name `minecraft/<version>`.

| Minecraft | Java | Bukkit | Forge | Fabric | Links |
|-----------|------|--------|-------|--------|-------------------------------------------------------------------------|
| 1.21.1 | 21 | ✅ | ✅ | ✅ | (master) |
| 1.18.2 | 17 | ❌ | ❌ | ✅ | [Branch](https://github.com/CSSUoB/CSS-Minecraft/tree/minecraft/1.18.2) |
| 1.12.2 | 8 | ❌ | ✅ | ❌ | [Branch](https://github.com/CSSUoB/CSS-Minecraft/tree/minecraft/1.12.2) |

**Never merge `minecraft/*` branches into master.** Build features/fixes in master and cherry-pick backwards.

### Upgrading to future versions

The `master` branch should always target the latest version.
Before upgrading, create a new release branch for the current version using the naming
scheme `minecraft/<version>`.

Then, make the necessary changes to upgrade Minecraft version. Bukkit / Spigot / Paper
has a stable enough API where not many changes will be needed (if any at all), but
other platforms will likely break.

Once changes are done, update the version matrix and open a new PR to `master`.

### Backporting to older versions

This mod was originally made for Minecraft 1.21, thus
it will require backporting to work on older modpacks.

Create a branch from the nearest Minecraft version and name it `minecraft/<version>`.
You may be required to change the Java version, or upgrade/downgrade Gradle.
It should be noted that Fabric does not exist prior to Minecraft 1.14.

Once finished, push the branch to GitHub and update this version matrix with the platform
and version you have backported.

29 changes: 29 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id "java"
id "com.gradleup.shadow" version "8.3.0"
}

subprojects {
apply plugin: "java"
apply plugin: "com.gradleup.shadow"

group = "com.cssbham"
version = "1.0.0"

sourceCompatibility = 21
targetCompatibility = 21

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}

tasks.withType(Javadoc) {
options.encoding = "UTF-8"
}

repositories {
mavenCentral()
}

assemble.dependsOn shadowJar
}
31 changes: 31 additions & 0 deletions bukkit/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
plugins {
id "java"
}

processResources {
duplicatesStrategy = duplicatesStrategy.INCLUDE
from(sourceSets.main.resources.srcDirs) {
include "plugin.yml"
expand("version": project.version)
}
}

repositories {
maven { url = "https://repo.papermc.io/repository/maven-public/" }
}

dependencies {
compileOnly "io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT"

implementation project(path: ":common", configuration: "shadow")
}

shadowJar {
dependencies {
include(project(":common"))
}

archiveFileName = "cssminecraft-bukkit-${project.version}.jar"

minimize()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.cssbham.cssminecraft.bukkit;

import com.cssbham.cssminecraft.bukkit.adapter.BukkitServerChatAdapter;
import com.cssbham.cssminecraft.bukkit.command.BukkitCommandService;
import com.cssbham.cssminecraft.bukkit.executor.BukkitServerExecutor;
import com.cssbham.cssminecraft.bukkit.listener.BukkitEventListener;
import com.cssbham.cssminecraft.bukkit.logger.BukkitLogger;
import com.cssbham.cssminecraft.common.AbstractCSSMinecraftPlugin;
import com.cssbham.cssminecraft.common.adapter.ServerChatAdapter;
import com.cssbham.cssminecraft.common.command.CommandService;
import com.cssbham.cssminecraft.common.executor.ServerExecutor;
import com.cssbham.cssminecraft.common.logger.Logger;
import org.bukkit.plugin.java.JavaPlugin;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
* Implementation of CSS Minecraft Plugin for Bukkit
*/
public class BukkitCSSMinecraftPlugin extends AbstractCSSMinecraftPlugin {

private final JavaPlugin plugin;
private final BukkitLogger logger;
private final BukkitServerChatAdapter serverChatAdapter;
private final BukkitServerExecutor executor;
private final BukkitCommandService commandService;

public BukkitCSSMinecraftPlugin(JavaPlugin plugin) {
this.plugin = plugin;
this.logger = new BukkitLogger(plugin);
this.serverChatAdapter = new BukkitServerChatAdapter();
this.executor = new BukkitServerExecutor(logger, plugin);
this.commandService = new BukkitCommandService(logger, executor, serverChatAdapter);
}

@Override
public void enable() {
super.enable();

BukkitEventListener eventListener = new BukkitEventListener(plugin, executor);
eventListener.bindPlatformToEventBus(super.getEventBus());

plugin.getCommand("makegreen").setExecutor(commandService);
}

@Override
public Logger getLogger() {
return logger;
}

@Override
public ServerChatAdapter provideServerChatAdapter() {
return serverChatAdapter;
}

@Override
public Path provideConfigurationPath() {
return Paths.get(plugin.getDataFolder().getPath(), "config.yml");
}

@Override
public ServerExecutor provideServerExecutor() {
return executor;
}

@Override
public CommandService provideCommandService() {
return commandService;
}
}
Loading

0 comments on commit ac6e262

Please sign in to comment.