Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull upstream, fix Geyser extension #1

Merged
merged 7 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/geyser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
java-version: '21'

- name: Setup Gradle
uses: gradle/gradle-build-action@v2
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
9 changes: 9 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@ pluginManagement {
name = 'Forge'
url = 'https://maven.minecraftforge.net/'
}
maven {
name = 'NeoForge'
url = 'https://maven.neoforged.net/releases'
}
gradlePluginPortal()
}
}

plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}

rootProject.name = 'spark'
include (
'spark-api',
Expand All @@ -23,6 +31,7 @@ include (
'spark-sponge7',
'spark-sponge8',
'spark-forge',
'spark-neoforge',
'spark-fabric',
'spark-nukkit',
'spark-waterdog',
Expand Down
18 changes: 9 additions & 9 deletions spark-fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import net.fabricmc.loom.task.RemapJarTask

plugins {
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'fabric-loom' version '1.6-SNAPSHOT'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

tasks.withType(JavaCompile) {
// override, compile targeting J17
options.release = 17
// override, compile targeting J21
options.release = 21
}

repositories {
Expand All @@ -28,9 +28,9 @@ configurations {

dependencies {
// https://modmuss50.me/fabric.html
minecraft 'com.mojang:minecraft:1.20.4'
mappings 'net.fabricmc:yarn:1.20.4+build.1:v2'
modImplementation 'net.fabricmc:fabric-loader:0.15.1'
minecraft 'com.mojang:minecraft:1.20.5'
mappings 'net.fabricmc:yarn:1.20.5+build.1:v2'
modImplementation 'net.fabricmc:fabric-loader:0.15.10'

Set<String> apiModules = [
"fabric-api-base",
Expand All @@ -40,12 +40,12 @@ dependencies {

// Add each module as a dependency
apiModules.forEach {
modImplementation(fabricApi.module(it, '0.91.2+1.20.4'))
modImplementation(fabricApi.module(it, '0.97.5+1.20.5'))
}

include(modImplementation('me.lucko:fabric-permissions-api:0.2-SNAPSHOT'))
include(modImplementation('me.lucko:fabric-permissions-api:0.3.1'))

modImplementation('eu.pb4:placeholder-api:2.0.0-beta.4+1.19')
modImplementation('eu.pb4:placeholder-api:2.4.0-pre.1+1.20.5')

shade project(':spark-common')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.rcon.RconCommandOutput;
Expand Down Expand Up @@ -64,7 +65,7 @@ public UUID getUniqueId() {

@Override
public void sendMessage(Component message) {
Text component = Text.Serialization.fromJsonTree(GsonComponentSerializer.gson().serializeToTree(message));
Text component = Text.Serialization.fromJsonTree(GsonComponentSerializer.gson().serializeToTree(message), DynamicRegistryManager.EMPTY);
super.delegate.sendMessage(component);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private JsonElement datapackMetadata() {
obj.addProperty("name", profile.getDisplayName().getString());
obj.addProperty("description", profile.getDescription().getString());
obj.addProperty("source", resourcePackSource(profile.getSource()));
datapacks.add(profile.getName(), obj);
datapacks.add(profile.getId(), obj);
}
return datapacks;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -60,7 +61,7 @@ private static PlaceholderResult toResult(Component component) {
}

private static Text toText(Component component) {
return Text.Serialization.fromJsonTree(GsonComponentSerializer.gson().serializeToTree(component));
return Text.Serialization.fromJsonTree(GsonComponentSerializer.gson().serializeToTree(component), DynamicRegistryManager.EMPTY);
}
}

Expand Down
3 changes: 2 additions & 1 deletion spark-fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"fabricloader": ">=0.4.0",
"fabric-api-base": "*",
"fabric-command-api-v2": "*",
"fabric-lifecycle-events-v1" : "*"
"fabric-lifecycle-events-v1" : "*",
"fabric-permissions-api-v0": "*"
}
}
1 change: 0 additions & 1 deletion spark-fabric/src/main/resources/spark.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"required": true,
"package": "me.lucko.spark.fabric.mixin",
"compatibilityLevel": "JAVA_17",
"client": [
"ClientEntityManagerAccessor",
"ClientWorldAccessor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ public void onPreInitialize(GeyserPreInitializeEvent event) {
this.logger().severe("spark is only supported on standalone Geyser instances! If you wish to use it on other platforms please download the spark version for that platform.");
this.disable();
}
this.platform = new SparkPlatform(this);
}

@Subscribe
public void onPostInitialize(GeyserPostInitializeEvent event) {
this.platform = new SparkPlatform(this);
this.platform.enable();
}

Expand Down
64 changes: 64 additions & 0 deletions spark-neoforge/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'net.neoforged.gradle.userdev' version '7.0.97'
}

java.toolchain.languageVersion = JavaLanguageVersion.of(17)

tasks.withType(JavaCompile) {
// override, compile targeting J17
options.release = 17
}

minecraft {
accessTransformers {
file('src/main/resources/META-INF/accesstransformer.cfg')
}
}

configurations {
shade
implementation.extendsFrom shade
}

dependencies {
implementation "net.neoforged:neoforge:20.4.223"
shade project(':spark-common')
}

processResources {
from(sourceSets.main.resources.srcDirs) {
include 'META-INF/mods.toml'
expand (
'pluginVersion': project.pluginVersion,
'pluginDescription': project.pluginDescription
)
}

from(sourceSets.main.resources.srcDirs) {
exclude 'META-INF/mods.toml'
}
}

shadowJar {
archiveFileName = "spark-${project.pluginVersion}-neoforge.jar"
configurations = [project.configurations.shade]

relocate 'net.kyori.adventure', 'me.lucko.spark.lib.adventure'
relocate 'net.kyori.examination', 'me.lucko.spark.lib.adventure.examination'
relocate 'net.bytebuddy', 'me.lucko.spark.lib.bytebuddy'
relocate 'com.google.protobuf', 'me.lucko.spark.lib.protobuf'
relocate 'org.objectweb.asm', 'me.lucko.spark.lib.asm'
relocate 'one.profiler', 'me.lucko.spark.lib.asyncprofiler'
relocate 'me.lucko.bytesocks.client', 'me.lucko.spark.lib.bytesocks'
relocate 'org.java_websocket', 'me.lucko.spark.lib.bytesocks.ws'

exclude 'module-info.class'
exclude 'META-INF/maven/**'
exclude 'META-INF/proguard/**'
}

artifacts {
archives shadowJar
shadow shadowJar
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.lucko.spark.neoforge;

import cpw.mods.modlauncher.TransformingClassLoader;
import me.lucko.spark.common.sampler.source.ClassSourceLookup;

public class NeoForgeClassSourceLookup implements ClassSourceLookup {

@Override
public String identify(Class<?> clazz) {
if (clazz.getClassLoader() instanceof TransformingClassLoader) {
String name = clazz.getModule().getName();
return name.equals("forge") || name.equals("minecraft") ? null : name;
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* This file is part of spark.
*
* Copyright (c) lucko (Luck) <[email protected]>
* Copyright (c) contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package me.lucko.spark.neoforge;

import me.lucko.spark.common.command.sender.AbstractCommandSender;
import me.lucko.spark.neoforge.plugin.NeoForgeSparkPlugin;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.commands.CommandSource;
import net.minecraft.network.chat.Component.Serializer;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.rcon.RconConsoleSource;
import net.minecraft.world.entity.player.Player;

import java.util.Objects;
import java.util.UUID;

public class NeoForgeCommandSender extends AbstractCommandSender<CommandSource> {
private final NeoForgeSparkPlugin plugin;

public NeoForgeCommandSender(CommandSource source, NeoForgeSparkPlugin plugin) {
super(source);
this.plugin = plugin;
}

@Override
public String getName() {
if (super.delegate instanceof Player) {
return ((Player) super.delegate).getGameProfile().getName();
} else if (super.delegate instanceof MinecraftServer) {
return "Console";
} else if (super.delegate instanceof RconConsoleSource) {
return "RCON Console";
} else {
return "unknown:" + super.delegate.getClass().getSimpleName();
}
}

@Override
public UUID getUniqueId() {
if (super.delegate instanceof Player) {
return ((Player) super.delegate).getUUID();
}
return null;
}

@Override
public void sendMessage(Component message) {
MutableComponent component = Serializer.fromJson(GsonComponentSerializer.gson().serializeToTree(message));
Objects.requireNonNull(component, "component");
super.delegate.sendSystemMessage(component);
}

@Override
public boolean hasPermission(String permission) {
return this.plugin.hasPermission(super.delegate, permission);
}
}
Loading
Loading